Skip to content

Commit

Permalink
Add input capture for allure reporting
Browse files Browse the repository at this point in the history
Signed-off-by: PatStLouis <[email protected]>
  • Loading branch information
PatStLouis committed Oct 17, 2024
1 parent d1fb6e5 commit 30db0e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/TestEndpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
createRequestBody,
createVerifyRequestBody
} from './mock.data.js';
import {addJsonAttachment} from './helpers.js';
import http from 'http';
import receiveJson from './receive-json.js';

Expand All @@ -26,7 +27,10 @@ export class TestEndpoints {
async issue(credential) {
const {issuer} = this;
const issueBody = createRequestBody({issuer, vc: credential});
return post(issuer, issueBody);
await addJsonAttachment('Request', issueBody);
const response = post(issuer, issueBody);
await addJsonAttachment('Response', response);
return response;
}
// FIXME implement createVp for implementation endpoints in the future
// @see https://w3c-ccg.github.io/vc-api/#create-presentation
Expand All @@ -35,10 +39,12 @@ export class TestEndpoints {
}
async verify(vc) {
const verifyBody = createVerifyRequestBody({vc});
await addJsonAttachment('Request', verifyBody);
const result = await post(this.verifier, verifyBody);
if(result?.errors?.length) {
throw result.errors[0];
}
await addJsonAttachment('Response', result);
return result;
}
async verifyVp(vp, options = {}) {
Expand Down
17 changes: 17 additions & 0 deletions tests/helpers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import * as allure from 'allure-js-commons';
import {ContentType} from 'allure-js-commons';

export function setupMatrix(match) {
// this will tell the report
// to make an interop matrix with this suite
Expand Down Expand Up @@ -36,3 +39,17 @@ export function extractIfEnveloped(input) {
return input;
}
}

export async function addJsonAttachment(fileName, content) {
try {
// Temporarily disable the console log to avoid unnecessary info logs.
const consoleLog = console.log;
console.log = function() {};
await allure.attachment(
fileName,
JSON.stringify(content, null, 2),
ContentType.JSON
);
console.log = consoleLog;
} catch(err) {}
}

0 comments on commit 30db0e4

Please sign in to comment.