Sails Multitenant Factory is a simple model factory for Sails.js 1.X with multitenancy features. This project is based on sails-factory. This project use sails-hook-multitenancy to provide with multitenancy features.
This project is inspired on Factory-girl and other factory testing tools.
Installation
npm install sails-factory-multitenant --save
Usage
Defining factories
Define a factory by giving it a name and an optional model name. The factory name will be the default model name if model name is not provided.
var factory = ; factory ; factoryparent"user" ; factoryparent"user";
Using factories
var active_user = factory; // active_user: non-persistent "active_user" instance // { // first_name: "First Name", // last_name: "Last Name", // random_id: <number>, // active: true // } var user = factory; // user: non-persistent "user" instance // { // first_name: "Hello", // last_name: "World", // random_id: <number> // } //-- asynchronous factory; factory; factory;
Auto increment attributes
Attributes can have an auto_increment option. By default, sequence will increment by 1, otherwise it will increment by whatever value the auto_increment option is set to. Counting starts at the initial value given. Sequence is shared among parent and children.
factory ; // OR with %d number character template. factory ; factoryparent"user"; factory; factory; factory;
Loading factories
Calling .load() without parameter will try to load factory definitions from test/factories folder. By default, the model name will be set to factory file name if not provided on define parameters.
// api/models/User.js moduleexports = attributes: first_name: "string" last_name: "string" random_id: "integer" active: "boolean" ; // test/factories/User.js module { factory ; factoryparent"user" ; }; // test/bootstrap.js ;
To load factory files from different folder:
factory;
To get the total number of loaded factory files:
factory;
Test
To run test of this library, please follow next command
npm test...33 passing
9. Contributors
This project is based on sails-factory project wrote by Alexander Magtipon.
Knownledge is power, share the Knownledge.
10. License
This project is develop by Parley for free use by the community, under MIT license.
Made with ❤ in Chile