Skip to content

Commit d9c5ada

Browse files
mfahadahmedmikeproeng37
authored andcommitted
Added unit tests for invalid types in User-Id validation. (#90)
1 parent b504705 commit d9c5ada

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/optimizely-sdk/lib/utils/user_id_validator/index.tests.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016, Optimizely
2+
* Copyright 2016, 2018, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,6 +45,20 @@ describe('lib/utils/user_id_validator', function() {
4545
userIdValidator.validate('');
4646
}, sprintf(ERROR_MESSAGES.INVALID_USER_ID, 'USER_ID_VALIDATOR'));
4747
});
48+
49+
it('should throw an error if userId is not a string', function() {
50+
assert.throws(function() {
51+
userIdValidator.validate(3);
52+
}, sprintf(ERROR_MESSAGES.INVALID_USER_ID, 'USER_ID_VALIDATOR'));
53+
54+
assert.throws(function() {
55+
userIdValidator.validate(true);
56+
}, sprintf(ERROR_MESSAGES.INVALID_USER_ID, 'USER_ID_VALIDATOR'));
57+
58+
assert.throws(function() {
59+
userIdValidator.validate([]);
60+
}, sprintf(ERROR_MESSAGES.INVALID_USER_ID, 'USER_ID_VALIDATOR'));
61+
});
4862
});
4963
});
5064
});

0 commit comments

Comments
 (0)