Skip to content

Commit

Permalink
Cimpress-MCP#62 moved the postal code check down and added a test so …
Browse files Browse the repository at this point in the history
…that empty postal codes are valid as well for countries that don't have a postal code standard
  • Loading branch information
jonathan committed Jan 4, 2021
1 parent 588af79 commit e860fb4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions postal-codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ module.exports.validate = function (countryCode, postalCode) {
return "Missing country code.";
}

if ( !postalCode ) {
return 'Missing postal code.';
}

var countryData = undefined;
var preparedCountryCode = countryCode.trim().toUpperCase();

Expand All @@ -43,6 +39,10 @@ module.exports.validate = function (countryCode, postalCode) {
return true;
}

if ( !postalCode ) {
return 'Missing postal code.';
}

var format = getFormat(countryData.postalCodeFormat);
if ( !format ) {
return 'Failed to load postal code format "' + countryData.postalCodeFormat + '".';
Expand Down
8 changes: 7 additions & 1 deletion test/validationTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ describe('Postal codes border cases: ', function () {
description: 'should return error when postal code is null',
expectedResult: 'Missing postal code.'
},
{
countryCode: 'bw',
postalCode: undefined,
description: 'should return true when postal code is undefined and the country does not have a postal code standard',
expectedResult: true
},
{
countryCode: 'gb',
postalCode: undefined,
Expand Down Expand Up @@ -98,4 +104,4 @@ describe('Postal codes border cases: ', function () {
expect(postalCodes.validate(test.countryCode, test.postalCode)).to.equal(test.expectedResult);
});
});
});
});

0 comments on commit e860fb4

Please sign in to comment.