Skip to content

Commit

Permalink
update vin to return randomly generated vin and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerreichle committed Oct 15, 2017
1 parent ef6bec4 commit 3303c7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 7 additions & 2 deletions lib/vehicle.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,16 @@ var Vehicle = function (faker) {
* @method faker.vehicle.vin
*/
self.vin = function () {
return faker.random.arrayElement(faker.definitions.vehicle.vin);
return (
faker.random.alphaNumeric(10) +
faker.random.alpha({ count: 1, upcase: true }) +
faker.random.alphaNumeric(1) +
faker.random.number({ min: 10000, max: 100000}) // return five digit #
).toUpperCase()
};

self.vin.schema = {
"description": "Generates a VIN number.",
"description": "Generates a valid VIN number.",
"sampleResults": ["YV1MH682762184654", "3C7WRMBJ2EG208836"]
};

Expand Down
9 changes: 3 additions & 6 deletions test/vehicle.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,9 @@ describe("vehicle.js", function () {
});

describe("vin()", function () {
it("returns a vin number", function () {
sinon.stub(faker.vehicle, 'vin').returns('YV1MH682762184654');
var vin = faker.vehicle.vin();

assert.equal(vin, 'YV1MH682762184654');
faker.vehicle.vin.restore();
it("returns valid vin number", function () {
var vin = faker.vehicle.vin();
assert.ok(vin.match(/^[A-Z0-9]{10}[A-Z]{1}[A-Z0-9]{1}\d{5}$/));
});
});

Expand Down

0 comments on commit 3303c7e

Please sign in to comment.