-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix alias check on account creation with Google
- Loading branch information
Showing
3 changed files
with
145 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { validateAlias } from './validateAlias' | ||
|
||
describe('validateAlias', () => { | ||
it('does not throw if alias is valid', () => { | ||
validateAlias({ valid: true, available: true }) | ||
}) | ||
it('throws if alias is taken', () => { | ||
expect(() => validateAlias({ valid: true, available: false })).toThrowError( | ||
'Sorry, that username has already been taken.', | ||
) | ||
}) | ||
it('throws if alias is invalid', () => { | ||
expect(() => validateAlias({ valid: false, available: true })).toThrowError( | ||
'Sorry, that username is not valid. User names can contain letters, numbers, dot (.), dash (-) and underscore (_) and must be at least 3 characters long.', | ||
) | ||
}) | ||
it('throws if invalid and unavailable, warning about validity', () => { | ||
expect(() => | ||
validateAlias({ valid: false, available: false }), | ||
).toThrowError( | ||
'Sorry, that username is not valid. User names can contain letters, numbers, dot (.), dash (-) and underscore (_) and must be at least 3 characters long.', | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { AliasCheckResponse } from '@sage-bionetworks/synapse-types' | ||
|
||
// Requirements for a valid username (set by backend) | ||
// https://github.com/Sage-Bionetworks/Synapse-Repository-Services/blob/f54c903e6e724b9567ebfa365200ef7f69b807a0/lib/models/src/main/java/org/sagebionetworks/repo/model/principal/AliasEnum.java#L15 | ||
|
||
export const VALID_USERNAME_DESCRIPTION = | ||
'User names can contain letters, numbers, dot (.), dash (-) and underscore (_) and must be at least 3 characters long.' | ||
|
||
export function validateAlias(aliasCheckResponse: AliasCheckResponse) { | ||
if (!aliasCheckResponse.valid) { | ||
throw new Error( | ||
`Sorry, that username is not valid. ${VALID_USERNAME_DESCRIPTION}`, | ||
) | ||
} | ||
if (!aliasCheckResponse.available) { | ||
throw new Error('Sorry, that username has already been taken.') | ||
} | ||
} |