Skip to content

Commit

Permalink
fix(client): AnonCredsRegistry constructor (#2)
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <[email protected]>
  • Loading branch information
genaris authored Apr 5, 2023
1 parent 6743a73 commit e98a734
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/anoncreds/DidWebAnonCredsRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetSchemaReturn> {
try {
Expand Down Expand Up @@ -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']
Expand Down
5 changes: 3 additions & 2 deletions test/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DidsApi>
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
Expand All @@ -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(),
Expand Down

0 comments on commit e98a734

Please sign in to comment.