Skip to content

Commit

Permalink
feat(user): add test on register with same email ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBrisorgueil committed Mar 20, 2019
1 parent c8cfc6d commit a5bbec2
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions modules/users/tests/user.crud.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,25 @@ describe('User CRUD Unit Tests :', () => {
// Init user edited
_userEdited.username = 'register_new_user';
_userEdited.email = 'register_new_user_@test.com';
_userEdited.password = 'azerty';

try {
const result = await agent.post('/api/auth/signup')
.send(_userEdited)
.expect(422);
expect(result.body.type).toBe('error');
expect(result.body.message).toBe('schema validation error');
expect(result.body.error.details[0].message).toBe('password Password strength score 0 does not suffice the minimum of 3');
} catch (err) {
console.log(err);
expect(err).toBeFalsy();
}
});

test('should be able to register a new user ', async () => {
// Init user edited
_userEdited.username = 'register_new_user';
_userEdited.email = 'register_new_user_@test.com';

try {
const result = await agent.post('/api/auth/signup')
Expand Down Expand Up @@ -116,19 +135,42 @@ describe('User CRUD Unit Tests :', () => {
}
});

test('should be able to register a new user', async () => {
test('should not be able to register a user with same email', async () => {
// Init user edited
_userEdited.username = 'register_new_user';
_userEdited.email = 'register_new_user_@test.com';
_userEdited.password = 'azerty';

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

expect(result.body.user.username).toBe(_userEdited.username);
expect(result.body.user.email).toBe(_userEdited.email);
expect(result.body.user.roles).toBeInstanceOf(Array);
expect(result.body.user.roles).toHaveLength(1);
expect(result.body.user.roles).toEqual(
expect.arrayContaining(['user']),
);
} catch (err) {
console.log(err);
expect(err).toBeFalsy();
}

try {
const result = await agent.post('/api/auth/signup')
.send(_userEdited)
.expect(422);
expect(result.body.type).toBe('error');
expect(result.body.message).toBe('schema validation error');
expect(result.body.error.details[0].message).toBe('password Password strength score 0 does not suffice the minimum of 3');
expect(result.body.message).toBe('Email already exists');
} catch (err) {
console.log(err);
expect(err).toBeFalsy();
}

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

0 comments on commit a5bbec2

Please sign in to comment.