Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v2 bookings return cancelledBy and rescheduledBy #19110

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,108 @@ describe("Bookings Endpoints 2024-08-13", () => {
});
});

describe("who cancelled and rescheduled a booking", () => {
it("should return who cancelled a booking", async () => {
const cancelledByEmail = `user-bookings-canceller-${randomString()}@canceller.com`;
const cancelledBooking = await bookingsRepositoryFixture.create({
uid: `booking-uid-${eventTypeId}`,
title: "booking title",
startTime: "2050-09-05T11:00:00.000Z",
endTime: "2050-09-05T12:00:00.000Z",
eventType: {
connect: {
id: eventTypeId,
},
},
status: "CANCELLED",
cancelledBy: cancelledByEmail,
metadata: {},
responses: {
name: "tester",
email: "[email protected]",
guests: [],
},
user: {
connect: {
id: user.id,
},
},
});

return request(app.getHttpServer())
.get(`/v2/bookings/${cancelledBooking.uid}`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
.expect(200)
.then(async (response) => {
await bookingsRepositoryFixture.deleteById(cancelledBooking.id);
const responseBody: GetBookingOutput_2024_08_13 = response.body;
expect(responseBody.status).toEqual(SUCCESS_STATUS);
expect(responseBody.data).toBeDefined();
expect(responseDataIsBooking(responseBody.data)).toBe(true);

if (responseDataIsBooking(responseBody.data)) {
const data: BookingOutput_2024_08_13 = responseBody.data;
expect(data.uid).toEqual(cancelledBooking.uid);
expect(data.cancelledByEmail).toEqual(cancelledByEmail);
} else {
throw new Error(
"Invalid response data - expected booking but received array of possibily recurring bookings"
);
}
});
});

it("should return who rescheduled a booking", async () => {
const rescheduledByEmail = `user-bookings-rescheduler-${randomString()}@rescheduler.com`;
const rescheduledBooking = await bookingsRepositoryFixture.create({
uid: `booking-uid-${eventTypeId}`,
title: "booking title",
startTime: "2050-09-05T11:00:00.000Z",
endTime: "2050-09-05T12:00:00.000Z",
eventType: {
connect: {
id: eventTypeId,
},
},
status: "CANCELLED",
rescheduledBy: rescheduledByEmail,
metadata: {},
responses: {
name: "tester",
email: "[email protected]",
guests: [],
},
user: {
connect: {
id: user.id,
},
},
});

return request(app.getHttpServer())
.get(`/v2/bookings/${rescheduledBooking.uid}`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
.expect(200)
.then(async (response) => {
await bookingsRepositoryFixture.deleteById(rescheduledBooking.id);
const responseBody: GetBookingOutput_2024_08_13 = response.body;
expect(responseBody.status).toEqual(SUCCESS_STATUS);
expect(responseBody.data).toBeDefined();
expect(responseDataIsBooking(responseBody.data)).toBe(true);

if (responseDataIsBooking(responseBody.data)) {
const data: BookingOutput_2024_08_13 = responseBody.data;
expect(data.uid).toEqual(rescheduledBooking.uid);
expect(data.rescheduledByEmail).toEqual(rescheduledByEmail);
} else {
throw new Error(
"Invalid response data - expected booking but received array of possibily recurring bookings"
);
}
});
});
});

function responseDataIsRecurranceBooking(data: any): data is RecurringBookingOutput_2024_08_13 {
return (
!Array.isArray(data) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ export class OutputBookingsService_2024_08_13 {
hosts: [this.getHost(databaseBooking.user)],
status: databaseBooking.status.toLowerCase(),
cancellationReason: databaseBooking.cancellationReason || undefined,
cancelledByEmail: databaseBooking.cancelledBy || undefined,
reschedulingReason: bookingResponses?.rescheduledReason,
rescheduledByEmail: databaseBooking.rescheduledBy || undefined,
rescheduledFromUid: databaseBooking.fromReschedule || undefined,
start: databaseBooking.startTime,
end: databaseBooking.endTime,
Expand Down Expand Up @@ -198,7 +200,9 @@ export class OutputBookingsService_2024_08_13 {
hosts: [this.getHost(databaseBooking.user)],
status: databaseBooking.status.toLowerCase(),
cancellationReason: databaseBooking.cancellationReason || undefined,
cancelledByEmail: databaseBooking.cancelledBy || undefined,
reschedulingReason: bookingResponses?.rescheduledReason,
rescheduledByEmail: databaseBooking.rescheduledBy || undefined,
rescheduledFromUid: databaseBooking.fromReschedule || undefined,
start: databaseBooking.startTime,
end: databaseBooking.endTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,24 @@ class BaseBookingOutput_2024_08_13 {
@Expose()
cancellationReason?: string;

@ApiPropertyOptional({ type: String, example: "[email protected]" })
@IsEmail()
@IsOptional()
@Expose()
cancelledByEmail?: string;

@ApiPropertyOptional({ type: String, example: "User rescheduled the event" })
@IsString()
@IsOptional()
@Expose()
reschedulingReason?: string;

@ApiPropertyOptional({ type: String, example: "[email protected]" })
@IsEmail()
@IsOptional()
@Expose()
rescheduledByEmail?: string;

@ApiPropertyOptional({ type: String, example: "previous_uid_123" })
@IsString()
@IsOptional()
Expand Down
Loading