@@ -4,6 +4,7 @@ import { DemoService } from '../demo/demo.service';
4
4
import { AuthController } from './auth.controller' ;
5
5
import { AuthService } from './auth.service' ;
6
6
import { UserRegisterDto } from './dto/user-register.dto' ;
7
+ import { AuthEmailsService } from '../auth-emails/auth-emails.service' ;
7
8
8
9
describe ( 'AuthController' , ( ) => {
9
10
let controller : AuthController ;
@@ -23,15 +24,23 @@ describe('AuthController', () => {
23
24
} ) ,
24
25
} ;
25
26
27
+ const mockAuthEmailService = {
28
+ sendEmailConfirmation : jest . fn ( ( ) => Promise . resolve ( ) ) ,
29
+ } ;
30
+
31
+ const sendEmailConfirmationSpy = jest . spyOn ( mockAuthEmailService , 'sendEmailConfirmation' ) ;
32
+
26
33
beforeEach ( async ( ) => {
27
34
const module : TestingModule = await Test . createTestingModule ( {
28
35
controllers : [ AuthController ] ,
29
- providers : [ AuthService , DemoService ] ,
36
+ providers : [ AuthService , DemoService , AuthEmailsService ] ,
30
37
} )
31
38
. overrideProvider ( AuthService )
32
39
. useValue ( mockAuthService )
33
40
. overrideProvider ( DemoService )
34
41
. useValue ( mockDemoService )
42
+ . overrideProvider ( AuthEmailsService )
43
+ . useValue ( mockAuthEmailService )
35
44
. compile ( ) ;
36
45
37
46
controller = module . get < AuthController > ( AuthController ) ;
@@ -41,14 +50,20 @@ describe('AuthController', () => {
41
50
expect ( controller ) . toBeDefined ( ) ;
42
51
} ) ;
43
52
44
- it ( 'should register' , ( ) => {
45
- expect (
46
- controller . register ( { email :
'[email protected] ' , username :
'test' , password :
'test' } ) ,
47
- ) . resolves . toEqual (
53
+ it ( 'should register' , async ( ) => {
54
+ const user = await controller . register ( {
55
+
56
+ username : 'test' ,
57
+ password : 'test' ,
58
+ } ) ;
59
+ expect ( user ) . toEqual (
48
60
expect . objectContaining ( {
49
61
50
62
} ) ,
51
63
) ;
64
+
65
+ expect ( sendEmailConfirmationSpy ) . toBeCalledTimes ( 1 ) ;
66
+ expect ( sendEmailConfirmationSpy ) . toBeCalledWith ( user . id ) ;
52
67
} ) ;
53
68
54
69
it ( 'should create demo account' , async ( ) => {
0 commit comments