Skip to content

Commit

Permalink
⭐ new: createGenerator method
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed May 27, 2016
1 parent 4f47db3 commit b1cdd88
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 44 deletions.
13 changes: 6 additions & 7 deletions lib/fakerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,12 @@ module.exports = function(localeID = "default") {
return self.generate(res, ...args);
};

/*function createGeneratorMethods(obj, definitions, level) {
function createGeneratorMethods(obj, definitions, level) {
each(Object.keys(definitions), (item) => {
if (item === "_meta") return;

console.log(item);
let def = definitions[item];
if (isObject(def) && level < 2) {
if (isObject(def) && !isArray(def) && !isFunction(def) && level < 10) {
obj[item] = {};
createGeneratorMethods(obj[item], def, level + 1);
}
Expand All @@ -266,11 +265,11 @@ module.exports = function(localeID = "default") {
};
}
});
}*/
}

//createGeneratorMethods(self, self.locale, 1);
createGeneratorMethods(self, self.locale, 1);


/*
// Set helper functions from locale definitions
each(Object.keys(self.locale), (category) => {
if (category === "_meta") return;
Expand All @@ -284,7 +283,7 @@ module.exports = function(localeID = "default") {
//console.log("Set " + category + "." + item);
});
});
});*/

return self;
};
7 changes: 1 addition & 6 deletions test/specs/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,4 @@ describe("Fakerator", () => {
expect(fakerator.locale.lorem).to.be.an("Object");
});

it.skip("generate", () => {
let fakerator = new Fakerator();

console.log(fakerator.generate(fakerator.locale.address.buildingNumber));
})
})
});
62 changes: 31 additions & 31 deletions test/specs/locales/hu-HU/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("Locale hu-HU", () => {
expect(fakerator.address.buildingNumber()).to.be.equal("5");
expect(fakerator.address.postCode()).to.be.equal("0086");

//expect(fakerator.address.state()).to.be.undefined;
expect(fakerator.address.state()).to.be.undefined;
});

it("check internet definitions", () => {
Expand All @@ -56,35 +56,35 @@ describe("Locale hu-HU", () => {
expect(fakerator.internet.email()).to.be.equal("rita19@gmail.com");
});

it("check entity.user", () => {
let user = fakerator.entity.user();
expect(user).to.be.an("Object");
//console.log(user);

expect(user).to.have.property("firstName").an("String");
expect(user).to.have.property("lastName").an("String");
expect(user).to.have.property("userName").an("String");
expect(user).to.have.property("password").an("String");
expect(user).to.have.property("email").an("String");
expect(user).to.have.property("phone").an("String");
expect(user).to.have.property("dob").an("Date");
expect(user).to.have.property("website").an("String");
expect(user).to.have.property("ip").an("String");
expect(user).to.have.property("avatar").an("String");
expect(user).to.have.property("gravatar").an("String");
expect(user).to.have.property("status").an("Boolean");
expect(user).to.have.property("address").an("Object");

expect(user.address).to.have.property("country").an("String");
expect(user.address).to.have.property("countryCode").an("String").length(2);
//expect(user.address).to.have.not.property("state");
expect(user.address).to.have.property("city").an("String");
expect(user.address).to.have.property("street").an("String");
expect(user.address).to.have.property("zip").an("String");
expect(user.address).to.have.property("geo").an("Object");
expect(user.address.geo).to.have.property("latitude").an("Number");
expect(user.address.geo).to.have.property("longitude").an("Number");

});
it("check entity.user", () => {
let user = fakerator.entity.user();
expect(user).to.be.an("Object");
//console.log(user);

expect(user).to.have.property("firstName").an("String");
expect(user).to.have.property("lastName").an("String");
expect(user).to.have.property("userName").an("String");
expect(user).to.have.property("password").an("String");
expect(user).to.have.property("email").an("String");
expect(user).to.have.property("phone").an("String");
expect(user).to.have.property("dob").an("Date");
expect(user).to.have.property("website").an("String");
expect(user).to.have.property("ip").an("String");
expect(user).to.have.property("avatar").an("String");
expect(user).to.have.property("gravatar").an("String");
expect(user).to.have.property("status").an("Boolean");
expect(user).to.have.property("address").an("Object");

expect(user.address).to.have.property("country").an("String");
expect(user.address).to.have.property("countryCode").an("String").length(2);
expect(user.address.state).to.be.undefined;
expect(user.address).to.have.property("city").an("String");
expect(user.address).to.have.property("street").an("String");
expect(user.address).to.have.property("zip").an("String");
expect(user.address).to.have.property("geo").an("Object");
expect(user.address.geo).to.have.property("latitude").an("Number");
expect(user.address.geo).to.have.property("longitude").an("Number");

});

})

0 comments on commit b1cdd88

Please sign in to comment.