@@ -3,12 +3,18 @@ import { Request, Response } from 'express';
3
3
4
4
import { AuthController } from './auth.controller' ;
5
5
import { AuthService } from './auth.service' ;
6
+ import { MagicLinkEmailStrategy } from './strategies/magicLinkEmail.strategy' ;
6
7
7
8
const mockAuthService = {
8
9
githubLogin : jest . fn ( ) ,
9
10
googleLogin : jest . fn ( ) ,
10
11
discordLogin : jest . fn ( ) ,
11
12
verifyToken : jest . fn ( ) ,
13
+ loginWithEmail : jest . fn ( ) ,
14
+ } ;
15
+
16
+ const mockMagicLinkEmailStrategy = {
17
+ send : jest . fn ( ) ,
12
18
} ;
13
19
14
20
describe ( 'AuthController' , ( ) => {
@@ -23,6 +29,10 @@ describe('AuthController', () => {
23
29
provide : AuthService ,
24
30
useValue : mockAuthService ,
25
31
} ,
32
+ {
33
+ provide : MagicLinkEmailStrategy ,
34
+ useValue : mockMagicLinkEmailStrategy ,
35
+ } ,
26
36
] ,
27
37
} ) . compile ( ) ;
28
38
@@ -56,6 +66,13 @@ describe('AuthController', () => {
56
66
} ) ;
57
67
} ) ;
58
68
69
+ describe ( 'githubLogin' , ( ) => {
70
+ it ( 'should call AuthService.githubLogin' , async ( ) => {
71
+ await controller . githubLogin ( ) ;
72
+ expect ( authService . githubLogin ) . toHaveBeenCalled ( ) ;
73
+ } ) ;
74
+ } ) ;
75
+
59
76
describe ( 'googleRedirect' , ( ) => {
60
77
it ( 'should call AuthService.googleLogin' , async ( ) => {
61
78
const req = { } as Request ;
@@ -78,6 +95,13 @@ describe('AuthController', () => {
78
95
} ) ;
79
96
} ) ;
80
97
98
+ describe ( 'googleLogin' , ( ) => {
99
+ it ( 'should call AuthService.googleLogin' , async ( ) => {
100
+ await controller . googleLogin ( ) ;
101
+ expect ( authService . googleLogin ) . toHaveBeenCalled ( ) ;
102
+ } ) ;
103
+ } ) ;
104
+
81
105
describe ( 'discordRedirect' , ( ) => {
82
106
it ( 'should call AuthService.discordLogin' , async ( ) => {
83
107
const req = { } as Request ;
@@ -100,6 +124,46 @@ describe('AuthController', () => {
100
124
} ) ;
101
125
} ) ;
102
126
127
+ describe ( 'discordLogin' , ( ) => {
128
+ it ( 'should call AuthService.discordLogin' , async ( ) => {
129
+ await controller . discordLogin ( ) ;
130
+ expect ( authService . discordLogin ) . toHaveBeenCalled ( ) ;
131
+ } ) ;
132
+ } ) ;
133
+
134
+ describe ( 'magicLinkRedirect' , ( ) => {
135
+ it ( 'should call AuthService.loginWithEmail' , async ( ) => {
136
+ const req = { } as Request ;
137
+ const res = { } as Response ;
138
+
139
+ await controller . magicLinkRedirect ( req , res ) ;
140
+
141
+ expect ( authService . loginWithEmail ) . toHaveBeenCalledWith ( req , res ) ;
142
+ } ) ;
143
+
144
+ it ( 'should handle exceptions' , async ( ) => {
145
+ const req = { } as Request ;
146
+ const res = { } as Response ;
147
+ const error = new Error ( 'Test error' ) ;
148
+ ( authService . loginWithEmail as jest . Mock ) . mockRejectedValueOnce ( error ) ;
149
+
150
+ await expect ( controller . magicLinkRedirect ( req , res ) ) . rejects . toThrow (
151
+ 'Test error' ,
152
+ ) ;
153
+ } ) ;
154
+ } ) ;
155
+
156
+ describe ( 'magicLinkLogin' , ( ) => {
157
+ it ( 'should call AuthService.discordLogin' , async ( ) => {
158
+ const req = { } as Request ;
159
+ const res = { } as Response ;
160
+
161
+ await controller . magicLinkLogin ( req , res ) ;
162
+
163
+ expect ( mockMagicLinkEmailStrategy . send ) . toHaveBeenCalledWith ( req , res ) ;
164
+ } ) ;
165
+ } ) ;
166
+
103
167
describe ( 'verify' , ( ) => {
104
168
it ( 'should call AuthService.verifyToken' , async ( ) => {
105
169
const req = { } as Request ;
0 commit comments