Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user/checkusernameavailability now returns boolean #466

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions controllers/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,7 @@ class UserController {
}

User.findOne({name: {$eq: username}}).lean().then(userFound => {
if (userFound) {
return resolve(HTTPWTHandler.OK('Username is not available'))
} else {
return resolve(HTTPWTHandler.OK('Username is available'))
}
return resolve(HTTPWTHandler.OK(!userFound))
}).catch(err => {
console.error('An error occurred while finding one user with name:', username, '. The error was:', err)
return resolve(HTTPWTHandler.serverError('An error occurred while finding user with username. Please try again.'))
Expand Down
2 changes: 1 addition & 1 deletion libraries/HTTPWT.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class HTTPWT {
statusCode: 200,
data: {
status: 'SUCCESS',
message: message || '',
message: message ?? '',
...extras
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/user/checkusernameavailability.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test('user/checkusernameavailability says available when username is available',

const returned = await UserController.checkusernameavailability('seb')

expect(returned.data.message).toBe('Username is available')
expect(returned.data.message).toBe(true)
expect(returned.statusCode).toBe(200)
expect(await DB.noChangesMade()).toBe(true)
})
Expand All @@ -56,7 +56,7 @@ test('user/checkusernameavailability says not available when username is not ava

const returned = await UserController.checkusernameavailability('seb')

expect(returned.data.message).toBe('Username is not available')
expect(returned.data.message).toBe(false)
expect(returned.statusCode).toBe(200)
expect(await DB.noChangesMade()).toBe(true)
})
Expand Down