Home Reference Source Test Repository

unit/util/validator.js

  1. import chai from 'chai';
  2. import Validator from '../../../src/util/validator.js';
  3. import { IDENTITY_V2_USER_RESPONSE, ACCESS_TOKEN_RESPONSE, DEVICE_CODE_RESPONSE } from '../../test-data';
  4.  
  5.  
  6. const should = chai.should();
  7.  
  8.  
  9. /** @test {Validator} */
  10. describe('Validator', () => {
  11. let responseClone;
  12.  
  13.  
  14. /** @test {Validator.validateCollectionDoc} */
  15. describe('validateCollectionDoc', () => {
  16. beforeEach(() => {
  17. responseClone = JSON.parse(JSON.stringify(IDENTITY_V2_USER_RESPONSE));
  18. });
  19.  
  20. it('should not throw an error on valid input', () => {
  21. should.not.exist(Validator.validateCollectionDoc(responseClone));
  22. });
  23.  
  24. it('should throw an error on invalid input', () => {
  25. delete responseClone.version;
  26. should.Throw(Validator.validateCollectionDoc.bind(this, responseClone));
  27. });
  28. });
  29.  
  30.  
  31. /** @test {Validator.validateAccessToken} */
  32. describe('validateAccessToken', () => {
  33. beforeEach(() => {
  34. responseClone = JSON.parse(JSON.stringify(ACCESS_TOKEN_RESPONSE));
  35. });
  36.  
  37. it('should not throw an error on valid input', () => {
  38. should.not.exist(Validator.validateAccessToken(responseClone));
  39. });
  40.  
  41. it('should throw an error on invalid input', () => {
  42. delete responseClone.token_type;
  43. should.Throw(Validator.validateAccessToken.bind(this, responseClone));
  44. });
  45. });
  46.  
  47.  
  48. /** @test {Validator.validateDeviceCode} */
  49. describe('validateDeviceCode', () => {
  50. beforeEach(() => {
  51. responseClone = JSON.parse(JSON.stringify(DEVICE_CODE_RESPONSE));
  52. });
  53.  
  54. it('should not throw an error on valid input', () => {
  55. should.not.exist(Validator.validateDeviceCode(responseClone));
  56. });
  57.  
  58. it('should throw an error on invalid input', () => {
  59. delete responseClone.verification_uri;
  60. should.Throw(Validator.validateDeviceCode.bind(this, responseClone));
  61. });
  62. });
  63. });