import { MemoryAppointmentClient, AppointmentEdit, } from "../../apis/appointment-client"; describe("MemoryAppointmentClient", () => { describe("addAppoinment", () => { it("should add an appointment", async () => { // Arrange const appointment: AppointmentEdit = { name: "test", email: "test@test.se", phoneNumber: "123", startTime: new Date(2020, 1, 1), endTime: new Date(2020, 1, 2), date: new Date(2020, 1, 1), }; const client = new MemoryAppointmentClient(); // Act const { id } = await client.addAppointment(appointment); const result = await client.getAppointment(id); // Assert expect(result!.name).toStrictEqual(appointment.name); expect(result!.email).toStrictEqual(appointment.email); expect(result!.phoneNumber).toStrictEqual(appointment.phoneNumber); expect(result!.startTime).toStrictEqual(appointment.startTime); expect(result!.endTime).toStrictEqual(appointment.endTime); expect(result!.date).toStrictEqual(appointment.date); }); it("should throw if appointment is overlapping with another appointment", async () => { // Arrange const client = new MemoryAppointmentClient(); const appointment: AppointmentEdit = { name: "test", email: "test@test.se", phoneNumber: "123", startTime: new Date(2020, 1, 1), endTime: new Date(2020, 1, 2), date: new Date(2020, 1, 1), }; // Act await client.addAppointment(appointment); // Assert await expect(client.addAppointment(appointment)).rejects.toThrowError(); }); }); describe("updateAppointment", () => { it("should update the appointment with new values", async () => { // Arrange const client = new MemoryAppointmentClient(); const appointmentNew: AppointmentEdit = { name: "test", email: "test@test.se", phoneNumber: "123", startTime: new Date(2020, 1, 1), endTime: new Date(2020, 1, 2), date: new Date(2020, 1, 1), }; const appointmentUpdate: AppointmentEdit = { name: "updated", email: "updated@test.se", phoneNumber: "12345", startTime: new Date(2020, 2, 1), endTime: new Date(2020, 2, 2), date: new Date(2020, 2, 1), }; // Act const { id } = await client.addAppointment(appointmentNew); await client.updateAppointment(id, appointmentUpdate); const result = await client.getAppointment(id); // Assert expect(result!.name).toStrictEqual(appointmentUpdate.name); expect(result!.email).toStrictEqual(appointmentUpdate.email); expect(result!.phoneNumber).toStrictEqual(appointmentUpdate.phoneNumber); expect(result!.startTime).toStrictEqual(appointmentUpdate.startTime); expect(result!.endTime).toStrictEqual(appointmentUpdate.endTime); expect(result!.date).toStrictEqual(appointmentUpdate.date); }); it("should throw if appointment is overlapping with another appointment", async () => { // Arrange const client = new MemoryAppointmentClient(); const appointmentNew: AppointmentEdit = { name: "test", email: "test@test.se", phoneNumber: "123", startTime: new Date(2020, 1, 1), endTime: new Date(2020, 1, 2), date: new Date(2020, 1, 1), }; const appointmentUpdate: AppointmentEdit = { name: "updated", email: "updated@test.se", phoneNumber: "12345", startTime: new Date(2020, 2, 1), endTime: new Date(2020, 2, 2), date: new Date(2020, 2, 1), }; // Act const { id } = await client.addAppointment(appointmentNew); await client.addAppointment(appointmentUpdate); // Assert await expect(client.updateAppointment(id, appointmentUpdate)).rejects.toThrowError(); }); }); });