Skip to content

Added unit tests for invalid types in User-Id validation. #90

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

Merged
merged 2 commits into from
Apr 18, 2018
Merged
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions packages/optimizely-sdk/lib/utils/user_id_validator/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ describe('lib/utils/user_id_validator', function() {
userIdValidator.validate('');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the license headers to include the year 2018 --> 2016, 2018

}, sprintf(ERROR_MESSAGES.INVALID_USER_ID, 'USER_ID_VALIDATOR'));
});

it('should throw an error if userId is int', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can be consolidated into one test case, which is, should throw an error if userId is not a string and you can run the 3 assertions in that one test

assert.throws(function() {
userIdValidator.validate(3);
}, sprintf(ERROR_MESSAGES.INVALID_USER_ID, 'USER_ID_VALIDATOR'));
});

it('should throw an error if userId is boolean', function() {
assert.throws(function() {
userIdValidator.validate(true);
}, sprintf(ERROR_MESSAGES.INVALID_USER_ID, 'USER_ID_VALIDATOR'));
});

it('should throw an error if userId is array', function() {
assert.throws(function() {
userIdValidator.validate([]);
}, sprintf(ERROR_MESSAGES.INVALID_USER_ID, 'USER_ID_VALIDATOR'));
});
});
});
});