-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathcredential-status.test.ts
More file actions
119 lines (107 loc) · 3.76 KB
/
credential-status.test.ts
File metadata and controls
119 lines (107 loc) · 3.76 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { createAgent, VerifiableCredential } from '@veramo/core'
import { ICredentialStatusVerifier } from '@veramo/core/src/types/ICredentialStatusVerifier.js'
import { DIDResolverPlugin } from '@veramo/did-resolver'
import { CredentialStatusPlugin } from '../credential-status'
import { DIDDocument, DIDResolutionOptions, DIDResolutionResult, Resolvable } from 'did-resolver'
import { jest } from '@jest/globals'
import { CredentialStatusReference } from '@veramo/core/src/types/vc-data-model.js'
describe('@veramo/credential-status', () => {
const referenceDoc: DIDDocument = { id: 'did:example:1234' }
const referenceCredential: VerifiableCredential & { credentialStatus: CredentialStatusReference } = {
'@context': [],
issuanceDate: new Date().toISOString(),
proof: {},
issuer: referenceDoc.id,
credentialSubject: {},
credentialStatus: {
type: 'ExoticStatusMethod2022',
id: 'some-exotic-id',
},
}
it('should check the credential status', async () => {
expect.assertions(3)
const expectedResult = { verified: true }
const checkStatus = jest.fn(async () => expectedResult)
const agent = createAgent<ICredentialStatusVerifier>({
plugins: [
new CredentialStatusPlugin({
ExoticStatusMethod2022: checkStatus,
}),
],
})
const result = await agent.checkCredentialStatus({
credential: referenceCredential,
didDocumentOverride: referenceDoc,
})
expect(result).toStrictEqual(expectedResult)
expect(checkStatus).toBeCalledTimes(1)
expect(checkStatus).toBeCalledWith(referenceCredential, referenceDoc)
})
it('should check the credential status using DID resolver to get the issuer doc', async () => {
expect.assertions(4)
const expectedResult = { verified: true }
const checkStatus = jest.fn(async () => expectedResult)
const fakeResolver: Resolvable = {
resolve: jest.fn(
async (didUrl: string, options?: DIDResolutionOptions): Promise<DIDResolutionResult> => {
return {
didDocument: { id: didUrl },
didResolutionMetadata: {},
didDocumentMetadata: {},
}
},
),
}
const agent = createAgent({
plugins: [
new CredentialStatusPlugin({
ExoticStatusMethod2022: checkStatus,
}),
new DIDResolverPlugin({ resolver: fakeResolver }),
],
})
const result = await agent.checkCredentialStatus({
credential: referenceCredential,
})
expect(result).toStrictEqual(expectedResult)
expect(checkStatus).toBeCalledTimes(1)
expect(checkStatus).toBeCalledWith(referenceCredential, referenceDoc)
expect(fakeResolver.resolve).toBeCalledTimes(1)
})
it('should not perform status check if no `credentialStatus` present', async () => {
expect.assertions(2)
const checkStatus = jest.fn()
const agent = createAgent({
plugins: [
new CredentialStatusPlugin({
// @ts-ignore
ExoticStatusMethod2022: checkStatus,
}),
],
})
const result = await agent.checkCredentialStatus({
credential: {},
didDocumentOverride: referenceDoc,
})
expect(result).toEqual({ verified: true })
expect(checkStatus).toBeCalledTimes(0)
})
it('should throw if unknown status check was provided', async () => {
expect.assertions(1)
const agent = createAgent({
plugins: [
new CredentialStatusPlugin({
NotCalled: jest.fn(),
}),
],
})
await expect(
agent.checkCredentialStatus({
credential: referenceCredential,
didDocumentOverride: referenceDoc,
}),
).rejects.toThrow(
`unknown_method: credentialStatus method ExoticStatusMethod2022 unknown. Validity can not be determined.`,
)
})
})