-
Notifications
You must be signed in to change notification settings - Fork 0
/
smoke.ts
115 lines (87 loc) · 2.28 KB
/
smoke.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// run with:
//
// env $(cat .env) yarn smoke
import {
subscribe,
findAll,
findOne,
Message,
connect,
upsertTopic,
deleteTopic,
listTopics,
describe
} from "./src";
import * as credentials from "./test/support/credentials";
import { OpportunitySObject, OpportunityModel } from "./test/support/types";
import { OpportunityMapper, OpportunityFields } from "./test/support/mapping";
async function povo(): Promise<void> {
const conn = await connect(credentials);
const meta = await describe(conn, "Opportunity");
console.log("describe:", meta.name);
const messages: Message[] = [];
const subscription = {
topic: "OpportunityUpdates",
replayId: null
};
const onReceiveMessage = async (message: Message): Promise<void> => {
messages.push(message);
};
await subscribe(conn, subscription, 10000, onReceiveMessage);
console.log("subscribe:", messages);
const message = messages[0];
if (message) {
const model = await findOne<OpportunitySObject, OpportunityModel>(
conn,
"Opportunity",
message.sobject.Id,
OpportunityMapper,
OpportunityFields
);
console.log("findOne: ", model);
}
const where = "iswon = true";
const query = {
where,
limit: 1,
fields: OpportunityFields
};
const models = await findAll<OpportunitySObject, OpportunityModel>(
conn,
"Opportunity",
60000,
OpportunityMapper,
query
);
console.log("findAll: ", models);
const topics = await listTopics(conn);
console.log(
"listTopics: ",
topics.map(topic => topic.Name)
);
const topic = await upsertTopic(conn, "Opportunity", "OpportunityUpdates", {
where
});
console.log("upsertTopic: ", topic.Name);
await upsertTopic(conn, "Opportunity", "ToDeleteTopic");
await deleteTopic(conn, "ToDeleteTopic");
const toDeleteTopics = await listTopics(conn);
const shouldBeDeletedTopic = toDeleteTopics.find(
topic => topic.Name === "ToDeleteTopic"
);
if (shouldBeDeletedTopic) {
throw new Error("Should have deleted topic");
}
console.log("deleteTopic: ", true);
}
const main = async function(): Promise<void> {
try {
await povo();
console.log("Success");
process.exit(0);
} catch (e) {
console.error(e.message);
process.exit(1);
}
};
main();