Unit Testing Mutations
May 17, 2020
In this chapter we will be unit testing our mutation.
In the tests
folder, create a makeABooking.test.js
file and add the following:
import { makeABooking } from "../src/resolvers/mutation";
describe("Make a booking", () => {
test("Successfully able to make a booking", async () => {
const args = {
listingId: "a114dded-ddef-4052-a106-bb18b94e6b51",
bookingDate: "24-Apr-20",
size: 2,
customerEmail: "angela@dundler.com",
customers: [
{
name: "Dwight",
surname: "Shrut",
passportNumber: "3333344",
physioScore: "454",
},
{
name: "Pam",
surname: "Papper",
passportNumber: "34354",
physioScore: "2945",
},
],
};
const context = "context";
const response = await makeABooking(args, context);
console.log(response);
});
}
π£ We are creating a mutation in the args
with the necessary data.
π£ Next we are making sure we get back a bookingId
that the charge matches what we expect it to be.
Then go to your terminal and run the test:
$ yarn test makeABooking.test.js
Now all our tests are passing!