-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest.js
More file actions
37 lines (30 loc) · 820 Bytes
/
test.js
File metadata and controls
37 lines (30 loc) · 820 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 Emitter = require('events')
const ram = require('random-access-memory')
const crypto = require('hypercore-crypto')
const Saga = require('.')
class MockedPeer extends Emitter {
constructor (data) {
super()
this.remoteUserData = JSON.stringify(data)
}
}
describe('problem 09', () => {
const saga = new Saga(ram, null, 'peti')
const keyPair = crypto.keyPair()
const peerKey = keyPair.publicKey
const peer = new MockedPeer({
username: 'test',
key: peerKey,
timestamp: Date.now()
})
beforeAll(() => saga.initialize())
test('call connect and authorize a new peer', async (done) => {
expect.assertions(2)
await saga.connect(peer)
saga.db.authorized(peerKey, (err, auth) => {
expect(err).toBeNull()
expect(auth).toBeTruthy()
done()
})
})
})