Skip to content

Commit

Permalink
Add test to verify that updating parallel reservations work
Browse files Browse the repository at this point in the history
It does work in that multiple reservation updates are sent but not with
the expected payload. That will have to be fixed separately.
  • Loading branch information
kasperg committed Nov 14, 2023
1 parent 104558a commit d9ff337
Showing 1 changed file with 149 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};

0 comments on commit d9ff337

Please sign in to comment.