Skip to content
Snippets Groups Projects
Commit e568479a authored by Jure's avatar Jure
Browse files

Merge branch 'unique-user-check' into 'master'

Fix typo in user unique check

See merge request !128
parents c6606268 033a21b6
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,7 @@ class User extends Model {
throw new ConflictError('User already exists')
}
result = await User.findByUsername(user.email).catch(swallowNotFound)
result = await User.findByUsername(user.username).catch(swallowNotFound)
if (result) {
throw new ConflictError('User already exists')
......
......@@ -21,9 +21,28 @@ describe('User', function () {
expect(shouldBeInvalid).toEqual(false)
})
it('raises an error if trying to save a non-unique user', async () => {
it('raises an error if trying to save a user with a non-unique username', async () => {
const user = new User(userFixture)
const duplicateUser = new User(userFixture)
const otherUserFixture = fixtures.otherUser
otherUserFixture.username = userFixture.username
const duplicateUser = new User(otherUserFixture)
await user.save()
try {
await duplicateUser.save()
} catch (err) {
expect(err.name).toEqual('ConflictError')
}
expect.hasAssertions()
})
it('raises an error if trying to save a user with a non-unique email', async () => {
const user = new User(userFixture)
const otherUserFixture = fixtures.otherUser
otherUserFixture.email = userFixture.email
const duplicateUser = new User(otherUserFixture)
await user.save()
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment