@@ -3,12 +3,18 @@ import { Request, Response } from 'express';
33
44import { AuthController } from './auth.controller' ;
55import { AuthService } from './auth.service' ;
6+ import { MagicLinkEmailStrategy } from './strategies/magicLinkEmail.strategy' ;
67
78const mockAuthService = {
89 githubLogin : jest . fn ( ) ,
910 googleLogin : jest . fn ( ) ,
1011 discordLogin : jest . fn ( ) ,
1112 verifyToken : jest . fn ( ) ,
13+ loginWithEmail : jest . fn ( ) ,
14+ } ;
15+
16+ const mockMagicLinkEmailStrategy = {
17+ send : jest . fn ( ) ,
1218} ;
1319
1420describe ( 'AuthController' , ( ) => {
@@ -23,6 +29,10 @@ describe('AuthController', () => {
2329 provide : AuthService ,
2430 useValue : mockAuthService ,
2531 } ,
32+ {
33+ provide : MagicLinkEmailStrategy ,
34+ useValue : mockMagicLinkEmailStrategy ,
35+ } ,
2636 ] ,
2737 } ) . compile ( ) ;
2838
@@ -56,6 +66,13 @@ describe('AuthController', () => {
5666 } ) ;
5767 } ) ;
5868
69+ describe ( 'githubLogin' , ( ) => {
70+ it ( 'should call AuthService.githubLogin' , async ( ) => {
71+ await controller . githubLogin ( ) ;
72+ expect ( authService . githubLogin ) . toHaveBeenCalled ( ) ;
73+ } ) ;
74+ } ) ;
75+
5976 describe ( 'googleRedirect' , ( ) => {
6077 it ( 'should call AuthService.googleLogin' , async ( ) => {
6178 const req = { } as Request ;
@@ -78,6 +95,13 @@ describe('AuthController', () => {
7895 } ) ;
7996 } ) ;
8097
98+ describe ( 'googleLogin' , ( ) => {
99+ it ( 'should call AuthService.googleLogin' , async ( ) => {
100+ await controller . googleLogin ( ) ;
101+ expect ( authService . googleLogin ) . toHaveBeenCalled ( ) ;
102+ } ) ;
103+ } ) ;
104+
81105 describe ( 'discordRedirect' , ( ) => {
82106 it ( 'should call AuthService.discordLogin' , async ( ) => {
83107 const req = { } as Request ;
@@ -100,6 +124,46 @@ describe('AuthController', () => {
100124 } ) ;
101125 } ) ;
102126
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+
103167 describe ( 'verify' , ( ) => {
104168 it ( 'should call AuthService.verifyToken' , async ( ) => {
105169 const req = { } as Request ;
0 commit comments