Skip to content

Commit

Permalink
Merge pull request #6 from dgodongm/dg_partialupdate_tests
Browse files Browse the repository at this point in the history
partial booking update tests
  • Loading branch information
dgodongm authored Jan 30, 2024
2 parents 7675d94 + bee3099 commit e5866fe
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cypress/e2e/update_booking.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
54 changes: 54 additions & 0 deletions cypress/e2e/update_partial_booking.cy.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});
16 changes: 16 additions & 0 deletions cypress/utils/bookings_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit e5866fe

Please sign in to comment.