|
| 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