Skip to content

Commit e2d12c2

Browse files
authored
SDK-3368: Feature flag problem details tests (#1166)
The end-to-end tests need to run against older supported versions of ESS, not all of which support problem details. By default, only the response status and title are checked, which are provided by default against any HTTP response. Problem details and instance are only checked if the environment variable E2E_TEST_FEATURE_PROBLEM_DETAILS is set to true.
1 parent f0b232a commit e2d12c2

1 file changed

Lines changed: 69 additions & 44 deletions

File tree

e2e/node/e2e.test.ts

Lines changed: 69 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
1919
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2020
//
21+
22+
// Assertions are made conditionally on problem details responses because not all
23+
// servers support this feature.
24+
/* eslint-disable jest/no-conditional-expect */
25+
2126
import {
2227
getAuthenticatedSession,
2328
getNodeTestingEnvironment,
@@ -313,18 +318,23 @@ describe("End-to-end verifiable credentials tests for environment", () => {
313318
},
314319
);
315320

321+
const expectedErrorShape: Record<string, string | object> = {
322+
name: "Error",
323+
message: `The VC issuing endpoint [${issuerService}] could not successfully issue a VC`,
324+
};
325+
326+
if (env?.features?.PROBLEM_DETAILS === "true") {
327+
// Check that the Error contains Problem Details
328+
expectedErrorShape.problemDetails = expect.objectContaining({
329+
status: 400,
330+
title: "Bad Request",
331+
detail: expect.stringMatching(/.+/),
332+
instance: expect.not.stringMatching(""),
333+
});
334+
}
335+
316336
await expect(vcPromise).rejects.toThrow(
317-
expect.objectContaining({
318-
name: "Error",
319-
message: `The VC issuing endpoint [${issuerService}] could not successfully issue a VC`,
320-
// Check that the Error contains Problem Details
321-
problemDetails: expect.objectContaining({
322-
status: 400,
323-
title: "Bad Request",
324-
detail: expect.stringMatching(/.+/),
325-
instance: expect.not.stringMatching(""),
326-
}),
327-
}),
337+
expect.objectContaining(expectedErrorShape),
328338
);
329339
});
330340
});
@@ -566,18 +576,23 @@ describe("End-to-end verifiable credentials tests for environment", () => {
566576
returnLegacyJsonld: false,
567577
});
568578

579+
const expectedErrorShape: Record<string, string | object> = {
580+
name: "Error",
581+
message: `Fetching the Verifiable Credential [${vcUrl}] failed`,
582+
};
583+
584+
if (env?.features?.PROBLEM_DETAILS === "true") {
585+
// Check that the Error contains Problem Details
586+
expectedErrorShape.problemDetails = expect.objectContaining({
587+
status: 404,
588+
title: "Not Found",
589+
detail: expect.stringMatching(/.+/),
590+
instance: expect.not.stringMatching(""),
591+
});
592+
}
593+
569594
await expect(vcPromise).rejects.toThrow(
570-
expect.objectContaining({
571-
name: "Error",
572-
message: `Fetching the Verifiable Credential [${vcUrl}] failed`,
573-
// Check that the Error contains Problem Details
574-
problemDetails: expect.objectContaining({
575-
status: 404,
576-
title: "Not Found",
577-
detail: expect.stringMatching(/.+/),
578-
instance: expect.not.stringMatching(""),
579-
}),
580-
}),
595+
expect.objectContaining(expectedErrorShape),
581596
);
582597
});
583598

@@ -593,18 +608,23 @@ describe("End-to-end verifiable credentials tests for environment", () => {
593608
},
594609
);
595610

611+
const expectedErrorShape: Record<string, string | object> = {
612+
name: "Error",
613+
message: `The query endpoint [${derivationService}] returned an error`,
614+
};
615+
616+
if (env?.features?.PROBLEM_DETAILS === "true") {
617+
// Check that the Error contains Problem Details
618+
expectedErrorShape.problemDetails = expect.objectContaining({
619+
status: 400,
620+
title: "Bad Request",
621+
detail: expect.stringMatching(/.+/),
622+
instance: expect.not.stringMatching(""),
623+
});
624+
}
625+
596626
await expect(queryPromise).rejects.toThrow(
597-
expect.objectContaining({
598-
name: "Error",
599-
message: `The query endpoint [${derivationService}] returned an error`,
600-
// Check that the Error contains Problem Details
601-
problemDetails: expect.objectContaining({
602-
status: 400,
603-
title: "Bad Request",
604-
detail: expect.stringMatching(/.+/),
605-
instance: expect.not.stringMatching(""),
606-
}),
607-
}),
627+
expect.objectContaining(expectedErrorShape),
608628
);
609629
});
610630
});
@@ -643,18 +663,23 @@ describe("End-to-end verifiable credentials tests for environment", () => {
643663
fetch: session.fetch,
644664
});
645665

666+
const expectedErrorShape: Record<string, string | object> = {
667+
name: "Error",
668+
message: `The issuer [${statusService}] returned an error`,
669+
};
670+
671+
if (env?.features?.PROBLEM_DETAILS === "true") {
672+
// Check that the Error contains Problem Details
673+
expectedErrorShape.problemDetails = expect.objectContaining({
674+
status: 404,
675+
title: "Not Found",
676+
detail: expect.stringMatching(/.+/),
677+
instance: expect.not.stringMatching(""),
678+
});
679+
}
680+
646681
await expect(vcPromise).rejects.toThrow(
647-
expect.objectContaining({
648-
name: "Error",
649-
message: `The issuer [${statusService}] returned an error`,
650-
// Check that the Error contains Problem Details
651-
problemDetails: expect.objectContaining({
652-
status: 404,
653-
title: "Not Found",
654-
detail: expect.stringMatching(/.+/),
655-
instance: expect.not.stringMatching(""),
656-
}),
657-
}),
682+
expect.objectContaining(expectedErrorShape),
658683
);
659684
});
660685
});

0 commit comments

Comments
 (0)