fix: edge case in test

if user is created the other one will be renamed
This commit is contained in:
Barış Soner Uşaklı
2020-07-23 21:42:23 -04:00
parent a6ae69737b
commit b9cff5775c

View File

@@ -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 {
@@ -111,11 +111,19 @@ describe('User', function () {
}
}
await Promise.all([
const [uid1, uid2] = await Promise.all([
tryCreate({ username: 'dupe1' }),
tryCreate({ username: 'dupe1' }),
]);
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 () {