From 0c1e7767132adfb8023bf875c1c69e9744ea9339 Mon Sep 17 00:00:00 2001 From: "demi (Alvaro Martinez)" Date: Thu, 27 Jan 2022 12:24:56 +0100 Subject: [PATCH 1/4] fix: Vehicle vin is always 17 characters long --- src/vehicle.ts | 2 +- test/vehicle.spec.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/vehicle.ts b/src/vehicle.ts index e2678bee4d4..979631bdddc 100644 --- a/src/vehicle.ts +++ b/src/vehicle.ts @@ -82,7 +82,7 @@ export class Vehicle { bannedChars, })}${this.faker.random.alphaNumeric(1, { bannedChars, - })}${this.faker.datatype.number({ min: 10000, max: 100000 })}` // return five digit # + })}${this.faker.datatype.number({ min: 10000, max: 99999 })}` // return five digit # .toUpperCase(); } diff --git a/test/vehicle.spec.ts b/test/vehicle.spec.ts index b52ccff6b74..dfe39b4343f 100644 --- a/test/vehicle.spec.ts +++ b/test/vehicle.spec.ts @@ -106,6 +106,24 @@ describe('vehicle', () => { ); }); }); + + describe('vin()', () => { + it('returns valid vin number', () => { + const vin = faker.vehicle.vin(); + expect(vin).match( + /^([A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}\d{5})$/ + ); + }); + + it('is 17 characters long', () => { + for (let step = 0; step < 300000; step++) { + const vin = faker.vehicle.vin(); + expect(vin).match( + /^([A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}\d{5})$/ + ); + } + }); + }); describe('model()', () => { it('should return random vehicle model', () => { From 951aa911c94e21bc7d59b6672ad8d4614de5e823 Mon Sep 17 00:00:00 2001 From: "demi (Alvaro Martinez)" Date: Fri, 28 Jan 2022 11:49:50 +0100 Subject: [PATCH 2/4] test: merge tests --- test/vehicle.spec.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/vehicle.spec.ts b/test/vehicle.spec.ts index dfe39b4343f..2556efd81ab 100644 --- a/test/vehicle.spec.ts +++ b/test/vehicle.spec.ts @@ -106,16 +106,9 @@ describe('vehicle', () => { ); }); }); - + describe('vin()', () => { it('returns valid vin number', () => { - const vin = faker.vehicle.vin(); - expect(vin).match( - /^([A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}\d{5})$/ - ); - }); - - it('is 17 characters long', () => { for (let step = 0; step < 300000; step++) { const vin = faker.vehicle.vin(); expect(vin).match( From f7a6827a2e1c66d8fc8bc22a7d181dc7b94ab768 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 28 Mar 2022 17:14:20 +0200 Subject: [PATCH 3/4] test: fix tests --- test/vehicle.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/vehicle.spec.ts b/test/vehicle.spec.ts index 2556efd81ab..1585eeb4e32 100644 --- a/test/vehicle.spec.ts +++ b/test/vehicle.spec.ts @@ -24,7 +24,7 @@ const seededRuns = [ model: 'Colorado', type: 'Coupe', fuel: 'Electric', - vin: '8J579HF1A7MK33575', + vin: '8J579HF1A7MK33574', color: 'black', vrm: 'GO12HOL', bicycle: 'Cyclocross Bicycle', @@ -38,7 +38,7 @@ const seededRuns = [ model: '2', type: 'Wagon', fuel: 'Hybrid', - vin: 'XFWS74Z1N5S678768', + vin: 'XFWS74Z1N5S678767', color: 'azure', vrm: 'YL87FDZ', bicycle: 'Triathlon/Time Trial Bicycle', @@ -109,9 +109,9 @@ describe('vehicle', () => { describe('vin()', () => { it('returns valid vin number', () => { - for (let step = 0; step < 300000; step++) { + for (let step = 0; step < 5; step++) { const vin = faker.vehicle.vin(); - expect(vin).match( + expect(vin).toMatch( /^([A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}\d{5})$/ ); } From 02f4b883e6b3da2ce7a6c9030427f0b87319f696 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Mon, 28 Mar 2022 18:33:12 +0200 Subject: [PATCH 4/4] test: run only once --- test/vehicle.spec.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/vehicle.spec.ts b/test/vehicle.spec.ts index 1585eeb4e32..28757e6b03a 100644 --- a/test/vehicle.spec.ts +++ b/test/vehicle.spec.ts @@ -109,12 +109,10 @@ describe('vehicle', () => { describe('vin()', () => { it('returns valid vin number', () => { - for (let step = 0; step < 5; step++) { - const vin = faker.vehicle.vin(); - expect(vin).toMatch( - /^([A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}\d{5})$/ - ); - } + const vin = faker.vehicle.vin(); + expect(vin).toMatch( + /^([A-HJ-NPR-Z0-9]{10}[A-HJ-NPR-Z0-9]{1}[A-HJ-NPR-Z0-9]{1}\d{5})$/ + ); }); });