-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTS_Gm.test.ts
88 lines (75 loc) · 2.44 KB
/
TS_Gm.test.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
import { closeEnv, loadEnv } from "@helpers/client";
import { sendTestResults } from "@helpers/datadog";
import { logError } from "@helpers/tests";
import {
IdentifierKind,
type Conversation,
type NestedPersonas,
} from "@helpers/types";
import { getWorkers } from "@helpers/workers/factory";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { testGmBot } from "../playwright/gm-bot.playwright";
const testName = "ts_gm";
loadEnv(testName);
const gmBotAddress = process.env.GM_BOT_ADDRESS as string;
console.log(`[${testName}] GM Bot Address: ${gmBotAddress}`);
describe(testName, () => {
let convo: Conversation;
let personas: NestedPersonas;
let hasFailures: boolean = false;
beforeAll(async () => {
try {
personas = await getWorkers(["bob"], testName);
expect(personas).toBeDefined();
expect(personas.getPersonas().length).toBe(1);
} catch (e) {
hasFailures = logError(e, expect);
throw e;
}
});
afterAll(async () => {
try {
sendTestResults(hasFailures ? "failure" : "success", testName);
await closeEnv(testName, personas);
} catch (e) {
hasFailures = logError(e, expect);
throw e;
}
});
it("gm-bot: should check if bot is alive", async () => {
try {
// Create conversation with the bot
convo = await personas
.get("bob")!
.client.conversations.newDmByIdentifier({
identifierKind: IdentifierKind.Ethereum,
identifier: gmBotAddress,
});
await convo.sync();
const prevMessages = (await convo.messages()).length;
// Send a simple message
await convo.send("gm");
// Wait briefly for response
await new Promise((resolve) => setTimeout(resolve, 3000));
const messages = await convo.messages();
const messagesAfter = messages.length;
// We should have at least 2 messages (our message and bot's response)
expect(messagesAfter).toBe(prevMessages + 2);
console.log("Messages before:", prevMessages, "after:", messagesAfter);
} catch (e) {
hasFailures = logError(e, expect);
throw e;
}
});
it("should respond to a message", async () => {
try {
console.time("respond-to-message-test");
const result = await testGmBot(gmBotAddress);
expect(result).toBe(true);
console.timeEnd("respond-to-message-test");
} catch (e) {
hasFailures = logError(e, expect);
throw e;
}
});
});