Overrides for generateUser and test adjustment

This commit is contained in:
Randi Miller
2019-03-22 14:44:27 -04:00
parent e277a088ee
commit e644ae83fd
2 changed files with 14 additions and 19 deletions

View File

@@ -54,7 +54,7 @@ describe('GET /heroes/:heroId', () => {
expect(heroRes.profile).to.have.all.keys(['name']);
});
it('returns only necessary hero data given username with display case', async () => {
it('returns only necessary hero data given username', async () => {
let hero = await generateUser({
contributor: {tier: 23},
});
@@ -68,15 +68,9 @@ describe('GET /heroes/:heroId', () => {
expect(heroRes.profile).to.have.all.keys(['name']);
});
it('returns hero data given username without case sensitivity', async () => {
let hero = await generateUser({}, 'TestUpperCaseName123');
let heroRes = await user.get(`/hall/heroes/${hero.auth.local.username.toLowerCase()}`);
expect(heroRes).to.have.all.keys([
'_id', 'id', 'balance', 'profile', 'purchased',
'contributor', 'auth', 'items',
]);
expect(heroRes.auth.local).not.to.have.keys(['salt', 'hashed_password']);
expect(heroRes.profile).to.have.all.keys(['name']);
it('returns correct hero using search with difference case', async () => {
let hero = await generateUser({}, { username: 'TestUpperCaseName123' });
let heroRes = await user.get(`/hall/heroes/TestuPPerCasEName123`);
expect(heroRes.auth.local.username).to.equal('TestUpperCaseName123');
});
});

View File

@@ -14,14 +14,15 @@ import * as Tasks from '../../../../website/server/models/task';
// , you can do so by passing in the full path as a string:
// { 'items.eggs.Wolf': 10 }
//
// To manually set a username pass it as the second parameter.
// If no password is passed or it is falsy then a username will
// be auto-generated.
// Example: generateUser({}, 'TestName') adds user with the 'TestName' username.
export async function generateUser (update = {}, manualUsername = null) {
let username = manualUsername || (Date.now() + generateUUID()).substring(0, 20);
let password = 'password';
let email = `${username}@example.com`;
// To manually set a username, email or password pass it in as
// an object for the second parameter. Only overrides need to be
// added. Items that don't exist will be autogenerated.
// Example: generateUser({}, { username: 'TestName' }) adds user
// with the 'TestName' username.
export async function generateUser (update = {}, overrides = {}) {
let username = overrides.username || (Date.now() + generateUUID()).substring(0, 20);
let password = overrides.password || 'password';
let email = overrides.email || `${username}@example.com`;
let user = await requester().post('/user/auth/local/register', {
username,