@@ -17,6 +17,7 @@ import { MembershipRole, SchedulingType, TimeUnit, WorkflowTriggerEvents } from
1717import { teamMetadataSchema } from "@calcom/prisma/zod-utils" ;
1818import type { Schedule } from "@calcom/types/schedule" ;
1919
20+ import { createRoutingForm } from "../lib/test-helpers/routingFormHelpers" ;
2021import { selectFirstAvailableTimeSlotNextMonth , teamEventSlug , teamEventTitle } from "../lib/testUtils" ;
2122import type { createEmailsFixture } from "./emails" ;
2223import { TimeZoneEnum } from "./types" ;
@@ -274,6 +275,7 @@ export const createUsersFixture = (
274275 | null ,
275276 scenario : {
276277 seedRoutingForms ?: boolean ;
278+ seedRoutingFormWithAttributeRouting ?: boolean ;
277279 hasTeam ?: true ;
278280 numberOfTeams ?: number ;
279281 teamRole ?: MembershipRole ;
@@ -341,192 +343,6 @@ export const createUsersFixture = (
341343 } ) ;
342344 }
343345
344- if ( scenario . seedRoutingForms ) {
345- const multiSelectOption2Uuid = "d1302635-9f12-17b1-9153-c3a854649182" ;
346- const multiSelectOption1Uuid = "d1292635-9f12-17b1-9153-c3a854649182" ;
347- const selectOption1Uuid = "d0292635-9f12-17b1-9153-c3a854649182" ;
348- const selectOption2Uuid = "d0302635-9f12-17b1-9153-c3a854649182" ;
349- const multiSelectLegacyFieldUuid = "d4292635-9f12-17b1-9153-c3a854649182" ;
350- const multiSelectFieldUuid = "d9892635-9f12-17b1-9153-c3a854649182" ;
351- const selectFieldUuid = "d1302635-9f12-17b1-9153-c3a854649182" ;
352- const legacySelectFieldUuid = "f0292635-9f12-17b1-9153-c3a854649182" ;
353- await prisma . app_RoutingForms_Form . create ( {
354- data : {
355- routes : [
356- {
357- id : "8a898988-89ab-4cde-b012-31823f708642" ,
358- action : { type : "eventTypeRedirectUrl" , value : "pro/30min" } ,
359- queryValue : {
360- id : "8a898988-89ab-4cde-b012-31823f708642" ,
361- type : "group" ,
362- children1 : {
363- "8988bbb8-0123-4456-b89a-b1823f70c5ff" : {
364- type : "rule" ,
365- properties : {
366- field : "c4296635-9f12-47b1-8153-c3a854649182" ,
367- value : [ "event-routing" ] ,
368- operator : "equal" ,
369- valueSrc : [ "value" ] ,
370- valueType : [ "text" ] ,
371- } ,
372- } ,
373- } ,
374- } ,
375- } ,
376- {
377- id : "aa8aaba9-cdef-4012-b456-71823f70f7ef" ,
378- action : { type : "customPageMessage" , value : "Custom Page Result" } ,
379- queryValue : {
380- id : "aa8aaba9-cdef-4012-b456-71823f70f7ef" ,
381- type : "group" ,
382- children1 : {
383- "b99b8a89-89ab-4cde-b012-31823f718ff5" : {
384- type : "rule" ,
385- properties : {
386- field : "c4296635-9f12-47b1-8153-c3a854649182" ,
387- value : [ "custom-page" ] ,
388- operator : "equal" ,
389- valueSrc : [ "value" ] ,
390- valueType : [ "text" ] ,
391- } ,
392- } ,
393- } ,
394- } ,
395- } ,
396- {
397- id : "a8ba9aab-4567-489a-bcde-f1823f71b4ad" ,
398- action : { type : "externalRedirectUrl" , value : `${ WEBAPP_URL } /pro` } ,
399- queryValue : {
400- id : "a8ba9aab-4567-489a-bcde-f1823f71b4ad" ,
401- type : "group" ,
402- children1 : {
403- "998b9b9a-0123-4456-b89a-b1823f7232b9" : {
404- type : "rule" ,
405- properties : {
406- field : "c4296635-9f12-47b1-8153-c3a854649182" ,
407- value : [ "external-redirect" ] ,
408- operator : "equal" ,
409- valueSrc : [ "value" ] ,
410- valueType : [ "text" ] ,
411- } ,
412- } ,
413- } ,
414- } ,
415- } ,
416- {
417- id : "aa8ba8b9-0123-4456-b89a-b182623406d8" ,
418- action : { type : "customPageMessage" , value : "Multiselect(Legacy) chosen" } ,
419- queryValue : {
420- id : "aa8ba8b9-0123-4456-b89a-b182623406d8" ,
421- type : "group" ,
422- children1 : {
423- "b98a8abb-cdef-4012-b456-718262343d27" : {
424- type : "rule" ,
425- properties : {
426- field : multiSelectLegacyFieldUuid ,
427- value : [ [ "Option-2" ] ] ,
428- operator : "multiselect_equals" ,
429- valueSrc : [ "value" ] ,
430- valueType : [ "multiselect" ] ,
431- } ,
432- } ,
433- } ,
434- } ,
435- } ,
436- {
437- id : "bb9ea8b9-0123-4456-b89a-b182623406d8" ,
438- action : { type : "customPageMessage" , value : "Multiselect chosen" } ,
439- queryValue : {
440- id : "aa8ba8b9-0123-4456-b89a-b182623406d8" ,
441- type : "group" ,
442- children1 : {
443- "b98a8abb-cdef-4012-b456-718262343d27" : {
444- type : "rule" ,
445- properties : {
446- field : multiSelectFieldUuid ,
447- value : [ [ multiSelectOption2Uuid ] ] ,
448- operator : "multiselect_equals" ,
449- valueSrc : [ "value" ] ,
450- valueType : [ "multiselect" ] ,
451- } ,
452- } ,
453- } ,
454- } ,
455- } ,
456- {
457- id : "898899aa-4567-489a-bcde-f1823f708646" ,
458- action : { type : "customPageMessage" , value : "Fallback Message" } ,
459- isFallback : true ,
460- queryValue : { id : "898899aa-4567-489a-bcde-f1823f708646" , type : "group" } ,
461- } ,
462- ] ,
463- fields : [
464- {
465- id : "c4296635-9f12-47b1-8153-c3a854649182" ,
466- type : "text" ,
467- label : "Test field" ,
468- required : true ,
469- } ,
470- {
471- id : multiSelectLegacyFieldUuid ,
472- type : "multiselect" ,
473- label : "Multi Select(with Legacy `selectText`)" ,
474- identifier : "multi" ,
475- selectText : "Option-1\nOption-2" ,
476- required : false ,
477- } ,
478- {
479- id : multiSelectFieldUuid ,
480- type : "multiselect" ,
481- label : "Multi Select" ,
482- identifier : "multi-new-format" ,
483- options : [
484- {
485- id : multiSelectOption1Uuid ,
486- label : "Option-1" ,
487- } ,
488- {
489- id : multiSelectOption2Uuid ,
490- label : "Option-2" ,
491- } ,
492- ] ,
493- required : false ,
494- } ,
495- {
496- id : legacySelectFieldUuid ,
497- type : "select" ,
498- label : "Legacy Select" ,
499- identifier : "test-select" ,
500- selectText : "Option-1\nOption-2" ,
501- required : false ,
502- } ,
503- {
504- id : selectFieldUuid ,
505- type : "select" ,
506- label : "Select" ,
507- identifier : "test-select-new-format" ,
508- options : [
509- {
510- id : selectOption1Uuid ,
511- label : "Option-1" ,
512- } ,
513- {
514- id : selectOption2Uuid ,
515- label : "Option-2" ,
516- } ,
517- ] ,
518- required : false ,
519- } ,
520- ] ,
521- user : {
522- connect : {
523- id : _user . id ,
524- } ,
525- } ,
526- name : seededForm . name ,
527- } ,
528- } ) ;
529- }
530346 const user = await prisma . user . findUniqueOrThrow ( {
531347 where : { id : _user . id } ,
532348 include : userIncludes ,
@@ -664,7 +480,94 @@ export const createUsersFixture = (
664480 }
665481 }
666482 }
667- const userFixture = createUserFixture ( user , store . page ) ;
483+
484+ if ( scenario . seedRoutingForms ) {
485+ const firstTeamMembership = await prisma . membership . findFirstOrThrow ( {
486+ where : {
487+ userId : _user . id ,
488+ team : {
489+ isOrganization : false ,
490+ } ,
491+ } ,
492+ } ) ;
493+ if ( ! firstTeamMembership ) {
494+ throw new Error ( "No sub-team created" ) ;
495+ }
496+ await createRoutingForm ( {
497+ userId : _user . id ,
498+ teamId : firstTeamMembership . teamId ,
499+ formType : scenario . seedRoutingFormWithAttributeRouting ? "attributeRouting" : "default" ,
500+ ...( scenario . seedRoutingFormWithAttributeRouting && {
501+ attributeRouting : {
502+ attributes : [
503+ {
504+ name : "Department" ,
505+ type : "SINGLE_SELECT" as const ,
506+ options : [ "Engineering" , "Sales" , "Marketing" , "Product" , "Design" ] ,
507+ } ,
508+ {
509+ name : "Location" ,
510+ type : "SINGLE_SELECT" as const ,
511+ options : [ "New York" , "London" , "Tokyo" , "Berlin" , "Remote" ] ,
512+ } ,
513+ {
514+ name : "Skills" ,
515+ type : "MULTI_SELECT" as const ,
516+ options : [ "JavaScript" , "React" , "Node.js" , "Python" , "Design" , "Sales" ] ,
517+ } ,
518+ {
519+ name : "Years of Experience" ,
520+ type : "NUMBER" as const ,
521+ } ,
522+ {
523+ name : "Bio" ,
524+ type : "TEXT" as const ,
525+ } ,
526+ ] ,
527+ assignments : [
528+ {
529+ memberIndex : 0 ,
530+ attributeValues : {
531+ Location : [ "New York" ] ,
532+ Skills : [ "JavaScript" ] ,
533+ } ,
534+ } ,
535+ {
536+ memberIndex : 1 ,
537+ attributeValues : {
538+ Location : [ "London" ] ,
539+ Skills : [ "React" , "JavaScript" ] ,
540+ } ,
541+ } ,
542+ ] ,
543+ teamEvents : [
544+ {
545+ title : "Team Sales" ,
546+ slug : "team-sales" ,
547+ schedulingType : "ROUND_ROBIN" ,
548+ assignAllTeamMembers : true ,
549+ length : 60 ,
550+ description : "Team Sales" ,
551+ } ,
552+ {
553+ title : "Team Javascript" ,
554+ slug : "team-javascript" ,
555+ schedulingType : "ROUND_ROBIN" ,
556+ assignAllTeamMembers : true ,
557+ length : 60 ,
558+ description : "Team Javascript" ,
559+ } ,
560+ ] ,
561+ } ,
562+ } ) ,
563+ } ) ;
564+ }
565+
566+ const finalUser = await prisma . user . findUniqueOrThrow ( {
567+ where : { id : user . id } ,
568+ include : userIncludes ,
569+ } ) ;
570+ const userFixture = createUserFixture ( finalUser , store . page ) ;
668571 store . users . push ( userFixture ) ;
669572 return userFixture ;
670573 } ,
@@ -781,7 +684,7 @@ const createUserFixture = (user: UserWithIncludes, page: Page) => {
781684 getFirstTeamMembership : async ( ) => {
782685 const memberships = await prisma . membership . findMany ( {
783686 where : { userId : user . id } ,
784- include : { team : true } ,
687+ include : { team : true , user : true } ,
785688 } ) ;
786689
787690 const membership = memberships
0 commit comments