-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
37 lines (30 loc) · 816 Bytes
/
test.js
File metadata and controls
37 lines (30 loc) · 816 Bytes
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
const Saga = require('./');
jest.mock('hyperdb', () => {
return () => ({
ready: jest.fn((resolver) => resolver()),
authorized: jest.fn((key, cb) => cb(null, true)),
authorize: jest.fn(() => Promise.resolve()),
createHistoryStream: jest.fn(),
watch: jest.fn(() => ({ on: jest.fn() }))
});
});
jest.mock('pump', (str1, str2, lastFn) => {
return jest.fn()
});
const validPeer = {
remoteUserData: JSON.stringify({
username: 'test',
key: 'k3y'
}),
on: jest.fn()
};
test('connect and close', async () => {
expect.assertions(2);
const saga = Saga('/tmp', null, 'test');
expect(saga).toBeDefined();
await saga.initialize();
saga.on('join', data => {
expect(data.username).toEqual(JSON.parse(validPeer.remoteUserData).username);
})
saga.connect(validPeer);
})