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