Skip to content

Commit

Permalink
Adding test for zipcode by state, basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
karllhughes committed Jan 20, 2018
1 parent 220e5cb commit fd6df80
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ function Address (faker) {
return Helpers.replaceSymbols(format);
}


this.zipCodeByState = function (state) {
var zipFormat = faker.definitions.address.postcode_by_state[state];
if (zipFormat) {
return this.zipCode(zipFormat);
}
return undefined;
}

/**
* Generates a random localized city name. The format string can contain any
* method provided by faker wrapped in `{{}}`, e.g. `{{name.firstName}}` in
Expand Down
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", "direction", "direction_abbr"],
"address": ["city_prefix", "city_suffix", "street_suffix", "county", "country", "country_code", "state", "state_abbr", "street_prefix", "postcode", "postcode_by_state", "direction", "direction_abbr"],
"company": ["adjective", "noun", "descriptor", "bs_adjective", "bs_noun", "bs_verb", "suffix"],
"lorem": ["words"],
"hacker": ["abbreviation", "adjective", "noun", "verb", "ingverb", "phrase"],
Expand Down
16 changes: 16 additions & 0 deletions test/address.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,22 @@ describe("address.js", function () {
});
});

describe.only("zipCodeByState()", function () {
it("returns zipCode valid for specified State", function () {
faker.locale = "en_US";
var state = "IL";
var zipCode = faker.address.zipCodeByState(state);

assert.ok(zipCode >= 60000);
assert.ok(zipCode <= 60099);
});

it("throws error if locale is invalid", function () {
});
it("throws error if state is invalid", function () {
});
});

describe("latitude()", function () {
it("returns random latitude", function () {
for (var i = 0; i < 100; i++) {
Expand Down

0 comments on commit fd6df80

Please sign in to comment.