@@ -22,17 +22,31 @@ import { UserRepositoryFixture } from "test/fixtures/repository/users.repository
2222import { randomString } from "test/utils/randomString" ;
2323import { withApiAuth } from "test/utils/withApiAuth" ;
2424
25-
26-
2725import { CAL_API_VERSION_HEADER , SUCCESS_STATUS , VERSION_2024_06_14 } from "@calcom/platform-constants" ;
28- import { BookingWindowPeriodInputTypeEnum_2024_06_14 , BookerLayoutsInputEnum_2024_06_14 , ConfirmationPolicyEnum , NoticeThresholdUnitEnum , FrequencyInput } from "@calcom/platform-enums" ;
26+ import {
27+ BookingWindowPeriodInputTypeEnum_2024_06_14 ,
28+ BookerLayoutsInputEnum_2024_06_14 ,
29+ ConfirmationPolicyEnum ,
30+ NoticeThresholdUnitEnum ,
31+ FrequencyInput ,
32+ } from "@calcom/platform-enums" ;
2933import { SchedulingType } from "@calcom/platform-libraries" ;
30- import { type ApiSuccessResponse , type CreateEventTypeInput_2024_06_14 , type EventTypeOutput_2024_06_14 , type GuestsDefaultFieldOutput_2024_06_14 , type NameDefaultFieldInput_2024_06_14 , type NotesDefaultFieldInput_2024_06_14 , type SplitNameDefaultFieldOutput_2024_06_14 , type UpdateEventTypeInput_2024_06_14 } from "@calcom/platform-types" ;
34+ import {
35+ BaseConfirmationPolicy_2024_06_14 ,
36+ TeamEventTypeOutput_2024_06_14 ,
37+ type ApiSuccessResponse ,
38+ type CreateEventTypeInput_2024_06_14 ,
39+ type EventTypeOutput_2024_06_14 ,
40+ type GuestsDefaultFieldOutput_2024_06_14 ,
41+ type NameDefaultFieldInput_2024_06_14 ,
42+ type NotesDefaultFieldInput_2024_06_14 ,
43+ type SplitNameDefaultFieldOutput_2024_06_14 ,
44+ type UpdateEventTypeInput_2024_06_14 ,
45+ } from "@calcom/platform-types" ;
3146import { FAILED_RECURRING_EVENT_TYPE_WITH_BOOKER_LIMITS_ERROR_MESSAGE } from "@calcom/platform-types/event-types/event-types_2024_06_14/inputs/validators/CantHaveRecurrenceAndBookerActiveBookingsLimit" ;
3247import { REQUIRES_AT_LEAST_ONE_PROPERTY_ERROR } from "@calcom/platform-types/utils/RequiresOneOfPropertiesWhenNotDisabled" ;
3348import type { PlatformOAuthClient , Team , User , Schedule , EventType } from "@calcom/prisma/client" ;
3449
35-
3650const orderBySlug = ( a : { slug : string } , b : { slug : string } ) => {
3751 if ( a . slug < b . slug ) return - 1 ;
3852 if ( a . slug > b . slug ) return 1 ;
@@ -83,6 +97,8 @@ describe("Event types Endpoints", () => {
8397 let apiKeysRepositoryFixture : ApiKeysRepositoryFixture ;
8498 let apiKeyString : string ;
8599 let apiKeyOrgUser : string ;
100+ let systemAdminUser : User ;
101+ let systemAdminApiKeyString : string ;
86102
87103 const userEmail = `event-types-2024-06-14-user-${ randomString ( ) } @api.com` ;
88104 const falseTestEmail = `event-types-2024-06-14-false-user-${ randomString ( ) } @api.com` ;
@@ -196,6 +212,17 @@ describe("Event types Endpoints", () => {
196212 const { keyString } = await apiKeysRepositoryFixture . createApiKey ( user . id , null ) ;
197213 apiKeyString = `cal_test_${ keyString } ` ;
198214
215+ systemAdminUser = await userRepositoryFixture . create ( {
216+ email : `event-types-2024-06-14-system-admin-${ randomString ( ) } @api.com` ,
217+ username : `event-types-2024-06-14-system-admin-${ randomString ( ) } ` ,
218+ role : "ADMIN" ,
219+ } ) ;
220+ const { keyString : adminKeyString } = await apiKeysRepositoryFixture . createApiKey (
221+ systemAdminUser . id ,
222+ null
223+ ) ;
224+ systemAdminApiKeyString = `cal_test_${ adminKeyString } ` ;
225+
199226 orgUser = await userRepositoryFixture . create ( {
200227 email : `event-types-2024-06-14-org-user-${ randomString ( ) } @example.com` ,
201228 name : `event-types-2024-06-14-org-user-${ randomString ( ) } ` ,
@@ -1375,6 +1402,99 @@ describe("Event types Endpoints", () => {
13751402 expect ( fetchedEventType . color ) . toEqual ( eventType . color ) ;
13761403 } ) ;
13771404
1405+ it ( "system admin can access another user's event type by id" , async ( ) => {
1406+ return request ( app . getHttpServer ( ) )
1407+ . get ( `/api/v2/event-types/${ orgUserEventType1 . id } ` )
1408+ . set ( CAL_API_VERSION_HEADER , VERSION_2024_06_14 )
1409+ . set ( "Authorization" , `Bearer ${ systemAdminApiKeyString } ` )
1410+ . expect ( 200 )
1411+ . then ( ( response ) => {
1412+ const responseBody : ApiSuccessResponse < EventTypeOutput_2024_06_14 > = response . body ;
1413+ expect ( responseBody . status ) . toEqual ( SUCCESS_STATUS ) ;
1414+ expect ( responseBody . data . id ) . toEqual ( orgUserEventType1 . id ) ;
1415+ expect ( responseBody . data . ownerId ) . toEqual ( orgUser . id ) ;
1416+ } ) ;
1417+ } ) ;
1418+
1419+ it ( "user can access a team event type as team member (using user's API key)" , async ( ) => {
1420+ const team = await teamRepositoryFixture . create ( {
1421+ name : `event-types-2024-06-14-team-${ randomString ( ) } ` ,
1422+ isOrganization : false ,
1423+ } ) ;
1424+
1425+ await membershipsRepositoryFixture . create ( {
1426+ role : "ADMIN" ,
1427+ user : { connect : { id : user . id } } ,
1428+ team : { connect : { id : team . id } } ,
1429+ accepted : true ,
1430+ } ) ;
1431+
1432+ const teamEventType = await eventTypesRepositoryFixture . createTeamEventType ( {
1433+ title : `event-types-2024-06-14-team-event-${ randomString ( ) } ` ,
1434+ slug : `event-types-2024-06-14-team-event-${ randomString ( ) } ` ,
1435+ length : 60 ,
1436+ locations : [ ] ,
1437+ schedulingType : "COLLECTIVE" ,
1438+ team : { connect : { id : team . id } } ,
1439+ } ) ;
1440+
1441+ return request ( app . getHttpServer ( ) )
1442+ . get ( `/api/v2/event-types/${ teamEventType . id } ` )
1443+ . set ( CAL_API_VERSION_HEADER , VERSION_2024_06_14 )
1444+ . set ( "Authorization" , `Bearer ${ apiKeyString } ` )
1445+ . expect ( 200 )
1446+ . then ( async ( response ) => {
1447+ const responseBody : ApiSuccessResponse < TeamEventTypeOutput_2024_06_14 > = response . body ;
1448+ expect ( responseBody . status ) . toEqual ( SUCCESS_STATUS ) ;
1449+ expect ( responseBody . data . id ) . toEqual ( teamEventType . id ) ;
1450+ expect ( responseBody . data . teamId ) . toEqual ( team . id ) ;
1451+ await teamRepositoryFixture . delete ( team . id ) ;
1452+ } ) ;
1453+ } ) ;
1454+
1455+ it ( "user can access a team event type as HOST even if membership role is MEMBER (using user's API key)" , async ( ) => {
1456+ const team = await teamRepositoryFixture . create ( {
1457+ name : `event-types-2024-06-14-host-team-${ randomString ( ) } ` ,
1458+ isOrganization : false ,
1459+ } ) ;
1460+
1461+ await membershipsRepositoryFixture . create ( {
1462+ role : "MEMBER" ,
1463+ user : { connect : { id : user . id } } ,
1464+ team : { connect : { id : team . id } } ,
1465+ accepted : true ,
1466+ } ) ;
1467+
1468+ const teamEventType = await eventTypesRepositoryFixture . createTeamEventType ( {
1469+ title : `event-types-2024-06-14-host-event-${ randomString ( ) } ` ,
1470+ slug : `event-types-2024-06-14-host-event-${ randomString ( ) } ` ,
1471+ length : 60 ,
1472+ locations : [ ] ,
1473+ schedulingType : "COLLECTIVE" ,
1474+ team : { connect : { id : team . id } } ,
1475+ hosts : {
1476+ create : [
1477+ {
1478+ user : { connect : { id : user . id } } ,
1479+ } ,
1480+ ] ,
1481+ } ,
1482+ } ) ;
1483+
1484+ return request ( app . getHttpServer ( ) )
1485+ . get ( `/api/v2/event-types/${ teamEventType . id } ` )
1486+ . set ( CAL_API_VERSION_HEADER , VERSION_2024_06_14 )
1487+ . set ( "Authorization" , `Bearer ${ apiKeyString } ` )
1488+ . expect ( 200 )
1489+ . then ( async ( response ) => {
1490+ const responseBody : ApiSuccessResponse < TeamEventTypeOutput_2024_06_14 > = response . body ;
1491+ expect ( responseBody . status ) . toEqual ( SUCCESS_STATUS ) ;
1492+ expect ( responseBody . data . id ) . toEqual ( teamEventType . id ) ;
1493+ expect ( responseBody . data . teamId ) . toEqual ( team . id ) ;
1494+ await teamRepositoryFixture . delete ( team . id ) ;
1495+ } ) ;
1496+ } ) ;
1497+
13781498 it ( `/GET/event-types by username and eventSlug` , async ( ) => {
13791499 const response = await request ( app . getHttpServer ( ) )
13801500 . get ( `/api/v2/event-types?username=${ username } &eventSlug=${ eventType . slug } ` )
@@ -1780,7 +1900,7 @@ describe("Event types Endpoints", () => {
17801900 . then ( async ( response ) => {
17811901 const responseBody : ApiSuccessResponse < EventTypeOutput_2024_06_14 > = response . body ;
17821902 const updatedEventType = responseBody . data ;
1783- const policy = updatedEventType . confirmationPolicy as any ;
1903+ const policy = updatedEventType . confirmationPolicy as BaseConfirmationPolicy_2024_06_14 ;
17841904 expect ( policy ?. type ) . toEqual ( ConfirmationPolicyEnum . ALWAYS ) ;
17851905 expect ( policy ?. blockUnconfirmedBookingsInBooker ) . toEqual ( false ) ;
17861906 expect ( policy ?. noticeThreshold ) . toBeUndefined ( ) ;
@@ -1808,7 +1928,7 @@ describe("Event types Endpoints", () => {
18081928 . then ( async ( response ) => {
18091929 const responseBody : ApiSuccessResponse < EventTypeOutput_2024_06_14 > = response . body ;
18101930 const updatedEventType = responseBody . data ;
1811- const policy = updatedEventType . confirmationPolicy as any ;
1931+ const policy = updatedEventType . confirmationPolicy as BaseConfirmationPolicy_2024_06_14 ;
18121932 expect ( policy ?. type ) . toEqual ( ConfirmationPolicyEnum . TIME ) ;
18131933 expect ( policy ?. noticeThreshold ) . toEqual ( {
18141934 unit : NoticeThresholdUnitEnum . MINUTES ,
@@ -2793,4 +2913,4 @@ describe("Event types Endpoints", () => {
27932913 await app . close ( ) ;
27942914 } ) ;
27952915 } ) ;
2796- } ) ;
2916+ } ) ;
0 commit comments