@@ -4,6 +4,35 @@ import supertest from 'supertest'
4
4
import app from '../../app'
5
5
import USER from '../../models/User'
6
6
import Tokens from '../../models/token'
7
+ import { httpRequest , httpResponse } from '../mock/user.mock'
8
+ import GoogleController from '../googleAuthController'
9
+ jest . setTimeout ( 20000 )
10
+ describe ( 'Login via google' , ( ) => {
11
+ afterAll ( async ( ) => {
12
+ USER . destroy ( {
13
+ where :
{ email :
'[email protected] ' } ,
14
+ } )
15
+ } )
16
+ test ( 'redirect to google and authenticate' , async ( ) => {
17
+ const data = await GoogleController . googleAuth (
18
+
19
+ httpResponse ( ) ,
20
+ )
21
+ expect ( data . body ) . toHaveProperty ( 'user' )
22
+ } )
23
+
24
+ test ( 'testing register' , async ( ) => {
25
+ const data : any = await GoogleController . googleAuth (
26
+
27
+ httpResponse ( ) ,
28
+ )
29
+ expect ( data . body ) . toHaveProperty ( 'user' )
30
+ } )
31
+ test ( 'testing 500' , async ( ) => {
32
+ const data : any = await GoogleController . googleAuth ( 'helll' , httpResponse ( ) )
33
+ expect ( data . body . status ) . toBe ( 500 )
34
+ } )
35
+ } )
7
36
8
37
/* eslint-disable @typescript-eslint/no-explicit-any */
9
38
describe ( 'Math functions' , ( ) => {
@@ -18,48 +47,59 @@ describe('Math functions', () => {
18
47
} )
19
48
} )
20
49
// reset password coontroller tests
21
- describe ( 'reset password' , ( ) => {
22
- describe ( 'send link to email' , ( ) => {
23
- test ( 'incase of unregistered email' , async ( ) => {
24
- const response = await supertest ( app ) . post ( "/resetpassword/link" ) . send ( { email :
"[email protected] " } )
50
+ describe ( 'reset password' , ( ) => {
51
+ describe ( 'send link to email' , ( ) => {
52
+ test ( 'incase of unregistered email' , async ( ) => {
53
+ const response = await supertest ( app )
54
+ . post ( '/resetpassword/link' )
55
+ . send ( { email :
'[email protected] ' } )
25
56
expect ( response . status ) . toBe ( 400 )
26
- } , 10000 ) // timeout 10 seconds
57
+ } , 10000 ) // timeout 10 seconds
27
58
} )
28
- test ( 'incase of a registered email' , async ( ) => {
29
- const response = await supertest ( app ) . post ( "/resetpassword/link" ) . send ( { email :
"[email protected] " } )
30
- expect ( response . status ) . toBe ( 200 )
31
- } , 20000 )
32
- test ( 'incase invalid email input' , async ( ) => {
33
- const response = await supertest ( app ) . post ( "/resetpassword/link" ) . send ( { email : "rukundjoseph" } )
34
- expect ( response . status ) . toBe ( 400 )
35
- } , 20000 )
36
- describe ( 'add token and change password' , ( ) => {
37
- test ( 'incase incorrect token' , async ( ) => {
38
- const response = await supertest ( app ) . patch ( "/changepassword/[email protected] /65328dba23" ) . send ( { newpassword :
"newpassword" ,
39
- confirmpass : "newpassword" } )
59
+ test ( 'incase of a registered email' , async ( ) => {
60
+ const response = await supertest ( app )
61
+ . post ( '/resetpassword/link' )
62
+ . send ( { email :
'[email protected] ' } )
63
+ expect ( response . status ) . toBe ( 200 )
64
+ } , 20000 )
65
+ test ( 'incase invalid email input' , async ( ) => {
66
+ const response = await supertest ( app )
67
+ . post ( '/resetpassword/link' )
68
+ . send ( { email : 'rukundjoseph' } )
69
+ expect ( response . status ) . toBe ( 400 )
70
+ } , 20000 )
71
+ describe ( 'add token and change password' , ( ) => {
72
+ test ( 'incase incorrect token' , async ( ) => {
73
+ const response = await supertest ( app )
74
+ . patch ( '/changepassword/[email protected] /65328dba23' )
75
+ . send ( { newpassword : 'newpassword' , confirmpass : 'newpassword' } )
40
76
expect ( response . status ) . toBe ( 400 )
41
- } , 20000 )
42
- test ( 'incase incorrect token' , async ( ) => {
43
- const response = await supertest ( app ) . patch ( "/changepassword/[email protected] /65328dba23" ) . send ( { newpassword :
"newpassword" ,
44
- confirmpass : "newpassword" } )
45
- expect ( response . status ) . toBe ( 400 )
46
- } , 20000 )
47
- test ( 'incase of a unmatching passwords' , async ( ) => {
48
- const user :
any = await USER . findOne ( { where :
{ email :
"[email protected] " } } )
49
- const token : any = await Tokens . findOne ( { where : { userId : `${ user . id } ` } } )
50
- const response = await supertest ( app ) . patch ( `/changepassword/[email protected] /${ token . token } ` ) . send ( { newpassword :
"newpas" ,
51
- confirmpass : "newpaa" } )
52
- expect ( response . status ) . toBe ( 400 )
53
- } )
54
- test ( 'incase of a valid token and email' , async ( ) => {
55
- const user :
any = await USER . findOne ( { where :
{ email :
"[email protected] " } } )
56
- const token : any = await Tokens . findOne ( { where : { userId : `${ user . id } ` } } )
57
- const response = await supertest ( app ) . patch ( `/changepassword/[email protected] /${ token . token } ` ) . send ( { newpassword :
"newpas" ,
58
- confirmpass : "newpas" } )
59
- expect ( response . status ) . toBe ( 200 )
60
- } )
61
-
62
- } )
63
- } )
64
-
65
-
77
+ } , 20000 )
78
+ test ( 'incase incorrect token' , async ( ) => {
79
+ const response = await supertest ( app )
80
+ . patch ( '/changepassword/[email protected] /65328dba23' )
81
+ . send ( { newpassword : 'newpassword' , confirmpass : 'newpassword' } )
82
+ expect ( response . status ) . toBe ( 400 )
83
+ } , 20000 )
84
+ test ( 'incase of a unmatching passwords' , async ( ) => {
85
+ const user : any = await USER . findOne ( {
86
+ where :
{ email :
'[email protected] ' } ,
87
+ } )
88
+ const token : any = await Tokens . findOne ( { where : { userId : `${ user . id } ` } } )
89
+ const response = await supertest ( app )
90
+ . patch ( `/changepassword/[email protected] /${ token . token } ` )
91
+ . send ( { newpassword : 'newpas' , confirmpass : 'newpaa' } )
92
+ expect ( response . status ) . toBe ( 400 )
93
+ } )
94
+ test ( 'incase of a valid token and email' , async ( ) => {
95
+ const user : any = await USER . findOne ( {
96
+ where :
{ email :
'[email protected] ' } ,
97
+ } )
98
+ const token : any = await Tokens . findOne ( { where : { userId : `${ user . id } ` } } )
99
+ const response = await supertest ( app )
100
+ . patch ( `/changepassword/[email protected] /${ token . token } ` )
101
+ . send ( { newpassword : 'newpas' , confirmpass : 'newpas' } )
102
+ expect ( response . status ) . toBe ( 200 )
103
+ } )
104
+ } )
105
+ } )
0 commit comments