From e98a73410c471d6782d1d4046cec820fdcdcc012 Mon Sep 17 00:00:00 2001 From: Ariel Gentile Date: Wed, 5 Apr 2023 11:06:11 -0300 Subject: [PATCH] fix(client): AnonCredsRegistry constructor (#2) Signed-off-by: Ariel Gentile --- src/anoncreds/DidWebAnonCredsRegistry.ts | 8 ++------ test/schema.test.ts | 5 +++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/anoncreds/DidWebAnonCredsRegistry.ts b/src/anoncreds/DidWebAnonCredsRegistry.ts index a83c075..def6ee8 100644 --- a/src/anoncreds/DidWebAnonCredsRegistry.ts +++ b/src/anoncreds/DidWebAnonCredsRegistry.ts @@ -23,11 +23,6 @@ export class DidWebAnonCredsRegistry implements AnonCredsRegistry { public readonly methodName = 'web' public readonly supportedIdentifier = /^did:web:[_a-z0-9.%A-]*/ - private didsApi: DidsApi - - public constructor(didsApi: DidsApi) { - this.didsApi = didsApi - } public async getSchema(agentContext: AgentContext, schemaId: string): Promise { try { @@ -230,7 +225,8 @@ export class DidWebAnonCredsRegistry implements AnonCredsRegistry { throw new Error('DidWebAnonCredsRegistry only supports did:web identifiers') } - const didDocument = await this.didsApi.resolveDidDocument(parsedDid.did) + const didsApi = agentContext.dependencyManager.resolve(DidsApi) + const didDocument = await didsApi.resolveDidDocument(parsedDid.did) const parsedUrl = parseUrl(didUrl) const queriedService = parsedUrl.query['service'] diff --git a/test/schema.test.ts b/test/schema.test.ts index 79a0543..491d0b7 100644 --- a/test/schema.test.ts +++ b/test/schema.test.ts @@ -17,11 +17,13 @@ import fetch, { Response } from 'node-fetch' jest.mock('@aries-framework/core/build/modules/dids/DidsApi') const DidsApiMock = DidsApi as jest.Mock +const didsApiMock = new DidsApiMock() function getAgentContext() { const dependencyManager = new DependencyManager() dependencyManager.registerInstance(AgentConfig, new AgentConfig({ label: 'mock' }, agentDependencies)) + dependencyManager.registerInstance(DidsApi, didsApiMock) const agentContext = new AgentContext({ dependencyManager, contextCorrelationId: 'mock' }) agentContext.config @@ -33,10 +35,9 @@ describe('Schema', () => { //@ts-ignore fetch.mockReturnValueOnce(Promise.resolve(new Response(JSON.stringify(didDocument1)))) - const didsApiMock = new DidsApiMock() jest.spyOn(didsApiMock, 'resolveDidDocument').mockResolvedValue(JsonTransformer.fromJSON(didDocument1, DidDocument)) - const registry = new DidWebAnonCredsRegistry(didsApiMock) + const registry = new DidWebAnonCredsRegistry() const schemaResponse = await registry.getSchema( getAgentContext(),