girassolbit / meteor-fakefill

Automatically creates random fake data such as names, addresses, and phone numbers based in your SimpleSchema
5 stars 0 forks source link

Stories in Ready Build Status Fakefill

Magically creates a random fake data such as names, addresses, and phone numbers based in your SimpleSchema. Good for testing fixtures.

Installation

Install using Meteor's package management system:

> meteor add gbit:fakefill

Testing (if you clone the package)

$ meteor test-packages ./

How to use

Mongo.Collection instances

You can call Fakefill from your Collection namespace

Collection.fakefill().insert

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: '...' }, ..., ..., ... } ]

Colection.fakefill.gen

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: '...' }, ..., ..., ... } ]

Fakefill goal: easily seed data

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);

Fakefill.fromSchema(simpleSchemaInstance, overrides, options)

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.

Fakefill.genDoc(MongoCollectionInstance, overrides)

This method is just a shortcut for Fakefill(Collection.simpleSchema())

    var doc = Fakefill.genDoc(Users);

    => { username: 'Maria_Juana666', email: 'aycarmela@example.net', ... }

Fakefill.setLocale(locate)

    Fakefill.setLocale('pt_BR');

Set the language locate you want. See the supported locales:

Faker

This package includes gbit:faker, so you can use it too calling faker.

Issues

Pull request

Accepting pull requests that increase Fakefill perfomance.