|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +/** |
| 4 | + * Module dependencies. |
| 5 | + */ |
| 6 | + |
| 7 | +const { Assert: BaseAssert, Violation } = require('validator.js'); |
| 8 | +const AbaAccountNumberAssert = require('../../src/asserts/aba-account-number-assert'); |
| 9 | + |
| 10 | +/** |
| 11 | + * Extend `Assert` with `AbaAccountNumberAssert`. |
| 12 | + */ |
| 13 | + |
| 14 | +const Assert = BaseAssert.extend({ |
| 15 | + AbaAccountNumber: AbaAccountNumberAssert |
| 16 | +}); |
| 17 | + |
| 18 | +/** |
| 19 | + * Test `AbaAccountNumberAssert`. |
| 20 | + */ |
| 21 | + |
| 22 | +describe('AbaAccountNumberAssert', () => { |
| 23 | + it('should throw an error if the input value is not a string', () => { |
| 24 | + [{}, []].forEach(choice => { |
| 25 | + try { |
| 26 | + Assert.abaAccountNumber().validate(choice); |
| 27 | + |
| 28 | + fail(); |
| 29 | + } catch (e) { |
| 30 | + expect(e).toBeInstanceOf(Violation); |
| 31 | + expect(e.violation.value).toBe('must_be_a_string'); |
| 32 | + } |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should throw an error if the input value is not a valid ABA account number', () => { |
| 37 | + try { |
| 38 | + Assert.abaAccountNumber().validate('foo'); |
| 39 | + |
| 40 | + fail(); |
| 41 | + } catch (e) { |
| 42 | + expect(e).toBeInstanceOf(Violation); |
| 43 | + expect(e.show().value).toBe('foo'); |
| 44 | + } |
| 45 | + }); |
| 46 | + |
| 47 | + it('should expose `assert` equal to `AbaAccountNumber`', () => { |
| 48 | + try { |
| 49 | + Assert.abaAccountNumber().validate(123); |
| 50 | + |
| 51 | + fail(); |
| 52 | + } catch (e) { |
| 53 | + expect(e.show().assert).toBe('AbaAccountNumber'); |
| 54 | + } |
| 55 | + }); |
| 56 | + |
| 57 | + it.each(['76175925', '76175925761759257', '76175', 'abcdefghijklmnopq', 'abcde', 'ABcDeFGH'])( |
| 58 | + 'should accept a valid ABA account number', |
| 59 | + accountNumber => { |
| 60 | + Assert.abaAccountNumber().validate(accountNumber); |
| 61 | + } |
| 62 | + ); |
| 63 | +}); |
0 commit comments