@@ -705,24 +705,129 @@ describe("OAuth Client Users Endpoints", () => {
705705 . expect ( 200 ) ;
706706 } ) ;
707707
708+ describe ( "managed user time zone" , ( ) => {
709+ describe ( "negative tests" , ( ) => {
710+ it ( "should not allow '' time zone" , async ( ) => {
711+ const requestBody = {
712+ email : "whatever2@gmail.com" ,
713+ timeZone : "" ,
714+ name : "Bob Smithson" ,
715+ } ;
716+
717+ await request ( app . getHttpServer ( ) )
718+ . post ( `/api/v2/oauth-clients/${ oAuthClient . id } /users` )
719+ . set ( "x-cal-secret-key" , oAuthClient . secret )
720+ . send ( requestBody )
721+ . expect ( 400 ) ;
722+ } ) ;
723+
724+ it ( "should not allow 'invalid-timezone' time zone" , async ( ) => {
725+ const requestBody = {
726+ email : "whatever2@gmail.com" ,
727+ timeZone : "invalid-timezone" ,
728+ name : "Bob Smithson" ,
729+ } ;
730+
731+ await request ( app . getHttpServer ( ) )
732+ . post ( `/api/v2/oauth-clients/${ oAuthClient . id } /users` )
733+ . set ( "x-cal-secret-key" , oAuthClient . secret )
734+ . send ( requestBody )
735+ . expect ( 400 ) ;
736+ } ) ;
737+ } ) ;
738+
739+ describe ( "positive tests" , ( ) => {
740+ it ( "should allow null timezone" , async ( ) => {
741+ const requestBody = {
742+ email : "whatever1@gmail.com" ,
743+ timeZone : null ,
744+ name : "Bob Smithson" ,
745+ } ;
746+
747+ const response = await request ( app . getHttpServer ( ) )
748+ . post ( `/api/v2/oauth-clients/${ oAuthClient . id } /users` )
749+ . set ( "x-cal-secret-key" , oAuthClient . secret )
750+ . send ( requestBody )
751+ . expect ( 201 ) ;
752+
753+ const responseBody : CreateManagedUserOutput = response . body ;
754+ expect ( responseBody . data . user . timeZone ) . toEqual ( "Europe/London" ) ;
755+ await userRepositoryFixture . delete ( responseBody . data . user . id ) ;
756+ } ) ;
757+
758+ it ( "should allow undefined time zone" , async ( ) => {
759+ const requestBody = {
760+ email : "whatever3@gmail.com" ,
761+ timeZone : undefined ,
762+ name : "Bob Smithson" ,
763+ } ;
764+
765+ const response = await request ( app . getHttpServer ( ) )
766+ . post ( `/api/v2/oauth-clients/${ oAuthClient . id } /users` )
767+ . set ( "x-cal-secret-key" , oAuthClient . secret )
768+ . send ( requestBody )
769+ . expect ( 201 ) ;
770+
771+ const responseBody : CreateManagedUserOutput = response . body ;
772+ expect ( responseBody . data . user . timeZone ) . toEqual ( "Europe/London" ) ;
773+ await userRepositoryFixture . delete ( responseBody . data . user . id ) ;
774+ } ) ;
775+
776+ it ( "should allow valid time zone" , async ( ) => {
777+ const requestBody = {
778+ email : "whatever4@gmail.com" ,
779+ timeZone : "Europe/Rome" ,
780+ name : "Bob Smithson" ,
781+ } ;
782+
783+ const response = await request ( app . getHttpServer ( ) )
784+ . post ( `/api/v2/oauth-clients/${ oAuthClient . id } /users` )
785+ . set ( "x-cal-secret-key" , oAuthClient . secret )
786+ . send ( requestBody )
787+ . expect ( 201 ) ;
788+
789+ const responseBody : CreateManagedUserOutput = response . body ;
790+ expect ( responseBody . data . user . timeZone ) . toBe ( "Europe/Rome" ) ;
791+ await userRepositoryFixture . delete ( responseBody . data . user . id ) ;
792+ } ) ;
793+
794+ it ( "should allow without any time zone" , async ( ) => {
795+ const requestBody = {
796+ email : "whatever5@gmail.com" ,
797+ name : "Bob Smithson" ,
798+ } ;
799+
800+ const response = await request ( app . getHttpServer ( ) )
801+ . post ( `/api/v2/oauth-clients/${ oAuthClient . id } /users` )
802+ . set ( "x-cal-secret-key" , oAuthClient . secret )
803+ . send ( requestBody )
804+ . expect ( 201 ) ;
805+
806+ const responseBody : CreateManagedUserOutput = response . body ;
807+ expect ( responseBody . data . user . timeZone ) . toEqual ( "Europe/London" ) ;
808+ await userRepositoryFixture . delete ( responseBody . data . user . id ) ;
809+ } ) ;
810+ } ) ;
811+ } ) ;
812+
708813 afterAll ( async ( ) => {
709814 await oauthClientRepositoryFixture . delete ( oAuthClient . id ) ;
710815 await oauthClientRepositoryFixture . delete ( oAuthClientEventTypesDisabled . id ) ;
711816 await teamRepositoryFixture . delete ( organization . id ) ;
712817 try {
713818 await userRepositoryFixture . delete ( postResponseData . user . id ) ;
714819 } catch ( e ) {
715- // User might have been deleted by the test
820+ console . log ( e ) ;
716821 }
717822 try {
718823 await userRepositoryFixture . delete ( postResponseData2 . user . id ) ;
719824 } catch ( e ) {
720- // User might have been deleted by the test
825+ console . log ( e ) ;
721826 }
722827 try {
723828 await userRepositoryFixture . delete ( platformAdmin . id ) ;
724829 } catch ( e ) {
725- // User might have been deleted by the test
830+ console . log ( e ) ;
726831 }
727832 await app . close ( ) ;
728833 } ) ;
@@ -931,7 +1036,7 @@ describe("OAuth Client Users Endpoints", () => {
9311036 try {
9321037 await userRepositoryFixture . delete ( postResponseData . user . id ) ;
9331038 } catch ( e ) {
934- // User might have been deleted by the test
1039+ console . log ( e ) ;
9351040 }
9361041 await app . close ( ) ;
9371042 } ) ;
0 commit comments