|
| 1 | +import { VPA } from '../src/vpa'; |
| 2 | + |
| 3 | +describe('VPA', () => { |
| 4 | + const tests: [string, boolean][] = [ |
| 5 | + ['amazing-uid@upi', true], |
| 6 | + ['random9999@upi', true], |
| 7 | + ['vpa_with_underscore@upi', true], |
| 8 | + ['vpa-with-hyphen@upi', true], |
| 9 | + ['vpa.with.dot@upi', true], |
| 10 | + ['9876543210@upi', true], |
| 11 | + |
| 12 | + ['it@upi', false], |
| 13 | + ['with#hash@upi', false], |
| 14 | + ['with space@upi', false], |
| 15 | + ['with@at@upi', false], |
| 16 | + ['very-long-upi-id-or-vpa-should-not-pass-the-validation@upi', false], |
| 17 | + ]; |
| 18 | + test.each(tests)(`Check %s => %s`, (value, expected) => { |
| 19 | + expect(VPA.validate(value)).toBe(expected); |
| 20 | + }); |
| 21 | +}); |
| 22 | + |
| 23 | +describe('VPA with options: { maxLength: 20 }', () => { |
| 24 | + const tests: [string, boolean][] = [ |
| 25 | + ['amazing-uid@upi', true], |
| 26 | + ['random9999@upi', true], |
| 27 | + |
| 28 | + ['vpa_with_underscore@upi', false], |
| 29 | + ['very-long-upi-id-or-vpa-should-not-pass-the-validation@upi', false], |
| 30 | + ]; |
| 31 | + test.each(tests)(`Check %s => %s`, (value, expected) => { |
| 32 | + expect(VPA.validate(value, { maxLength: 20 })).toBe(expected); |
| 33 | + }); |
| 34 | +}); |
| 35 | + |
| 36 | +describe('VPA with options: { handles: true }', () => { |
| 37 | + const tests: [string, boolean][] = [ |
| 38 | + ['amazing-uid@upi', true], |
| 39 | + ['random9999@upi', true], |
| 40 | + ['yesbank@ybl', true], |
| 41 | + ['axisbank@okaxis', true], |
| 42 | + |
| 43 | + ['axisbank@bankaxis', false], |
| 44 | + ['very-long-upi-id-or-vpa-should-not-pass-the-validation@upi', false], |
| 45 | + ]; |
| 46 | + test.each(tests)(`Check %s => %s`, (value, expected) => { |
| 47 | + expect(VPA.validate(value, { handles: true })).toBe(expected); |
| 48 | + }); |
| 49 | +}); |
| 50 | + |
| 51 | +describe('VPA with options: { handles: ["bankaxis", "superbank"] }', () => { |
| 52 | + const tests: [string, boolean][] = [ |
| 53 | + ['amazing-uid@upi', true], |
| 54 | + ['random9999@upi', true], |
| 55 | + ['yesbank@ybl', true], |
| 56 | + ['axisbank@okaxis', true], |
| 57 | + ['axisbank@bankaxis', true], |
| 58 | + ['super-vpa@superbank', true], |
| 59 | + |
| 60 | + ['super-vpa@banksuper', false], |
| 61 | + ['very-long-upi-id-or-vpa-should-not-pass-the-validation@upi', false], |
| 62 | + ['very-long-upi-id-or-vpa-should-not-pass-the-validation@superbank', false], |
| 63 | + ]; |
| 64 | + const handles = ['bankaxis', 'superbank']; |
| 65 | + test.each(tests)(`Check %s => %s`, (value, expected) => { |
| 66 | + expect(VPA.validate(value, { handles })).toBe(expected); |
| 67 | + }); |
| 68 | +}); |
| 69 | + |
| 70 | +describe('VPA with options: { maxLength: 20, handles: ["bankaxis", "superbank"] }', () => { |
| 71 | + const tests: [string, boolean][] = [ |
| 72 | + ['amazing-uid@upi', true], |
| 73 | + ['random9999@upi', true], |
| 74 | + ['yesbank@ybl', true], |
| 75 | + ['axisbank@okaxis', true], |
| 76 | + ['axisbank@bankaxis', true], |
| 77 | + ['super-vpa@superbank', true], |
| 78 | + |
| 79 | + ['super-vpa@banksuper', false], |
| 80 | + ['very-long-upi-id-or-vpa-should-not-pass-the-validation@upi', false], |
| 81 | + ['very-long-upi-id-or-vpa-should-not-pass-the-validation@superbank', false], |
| 82 | + ]; |
| 83 | + const handles = ['bankaxis', 'superbank']; |
| 84 | + test.each(tests)(`Check %s => %s`, (value, expected) => { |
| 85 | + expect(VPA.validate(value, { maxLength: 20, handles })).toBe(expected); |
| 86 | + }); |
| 87 | +}); |
0 commit comments