2
2
* @jest -environment node
3
3
*/
4
4
5
-
6
- import marketplaceController from '../server/controllers/marketplaceController' ;
7
5
import app from '../server/server' ;
8
6
import mockData from '../mockData' ;
9
- import { profileEnd } from 'console' ;
10
7
import { Sessions , Users } from '../server/models/reactypeModels' ;
11
8
const request = require ( 'supertest' ) ;
12
9
const mongoose = require ( 'mongoose' ) ;
13
- const mockNext = jest . fn ( ) ; // Mock nextFunction
14
10
const MONGO_DB = process . env . MONGO_DB_TEST ;
15
- const { state, projectToSave, user } = mockData
16
- const PORT = 8080 ;
11
+ const { user } = mockData ;
17
12
18
13
const num = Math . floor ( Math . random ( ) * 1000 ) ;
19
14
20
15
beforeAll ( async ( ) => {
21
16
await mongoose . connect ( MONGO_DB , {
22
17
useNewUrlParser : true ,
23
- useUnifiedTopology : true ,
18
+ useUnifiedTopology : true
24
19
} ) ;
25
20
} ) ;
26
21
27
22
afterAll ( async ( ) => {
28
-
29
- const result = await Users . deleteMany ( { _id : { $ne : '64f551e5b28d5292975e08c8' } } ) ; //clear the users collection after tests are done except for the mockdata user account
30
- const result2 = await Sessions . deleteMany ( { cookieId : { $ne : '64f551e5b28d5292975e08c8' } } ) ;
31
- console . log ( `${ result . deletedCount } and ${ result2 . deletedCount } documents deleted.` ) ;
23
+ const result = await Users . deleteMany ( {
24
+ _id : { $ne : '64f551e5b28d5292975e08c8' }
25
+ } ) ; //clear the users collection after tests are done except for the mockdata user account
26
+ const result2 = await Sessions . deleteMany ( {
27
+ cookieId : { $ne : '64f551e5b28d5292975e08c8' }
28
+ } ) ;
29
+ console . log (
30
+ `${ result . deletedCount } and ${ result2 . deletedCount } documents deleted.`
31
+ ) ;
32
32
await mongoose . connection . close ( ) ;
33
33
} ) ;
34
34
@@ -40,7 +40,8 @@ describe('User Authentication tests', () => {
40
40
expect ( response . text ) . toBe ( 'test request is working' ) ;
41
41
} ) ;
42
42
} ) ;
43
- describe ( '/signup' , ( ) => {
43
+
44
+ describe ( '/signup' , ( ) => {
44
45
describe ( 'POST' , ( ) => {
45
46
//testing new signup
46
47
it ( 'responds with status 200 and sessionId on valid new user signup' , ( ) => {
@@ -55,7 +56,7 @@ describe('User Authentication tests', () => {
55
56
. expect ( 200 )
56
57
. then ( ( res ) => expect ( res . body . sessionId ) . not . toBeNull ( ) ) ;
57
58
} ) ;
58
-
59
+
59
60
it ( 'responds with status 400 and json string on invalid new user signup (Already taken)' , ( ) => {
60
61
return request ( app )
61
62
. post ( '/signup' )
@@ -67,8 +68,9 @@ describe('User Authentication tests', () => {
67
68
} ) ;
68
69
} ) ;
69
70
} ) ;
71
+
70
72
describe ( '/login' , ( ) => {
71
- // tests whether existing login information permits user to log in
73
+ // tests whether existing login information permits user to log in
72
74
describe ( 'POST' , ( ) => {
73
75
it ( 'responds with status 200 and json object on verified user login' , ( ) => {
74
76
return request ( app )
@@ -80,152 +82,74 @@ describe('User Authentication tests', () => {
80
82
. then ( ( res ) => expect ( res . body . sessionId ) . toEqual ( user . userId ) ) ;
81
83
} ) ;
82
84
// if invalid username/password, should respond with status 400
83
- it ( 'responds with status 400 and json string on invalid user login' , ( ) => {
85
+ it ( 'responds with status 400 and json string on invalid user login' , ( ) => {
84
86
return request ( app )
85
87
. post ( '/login' )
86
88
. send ( { username : 'wrongusername' , password : 'wrongpassword' } )
87
89
. expect ( 400 )
88
90
. expect ( 'Content-Type' , / j s o n / )
89
91
. then ( ( res ) => expect ( typeof res . body ) . toBe ( 'string' ) ) ;
90
92
} ) ;
91
- } ) ;
92
- } ) ;
93
-
94
- } ) ;
95
-
96
-
97
-
98
- // import request from 'supertest';
99
- // import app from '../server/server';
100
- // import mockObj from '../mockData';
101
- // const user = mockObj.user;
102
- // import mongoose from 'mongoose';
103
- // const URI = process.env.MONGO_DB;
104
-
105
- // beforeAll(() => {
106
- // mongoose
107
- // .connect(URI, { useNewUrlParser: true }, { useUnifiedTopology: true })
108
- // .then(() => console.log('connected to test database'));
109
- // });
93
+ it ( "returns the message 'No Username Input' when no username is entered" , ( ) => {
94
+ return request ( app )
95
+ . post ( '/login' )
96
+ . send ( {
97
+ username : '' ,
98
+ password : 'Reactype123!@#' ,
99
+ isFbOauth : false
100
+ } )
101
+ . then ( ( res ) => expect ( res . text ) . toBe ( '"No Username Input"' ) ) ;
102
+ } ) ;
110
103
111
- // afterAll(async () => {
112
- // await mongoose.connection.close();
113
- // });
114
- // //for creating unqiue login credentials
115
- // const num = Math.floor(Math.random() * 1000);
104
+ it ( "returns the message 'No Username Input' when no username is entered" , ( ) => {
105
+ return request ( app )
106
+ . post ( '/login' )
107
+ . send ( {
108
+ username : '' ,
109
+ password : 'Reactype123!@#' ,
110
+ isFbOauth : false
111
+ } )
112
+ . then ( ( res ) => expect ( res . text ) . toBe ( '"No Username Input"' ) ) ;
113
+ } ) ;
116
114
117
- // describe('User authentication tests', () => {
118
- // //test connection to server
119
- // describe('initial connection test', () => {
120
- // it('should connect to the server', async () => {
121
- // const response = await request(app).get('/test');
122
- // expect(response.text).toEqual('test request is working');
123
- // });
124
- // });
115
+ it ( "returns the message 'No Password Input' when no password is entered" , ( ) => {
116
+ return request ( app )
117
+ . post ( '/login' )
118
+ . send ( {
119
+ username : 'reactype123' ,
120
+ password : '' ,
121
+ isFbOauth : false
122
+ } )
123
+ . then ( ( res ) => expect ( res . text ) . toBe ( '"No Password Input"' ) ) ;
124
+ } ) ;
125
125
126
- // xdescribe('POST', () => {
127
- // it('responds with status 200 and json object on valid new user signup', () => {
128
- // return request(app)
129
- // .post('/signup')
130
- // .set('Content-Type', 'application/json')
131
- // .send({
132
- // username: `supertest${num}`,
133
- // email: `test${num}@test .com`,
134
- // password: `${num}`
135
- // })
136
- // .expect(200)
137
- // .then((res) => expect(typeof res.body).toBe('object'));
138
- // });
126
+ it ( "returns the message 'Invalid Username' when username does not exist" , ( ) => {
127
+ return request ( app )
128
+ . post ( '/login' )
129
+ . send ( {
130
+ username : 'l!b' ,
131
+ password : 'test' ,
132
+ isFbOauth : false
133
+ } )
134
+ . then ( ( res ) => expect ( res . text ) . toBe ( '"Invalid Username"' ) ) ;
135
+ } ) ;
136
+ } ) ;
139
137
140
- // it('responds with status 400 and json string on invalid new user signup', () => {
141
- // return request(app)
142
- // .post('/signup')
143
- // .send(user)
144
- // .set('Accept', 'application/json')
145
- // .expect('Content-Type', /json/)
146
- // .expect(400)
147
- // .then((res) => expect(typeof res.body).toBe('string'));
148
- // });
149
- // });
150
- // });
151
- // describe('/login', () => {
152
- // // tests whether existing login information permits user to log in
153
- // xdescribe('POST', () => {
154
- // it('responds with status 200 and json object on verified user login', () => {
155
- // return request(app)
156
- // .post('/login')
157
- // .set('Accept', 'application/json')
158
- // .send(user)
159
- // .expect(200)
160
- // .expect('Content-Type', /json/)
161
- // .then((res) => expect(res.body.sessionId).toEqual(user.userId));
162
- // });
163
- // // if invalid username/password, should respond with status 400
164
- // it('responds with status 400 and json string on invalid user login', () => {
165
- // return request(app)
166
- // .post('/login')
167
- // .send({ username: 'wrongusername', password: 'wrongpassword' })
168
- // .expect(400)
169
- // .expect('Content-Type', /json/)
170
- // .then((res) => expect(typeof res.body).toBe('string'));
171
- // });
172
- // it('responds with status 400 and json string on invalid new user signup', () => {
173
- // return request(app)
174
- // .post('/signup')
175
- // .send(user)
176
- // .set('Accept', 'application/json')
177
- // .expect('Content-Type', /json/)
178
- // .expect(400)
179
- // .then((res) => expect(typeof res.body).toBe('string'));
180
- // });
181
- // });
182
- // });
138
+ it ( "returns the message 'Incorrect Password' when password does not match" , ( ) => {
139
+ return request ( app )
140
+ . post ( '/login' )
141
+ . send ( {
142
+ username : 'test' ,
143
+ password : 'test' ,
144
+ isFbOauth : false
145
+ } )
146
+ . then ( ( res ) => expect ( res . text ) . toBe ( '"Incorrect Password"' ) ) ;
147
+ } ) ;
148
+ } ) ;
149
+ } ) ;
183
150
184
151
// describe('sessionIsCreated', () => {
185
- // it("returns the message 'No Username Input' when no username is entered", () => {
186
- // return request(app)
187
- // .post('/login')
188
- // .send({
189
- // username: '',
190
- // password: 'Reactype123!@#',
191
- // isFbOauth: false
192
- // })
193
- // .then((res) => expect(res.text).toBe('"No Username Input"'));
194
- // });
195
152
196
- // it("returns the message 'No Password Input' when no password is entered", () => {
197
- // return request(app)
198
- // .post('/login')
199
- // .send({
200
- // username: 'reactype123',
201
- // password: '',
202
- // isFbOauth: false
203
- // })
204
- // .then((res) => expect(res.text).toBe('"No Password Input"'));
205
- // });
206
-
207
- // it("returns the message 'Invalid Username' when username does not exist", () => {
208
- // return request(app)
209
- // .post('/login')
210
- // .send({
211
- // username: 'l!b',
212
- // password: 'test',
213
- // isFbOauth: false
214
- // })
215
- // .then((res) => expect(res.text).toBe('"Invalid Username"'));
216
- // });
217
- // });
218
-
219
- // it("returns the message 'Incorrect Password' when password does not match", () => {
220
- // return request(app)
221
- // .post('/login')
222
- // .send({
223
- // username: 'test',
224
- // password: 'test',
225
- // isFbOauth: false
226
- // })
227
- // .then((res) => expect(res.text).toBe('"Incorrect Password"'));
228
- // });
229
153
// // note that the username and password in this test are kept in the heroku database
230
154
// // DO NOT CHANGE unless you have access to the heroku database
231
155
// it("returns the message 'Success' when the user passes all auth checks", () => {
@@ -240,7 +164,6 @@ describe('User Authentication tests', () => {
240
164
// });
241
165
242
166
// // // OAuth tests (currently inoperative)
243
-
244
167
// // xdescribe('Github oauth tests', () => {
245
168
// // describe('/github/callback?code=', () => {
246
169
// // describe('GET', () => {
0 commit comments