Skip to content

Commit 3d778ba

Browse files
supalarryibex088
andauthored
fix: get organization bookings bookingUid parameter (calcom#23186)
* fix: get organization bookings bookingUid parameter * chore: bump @calcom/platform-libraries from 0.0.315 to 0.0.318 --------- Co-authored-by: Somay Chauhan <somaychauhan98@gmail.com>
1 parent b8f0000 commit 3d778ba

5 files changed

Lines changed: 5873 additions & 51 deletions

File tree

apps/api/v2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@axiomhq/winston": "^1.2.0",
3939
"@calcom/platform-constants": "*",
4040
"@calcom/platform-enums": "*",
41-
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.315",
41+
"@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.318",
4242
"@calcom/platform-types": "*",
4343
"@calcom/platform-utils": "*",
4444
"@calcom/prisma": "*",

apps/api/v2/src/ee/bookings/2024-08-13/controllers/e2e/managed-user-bookings.e2e-spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,11 @@ describe("Managed user bookings 2024-08-13", () => {
714714
});
715715

716716
it("should return unauthorized when org admin tries to confirm regular user's booking", async () => {
717-
// Create regular user (not managed)
718717
const regularUser = await userRepositoryFixture.create({
719718
email: `managed-user-bookings-2024-08-13-regular-user-${randomString()}@api.com`,
720719
name: "Regular User",
721720
});
722721

723-
// Create event type requiring confirmation for regular user
724722
const regularUserEventType = await eventTypesRepositoryFixture.create(
725723
{
726724
title: `regular-user-event-type-requires-confirmation-${randomString()}`,
@@ -731,7 +729,6 @@ describe("Managed user bookings 2024-08-13", () => {
731729
regularUser.id
732730
);
733731

734-
// Create booking for regular user
735732
const regularUserBooking = await bookingsRepositoryFixture.create({
736733
user: {
737734
connect: {
@@ -765,14 +762,12 @@ describe("Managed user bookings 2024-08-13", () => {
765762
},
766763
});
767764

768-
// Org admin should not be able to confirm regular user's booking
769765
await request(app.getHttpServer())
770766
.post(`/v2/bookings/${regularUserBooking.uid}/confirm`)
771767
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
772768
.set("Authorization", `Bearer ${orgAdminManagedUser.accessToken}`)
773769
.expect(401);
774770

775-
// Clean up
776771
await userRepositoryFixture.delete(regularUser.id);
777772
});
778773
});

apps/api/v2/src/ee/bookings/2024-08-13/services/input.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ export class InputBookingsService_2024_08_13 {
702702
beforeUpdatedDate: queryParams.beforeUpdatedAt,
703703
afterCreatedDate: queryParams.afterCreatedAt,
704704
beforeCreatedDate: queryParams.beforeCreatedAt,
705+
bookingUid: queryParams.bookingUid,
705706
};
706707
}
707708

apps/api/v2/src/modules/organizations/bookings/organizations-bookings.controller.e2e-spec.ts

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ describe("Organizations Bookings Endpoints 2024-08-13", () => {
6666
let orgEventTypeId2: number;
6767
let nonOrgEventTypeId: number;
6868

69+
let collectiveOrgBookingUid: string;
70+
6971
beforeAll(async () => {
7072
const moduleRef = await withApiAuth(
7173
orgUserEmail2,
@@ -91,12 +93,17 @@ describe("Organizations Bookings Endpoints 2024-08-13", () => {
9193
schedulesService = moduleRef.get<SchedulesService_2024_04_15>(SchedulesService_2024_04_15);
9294

9395
organization = await organizationsRepositoryFixture.create({ name: "organization bookings" });
96+
oAuthClient = await createOAuthClient(organization.id);
9497
team1 = await teamRepositoryFixture.create({
9598
name: "team orgs booking 1",
9699
isOrganization: false,
97100
parent: { connect: { id: organization.id } },
101+
createdByOAuthClient: {
102+
connect: {
103+
id: oAuthClient.id,
104+
},
105+
},
98106
});
99-
oAuthClient = await createOAuthClient(organization.id);
100107

101108
nonOrgUser1 = await userRepositoryFixture.create({
102109
email: nonOrgUserEmail1,
@@ -315,6 +322,7 @@ describe("Organizations Bookings Endpoints 2024-08-13", () => {
315322

316323
if (responseDataIsBooking(responseBody.data)) {
317324
const data: BookingOutput_2024_08_13 = responseBody.data;
325+
collectiveOrgBookingUid = data.uid;
318326
expect(data.id).toBeDefined();
319327
expect(data.uid).toBeDefined();
320328
expect(data.hosts.length).toEqual(1);
@@ -669,6 +677,125 @@ describe("Organizations Bookings Endpoints 2024-08-13", () => {
669677
);
670678
});
671679
});
680+
681+
describe("get by bookingUid param", () => {
682+
it("should get a specific booking by bookingUid query param", async () => {
683+
return request(app.getHttpServer())
684+
.get(`/v2/organizations/${organization.id}/bookings?bookingUid=${collectiveOrgBookingUid}`)
685+
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
686+
.set(X_CAL_CLIENT_ID, oAuthClient.id)
687+
.set(X_CAL_SECRET_KEY, oAuthClient.secret)
688+
.expect(200)
689+
.then(async (response) => {
690+
const responseBody: GetBookingsOutput_2024_08_13 = response.body;
691+
expect(responseBody.status).toEqual(SUCCESS_STATUS);
692+
expect(responseBody.data).toBeDefined();
693+
694+
const data: (
695+
| BookingOutput_2024_08_13
696+
| RecurringBookingOutput_2024_08_13
697+
| GetSeatedBookingOutput_2024_08_13
698+
)[] = responseBody.data;
699+
expect(data.length).toEqual(1);
700+
expect(responseDataIsBooking(data[0])).toBe(true);
701+
702+
if (responseDataIsBooking(data[0])) {
703+
const booking: BookingOutput_2024_08_13 = data[0];
704+
expect(booking.uid).toEqual(collectiveOrgBookingUid);
705+
expect(booking.eventTypeId).toEqual(orgEventTypeId);
706+
expect(booking.status).toEqual("accepted");
707+
expect(booking.attendees.length).toEqual(2);
708+
expect(booking.attendees[0].name).toEqual("alice");
709+
expect(booking.attendees[0].email).toEqual("alice@gmail.com");
710+
} else {
711+
throw new Error("Expected single booking but received different response type");
712+
}
713+
});
714+
});
715+
716+
it("should return empty array for non-existent booking UID query param", async () => {
717+
const nonExistentUid = "non-existent-booking-uid";
718+
719+
return request(app.getHttpServer())
720+
.get(`/v2/organizations/${organization.id}/bookings?bookingUid=${nonExistentUid}`)
721+
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
722+
.set(X_CAL_CLIENT_ID, oAuthClient.id)
723+
.set(X_CAL_SECRET_KEY, oAuthClient.secret)
724+
.expect(200)
725+
.then(async (response) => {
726+
const responseBody: GetBookingsOutput_2024_08_13 = response.body;
727+
expect(responseBody.status).toEqual(SUCCESS_STATUS);
728+
expect(responseBody.data).toBeDefined();
729+
expect(responseBody.data.length).toEqual(0);
730+
});
731+
});
732+
733+
it("should return empty array for booking UID not belonging to the organization", async () => {
734+
const regularUser = await userRepositoryFixture.create({
735+
email: `org-bookings-regular-user-${Math.floor(Math.random() * 10000)}@api.com`,
736+
name: "Regular User",
737+
});
738+
739+
const regularUserEventType = await eventTypesRepositoryFixture.create(
740+
{
741+
title: `regular-user-event-type-${Math.floor(Math.random() * 10000)}`,
742+
slug: `regular-user-event-type-${Math.floor(Math.random() * 10000)}`,
743+
length: 60,
744+
bookingFields: [],
745+
locations: [],
746+
},
747+
regularUser.id
748+
);
749+
750+
const regularUserBooking = await bookingsRepositoryFixture.create({
751+
user: {
752+
connect: {
753+
id: regularUser.id,
754+
},
755+
},
756+
startTime: new Date(Date.UTC(2030, 0, 15, 13, 0, 0)),
757+
endTime: new Date(Date.UTC(2030, 0, 15, 14, 0, 0)),
758+
title: "Regular user booking",
759+
uid: `regular-user-booking-${Math.floor(Math.random() * 10000)}`,
760+
eventType: {
761+
connect: {
762+
id: regularUserEventType.id,
763+
},
764+
},
765+
location: "https://meet.google.com/regular-user",
766+
customInputs: {},
767+
metadata: {},
768+
status: "ACCEPTED",
769+
responses: {
770+
name: "Regular Attendee",
771+
email: "regular@example.com",
772+
},
773+
attendees: {
774+
create: {
775+
email: "regular@example.com",
776+
name: "Regular Attendee",
777+
locale: "en",
778+
timeZone: "Europe/Rome",
779+
},
780+
},
781+
});
782+
783+
return request(app.getHttpServer())
784+
.get(`/v2/organizations/${organization.id}/bookings?bookingUid=${regularUserBooking.uid}`)
785+
.set(CAL_API_VERSION_HEADER, VERSION_2024_08_13)
786+
.set(X_CAL_CLIENT_ID, oAuthClient.id)
787+
.set(X_CAL_SECRET_KEY, oAuthClient.secret)
788+
.expect(200)
789+
.then(async (response) => {
790+
const responseBody: GetBookingsOutput_2024_08_13 = response.body;
791+
expect(responseBody.status).toEqual(SUCCESS_STATUS);
792+
expect(responseBody.data).toBeDefined();
793+
expect(responseBody.data.length).toEqual(0);
794+
795+
await userRepositoryFixture.delete(regularUser.id);
796+
});
797+
});
798+
});
672799
});
673800

674801
async function createOAuthClient(organizationId: number) {

0 commit comments

Comments
 (0)