Chkhikvadze / mongoose-easy-types

mongoose easy types
8 stars 0 forks source link

How to add Fake refences? #1

Open damianfabian opened 8 years ago

damianfabian commented 8 years ago

Hi Guys,

Nice job, I found this library really useful to make tests, I'm wondering if you already has an option to map fake references, something like this:

var schema = mongoose.Schema({ firstName : Types.name.firstName({}), date : Types.date.future(), price : Types.commerce.price(), email : Types.internet.email({required: true}), gender : Types.random.boolean({default: true }), notifications: Types.models.ref({ model: notification, type: Array, seed: 20}) });

Chkhikvadze commented 8 years ago

Hello, Glad to hear from you. Currently we do not have such option, but we were planning to do something like this:

var schema = mongoose.Schema({
  notifications:  [{
    name: Types.lorem.word(),
    date: Types.date.future()
  }]
});

and then call

Model.seed(20, {notifications: 30});

But your suggestion looks good and we will add that to our roadmap.

Also we are planning to add validations and by assigning Types.internet.email() you will get validations for 'email' value and so on for all types. So you can use this library not only in tests but also in app models. Would be great to hear from you what are your thoughts and as always suggestions are welcome :)

damianfabian commented 8 years ago

Sorry for the late respond but I have been kind of busy, I see your point, I will start to using it like a model in my app to see if there is any performance issue, also I was thinking to create a type "switch", It means you define an element like this:

status: Types.numeric.choose({ 1, 2, 3, 4, 5})

in this case the field will be created with a numeric value, but It will choose the value from the array it's defined by the user. If I got time the next week I will tell you more about it.. Cheers and thanks for this!!