-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation to new root profile attributes
- Loading branch information
Showing
5 changed files
with
240 additions
and
226 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Immutable from 'immutable'; | ||
import { setField } from '../../field'; | ||
|
||
const createModel = field => | ||
Immutable.fromJS({ | ||
field: { | ||
[field]: `old_test_${field}` | ||
} | ||
}); | ||
|
||
const testField = (field, maxLength) => { | ||
const m = createModel(field); | ||
expect(setField(m, field, '').toJS().field[field].valid).toBe(false); | ||
expect(setField(m, field, 'test_value').toJS().field[field].valid).toBe(true); | ||
if (maxLength) { | ||
expect(setField(m, field, 'a'.repeat(maxLength + 1)).toJS().field[field].valid).toBe(false); | ||
} | ||
}; | ||
describe('field/index', () => { | ||
describe('default validation', () => { | ||
it('validates family_name', () => { | ||
testField('family_name', 150); | ||
}); | ||
it('validates family_name', () => { | ||
testField('given_name', 150); | ||
}); | ||
it('validates name', () => { | ||
testField('name', 300); | ||
}); | ||
it('validates nickname', () => { | ||
testField('nickname', 300); | ||
}); | ||
it('validates other fields', () => { | ||
testField('test'); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -24,9 +24,10 @@ describe('field/username', () => { | |
}); | ||
}); | ||
describe('usernameLooksLikeEmail()', () => { | ||
it('checks for @', () => { | ||
it('checks for @ and .', () => { | ||
expect(username.usernameLooksLikeEmail('[email protected]')).toBe(true); | ||
expect(username.usernameLooksLikeEmail('tt.com')).toBe(false); | ||
expect(username.usernameLooksLikeEmail('t@tcom')).toBe(false); | ||
}); | ||
}); | ||
describe('getUsernameValidation()', () => { | ||
|
@@ -134,11 +135,11 @@ describe('field/username', () => { | |
expectToFailWith('aaaaaa'); | ||
}); | ||
it('validates invalid chars', () => { | ||
const invalidChars = `{}[],;?/\\!@#$%¨&*()¹²³\`~^´ªº§£¢¬<>|"' `.split(''); | ||
const invalidChars = `{}[],;?/\\%¨&*()¹²³ªº§£¢¬<>|" `.split(''); | ||
invalidChars.forEach(i => expectToFailWith(`aa${i}`)); | ||
}); | ||
it('accepts letters, numbers, `_`, `-`, `+` and `.`', () => { | ||
const validChars = `_-+.`.split(''); | ||
const validChars = `_+-.!#$'^\`~@`.split(''); | ||
validChars.forEach(i => expectToSuccedWith(`aa${i}`)); | ||
}); | ||
}); | ||
|
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
Oops, something went wrong.