forked from PastVu/pastvu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,73 +52,64 @@ describe('user registration', () => { | |
// Register user. | ||
const data = { 'login': 'user1', 'email': '[email protected]', 'pass': 'pass1', 'pass2': 'pass1' }; | ||
|
||
return auth.register(data).catch(e => { | ||
// Restore original mock. | ||
send.mockResolvedValue(); | ||
await expect(auth.register(data)).rejects.toThrow(new AuthenticationError(constants.AUTHENTICATION_REGISTRATION)); | ||
|
||
expect(e).toEqual(new AuthenticationError(constants.AUTHENTICATION_REGISTRATION)); | ||
// Check user record was deleted. | ||
expect(User.findOne({ 'login': data.login })).resolves.toBeNull(); | ||
}); | ||
// Restore original mock. | ||
send.mockResolvedValue(); | ||
|
||
// Check user record was deleted. | ||
await expect(User.findOne({ 'login': data.login })).resolves.toBeNull(); | ||
}); | ||
|
||
describe('throws on invalid input values', () => { | ||
it('empty login field', async () => { | ||
expect.assertions(1); | ||
|
||
return auth.register({ 'login': '' }).catch(e => { | ||
expect(e).toEqual(new InputError(constants.INPUT_LOGIN_REQUIRED)); | ||
}); | ||
await expect(auth.register({ 'login': '' })).rejects.toThrow(new InputError(constants.INPUT_LOGIN_REQUIRED)); | ||
}); | ||
|
||
it('login field starts with digit', async () => { | ||
expect.assertions(1); | ||
|
||
return auth.register({ 'login': '1user' }).catch(e => { | ||
expect(e).toEqual(new AuthenticationError(constants.INPUT_LOGIN_CONSTRAINT)); | ||
}); | ||
await expect(auth.register({ 'login': '1user' })).rejects.toThrow(new AuthenticationError(constants.INPUT_LOGIN_CONSTRAINT)); | ||
}); | ||
|
||
it('login field is shorter than 3 characters', async () => { | ||
expect.assertions(1); | ||
|
||
return auth.register({ 'login': 'u' }).catch(e => { | ||
expect(e).toEqual(new AuthenticationError(constants.INPUT_LOGIN_CONSTRAINT)); | ||
}); | ||
await expect(auth.register({ 'login': 'u' })).rejects.toThrow(new AuthenticationError(constants.INPUT_LOGIN_CONSTRAINT)); | ||
}); | ||
|
||
it('login field is longer than 15 characters', async () => { | ||
expect.assertions(1); | ||
|
||
return auth.register({ 'login': 'user'.repeat(5) }).catch(e => { | ||
expect(e).toEqual(new AuthenticationError(constants.INPUT_LOGIN_CONSTRAINT)); | ||
}); | ||
const data = { 'login': 'user'.repeat(5) }; | ||
|
||
await expect(auth.register(data)).rejects.toThrow(new AuthenticationError(constants.INPUT_LOGIN_CONSTRAINT)); | ||
}); | ||
|
||
it('empty email field', async () => { | ||
expect.assertions(1); | ||
|
||
return auth.register({ 'login': 'user', 'email': '' }).catch(e => { | ||
expect(e).toEqual(new InputError(constants.INPUT_EMAIL_REQUIRED)); | ||
}); | ||
const data = { 'login': 'user', 'email': '' }; | ||
|
||
await expect(auth.register(data)).rejects.toThrow(new InputError(constants.INPUT_EMAIL_REQUIRED)); | ||
}); | ||
|
||
it('empty password field', async () => { | ||
expect.assertions(1); | ||
|
||
return auth.register({ 'login': 'user', 'email': '[email protected]', 'pass': '' }).catch(e => { | ||
expect(e).toEqual(new InputError(constants.INPUT_PASS_REQUIRED)); | ||
}); | ||
const data = { 'login': 'user', 'email': '[email protected]', 'pass': '' }; | ||
|
||
await expect(auth.register(data)).rejects.toThrow(new InputError(constants.INPUT_PASS_REQUIRED)); | ||
}); | ||
|
||
it('passwords don\'t match', async () => { | ||
expect.assertions(1); | ||
|
||
const data = { 'login': 'user1', 'email': '[email protected]', 'pass': 'pass1', 'pass2': 'pass2' }; | ||
|
||
return auth.register(data).catch(e => { | ||
expect(e).toEqual(new AuthenticationError(constants.AUTHENTICATION_PASSWORDS_DONT_MATCH)); | ||
}); | ||
await expect(auth.register(data)).rejects.toThrow(new AuthenticationError(constants.AUTHENTICATION_PASSWORDS_DONT_MATCH)); | ||
}); | ||
|
||
it('user login exists', async () => { | ||
|
@@ -131,9 +122,7 @@ describe('user registration', () => { | |
// Change email and register again. | ||
data.email = '[email protected]'; | ||
|
||
return auth.register(data).catch(e => { | ||
expect(e).toEqual(new AuthenticationError(constants.AUTHENTICATION_USER_EXISTS)); | ||
}); | ||
await expect(auth.register(data)).rejects.toThrow(new AuthenticationError(constants.AUTHENTICATION_USER_EXISTS)); | ||
}); | ||
|
||
it('user email exists', async () => { | ||
|
@@ -146,9 +135,7 @@ describe('user registration', () => { | |
// Change login and register again. | ||
data.login = 'user2'; | ||
|
||
return auth.register(data).catch(e => { | ||
expect(e).toEqual(new AuthenticationError(constants.AUTHENTICATION_EMAIL_EXISTS)); | ||
}); | ||
await expect(auth.register(data)).rejects.toThrow(new AuthenticationError(constants.AUTHENTICATION_EMAIL_EXISTS)); | ||
}); | ||
}); | ||
}); |