Skip to content

Commit

Permalink
Add accountNumber and sortCode length validation
Browse files Browse the repository at this point in the history
  • Loading branch information
João Barbosa committed Apr 29, 2016
1 parent e0c1eec commit 8276bb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ export default class UkModulusChecking {
*/

isValid() {
if (this.accountNumber.length < 6 || this.accountNumber.length > 10 || this.sortCode.length !== 6) {
return false;
}

const checks = this.getSortCodeChecks();

// If no range is found that contains the sorting code, there is no modulus check that can be performed.
Expand Down
12 changes: 12 additions & 0 deletions test/index_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ const accounts = {

describe('UkModulusChecking', () => {
describe('isValid()', () => {
it('should return false if account number length is less than 6', () => {
new UkModulusChecking({ accountNumber: '12345', sortCode: '123456' }).isValid().should.be.false();
});

it('should return false if account number length is greater than 10', () => {
new UkModulusChecking({ accountNumber: '12345678901', sortCode: '123456' }).isValid().should.be.false();
});

it('should return false if sort code length is not 6', () => {
new UkModulusChecking({ accountNumber: '12345789', sortCode: '12345' }).isValid().should.be.false();
});

accounts.invalid.forEach((account) => {
it(`should return false if sort code is ${account.sortCode} and account number is ${account.accountNumber}`, () => {
new UkModulusChecking({ accountNumber: account.accountNumber, sortCode: account.sortCode }).isValid().should.be.false();
Expand Down

0 comments on commit 8276bb8

Please sign in to comment.