Skip to content

Commit

Permalink
test(users): add admin test list ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBrisorgueil committed Jun 8, 2019
1 parent 84b1078 commit d21b25c
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion modules/users/tests/user.crud.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,44 @@ describe('User CRUD Unit Tests :', () => {
test('should not be able to retrieve a list of users if not admin', async () => {
try {
await agent.get('/api/users')
.send(credentials[0])
.expect(403);
} catch (err) {
console.log(err);
expect(err).toBeFalsy();
}
});

test('should be able to retrieve a list of users if not admin', async () => {
_userEdited.roles = ['user', 'admin'];

try {
const result = await agent.post('/api/auth/signup')
.send(_userEdited)
.expect(200);
userEdited = result.body.user;
} catch (err) {
console.log(err);
expect(err).toBeFalsy();
}

try {
const result = await agent.get('/api/users')
.expect(200);
expect(result.body.type).toBe('success');
expect(result.body.message).toBe('user list');
expect(result.body.data).toBeInstanceOf(Array);
} catch (err) {
console.log(err);
expect(err).toBeFalsy();
}

try {
await UserService.delete(userEdited);
} catch (err) {
console.log(err);
expect(err).toBeFalsy();
}
});

test('should be able to get a single user details if admin', async () => {
_userEdited.roles = ['user', 'admin'];
Expand Down

0 comments on commit d21b25c

Please sign in to comment.