Skip to content

Commit

Permalink
Add ability to add did:web DID docs in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Apr 15, 2024
1 parent a7861c7 commit 2ca4eb1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/mocha/mock.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {config} from '@bedrock/core';

export const mockData = {};

mockData.didWebDocuments = new Map();

// mock product IDs and reverse lookup for service products
mockData.productIdMap = new Map([
// edv service
Expand Down
20 changes: 20 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import '@bedrock/vc-status';

import {mockData} from './mocha/mock.data.js';

const {util: {BedrockError}} = bedrock;

bedrock.events.on('bedrock.init', async () => {
/* Handlers need to be added before `bedrock.start` is called. These are
no-op handlers to enable meter usage without restriction */
Expand Down Expand Up @@ -48,5 +50,23 @@ bedrock.events.on('bedrock-express.configure.routes', app => {
});
});

// mock DID web server routes
bedrock.events.on('bedrock-express.configure.routes', app => {
app.get('/did-web/:localId/did.json', (req, res) => {
const {localId} = req.params;
const didDocument = mockData.didWebDocuments.get(localId);
if(!didDocument) {
throw new BedrockError('DID document not found.', {
name: 'NotFoundError',
details: {
httpStatusCode: 404,
public: true
}
});
}
res.json(didDocument);
});
});

import '@bedrock/test';
bedrock.start();

0 comments on commit 2ca4eb1

Please sign in to comment.