tests: Clean up styling of auth update tests

This commit is contained in:
Blade Barringer
2016-03-18 08:34:13 -05:00
parent f6f5b1a118
commit 75ed4080dc
3 changed files with 57 additions and 62 deletions

View File

@@ -3,20 +3,21 @@ import {
translate as t,
} from '../../../../../helpers/api-v3-integration.helper';
describe('PUT /user/auth/update-email', () => {
let user;
let fbUser;
let endpoint = '/user/auth/update-email';
let newEmail = 'some-new-email_2@example.net';
let thePassword = 'password'; // from habitrpg/test/helpers/api-integration/v3/object-generators.js
const ENDPOINT = '/user/auth/update-email';
describe('PUT /user/auth/update-email', () => {
let newEmail = 'some-new-email_2@example.net';
let oldPassword = 'password'; // from habitrpg/test/helpers/api-integration/v3/object-generators.js
context('Local Authenticaion User', async () => {
let user;
describe('local user', async () => {
beforeEach(async () => {
user = await generateUser();
});
it('does not change email if one is not provided', async () => {
await expect(user.put(endpoint)).to.eventually.be.rejected.and.eql({
it('does not change email if email is not provided', async () => {
await expect(user.put(ENDPOINT)).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: t('invalidReqParams'),
@@ -24,7 +25,7 @@ describe('PUT /user/auth/update-email', () => {
});
it('does not change email if password is not provided', async () => {
await expect(user.put(endpoint, {
await expect(user.put(ENDPOINT, {
newEmail,
})).to.eventually.be.rejected.and.eql({
code: 400,
@@ -34,7 +35,7 @@ describe('PUT /user/auth/update-email', () => {
});
it('does not change email if wrong password is provided', async () => {
await expect(user.put(endpoint, {
await expect(user.put(ENDPOINT, {
newEmail,
password: 'wrong password',
})).to.eventually.be.rejected.and.eql({
@@ -45,9 +46,9 @@ describe('PUT /user/auth/update-email', () => {
});
it('changes email if new email and existing password are provided', async () => {
let response = await user.put(endpoint, {
let response = await user.put(ENDPOINT, {
newEmail,
password: thePassword,
password: oldPassword,
});
expect(response).to.eql({ email: 'some-new-email_2@example.net' });
@@ -56,16 +57,18 @@ describe('PUT /user/auth/update-email', () => {
});
});
describe('facebook user', async () => {
context('Social Login User', async () => {
let socialUser;
beforeEach(async () => {
fbUser = await generateUser();
await fbUser.update({ 'auth.local': { ok: true } });
socialUser = await generateUser();
await socialUser.update({ 'auth.local': { ok: true } });
});
it('does not change email if user.auth.local.email does not exist for this user', async () => {
await expect(fbUser.put(endpoint, {
await expect(socialUser.put(ENDPOINT, {
newEmail,
password: thePassword,
password: oldPassword,
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',

View File

@@ -3,10 +3,11 @@ import {
translate as t,
} from '../../../../../helpers/api-v3-integration.helper';
const ENDPOINT = '/user/auth/update-password';
describe('PUT /user/auth/update-password', async () => {
let endpoint = '/user/auth/update-password';
let user;
let password = 'password';
let password = 'password'; // from habitrpg/test/helpers/api-integration/v3/object-generators.js
let wrongPassword = 'wrong-password';
let newPassword = 'new-password';
@@ -16,7 +17,7 @@ describe('PUT /user/auth/update-password', async () => {
it('successfully changes the password', async () => {
let previousHashedPassword = user.auth.local.hashed_password;
let response = await user.put(endpoint, {
let response = await user.put(ENDPOINT, {
password,
newPassword,
confirmPassword: newPassword,
@@ -26,8 +27,8 @@ describe('PUT /user/auth/update-password', async () => {
expect(user.auth.local.hashed_password).to.not.eql(previousHashedPassword);
});
it('new passwords mismatch', async () => {
await expect(user.put(endpoint, {
it('returns an error when confirmPassword does not match newPassword', async () => {
await expect(user.put(ENDPOINT, {
password,
newPassword,
confirmPassword: `${newPassword}-wrong-confirmation`,
@@ -38,8 +39,8 @@ describe('PUT /user/auth/update-password', async () => {
});
});
it('existing password is wrong', async () => {
await expect(user.put(endpoint, {
it('returns an error when existing password is wrong', async () => {
await expect(user.put(ENDPOINT, {
password: wrongPassword,
newPassword,
confirmPassword: newPassword,

View File

@@ -3,20 +3,19 @@ import {
translate as t,
} from '../../../../../helpers/api-v3-integration.helper';
const ENDPOINT = '/user/auth/update-username';
describe('PUT /user/auth/update-username', async () => {
let endpoint = '/user/auth/update-username';
let user;
let newUsername = 'new-username';
let existingUsername = 'existing-username';
let password = 'password'; // from habitrpg/test/helpers/api-integration/v3/object-generators.js
let wrongPassword = 'wrong-password';
beforeEach(async () => {
user = await generateUser();
});
it('successfully changes username', async () => {
let response = await user.put(endpoint, {
let response = await user.put(ENDPOINT, {
username: newUsername,
password,
});
@@ -26,28 +25,24 @@ describe('PUT /user/auth/update-username', async () => {
});
context('errors', async () => {
describe('new username is unavailable', async () => {
beforeEach(async () => {
user = await generateUser();
await user.update({'auth.local.username': existingUsername, 'auth.local.lowerCaseUsername': existingUsername });
});
it('prevents username update if new username is already taken', async () => {
let existingUsername = 'existing-username';
await generateUser({'auth.local.username': existingUsername, 'auth.local.lowerCaseUsername': existingUsername });
it('prevents username update', async () => {
await expect(user.put(endpoint, {
username: existingUsername,
password,
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: t('usernameTaken'),
});
await expect(user.put(ENDPOINT, {
username: existingUsername,
password,
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: t('usernameTaken'),
});
});
it('password is wrong', async () => {
await expect(user.put(endpoint, {
it('errors if password is wrong', async () => {
await expect(user.put(ENDPOINT, {
username: newUsername,
password: wrongPassword,
password: 'wrong-password',
})).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
@@ -55,26 +50,22 @@ describe('PUT /user/auth/update-username', async () => {
});
});
describe('social-only user', async () => {
beforeEach(async () => {
user = await generateUser();
await user.update({ 'auth.local': { ok: true } });
});
it('prevents username update', async () => {
await expect(user.put(endpoint, {
username: newUsername,
password,
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: t('userHasNoLocalRegistration'),
});
it('prevents social-only user from changing username', async () => {
let socialUser = await generateUser({ 'auth.local': { ok: true } });
await expect(socialUser.put(ENDPOINT, {
username: newUsername,
password,
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: t('userHasNoLocalRegistration'),
});
});
it('new username is not provided', async () => {
await expect(user.put(endpoint, {
it('errors if new username is not provided', async () => {
await expect(user.put(ENDPOINT, {
password,
})).to.eventually.be.rejected.and.eql({
code: 400,