-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathis-status-list-credential.test.ts
More file actions
87 lines (76 loc) · 2.36 KB
/
is-status-list-credential.test.ts
File metadata and controls
87 lines (76 loc) · 2.36 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
import { describe, expect, it } from "vitest"
import { isStatusListCredential } from "./is-status-list-credential"
const baseCredential = {
"@context": ["https://www.w3.org/2018/credentials/v1"],
type: ["VerifiableCredential", "BitstringStatusListCredential"],
issuer: { id: "did:web:issuer.example.com" },
issuanceDate: "2025-01-01T00:00:00.000Z",
}
const validStatusListCredential = {
...baseCredential,
credentialSubject: {
id: "https://status.example.com/list/1",
type: "BitstringStatusList",
statusPurpose: "revocation",
encodedList: "H4sIAAAAAAAA...",
},
}
describe("isStatusListCredential", () => {
it("returns true for a valid status list credential", () => {
expect(isStatusListCredential(validStatusListCredential)).toBe(true)
})
it("returns false when credentialSubject has wrong type", () => {
expect(
isStatusListCredential({
...baseCredential,
credentialSubject: {
id: "https://status.example.com/list/1",
type: "SomethingElse",
statusPurpose: "revocation",
encodedList: "H4sIAAAAAAAA...",
},
}),
).toBe(false)
})
it("returns false when credentialSubject is missing encodedList", () => {
expect(
isStatusListCredential({
...baseCredential,
credentialSubject: {
id: "https://status.example.com/list/1",
type: "BitstringStatusList",
statusPurpose: "revocation",
},
}),
).toBe(false)
})
it("returns false when credentialSubject is missing statusPurpose", () => {
expect(
isStatusListCredential({
...baseCredential,
credentialSubject: {
id: "https://status.example.com/list/1",
type: "BitstringStatusList",
encodedList: "H4sIAAAAAAAA...",
},
}),
).toBe(false)
})
it("returns false for a regular credential without status list subject", () => {
expect(
isStatusListCredential({
...baseCredential,
credentialSubject: { id: "did:web:subject.example.com" },
}),
).toBe(false)
})
it("rejects null", () => {
expect(isStatusListCredential(null)).toBe(false)
})
it("rejects an empty object", () => {
expect(isStatusListCredential({})).toBe(false)
})
it("rejects a plain string", () => {
expect(isStatusListCredential("not a credential")).toBe(false)
})
})