forked from openwallet-foundation/credo-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathagents.test.ts
80 lines (65 loc) · 2.53 KB
/
agents.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
import { Subject } from 'rxjs'
import { Agent } from '..'
import {
toBeConnectedWith,
SubjectInboundTransporter,
SubjectOutboundTransporter,
waitForBasicMessage,
} from './helpers'
import { InitConfig } from '../types'
import indy from 'indy-sdk'
import { ConnectionRecord } from '../modules/connections'
import testLogger from './logger'
expect.extend({ toBeConnectedWith })
const aliceConfig: InitConfig = {
label: 'Alice',
walletConfig: { id: 'alice' },
walletCredentials: { key: '00000000000000000000000000000Test01' },
autoAcceptConnections: true,
logger: testLogger,
indy,
}
const bobConfig: InitConfig = {
label: 'Bob',
walletConfig: { id: 'bob' },
walletCredentials: { key: '00000000000000000000000000000Test02' },
autoAcceptConnections: true,
logger: testLogger,
indy,
}
describe('agents', () => {
let aliceAgent: Agent
let bobAgent: Agent
let aliceConnection: ConnectionRecord
let bobConnection: ConnectionRecord
afterAll(async () => {
await aliceAgent.closeAndDeleteWallet()
await bobAgent.closeAndDeleteWallet()
})
test('make a connection between agents', async () => {
const aliceMessages = new Subject()
const bobMessages = new Subject()
const aliceAgentInbound = new SubjectInboundTransporter(aliceMessages)
const aliceAgentOutbound = new SubjectOutboundTransporter(bobMessages)
const bobAgentInbound = new SubjectInboundTransporter(bobMessages)
const bobAgentOutbound = new SubjectOutboundTransporter(aliceMessages)
aliceAgent = new Agent(aliceConfig, aliceAgentInbound, aliceAgentOutbound)
await aliceAgent.init()
bobAgent = new Agent(bobConfig, bobAgentInbound, bobAgentOutbound)
await bobAgent.init()
const aliceConnectionAtAliceBob = await aliceAgent.connections.createConnection()
const bobConnectionAtBobAlice = await bobAgent.connections.receiveInvitation(aliceConnectionAtAliceBob.invitation)
aliceConnection = await aliceAgent.connections.returnWhenIsConnected(aliceConnectionAtAliceBob.connectionRecord.id)
bobConnection = await bobAgent.connections.returnWhenIsConnected(bobConnectionAtBobAlice.id)
expect(aliceConnection).toBeConnectedWith(bobConnection)
expect(bobConnection).toBeConnectedWith(aliceConnection)
})
test('send a message to connection', async () => {
const message = 'hello, world'
await aliceAgent.basicMessages.sendMessage(aliceConnection, message)
const basicMessage = await waitForBasicMessage(bobAgent, {
content: message,
})
expect(basicMessage.content).toBe(message)
})
})