11import { describe , it , expect } from "vitest" ;
22
33import prisma from "@calcom/prisma" ;
4- import { SchedulingType } from "@calcom/prisma/enums" ;
54import type { TrpcSessionUser } from "@calcom/trpc/server/types" ;
65
76import { getEventTypesFromGroup } from "./getEventTypesFromGroup.handler" ;
@@ -10,13 +9,6 @@ describe("getEventTypesFromGroup", async () => {
109 const proUser = await prisma . user . findFirstOrThrow ( { where : { email : "pro@example.com" } } ) ;
1110 const proUserEventTypes = await prisma . eventType . findMany ( { where : { userId : proUser . id } } ) ;
1211
13- const teamProUser = await prisma . user . findFirstOrThrow ( { where : { email : "teampro@example.com" } } ) ;
14- const teamProMembership = await prisma . membership . findFirstOrThrow ( {
15- where : { userId : teamProUser . id , accepted : true } ,
16- } ) ;
17-
18- const teamId = teamProMembership . teamId ;
19-
2012 const proUserCtx = {
2113 user : {
2214 id : proUser . id ,
@@ -33,63 +25,6 @@ describe("getEventTypesFromGroup", async () => {
3325 prisma,
3426 } ;
3527
36- const teamProUserCtx = {
37- user : {
38- id : teamProUser . id ,
39- name : teamProUser . name ,
40- profile : {
41- name : teamProUser . name ,
42- organizationId : null ,
43- organization : null ,
44- username : teamProUser . username ,
45- id : null ,
46- upId : "usr-9" ,
47- } ,
48- } as NonNullable < TrpcSessionUser > ,
49- prisma,
50- } ;
51-
52- const createManagedEventTypes = async ( ) => {
53- const childEventType = await prisma . eventType . create ( {
54- data : {
55- title : "Child Event Type" ,
56- slug : "managed-event-type" ,
57- schedulingType : null ,
58- length : 30 ,
59- userId : teamProUser . id ,
60- } ,
61- } ) ;
62-
63- const parentEventType = await prisma . eventType . create ( {
64- data : {
65- title : "Managed Event Type" ,
66- slug : "managed-event-type" ,
67- schedulingType : SchedulingType . MANAGED ,
68- length : 30 ,
69- teamId,
70- } ,
71- } ) ;
72-
73- // Connect child event type to parent event type
74- await prisma . eventType . update ( {
75- where : {
76- id : childEventType . id ,
77- } ,
78- data : {
79- parent : {
80- connect : {
81- id : parentEventType . id ,
82- } ,
83- } ,
84- } ,
85- } ) ;
86-
87- return {
88- parentEventType,
89- childEventType,
90- } ;
91- } ;
92-
9328 it ( "should return personal event types for a user" , async ( ) => {
9429 const ctx = proUserCtx ;
9530
@@ -113,65 +48,4 @@ describe("getEventTypesFromGroup", async () => {
11348 expect ( resEventTypeIds ) . toEqual ( expect . arrayContaining ( proUserEventTypeIds ) ) ;
11449 expect ( resEventTypeIds . length ) . toBe ( proUserEventTypeIds . length ) ;
11550 } ) ;
116-
117- it ( "should return team event types for a user" , async ( ) => {
118- const response = await getEventTypesFromGroup ( {
119- ctx : teamProUserCtx ,
120- input : {
121- group : {
122- teamId,
123- parentId : null ,
124- } ,
125- limit : 10 ,
126- cursor : null ,
127- } ,
128- } ) ;
129-
130- const resEventTypeIds = response . eventTypes . map ( ( et ) => et . id ) ;
131-
132- const seededTeamEventTypes = await prisma . eventType . findMany ( { where : { teamId } } ) ;
133- const teamProUserEventTypeIds = seededTeamEventTypes . map ( ( et ) => et . id ) ;
134-
135- expect ( response . eventTypes ) . toBeDefined ( ) ;
136- expect ( response . eventTypes . length ) . toBeGreaterThan ( 0 ) ;
137- expect ( resEventTypeIds ) . toEqual ( expect . arrayContaining ( teamProUserEventTypeIds ) ) ;
138- expect ( resEventTypeIds . length ) . toBe ( teamProUserEventTypeIds . length ) ;
139- } ) ;
140-
141- it ( "should return managed event types event types" , async ( ) => {
142- const { parentEventType, childEventType } = await createManagedEventTypes ( ) ;
143-
144- const res = await getEventTypesFromGroup ( {
145- ctx : teamProUserCtx ,
146- input : {
147- group : {
148- teamId : null ,
149- parentId : null ,
150- } ,
151- limit : 10 ,
152- cursor : null ,
153- } ,
154- } ) ;
155-
156- const resEventTypeIds = res . eventTypes . map ( ( et ) => et . id ) ;
157-
158- const managedEventType = await prisma . eventType . findFirstOrThrow ( {
159- where : {
160- parentId : {
161- not : null ,
162- } ,
163- schedulingType : null ,
164- userId : teamProUser . id ,
165- } ,
166- } ) ;
167-
168- expect ( res . eventTypes ) . toBeDefined ( ) ;
169- expect ( resEventTypeIds ) . toContain ( managedEventType . id ) ;
170-
171- await deleteEventTypes ( { ids : [ parentEventType . id , childEventType . id ] } ) ;
172- } ) ;
17351} ) ;
174-
175- const deleteEventTypes = async ( { ids } : { ids : number [ ] } ) => {
176- await prisma . eventType . deleteMany ( { where : { id : { in : ids } } } ) ;
177- } ;
0 commit comments