forked from memochou1993/gpt-ai-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeactivate.test.js
48 lines (45 loc) · 1.27 KB
/
deactivate.test.js
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
import {
afterEach, beforeEach, expect, test,
} from '@jest/globals';
import { getPrompt, handleEvents, removePrompt } from '../app/index.js';
import { COMMAND_BOT_ACTIVATE, COMMAND_BOT_DEACTIVATE } from '../app/commands/index.js';
import { t } from '../locales/index.js';
import storage from '../storage/index.js';
import {
createEvents, MOCK_TEXT_OK, MOCK_USER_01, TIMEOUT,
} from './utils.js';
beforeEach(() => {
//
});
afterEach(() => {
removePrompt(MOCK_USER_01);
});
test('COMMAND_BOT_DEACTIVATE', async () => {
const events = [
...createEvents([COMMAND_BOT_ACTIVATE.text]),
...createEvents(['嗨!']),
...createEvents([COMMAND_BOT_DEACTIVATE.text]),
...createEvents(['嗨!']), // should be ignored
];
let results;
try {
results = await handleEvents(events);
} catch (err) {
console.error(err);
}
expect(getPrompt(MOCK_USER_01).sentences.length).toEqual(3);
const replies = results.map(({ messages }) => messages.map(({ text }) => text));
expect(replies).toEqual(
[
[
t('__ERROR_MISSING_ENV')('VERCEL_ACCESS_TOKEN'),
COMMAND_BOT_ACTIVATE.reply,
],
[MOCK_TEXT_OK],
[
t('__ERROR_MISSING_ENV')('VERCEL_ACCESS_TOKEN'),
COMMAND_BOT_DEACTIVATE.reply,
],
],
);
}, TIMEOUT);