Skip to content

Commit 90e1af9

Browse files
committed
fix: Vehicle vin is always 17 characters long
1 parent 2d68da1 commit 90e1af9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/vehicle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class Vehicle {
8787
bannedChars,
8888
})}${this.faker.random.alphaNumeric(1, {
8989
bannedChars,
90-
})}${this.faker.datatype.number({ min: 10000, max: 100000 })}` // return five digit #
90+
})}${this.faker.datatype.number({ min: 10000, max: 99999 })}` // return five digit #
9191
.toUpperCase();
9292
}
9393

test/vehicle.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ describe('vehicle', () => {
106106
);
107107
});
108108
});
109+
110+
describe('vin()', () => {
111+
it('returns valid vin number', () => {
112+
const vin = faker.vehicle.vin();
113+
expect(vin).match(
114+
/^([A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}\d{5})$/
115+
);
116+
});
117+
118+
it('is 17 characters long', () => {
119+
for (let step = 0; step < 300000; step++) {
120+
const vin = faker.vehicle.vin();
121+
expect(vin).match(
122+
/^([A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}\d{5})$/
123+
);
124+
}
125+
});
126+
});
109127

110128
describe('model()', () => {
111129
it('should return random vehicle model', () => {

0 commit comments

Comments
 (0)