@@ -5,15 +5,21 @@ import request from 'supertest';
5
5
import app from '../server/server' ;
6
6
import mockObj from '../mockData' ;
7
7
const user = mockObj . user ;
8
+ import { sessionIsCreated } from '../app/src/helperFunctions/auth' ;
8
9
9
10
//for creating unqiue login credentials
10
11
const num = Math . floor ( Math . random ( ) * 1000 ) ;
12
+ let username ;
13
+ let password ;
14
+ let isFbOauth ;
11
15
12
16
describe ( 'User authentication tests' , ( ) => {
13
17
//test connection to server
14
- test ( 'initial connection test' , async ( ) => {
15
- const response = await request ( app ) . get ( '/test' ) ;
16
- expect ( response . text ) . toEqual ( 'test request is working' ) ;
18
+ describe ( 'initial connection test' , ( ) => {
19
+ it ( 'should connect to the server' , async ( ) => {
20
+ const response = await request ( app ) . get ( '/test' ) ;
21
+ expect ( response . text ) . toEqual ( 'test request is working' ) ;
22
+ } ) ;
17
23
} ) ;
18
24
//navigating to signup page should serve
19
25
describe ( '/' , ( ) => {
@@ -83,6 +89,64 @@ describe('User authentication tests', () => {
83
89
} ) ;
84
90
} ) ;
85
91
} ) ;
92
+
93
+ describe ( 'sessionIsCreated' , ( ) => {
94
+ it ( "returns the message 'No Username Input' when no username is entered" , ( ) => {
95
+ return request ( app )
96
+ . post ( '/login' )
97
+ . send ( {
98
+ username : '' ,
99
+ password : 'Reactype123!@#' ,
100
+ isFbOauth : false
101
+ } )
102
+ . then ( ( res ) => expect ( res . text ) . toBe ( '"No Username Input"' ) ) ;
103
+ } ) ;
104
+
105
+ it ( "returns the message 'No Password Input' when no password is entered" , ( ) => {
106
+ return request ( app )
107
+ . post ( '/login' )
108
+ . send ( {
109
+ username : 'reactype123' ,
110
+ password : '' ,
111
+ isFbOauth : false
112
+ } )
113
+ . then ( ( res ) => expect ( res . text ) . toBe ( '"No Password Input"' ) ) ;
114
+ } ) ;
115
+
116
+ it ( "returns the message 'Invalid Username' when username does not exist" , ( ) => {
117
+ return request ( app )
118
+ . post ( '/login' )
119
+ . send ( {
120
+ username : 'l!b' ,
121
+ password : 'test' ,
122
+ isFbOauth : false
123
+ } )
124
+ . then ( ( res ) => expect ( res . text ) . toBe ( '"Invalid Username"' ) ) ;
125
+ } ) ;
126
+ } ) ;
127
+
128
+ it ( "returns the message 'Incorrect Password' when password does not match" , ( ) => {
129
+ return request ( app )
130
+ . post ( '/login' )
131
+ . send ( {
132
+ username : 'test' ,
133
+ password : 'test' ,
134
+ isFbOauth : false
135
+ } )
136
+ . then ( ( res ) => expect ( res . text ) . toBe ( '"Incorrect Password"' ) ) ;
137
+ } ) ;
138
+ // note that the username and password in this test are kept in the heroku database
139
+ // DO NOT CHANGE unless you have access to the heroku database
140
+ it ( "returns the message 'Success' when the user passes all auth checks" , ( ) => {
141
+ return request ( app )
142
+ . post ( '/login' )
143
+ . send ( {
144
+ username : 'test' ,
145
+ password : 'password1!' ,
146
+ isFbOauth : false
147
+ } )
148
+ . then ( ( res ) => expect ( res . body ) . toHaveProperty ( 'sessionId' ) ) ;
149
+ } ) ;
86
150
} ) ;
87
151
88
152
// // // OAuth tests (currently inoperative)
0 commit comments