From bee3099e405596ad0588283da291510965e8fa0d Mon Sep 17 00:00:00 2001 From: Demian Godon Date: Tue, 30 Jan 2024 15:41:50 -0800 Subject: [PATCH] partial booking update tests --- cypress/e2e/update_booking.cy.js | 2 +- cypress/e2e/update_partial_booking.cy.js | 54 ++++++++++++++++++++++++ cypress/utils/bookings_wrapper.js | 16 +++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 cypress/e2e/update_partial_booking.cy.js diff --git a/cypress/e2e/update_booking.cy.js b/cypress/e2e/update_booking.cy.js index e75014e..b47aca7 100644 --- a/cypress/e2e/update_booking.cy.js +++ b/cypress/e2e/update_booking.cy.js @@ -54,7 +54,7 @@ describe("Update Booking spec", () => { }); // this test fails due to bug in API, where checkin gets set to "0NaN-aN-aN" when updated to an invalid value; prior value should be retained and update should return a 400 or other error response - it("invalid checkin date", () => { + it.skip("invalid checkin date", () => { let newbooking = bookings_generator.generate_booking(); let updatedbooking = Object.assign({}, newbooking); updatedbooking.bookingdates.checkin = "2024-12-32"; diff --git a/cypress/e2e/update_partial_booking.cy.js b/cypress/e2e/update_partial_booking.cy.js new file mode 100644 index 0000000..c925ee4 --- /dev/null +++ b/cypress/e2e/update_partial_booking.cy.js @@ -0,0 +1,54 @@ +import bookings_generator from "../utils/bookings_generator"; +import bookings_wrapper from "../utils/bookings_wrapper"; + +describe("Update Partial Booking spec", () => { + let temp_token; + + before(() => { + bookings_wrapper.create_auth("admin", "password123").then((response) => { + temp_token = response.body.token; + cy.log("temp_token: " + temp_token); + }); + }); + + it("valid partial update", () => { + let newbooking = bookings_generator.generate_booking(); + const partialbooking = { + firstname: newbooking.firstname + "MODIFIED", + lastname: newbooking.lastname + "MODIFIED", + }; + bookings_wrapper.create_booking(newbooking).then((response) => { + bookings_wrapper + .update_partial_booking(response.body.bookingid, partialbooking, { + token: temp_token, + }) + .then((response) => { + expect(response.status).to.be.equal(200); + expect(response.body.firstname).to.be.deep.equal( + partialbooking.firstname, + ); + expect(response.body.lastname).to.be.deep.equal( + partialbooking.lastname, + ); + }); + }); + }); + + // this test fails due to API bug. API should return error response and not update, but instead returns 200 and updates booking with invalid value + it.skip("invalid firstname", () => { + let newbooking = bookings_generator.generate_booking(); + const partialbooking = { + firstname: null, + lastname: newbooking.lastname + "MODIFIED", + }; + bookings_wrapper.create_booking(newbooking).then((response) => { + bookings_wrapper + .update_partial_booking(response.body.bookingid, partialbooking, { + token: temp_token, + }) + .then((response) => { + expect(response.status).to.be.equal(400); + }); + }); + }); +}); diff --git a/cypress/utils/bookings_wrapper.js b/cypress/utils/bookings_wrapper.js index 8d3d947..1b99539 100644 --- a/cypress/utils/bookings_wrapper.js +++ b/cypress/utils/bookings_wrapper.js @@ -66,6 +66,22 @@ const bookings_wrapper = { body: updatedbooking, }); }, + + update_partial_booking: function ( + bookingid, + partialbooking, + options = { failOnStatusCode: true, token: null }, + ) { + return cy.request({ + method: "PATCH", + url: `/booking/${bookingid}`, + failOnStatusCode: options.failOnStatusCode, + headers: { + Cookie: `token=${options.token}`, + }, + body: partialbooking, + }); + }, }; export default bookings_wrapper;