fix: v2 event type locations (#17288)

* refactor: split internal locations in separate file

* refactor: rename TransformedLocationsSchema to InternalLocationsSchema

* feat: add missing locations in internal schema

* refactor: explicit input locations only for input

* refactor: explicit output locations only for output

* fix: v2

* fix: atoms

* test: internal to api locations transformation

* e2e tests

* upgrade platform libraries
This commit is contained in:
Lauris Skraucis authored and GitHub committed 2024-10-24 17:21:17 +00:00
1 parent 50a41109d0
commit c629d08a9c
20 files changed
+1087 -280

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@
"dependencies": {
"@calcom/platform-constants": "*",
"@calcom/platform-enums": "*",
"@calcom/platform-libraries": "npm:@calcom/[email protected]1",
"@calcom/platform-libraries": "npm:@calcom/[email protected]2",
"@calcom/platform-libraries-0.0.2": "npm:@calcom/[email protected]",
"@calcom/platform-types": "*",
"@calcom/platform-utils": "*",
@@ -1251,4 +1251,154 @@ describe("Event types Endpoints", () => {
await app.close();
});
});
describe("Handle event-types locations", () => {
let app: INestApplication;
let oAuthClient: PlatformOAuthClient;
let organization: Team;
let userRepositoryFixture: UserRepositoryFixture;
let oauthClientRepositoryFixture: OAuthClientRepositoryFixture;
let teamRepositoryFixture: TeamRepositoryFixture;
let eventTypesRepositoryFixture: EventTypesRepositoryFixture;
const userEmail = "[email protected]";
const name = "bob-the-locations-builder";
const username = name;
let user: User;
let legacyEventTypeId1: number;
let legacyEventTypeId2: number;
beforeAll(async () => {
const moduleRef = await withApiAuth(
userEmail,
Test.createTestingModule({
providers: [PrismaExceptionFilter, HttpExceptionFilter],
imports: [AppModule, UsersModule, EventTypesModule_2024_06_14, TokensModule],
})
)
.overrideGuard(PermissionsGuard)
.useValue({
canActivate: () => true,
})
.compile();
app = moduleRef.createNestApplication();
bootstrap(app as NestExpressApplication);
oauthClientRepositoryFixture = new OAuthClientRepositoryFixture(moduleRef);
userRepositoryFixture = new UserRepositoryFixture(moduleRef);
teamRepositoryFixture = new TeamRepositoryFixture(moduleRef);
eventTypesRepositoryFixture = new EventTypesRepositoryFixture(moduleRef);
organization = await teamRepositoryFixture.create({ name: "organization" });
oAuthClient = await createOAuthClient(organization.id);
user = await userRepositoryFixture.create({
email: userEmail,
name,
username,
});
await app.init();
});
async function createOAuthClient(organizationId: number) {
const data = {
logo: "logo-url",
name: "name",
redirectUris: ["redirect-uri"],
permissions: 32,
};
const secret = "secret";
const client = await oauthClientRepositoryFixture.create(organizationId, data, secret);
return client;
}
it("should return integration location with link and credentialId", async () => {
const eventTypeInput = {
title: "event type discord",
description: "event type description",
length: 40,
hidden: false,
slug: "discord-event-type",
locations: [
{
type: "integrations:discord_video",
link: "https://discord.com/users/100",
credentialId: 100,
},
],
schedulingType: SchedulingType.ROUND_ROBIN,
bookingFields: [],
};
const legacyEventType = await eventTypesRepositoryFixture.create(eventTypeInput, user.id);
legacyEventTypeId1 = legacyEventType.id;
return request(app.getHttpServer())
.get(`/api/v2/event-types/${legacyEventTypeId1}`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
.expect(200)
.then(async (response) => {
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
const fetchedEventType = responseBody.data;
expect(fetchedEventType.locations).toEqual([
{
type: "integration",
integration: "discord-video",
link: eventTypeInput.locations[0].link,
credentialId: eventTypeInput.locations[0].credentialId,
},
]);
});
});
it("should return unsupported location", async () => {
const eventTypeInput = {
title: "event type not existing",
description: "event type description",
length: 40,
hidden: false,
slug: "not-existing-event-type",
locations: [
{
type: "this-type-does-not-exist",
},
],
schedulingType: SchedulingType.ROUND_ROBIN,
bookingFields: [],
};
const legacyEventType = await eventTypesRepositoryFixture.create(eventTypeInput, user.id);
legacyEventTypeId1 = legacyEventType.id;
return request(app.getHttpServer())
.get(`/api/v2/event-types/${legacyEventTypeId1}`)
.set(CAL_API_VERSION_HEADER, VERSION_2024_06_14)
.expect(200)
.then(async (response) => {
const responseBody: ApiSuccessResponse<EventTypeOutput_2024_06_14> = response.body;
const fetchedEventType = responseBody.data;
expect(fetchedEventType.locations).toEqual([
{ type: "unknown", location: JSON.stringify(eventTypeInput.locations[0]) },
]);
});
});
afterAll(async () => {
await oauthClientRepositoryFixture.delete(oAuthClient.id);
await teamRepositoryFixture.delete(organization.id);
try {
await eventTypesRepositoryFixture.delete(legacyEventTypeId1);
await eventTypesRepositoryFixture.delete(legacyEventTypeId2);
} catch (e) {
// Event type might have been deleted by the test
}
try {
await userRepositoryFixture.delete(user.id);
} catch (e) {
// User might have been deleted by the test
}
await app.close();
});
});
});
@@ -7,7 +7,7 @@ import {
transformLocationsInternalToApi,
transformBookingFieldsInternalToApi,
parseRecurringEvent,
TransformedLocationsSchema,
InternalLocationSchema,
BookingFieldsSchema,
SystemField,
CustomField,
@@ -20,12 +20,14 @@ import {
transformEventTypeColorsInternalToApi,
parseEventTypeColor,
transformSeatsInternalToApi,
InternalLocation,
} from "@calcom/platform-libraries";
import {
TransformFutureBookingsLimitSchema_2024_06_14,
BookerLayoutsTransformedSchema,
NoticeThresholdTransformedSchema,
EventTypeOutput_2024_06_14,
OutputUnknownLocation_2024_06_14,
} from "@calcom/platform-types";
type EventTypeRelations = {
@@ -190,7 +192,20 @@ export class OutputEventTypesService_2024_06_14 {
transformLocations(locations: any) {
if (!locations) return [];
return transformLocationsInternalToApi(TransformedLocationsSchema.parse(locations));
const knownLocations: InternalLocation[] = [];
const unknownLocations: OutputUnknownLocation_2024_06_14[] = [];
const parsedLocations = locations.map((location: any) => {
const result = InternalLocationSchema.safeParse(location);
if (result.success) {
return knownLocations.push(result.data);
} else {
return unknownLocations.push({ type: "unknown", location: JSON.stringify(location) });
}
});
return [...transformLocationsInternalToApi(knownLocations), ...unknownLocations];
}
transformDestinationCalendar(destinationCalendar?: DestinationCalendar | null) {
+275 -45
View File
@@ -5485,6 +5485,9 @@
},
"data": {
"$ref": "#/components/schemas/CreateManagedUserData"
},
"error": {
"type": "object"
}
},
"required": [
@@ -5849,7 +5852,7 @@
"refreshToken"
]
},
"AddressLocation_2024_06_14": {
"InputAddressLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
@@ -5871,7 +5874,7 @@
"public"
]
},
"LinkLocation_2024_06_14": {
"InputLinkLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
@@ -5893,7 +5896,7 @@
"public"
]
},
"IntegrationLocation_2024_06_14": {
"InputIntegrationLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
@@ -5914,7 +5917,7 @@
"integration"
]
},
"PhoneLocation_2024_06_14": {
"InputPhoneLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
@@ -6606,7 +6609,7 @@
"showAvailabilityCount"
]
},
"AttendeeAddressLocation_2024_06_14": {
"InputAttendeeAddressLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
@@ -6619,7 +6622,7 @@
"type"
]
},
"AttendeePhoneLocation_2024_06_14": {
"InputAttendeePhoneLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
@@ -6632,7 +6635,7 @@
"type"
]
},
"AttendeeDefinedLocation_2024_06_14": {
"InputAttendeeDefinedLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
@@ -6734,25 +6737,25 @@
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/AddressLocation_2024_06_14"
"$ref": "#/components/schemas/InputAddressLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/LinkLocation_2024_06_14"
"$ref": "#/components/schemas/InputLinkLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/IntegrationLocation_2024_06_14"
"$ref": "#/components/schemas/InputIntegrationLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/PhoneLocation_2024_06_14"
"$ref": "#/components/schemas/InputPhoneLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/AttendeeAddressLocation_2024_06_14"
"$ref": "#/components/schemas/InputAttendeeAddressLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/AttendeePhoneLocation_2024_06_14"
"$ref": "#/components/schemas/InputAttendeePhoneLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/AttendeeDefinedLocation_2024_06_14"
"$ref": "#/components/schemas/InputAttendeeDefinedLocation_2024_06_14"
}
]
}
@@ -6943,6 +6946,219 @@
"slug"
]
},
"OutputAddressLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"address",
"link",
"integration",
"phone",
"attendeeAddress",
"attendeePhone",
"attendeeDefined"
],
"example": "address",
"description": "only allowed value for type is `address`"
},
"address": {
"type": "string",
"example": "123 Example St, City, Country"
},
"public": {
"type": "boolean"
}
},
"required": [
"type",
"address",
"public"
]
},
"OutputLinkLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"address",
"link",
"integration",
"phone",
"attendeeAddress",
"attendeePhone",
"attendeeDefined"
],
"example": "link",
"description": "only allowed value for type is `link`"
},
"link": {
"type": "string",
"example": "https://customvideo.com/join/123456"
},
"public": {
"type": "boolean"
}
},
"required": [
"type",
"link",
"public"
]
},
"OutputIntegrationLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"address",
"link",
"integration",
"phone",
"attendeeAddress",
"attendeePhone",
"attendeeDefined",
"conferencing",
"unknown"
],
"example": "integration",
"description": "only allowed value for type is `integration`"
},
"integration": {
"type": "string",
"enum": [
"cal-video",
"google-meet",
"zoom",
"whereby-video",
"whatsapp-video",
"webex-video",
"telegram-video",
"tandem",
"sylaps-video",
"skype-video",
"sirius-video",
"signal-video",
"shimmer-video",
"salesroom-video",
"roam-video",
"riverside-video",
"ping-video",
"office365-video",
"mirotalk-video",
"jitsi",
"jelly-video",
"jelly-conferencing",
"huddle",
"facetime-video",
"element-call-video",
"eightxeight-video",
"discord-video",
"demodesk-video",
"campsite-conferencing",
"campfire-video",
"around-video"
],
"example": "cal-video"
},
"link": {
"type": "string"
},
"credentialdId": {
"type": "number"
}
},
"required": [
"type",
"integration"
]
},
"OutputPhoneLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"address",
"link",
"integration",
"phone",
"attendeeAddress",
"attendeePhone",
"attendeeDefined"
],
"example": "phone",
"description": "only allowed value for type is `phone`"
},
"phone": {
"type": "string",
"example": "+37120993151"
},
"public": {
"type": "boolean"
}
},
"required": [
"type",
"phone",
"public"
]
},
"OutputConferencingLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"address",
"link",
"integration",
"phone",
"attendeeAddress",
"attendeePhone",
"attendeeDefined",
"conferencing",
"unknown"
],
"example": "conferencing",
"description": "only allowed value for type is `conferencing`"
}
},
"required": [
"type"
]
},
"OutputUnknownLocation_2024_06_14": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"address",
"link",
"integration",
"phone",
"attendeeAddress",
"attendeePhone",
"attendeeDefined",
"conferencing",
"unknown"
],
"example": "unknown",
"description": "only allowed value for type is `unknown`"
},
"location": {
"type": "string"
}
},
"required": [
"type",
"location"
]
},
"EmailDefaultFieldOutput_2024_06_14": {
"type": "object",
"properties": {
@@ -7885,16 +8101,22 @@
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/AddressLocation_2024_06_14"
"$ref": "#/components/schemas/OutputAddressLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/LinkLocation_2024_06_14"
"$ref": "#/components/schemas/OutputLinkLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/IntegrationLocation_2024_06_14"
"$ref": "#/components/schemas/OutputIntegrationLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/PhoneLocation_2024_06_14"
"$ref": "#/components/schemas/OutputPhoneLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/OutputConferencingLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/OutputUnknownLocation_2024_06_14"
}
]
}
@@ -8218,25 +8440,25 @@
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/AddressLocation_2024_06_14"
"$ref": "#/components/schemas/InputAddressLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/LinkLocation_2024_06_14"
"$ref": "#/components/schemas/InputLinkLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/IntegrationLocation_2024_06_14"
"$ref": "#/components/schemas/InputIntegrationLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/PhoneLocation_2024_06_14"
"$ref": "#/components/schemas/InputPhoneLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/AttendeeAddressLocation_2024_06_14"
"$ref": "#/components/schemas/InputAttendeeAddressLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/AttendeePhoneLocation_2024_06_14"
"$ref": "#/components/schemas/InputAttendeePhoneLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/AttendeeDefinedLocation_2024_06_14"
"$ref": "#/components/schemas/InputAttendeeDefinedLocation_2024_06_14"
}
]
}
@@ -9697,25 +9919,25 @@
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/AddressLocation_2024_06_14"
"$ref": "#/components/schemas/InputAddressLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/LinkLocation_2024_06_14"
"$ref": "#/components/schemas/InputLinkLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/IntegrationLocation_2024_06_14"
"$ref": "#/components/schemas/InputIntegrationLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/PhoneLocation_2024_06_14"
"$ref": "#/components/schemas/InputPhoneLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/AttendeeAddressLocation_2024_06_14"
"$ref": "#/components/schemas/InputAttendeeAddressLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/AttendeePhoneLocation_2024_06_14"
"$ref": "#/components/schemas/InputAttendeePhoneLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/AttendeeDefinedLocation_2024_06_14"
"$ref": "#/components/schemas/InputAttendeeDefinedLocation_2024_06_14"
}
]
}
@@ -10013,16 +10235,22 @@
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/AddressLocation_2024_06_14"
"$ref": "#/components/schemas/OutputAddressLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/LinkLocation_2024_06_14"
"$ref": "#/components/schemas/OutputLinkLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/IntegrationLocation_2024_06_14"
"$ref": "#/components/schemas/OutputIntegrationLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/PhoneLocation_2024_06_14"
"$ref": "#/components/schemas/OutputPhoneLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/OutputConferencingLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/OutputUnknownLocation_2024_06_14"
}
]
}
@@ -10433,25 +10661,25 @@
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/AddressLocation_2024_06_14"
"$ref": "#/components/schemas/InputAddressLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/LinkLocation_2024_06_14"
"$ref": "#/components/schemas/InputLinkLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/IntegrationLocation_2024_06_14"
"$ref": "#/components/schemas/InputIntegrationLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/PhoneLocation_2024_06_14"
"$ref": "#/components/schemas/InputPhoneLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/AttendeeAddressLocation_2024_06_14"
"$ref": "#/components/schemas/InputAttendeeAddressLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/AttendeePhoneLocation_2024_06_14"
"$ref": "#/components/schemas/InputAttendeePhoneLocation_2024_06_14"
},
{
"$ref": "#/components/schemas/AttendeeDefinedLocation_2024_06_14"
"$ref": "#/components/schemas/InputAttendeeDefinedLocation_2024_06_14"
}
]
}
@@ -11425,7 +11653,8 @@
"RECORDING_TRANSCRIPTION_GENERATED",
"OOO_CREATED",
"AFTER_HOSTS_CAL_VIDEO_NO_SHOW",
"AFTER_GUESTS_CAL_VIDEO_NO_SHOW"
"AFTER_GUESTS_CAL_VIDEO_NO_SHOW",
"FORM_SUBMITTED_NO_EVENT"
]
},
"active": {
@@ -11501,7 +11730,8 @@
"RECORDING_TRANSCRIPTION_GENERATED",
"OOO_CREATED",
"AFTER_HOSTS_CAL_VIDEO_NO_SHOW",
"AFTER_GUESTS_CAL_VIDEO_NO_SHOW"
"AFTER_GUESTS_CAL_VIDEO_NO_SHOW",
"FORM_SUBMITTED_NO_EVENT"
]
},
"active": {