diff --git a/lib/ips.test.js b/lib/ips.test.js index 5948228..c867e0a 100644 --- a/lib/ips.test.js +++ b/lib/ips.test.js @@ -9,14 +9,14 @@ describe('IPS data string generator', () => { c: 1, v: '01', k: 'PR', - r: '160000000001006645', + r: '123456789012345611', i: 'RSD1295,', n: 'JEST Ltd., Test', rs: 'test-2020', sf: '123', s: 'Testing' }; - const result = 'K:PR|V:01|C:1|R:160000000001006645|I:RSD1295,|N:JEST Ltd., Test|RS:test-2020|SF:123|S:Testing'; + const result = 'K:PR|V:01|C:1|R:123456789012345611|I:RSD1295,|N:JEST Ltd., Test|RS:test-2020|SF:123|S:Testing'; await expect(generateIpsDataString(args)).resolves.toBe(result); }); }); diff --git a/lib/schema.js b/lib/schema.js index 7e04586..46bb9ed 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -13,6 +13,9 @@ module.exports = yup.object({ r: yup.string() .matches(/^[0-9]{18}$/, "Must contain exactly 18 numeric characters") .test('bank-account', "Value is not a valid bank account", value => { + if (!value) { + return false; + } const account = parseInt(value.substr(0, 16)); const control = parseInt(value.substr(16)); return control === 98 - (account * 100) % 97; @@ -21,6 +24,9 @@ module.exports = yup.object({ o: yup.string() .matches(/^[0-9]{18}$/, "Must contain exactly 18 numeric characters") .test('bank-account', "Value is not a valid bank account", value => { + if (!value) { + return true; + } const account = parseInt(value.substr(0, 16)); const control = parseInt(value.substr(16)); return control === 98 - (account * 100) % 97;