diff --git a/lib/main.js b/lib/main.js index e7338de..7cbdd78 100644 --- a/lib/main.js +++ b/lib/main.js @@ -7,6 +7,8 @@ import {Implementation} from './Implementation.js'; import {implementerFiles} from '../implementations/index.js'; +export const rawImplementations = implementerFiles; + const keyValues = implementerFiles.map( implementation => [implementation.name, new Implementation(implementation)]); diff --git a/package.json b/package.json index 11195e0..c58298b 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ }, "devDependencies": { "chai": "^4.3.3", + "chai-datetime": "^1.8.1", "cross-env": "^7.0.3", "eslint": "^8.55.0", "eslint-config-digitalbazaar": "^5.0.1", diff --git a/test/Example.spec.js b/test/Example.spec.js deleted file mode 100644 index 0a590a2..0000000 --- a/test/Example.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -/*! - * Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved. - */ -import chai from 'chai'; -const should = chai.should(); - -import {allImplementations} from '../lib/main.js'; - -describe('implementations', () => { - it('should exist', async () => { - should.exist(allImplementations); - }); -}); diff --git a/test/implementations.spec.js b/test/implementations.spec.js new file mode 100644 index 0000000..f6170af --- /dev/null +++ b/test/implementations.spec.js @@ -0,0 +1,69 @@ +/* + * Copyright 2022-2024 Digital Bazaar, Inc. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +import chai from 'chai'; +import chaiDateTime from 'chai-datetime'; +const should = chai.should(); +chai.use(chaiDateTime); + +import {allImplementations, rawImplementations} from '../lib/main.js'; + +describe('Loading implementations', () => { + it('should result in no errors.', async () => { + should.exist(allImplementations); + }); + + describe('Implementations using DID:key identifiers', () => { + allImplementations.forEach(implementation => { + const {issuers, verifiers} = implementation; + + const isDidKeyFilter = ({settings: {id}}) => + id && id.startsWith('did:key'); + + describe(implementation.settings.name, () => { + issuers?.filter(isDidKeyFilter) + .map(({settings: {id}}, index) => { + describe(`issuer[${index}].id`, () => { + it('should not specify a fragment', () => { + chai.expect(id).not.match(/#/); + }); + }); + }); + + verifiers?.filter(isDidKeyFilter) + .map(({settings: {id}}, index) => { + describe(`verifier[${index}].id`, () => { + it('should not specify a fragment', () => { + chai.expect(id).not.match(/#/); + }); + }); + }); + }); + }); + }); + + describe('Implementations using ZCAPs', () => { + rawImplementations.forEach(implementation => { + Object.keys(implementation) + .filter(key => Array.isArray(implementation[key])) + .forEach(implementationType => { + describe(`${implementation.name} - ${implementationType}`, () => { + implementation[implementationType] + ?.filter(({zcap}) => zcap?.capability) + .forEach(issuer => { + it(`ZCAP should not be expired for ${issuer.id}`, () => { + const expiration = JSON.parse(issuer.zcap.capability).expires; + const today = new Date(); + const nextMonth = new Date( + today.getFullYear(), today.getMonth() + 1, today.getDate()); + chai.expect(new Date(expiration)).to.be.afterDate(nextMonth); + }); + }); + }); + }); + }); + }); +});