Skip to content

Commit a71fb0b

Browse files
committed
PYIC-8592: Add tests for pollVcReceiptStatus middleware.
1 parent 5aa478c commit a71fb0b

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/app/ipv/tests/checkVcReceiptStatus.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe("checkVcReceiptStatus middleware", () => {
6464
expect(next).to.have.not.been.calledOnce;
6565
});
6666

67-
it("should throw error if status is ERROR", async () => {
67+
it("should throw error if status is SERVER_ERROR", async () => {
6868
// Arrange
6969
const req = createRequest();
7070
const res = createResponse();

src/app/vc-receipt-status/middleware.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,34 @@ describe("vc receipt status middleware tests", () => {
6666
expect((req.session as any).journey).to.equal("journey/next");
6767
});
6868

69+
it("pollVcReceiptStatus should return CLIENT_ERROR status if appVcReceived returns 400", async () => {
70+
const error = { response: { status: 400 } };
71+
appVcReceivedStub.rejects(error);
72+
73+
await middleware.pollVcReceiptStatus(req as Request, res as Response, next);
74+
75+
expect(res.status).to.have.been.calledWith(400);
76+
expect(res.json).to.have.been.calledWith({ status: "CLIENT_ERROR" });
77+
});
78+
6979
it("pollVcReceiptStatus should return an error when appVcReceived does not return journey response", async () => {
7080
appVcReceivedStub.resolves({ data: {} });
7181
isJourneyResponse.returns(false);
7282

7383
await middleware.pollVcReceiptStatus(req as Request, res as Response, next);
7484

7585
expect(res.status).to.have.been.calledWith(500);
76-
expect(res.json).to.have.been.calledWith({ status: "ERROR" });
86+
expect(res.json).to.have.been.calledWith({ status: "SERVER_ERROR" });
7787
});
7888

79-
it("pollVcReceiptStatus should return ERROR status if appVcReceived throws non 404 error", async () => {
89+
it("pollVcReceiptStatus should return SERVER_ERROR status if appVcReceived throws non 400-499 error", async () => {
8090
const error = new Error("Test error");
8191
appVcReceivedStub.rejects(error);
8292

8393
await middleware.pollVcReceiptStatus(req as Request, res as Response, next);
8494

8595
expect(res.status).to.have.been.calledWith(500);
86-
expect(res.json).to.have.been.calledWith({ status: "ERROR" });
96+
expect(res.json).to.have.been.calledWith({ status: "SERVER_ERROR" });
8797
});
8898

8999
it("pollVcReceiptStatus should return COMPLETED status when query param snapshotTest is true", async () => {

0 commit comments

Comments
 (0)