Skip to content

Commit 84fe014

Browse files
committed
Bring over implementations.spec.js tests.
From VC WG version of this same repo: https://github.com/w3c/vc-test-suite-implementations
1 parent 35f5b83 commit 84fe014

File tree

4 files changed

+72
-13
lines changed

4 files changed

+72
-13
lines changed

lib/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import {Implementation} from './Implementation.js';
88
import {implementerFiles} from '../implementations/index.js';
99

10+
export const rawImplementations = implementerFiles;
11+
1012
const keyValues = implementerFiles.map(
1113
implementation => [implementation.name, new Implementation(implementation)]);
1214

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
},
4141
"devDependencies": {
4242
"chai": "^4.3.3",
43+
"chai-datetime": "^1.8.1",
4344
"cross-env": "^7.0.3",
4445
"eslint": "^8.55.0",
4546
"eslint-config-digitalbazaar": "^5.0.1",

test/Example.spec.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/implementations.spec.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2022-2024 Digital Bazaar, Inc.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
import chai from 'chai';
8+
import chaiDateTime from 'chai-datetime';
9+
const should = chai.should();
10+
chai.use(chaiDateTime);
11+
12+
import {allImplementations, rawImplementations} from '../lib/main.js';
13+
14+
describe('Loading implementations', () => {
15+
it('should result in no errors.', async () => {
16+
should.exist(allImplementations);
17+
});
18+
19+
describe('Implementations using DID:key identifiers', () => {
20+
allImplementations.forEach(implementation => {
21+
const {issuers, verifiers} = implementation;
22+
23+
const isDidKeyFilter = ({settings: {id}}) =>
24+
id && id.startsWith('did:key');
25+
26+
describe(implementation.settings.name, () => {
27+
issuers?.filter(isDidKeyFilter)
28+
.map(({settings: {id}}, index) => {
29+
describe(`issuer[${index}].id`, () => {
30+
it('should not specify a fragment', () => {
31+
chai.expect(id).not.match(/#/);
32+
});
33+
});
34+
});
35+
36+
verifiers?.filter(isDidKeyFilter)
37+
.map(({settings: {id}}, index) => {
38+
describe(`verifier[${index}].id`, () => {
39+
it('should not specify a fragment', () => {
40+
chai.expect(id).not.match(/#/);
41+
});
42+
});
43+
});
44+
});
45+
});
46+
});
47+
48+
describe('Implementations using ZCAPs', () => {
49+
rawImplementations.forEach(implementation => {
50+
Object.keys(implementation)
51+
.filter(key => Array.isArray(implementation[key]))
52+
.forEach(implementationType => {
53+
describe(`${implementation.name} - ${implementationType}`, () => {
54+
implementation[implementationType]
55+
?.filter(({zcap}) => zcap?.capability)
56+
.forEach(issuer => {
57+
it(`ZCAP should not be expired for ${issuer.id}`, () => {
58+
const expiration = JSON.parse(issuer.zcap.capability).expires;
59+
const today = new Date();
60+
const nextMonth = new Date(
61+
today.getFullYear(), today.getMonth() + 1, today.getDate());
62+
chai.expect(new Date(expiration)).to.be.afterDate(nextMonth);
63+
});
64+
});
65+
});
66+
});
67+
});
68+
});
69+
});

0 commit comments

Comments
 (0)