File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -220,14 +220,44 @@ describe('User CRUD Unit Tests :', () => {
220
220
test ( 'should not be able to retrieve a list of users if not admin' , async ( ) => {
221
221
try {
222
222
await agent . get ( '/api/users' )
223
- . send ( credentials [ 0 ] )
224
223
. expect ( 403 ) ;
225
224
} catch ( err ) {
226
225
console . log ( err ) ;
227
226
expect ( err ) . toBeFalsy ( ) ;
228
227
}
229
228
} ) ;
230
229
230
+ test ( 'should be able to retrieve a list of users if not admin' , async ( ) => {
231
+ _userEdited . roles = [ 'user' , 'admin' ] ;
232
+
233
+ try {
234
+ const result = await agent . post ( '/api/auth/signup' )
235
+ . send ( _userEdited )
236
+ . expect ( 200 ) ;
237
+ userEdited = result . body . user ;
238
+ } catch ( err ) {
239
+ console . log ( err ) ;
240
+ expect ( err ) . toBeFalsy ( ) ;
241
+ }
242
+
243
+ try {
244
+ const result = await agent . get ( '/api/users' )
245
+ . expect ( 200 ) ;
246
+ expect ( result . body . type ) . toBe ( 'success' ) ;
247
+ expect ( result . body . message ) . toBe ( 'user list' ) ;
248
+ expect ( result . body . data ) . toBeInstanceOf ( Array ) ;
249
+ } catch ( err ) {
250
+ console . log ( err ) ;
251
+ expect ( err ) . toBeFalsy ( ) ;
252
+ }
253
+
254
+ try {
255
+ await UserService . delete ( userEdited ) ;
256
+ } catch ( err ) {
257
+ console . log ( err ) ;
258
+ expect ( err ) . toBeFalsy ( ) ;
259
+ }
260
+ } ) ;
231
261
232
262
test ( 'should be able to get a single user details if admin' , async ( ) => {
233
263
_userEdited . roles = [ 'user' , 'admin' ] ;
You can’t perform that action at this time.
0 commit comments