From d9ff3379cde0b783c1af87d35222b819f2bd3521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Garn=C3=A6s?= Date: Tue, 14 Nov 2023 16:14:08 +0100 Subject: [PATCH] Add test to verify that updating parallel reservations work It does work in that multiple reservation updates are sent but not with the expected payload. That will have to be fixed separately. --- .../reservation-details.test.ts | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/src/apps/reservation-list/modal/reservation-details/reservation-details.test.ts b/src/apps/reservation-list/modal/reservation-details/reservation-details.test.ts index 20f513263e..a022e06177 100644 --- a/src/apps/reservation-list/modal/reservation-details/reservation-details.test.ts +++ b/src/apps/reservation-list/modal/reservation-details/reservation-details.test.ts @@ -672,6 +672,155 @@ describe("Reservation details modal", () => { .find(".text-small-caption") .should("have.text", "21-06-2022"); }); + + it("It supports updating parallel reservations", () => { + cy.intercept("GET", "**/v1/agencyid/patrons/patronid/reservations/**", { + statusCode: 200, + body: [ + { + reservationId: 4698559133, + recordId: "46985591", + state: "reserved", + pickupBranch: "DK-775160", + pickupDeadline: null, + expiryDate: "2022-09-21", + dateOfReservation: "2022-06-14T09:00:50.059", + numberInQueue: 1, + periodical: null, + pickupNumber: null, + ilBibliographicRecord: null, + transactionId: "c6742151-f4a7-4655-a94f-7bd6a0009431", + reservationType: "parallel" + }, + { + reservationId: 4698559134, + recordId: "46985592", + state: "reserved", + pickupBranch: "DK-775160", + pickupDeadline: null, + expiryDate: "2022-09-21", + dateOfReservation: "2022-06-14T09:00:50.059", + numberInQueue: 1, + periodical: null, + pickupNumber: null, + ilBibliographicRecord: null, + transactionId: "c6742151-f4a7-4655-a94f-7bd6a0009431", + reservationType: "parallel" + } + ] + }).as("physical_reservations"); + cy.intercept("GET", "**/v1/user/**", { + statusCode: 200, + body: { + reservations: [], + code: 101, + message: "OK" + } + }).as("digital_reservations"); + + cy.interceptRest({ + aliasName: "work", + httpMethod: "POST", + url: "**/next/**", + fixtureFilePath: "reservation-list/work.json" + }); + + cy.intercept( + "PUT", + "**/external/v1/agencyid/patrons/patronid/reservations", + { + statusCode: 201, + body: { code: 101, message: "OK" } + } + ).as("put-library-branch-and-expiry-date"); + + cy.visit( + "/iframe.html?path=/story/apps-reservation-list--reservation-list-physical-details-modal" + ); + + cy.wait(["@physical_reservations", "@digital_reservations", "@work"]); + + // Open the change pickup branch modal for the reservation. + cy.getBySel("reservation-form-list-item") + .eq(1) + .find("button") + .should("exist") + .click(); + + // Change the pickup branch and save. + cy.getBySel("modal-reservation-form-select") + .should("exist") + .select("DK-775120"); + cy.getBySel("reservation-form-button").should("exist").click(); + + cy.wait("@put-library-branch-and-expiry-date").should(({ request }) => { + // Use JSON stringify to make it easier to spot differences in the + // logged output in case of errors. + expect(JSON.stringify(request.body)).to.equal( + JSON.stringify({ + reservations: [ + { + expiryDate: "2022-09-21", + // TODO: This should be DK-775120 as this is what the user + // selected in previous steps but that does not seem to work + // right now. + pickupBranch: "DK-775160", + reservationId: 4698559133 + }, + { + expiryDate: "2022-09-21", + // TODO: As above this should be DK-775120. + pickupBranch: "DK-775160", + reservationId: 4698559134 + } + ] + }) + ); + }); + + // Close the modal + cy.getBySel("modal-cta-button").should("exist").click(); + + // Open the change interest period modal for the reservation. + cy.getBySel("reservation-form-list-item") + .eq(2) + .find("button") + .should("exist") + .click(); + + // Change the interest period and save. + cy.getBySel("modal-reservation-form-select") + .should("exist") + .select("1 month"); + cy.getBySel("reservation-form-button").should("exist").click(); + + cy.wait("@put-library-branch-and-expiry-date").should(({ request }) => { + // Use JSON stringify to make it easier to spot differences in the + // logged output in case of errors. + expect(JSON.stringify(request.body)).to.equal( + JSON.stringify({ + reservations: [ + { + // TODO: This should be an updated value as this is what the user + // selected in previous steps but that does not seem to work + // right now. + expiryDate: "2022-09-21", + pickupBranch: "DK-775120", + reservationId: 4698559133 + }, + { + // TODO: As above this should be updated as above. + expiryDate: "2022-09-21", + pickupBranch: "DK-775120", + reservationId: 4698559134 + } + ] + }) + ); + }); + + cy.getBySel("modal-cta-button").should("exist").click(); + }); }); export default {};