From d7fd2d2b03bf7fea499dda654df464b1c0467b0b Mon Sep 17 00:00:00 2001 From: Jakub Koci Date: Thu, 12 May 2022 21:43:23 +0200 Subject: [PATCH] Align postresql tests with agents tests Signed-off-by: Jakub Koci --- packages/core/tests/postgres.test.ts | 35 ++++++++++++---------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/packages/core/tests/postgres.test.ts b/packages/core/tests/postgres.test.ts index a7c5796f73..3a92c8ef46 100644 --- a/packages/core/tests/postgres.test.ts +++ b/packages/core/tests/postgres.test.ts @@ -9,6 +9,7 @@ import { SubjectInboundTransport } from '../../../tests/transport/SubjectInbound import { SubjectOutboundTransport } from '../../../tests/transport/SubjectOutboundTransport' import { loadPostgresPlugin, WalletScheme } from '../../node/src' import { Agent } from '../src/agent/Agent' +import { HandshakeProtocol } from '../src/modules/connections' import { waitForBasicMessage, getBasePostgresConfig } from './helpers' @@ -22,7 +23,8 @@ const bobPostgresConfig = getBasePostgresConfig('AgentsBob', { describe('postgres agents', () => { let aliceAgent: Agent let bobAgent: Agent - let aliceConnectionAtAliceBob: ConnectionRecord + let aliceConnection: ConnectionRecord + let bobConnection: ConnectionRecord afterAll(async () => { await bobAgent.shutdown() @@ -67,32 +69,25 @@ describe('postgres agents', () => { bobAgent.registerOutboundTransport(new SubjectOutboundTransport(subjectMap)) await bobAgent.initialize() - const aliceOutOfBandRecord = await aliceAgent.oob.createInvitation() - - const invitation = aliceOutOfBandRecord.outOfBandInvitation - const invitationUrl = invitation.toUrl({ domain: 'https://example.com' }) - - // Receive invitation first time with alice agent - let { connectionRecord: bobConnectionAtBobAlice } = await bobAgent.oob.receiveInvitationFromUrl(invitationUrl) - bobConnectionAtBobAlice = await aliceAgent.connections.returnWhenIsConnected(bobConnectionAtBobAlice!.id) - - let aliceConnectionAtAliceBob = await aliceAgent.connections.getByThreadId(bobConnectionAtBobAlice.threadId!) - aliceConnectionAtAliceBob = await aliceAgent.connections.returnWhenIsConnected(aliceConnectionAtAliceBob.id) - // =========================================================================== + const aliceBobOutOfBandRecord = await aliceAgent.oob.createInvitation({ + handshakeProtocols: [HandshakeProtocol.Connections], + }) - // const aliceConnectionAtAliceBob = await aliceAgent.connections.createConnection() - // const bobConnectionAtBobAlice = await bobAgent.connections.receiveInvitation(aliceConnectionAtAliceBob.invitation) + const { connectionRecord: bobConnectionAtBobAlice } = await bobAgent.oob.receiveInvitation( + aliceBobOutOfBandRecord.outOfBandInvitation + ) + bobConnection = await bobAgent.connections.returnWhenIsConnected(bobConnectionAtBobAlice!.id) - // aliceConnection = await aliceAgent.connections.returnWhenIsConnected(aliceConnectionAtAliceBob.connectionRecord.id) - // bobConnection = await bobAgent.connections.returnWhenIsConnected(bobConnectionAtBobAlice.id) + const [aliceConnectionAtAliceBob] = await aliceAgent.connections.findAllByOutOfBandId(aliceBobOutOfBandRecord.id) + aliceConnection = await aliceAgent.connections.returnWhenIsConnected(aliceConnectionAtAliceBob!.id) - expect(aliceConnectionAtAliceBob).toBeConnectedWith(bobConnectionAtBobAlice) - expect(bobConnectionAtBobAlice).toBeConnectedWith(aliceConnectionAtAliceBob) + expect(aliceConnection).toBeConnectedWith(bobConnection) + expect(bobConnection).toBeConnectedWith(aliceConnection) }) test('send a message to connection', async () => { const message = 'hello, world' - await aliceAgent.basicMessages.sendMessage(aliceConnectionAtAliceBob.id, message) + await aliceAgent.basicMessages.sendMessage(aliceConnection.id, message) const basicMessage = await waitForBasicMessage(bobAgent, { content: message,