-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient.test.js
84 lines (72 loc) · 2.29 KB
/
client.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
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
const { Client } = require('./client.js');
const chalk = require('chalk');
const Bot = new Client({
username: 'PS-Client',
password: 'PASSWORD',
rooms: ['botdevelopment'],
});
jest.mock('ws', () => require('./mocks/ws.js'));
jest.spyOn(global, 'fetch').mockImplementation((...args) => require('./mocks/fetch.js')(...args));
describe('PS-Client', () => {
beforeAll(() => {
return new Promise(resolve => {
Bot.connect();
Bot.on('activate', () => resolve());
});
});
it('should have the right info', () => {
expect(Bot.status.connected).toBe(true);
expect(Bot.isTrusted).toBe(true);
});
it('should be in BotDev', () => {
expect(Bot.getRoom('Bot Development')).toBeDefined();
});
it('should be able to send chat messages', () => {
return Bot.getRoom('Bot Development').send('Test');
});
it('should detect sent chat messages', () => {
return new Promise((resolve, reject) => {
Bot.getRoom('Bot Development')
.waitFor(msg => {
return msg.author.userid === 'otheruser' && msg.content === '/me pokes PS-Client';
})
.then(resolve)
.catch(reject);
Bot.getRoom('Bot Development').send('/me pokes Other User');
});
});
it('should be able to send PMs', () => {
return Bot.getUser('Other User').send('Test');
});
it('should detect sent PMs', () => {
return new Promise((resolve, reject) => {
Bot.getUser('Other User')
.waitFor(msg => msg.content === 'Hi!')
.then(resolve)
.catch(reject);
Bot.getUser('Other User').send('Hello!');
});
});
it.skip('should be able to send HTML', () => {
return new Promise((resolve, reject) => {
Bot.getRoom('Bot Development')
.waitFor(msg => msg.author.id === 'psclient' && /Test/.test(msg.content))
.then(resolve)
.catch(reject);
Bot.getRoom('Bot Development').sendHTML('<div style="font-weight: bold">Test</div>');
});
});
it.skip('should be able to send raw HTML', () => {
return new Promise((resolve, reject) => {
Bot.getRoom('Bot Development')
.waitFor(msg => msg.author.id === 'psclient' && /Test/.test(msg.content))
.then(resolve)
.catch(reject);
Bot.getRoom('Bot Development').sendRawHTML('<div style="font-weight: bold">Test</div>');
});
});
afterAll(() => {
require('console').log(chalk.red('xx'), chalk.dim('Disconnecting...'), '\n');
Bot.disconnect();
});
});