import type { ConnectionRecord } from '../../connections' import type { DiscoverFeaturesDisclosureReceivedEvent, DiscoverFeaturesQueryReceivedEvent, } from '../DiscoverFeaturesEvents' import { ReplaySubject } from 'rxjs' import { getIndySdkModules } from '../../../../../indy-sdk/tests/setupIndySdkModule' import { setupSubjectTransports } from '../../../../tests' import { getAgentOptions, makeConnection } from '../../../../tests/helpers' import { Agent } from '../../../agent/Agent' import { DiscoverFeaturesEventTypes } from '../DiscoverFeaturesEvents' import { waitForDisclosureSubject, waitForQuerySubject } from './helpers' const faberAgentOptions = getAgentOptions( 'Faber Discover Features V1 E2E', { endpoints: ['rxjs:faber'], }, getIndySdkModules() ) const aliceAgentOptions = getAgentOptions( 'Alice Discover Features V1 E2E', { endpoints: ['rxjs:alice'], }, getIndySdkModules() ) describe('v1 discover features', () => { let faberAgent: Agent let aliceAgent: Agent let faberConnection: ConnectionRecord beforeAll(async () => { faberAgent = new Agent(faberAgentOptions) aliceAgent = new Agent(aliceAgentOptions) setupSubjectTransports([faberAgent, aliceAgent]) await faberAgent.initialize() await aliceAgent.initialize() ;[faberConnection] = await makeConnection(faberAgent, aliceAgent) }) afterAll(async () => { await faberAgent.shutdown() await faberAgent.wallet.delete() await aliceAgent.shutdown() await aliceAgent.wallet.delete() }) test('Faber asks Alice for revocation notification protocol support', async () => { const faberReplay = new ReplaySubject() const aliceReplay = new ReplaySubject() faberAgent.events .observable(DiscoverFeaturesEventTypes.DisclosureReceived) .subscribe(faberReplay) aliceAgent.events .observable(DiscoverFeaturesEventTypes.QueryReceived) .subscribe(aliceReplay) await faberAgent.discovery.queryFeatures({ connectionId: faberConnection.id, protocolVersion: 'v1', queries: [{ featureType: 'protocol', match: 'https://didcomm.org/revocation_notification/*' }], }) const query = await waitForQuerySubject(aliceReplay, { timeoutMs: 10000 }) expect(query).toMatchObject({ protocolVersion: 'v1', queries: [{ featureType: 'protocol', match: 'https://didcomm.org/revocation_notification/*' }], }) const disclosure = await waitForDisclosureSubject(faberReplay, { timeoutMs: 10000 }) expect(disclosure).toMatchObject({ protocolVersion: 'v1', disclosures: [ { type: 'protocol', id: 'https://didcomm.org/revocation_notification/1.0', roles: ['holder'] }, { type: 'protocol', id: 'https://didcomm.org/revocation_notification/2.0', roles: ['holder'] }, ], }) }) test('Faber asks Alice for revocation notification protocol support synchronously', async () => { const matchingFeatures = await faberAgent.discovery.queryFeatures({ connectionId: faberConnection.id, protocolVersion: 'v1', queries: [{ featureType: 'protocol', match: 'https://didcomm.org/revocation_notification/*' }], awaitDisclosures: true, }) expect(matchingFeatures).toMatchObject({ features: [ { type: 'protocol', id: 'https://didcomm.org/revocation_notification/1.0', roles: ['holder'] }, { type: 'protocol', id: 'https://didcomm.org/revocation_notification/2.0', roles: ['holder'] }, ], }) }) })