Magically creates a random fake data such as names, addresses, and phone numbers based in your SimpleSchema. Good for testing fixtures.
Install using Meteor's package management system:
> meteor add gbit:fakefill
$ meteor test-packages ./
You can call Fakefill from your Collection namespace
Do you want to easily seed your collection with 10 fake docs? Just do it:
var docs = Authors.fakefill().insert(number, overrides, options);
=> [ { profile: { firstName: '...', lastName: '...', email: '...' }, ..., ..., ... } ]
This method inserts the number you specified of random documents to your collection.
If you want to omit some field, just pass an array in options.omit
:
var docs = Authors.fakefill().insert(number, overrides, {
omit: ['email']
});
=> [ { profile: { firstName: '...', lastName: '...' }, ..., ..., ... } ]
This method doesn't insert nothing to your collection, just returns a array with random documents.
var Authors = new Mongo.Collection('authors');
Authors.attachSchema(new SimpleSchema({
profile: {
type: new SimpleSchema({
firstName: {
type: String
},
lastName: {
type: String
},
email: {
type: String
}
})
}
}));
var docs = Authors.fakefill().gen(10); //
=> [ { profile: { firstName: '...', lastName: '...', email: '...' }, ..., ..., ... } ]
Do you want to seed your collection in a single line with zero effort?
// Create for me 10 random users, please.
Users.fakefill().gen(10);
You can get a random totally filled doc just passing a schema to Fakefill.fromSchema
.
Fakefill will load all the fields and generate the proper data for each of them.
So just relax and:
var doc = Fakefill.fromSchema(new SimpleSchema({
userName: {
type: String,
label: 'Site username'
},
email: {
type: SimpleSchema.RegEx.Email,
label: 'Your email'
}
}));
=> { username: 'Maria_Juana666', email: 'imnotyourfatha@example.net' }
But if you're unhappy with the generated data of a field, you can pass an override:
var doc = Fakefill.fromSchema(new SimpleSchema({
userName: {
type: String,
label: 'Site username'
},
email: {
type: SimpleSchema.RegEx.Email,
label: 'Your email'
}
}), {
userName: function(){
return 'oh my god';
}
});
=> { username: 'oh my god', email: 'imnotyourfatha@example.net' }
That's it.
This method is just a shortcut for Fakefill(Collection.simpleSchema())
var doc = Fakefill.genDoc(Users);
=> { username: 'Maria_Juana666', email: 'aycarmela@example.net', ... }
Fakefill.setLocale('pt_BR');
Set the language locate you want. See the supported locales:
This package includes gbit:faker, so you can use it too calling faker
.
Accepting pull requests that increase Fakefill perfomance.