Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
function validate(vin) {
if (!vin) {
return false;
}

vin = vin.toLowerCase();
if (!/^[a-hj-npr-z0-9]{8}[0-9xX][a-hj-npr-z0-9]{8}$/.test(vin)) {
return false;
Expand Down
24 changes: 24 additions & 0 deletions test/vin.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,27 @@ describe('Given a VIN with a correct check digit', function() {
});
});
});

describe('Given null value', function() {
var vin = null;

describe('When the VIN is validated', function() {
var valid;
beforeEach(function() { valid = vinValidator.validate(vin); })

it('Then it should fail', function() {
expect(valid).to.be.false;
});
});
});

describe('Given undefined', function() {
describe('When the VIN is validated', function() {
var valid;
beforeEach(function() { valid = vinValidator.validate(); })

it('Then it should fail', function() {
expect(valid).to.be.false;
});
});
});