11import { faker } from "@faker-js/faker" ;
22import { randomUUID } from "node:crypto" ;
3- import WelcomeEmail from "@server/emails/templates/WelcomeEmail" ;
43import { TeamDomain } from "@server/models" ;
54import Collection from "@server/models/Collection" ;
65import UserAuthentication from "@server/models/UserAuthentication" ;
@@ -15,7 +14,6 @@ describe("accountProvisioner", () => {
1514
1615 describe ( "hosted" , ( ) => {
1716 it ( "should create a new user and team" , async ( ) => {
18- const spy = jest . spyOn ( WelcomeEmail . prototype , "schedule" ) ;
1917 const email = faker . internet . email ( ) ;
2018 const { user, team, isNewTeam, isNewUser } = await accountProvisioner (
2119 ctx ,
@@ -50,19 +48,15 @@ describe("accountProvisioner", () => {
5048 expect ( user . email ) . toEqual ( email ) ;
5149 expect ( isNewUser ) . toEqual ( true ) ;
5250 expect ( isNewTeam ) . toEqual ( true ) ;
53- expect ( spy ) . toHaveBeenCalled ( ) ;
5451 const collectionCount = await Collection . count ( {
5552 where : {
5653 teamId : team . id ,
5754 } ,
5855 } ) ;
5956 expect ( collectionCount ) . toEqual ( 1 ) ;
60-
61- spy . mockRestore ( ) ;
6257 } ) ;
6358
64- it ( "should update exising user and authentication" , async ( ) => {
65- const spy = jest . spyOn ( WelcomeEmail . prototype , "schedule" ) ;
59+ it ( "should update existing user and authentication" , async ( ) => {
6660 const existingTeam = await buildTeam ( ) ;
6761 const providers = await existingTeam . $get ( "authenticationProviders" ) ;
6862 const authenticationProvider = providers [ 0 ] ;
@@ -100,9 +94,6 @@ describe("accountProvisioner", () => {
10094 expect ( user . email ) . toEqual ( newEmail ) ;
10195 expect ( isNewTeam ) . toEqual ( false ) ;
10296 expect ( isNewUser ) . toEqual ( false ) ;
103- expect ( spy ) . not . toHaveBeenCalled ( ) ;
104-
105- spy . mockRestore ( ) ;
10697 } ) ;
10798
10899 it ( "should allow authentication by email matching" , async ( ) => {
@@ -283,7 +274,6 @@ describe("accountProvisioner", () => {
283274 } ) ;
284275
285276 it ( "should create a new user in an existing team when the domain is allowed" , async ( ) => {
286- const spy = jest . spyOn ( WelcomeEmail . prototype , "schedule" ) ;
287277 const team = await buildTeam ( ) ;
288278 const admin = await buildAdmin ( { teamId : team . id } ) ;
289279 const authenticationProviders = await team . $get (
@@ -324,20 +314,16 @@ describe("accountProvisioner", () => {
324314 expect ( auth . scopes [ 0 ] ) . toEqual ( "read" ) ;
325315 expect ( user . email ) . toEqual ( email ) ;
326316 expect ( isNewUser ) . toEqual ( true ) ;
327- expect ( spy ) . toHaveBeenCalled ( ) ;
328317 // should provision welcome collection
329318 const collectionCount = await Collection . count ( {
330319 where : {
331320 teamId : team . id ,
332321 } ,
333322 } ) ;
334323 expect ( collectionCount ) . toEqual ( 1 ) ;
335-
336- spy . mockRestore ( ) ;
337324 } ) ;
338325
339326 it ( "should create a new user in an existing team" , async ( ) => {
340- const spy = jest . spyOn ( WelcomeEmail . prototype , "schedule" ) ;
341327 const team = await buildTeam ( ) ;
342328 const authenticationProviders = await team . $get (
343329 "authenticationProviders"
@@ -372,20 +358,16 @@ describe("accountProvisioner", () => {
372358 expect ( auth . scopes [ 0 ] ) . toEqual ( "read" ) ;
373359 expect ( user . email ) . toEqual ( email ) ;
374360 expect ( isNewUser ) . toEqual ( true ) ;
375- expect ( spy ) . toHaveBeenCalled ( ) ;
376361 // should provision welcome collection
377362 const collectionCount = await Collection . count ( {
378363 where : {
379364 teamId : team . id ,
380365 } ,
381366 } ) ;
382367 expect ( collectionCount ) . toEqual ( 1 ) ;
383-
384- spy . mockRestore ( ) ;
385368 } ) ;
386369
387370 it ( "should handle emails with capital letters correctly" , async ( ) => {
388- const spy = jest . spyOn ( WelcomeEmail . prototype , "schedule" ) ;
389371 const email = "Jenny.Tester@EXAMPLE.COM" ;
390372
391373 const params = {
@@ -418,7 +400,6 @@ describe("accountProvisioner", () => {
418400 expect ( user . email ) . toEqual ( email ) ;
419401 expect ( isNewUser ) . toEqual ( true ) ;
420402 expect ( isNewTeam ) . toEqual ( true ) ;
421- expect ( spy ) . toHaveBeenCalled ( ) ;
422403
423404 // Test that we can find the user again
424405 const existing = await accountProvisioner ( ctx , params ) ;
@@ -427,8 +408,6 @@ describe("accountProvisioner", () => {
427408 expect ( existing . isNewTeam ) . toEqual ( false ) ;
428409 expect ( existing . isNewUser ) . toEqual ( false ) ;
429410 expect ( existing . user . id ) . toEqual ( user . id ) ;
430-
431- spy . mockRestore ( ) ;
432411 } ) ;
433412
434413 it ( "should allow connecting a new authentication provider while logged in" , async ( ) => {
0 commit comments