Skip to content

Commit

Permalink
add unit tests and schema desciptions
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerreichle committed Oct 21, 2017
1 parent 4179b20 commit 9239055
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
19 changes: 14 additions & 5 deletions lib/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,26 +230,35 @@ function Address (faker) {
/**
* cardinal direction
*
* @method faker.address.cardDirection
* @method faker.address.cardinalDirection
*/
this.cardDirection = function () {
this.cardinalDirection = function () {
return faker.random.arrayElement(faker.definitions.address.direction);
}

this.cardinalDirection.schema = {
"description": "Generates a cardinal direction.",
"sampleResults": ["N", "S", "E", "W"]
};

/**
* ordinal direction
*
* @method faker.address.ordDirection
* @method faker.address.ordinalDirection
*/
this.ordDirection = function () {
this.ordinalDirection = function () {
return (
faker.random.arrayElement(faker.definitions.address.direction.slice(0, 2)) +
faker.random.arrayElement(faker.definitions.address.direction.slice(2, 4))
);
}

this.ordinalDirection.schema = {
"description": "Generates an ordinal direction.",
"sampleResults": ["NW", "SE", "SW", "NE"]
};

return this;
}


module.exports = Address;
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function Faker (opts) {

var _definitions = {
"name": ["first_name", "last_name", "prefix", "suffix", "gender", "title", "male_first_name", "female_first_name", "male_middle_name", "female_middle_name", "male_last_name", "female_last_name"],
"address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "state", "state_abbr", "street_prefix", "postcode"],
"address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "state", "state_abbr", "street_prefix", "postcode", "direction"],
"company": ["adjective", "noun", "descriptor", "bs_adjective", "bs_noun", "bs_verb", "suffix"],
"lorem": ["words"],
"hacker": ["abbreviation", "adjective", "noun", "verb", "ingverb", "phrase"],
Expand Down
19 changes: 19 additions & 0 deletions test/address.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,23 @@ describe("address.js", function () {
});
});

describe("ordinalDirection()", function () {
it("returns random ordinal direction", function () {
sinon.stub(faker.address, 'ordinalDirection').returns('W');
var ordinalDirection = faker.address.ordinalDirection();

assert.equal(ordinalDirection, 'W');
faker.address.ordinalDirection.restore();
})
})

describe("cardinalDirection()", function () {
it("returns random cardinal direction", function () {
sinon.stub(faker.address, 'cardinalDirection').returns('NW');
var cardinalDirection = faker.address.cardinalDirection();

assert.equal(cardinalDirection, 'NW');
faker.address.cardinalDirection.restore();
})
})
});

0 comments on commit 9239055

Please sign in to comment.