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',