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