Skip to content

Commit

Permalink
fix: edge case in test
Browse files Browse the repository at this point in the history
if user is created the other one will be renamed
  • Loading branch information
barisusakli committed Jul 24, 2020
1 parent a6ae697 commit b9cff57
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/user.js
Expand Up @@ -101,7 +101,7 @@ describe('User', function () {
});
});

it('should error if username is already taken', async function () {
it('should error if username is already taken or rename user', async function () {
let err;
async function tryCreate(data) {
try {
Expand All @@ -111,11 +111,19 @@ describe('User', function () {
}
}

await Promise.all([
const [uid1, uid2] = await Promise.all([
tryCreate({ username: 'dupe1' }),
tryCreate({ username: 'dupe1' }),
]);
assert.strictEqual(err.message, '[[error:username-taken]]');
if (err) {
assert.strictEqual(err.message, '[[error:username-taken]]');
} else {
const userData = await User.getUsersFields([uid1, uid2], ['username']);
const userNames = userData.map(u => u.username);
// make sure only 1 dupe1 is created
assert.equal(userNames.filter(username => username === 'dupe1').length, 1);
assert.equal(userNames.filter(username => username === 'dupe1 0').length, 1);
}
});

it('should error if email is already taken', async function () {
Expand Down

0 comments on commit b9cff57

Please sign in to comment.