bredikhin / barrels Goto Github PK
View Code? Open in Web Editor NEWSimple DB Fixtures for Sails.js
License: MIT License
Simple DB Fixtures for Sails.js
License: MIT License
I just noticed that barrels try to delete 'empty' models (no records at all) and this will create waterline problem with delete. Here is gist of my fixtures and actual error which I'm getting on sails lift https://gist.github.com/tarlepp/b42077c45955d5703276
Simple fix for this would be add model data fetch before destroy, if there isn't any record there is no need to make destroy.
Btw, this library has save alot of my time, thank!
Hey there,
I am currently facing this problem when migrating with barrels.
Post.json
"title": "just awesome",
"rating": 125,
Error message
{ rating:
[ { rule: 'number',
message: '`undefined` should be a number (instead of "125", which is a string)' } ],
This is weird because actually I entered the number not as a string.
Does anyone have an idea?
Please apply pull-request to support for non-integer IDs. #37
Hey,
No idea what happened here, but 1.1.1 breaks associations. Travis started complaining and I noticed that my associations contained value null. (Really simple oneToOne association, with model definition on both sides).
Sidenote, your versioning is wrong. You went from 1.0.1 to 1.1.1. Doesn't add up. :) Unless you combined a bugfix and functionality, in which case you've been a bad boy :p Resource: http://semver.org/
Asked this on Stackoverflow here, but I think this is more of a barrels issue because the populate
method doesn't do what it suppose to do.
Here's my setup
<Project>/test/specHelper.js
(which is the test bootstrap):
'use strict';
var Sails = require('sails')
, Barrels = require('barrels')
, barrels, fixtures;
before(function(done) {
Sails.lift(
{
// Configuration for testing
environment: 'test',
log: {
level: 'error'
},
connections: {
test: {
adapter: 'sails-memory'
}
},
models: {
connection: 'test'
},
port: 98765
},
function(err, sails) {
if (err)
return done(err);
// Load fixtures
barrels = new Barrels(process.cwd() + '/tests/fixtures');
fixtures = barrels.data;
barrels.populate(function(err) {
done(err, sails);
});
}
);
});
after(function(done) {
// Clear fixtures, etc.
Sails.lower(done);
});
and here's a spec file <Project>/tests/EntitySpec.js
var chai = require('chai');
, expect = chai.expect;
describe('Entity', function() {
describe('class methods', function() {
describe('#a_method', function() {
it('does something', function(done) {
Entity.find().then(function(results) {
console.log('in database', results);
done();
}).catch(done);
});
});
});
});
Even if I check on the specHelper.js
in the callback function from barrels.populate
, there's no record there. That would be awesome if you put a recommended way to setup barrels in the Readme or a wiki page. Thanks!
In my project User
s can have many Document
s.
My user.json
fixture looks like
{
"email": "[email protected]",
"emailVerified": true,
"dateEmailVerified": "2014-06-11",
"termsAccepted": true,
"dateTermsAccepted": "2014-06-11",
"documents": [
{
"name": "file_name.pdf",
"path": "/test/file.pdf",
"size": 0,
"localName": "file.pdf",
"purpose": "proof-of-identity",
"verified": false
}
],
"password": "Password1"
}
But alas that's not creating the appropriate Document
model.
I could of course have a separate document.json
file that has the document detail but how ought I connect the two?
//skill fixture
[
{
"id" : 1,
"name": "cook"
},
{
"id" : 2,
"name": "security"
}
]
//test
before(function (done) {
barrels.populate(function () {
done();
});
});
it("should increment id after barrels populates", {
Skill.find()
.then(function (skills) {
skills.length.should.equal(2);
skills[0].id.should.equal(1);
skills[1].id.should.equal(2);
return Skill.create({name: 'test'});
})
.then(function (skill) {
skill.id.should.equal(3);
//failed expected 1 to be 3 with both memory and disk adapter. mongo adapter gives the following error expected '1' to be 1
});
});
Manually associating models seems not to be possible to do reliably. In the following example, different passports get associated to users on multiple startups of the server.
I have two models I'm trying to populate. One is a User
model, the other a Passport
model, where a User
has many Passports
. So, I try to initialize them as follows:
User
:
[
{
"username" :"admin",
"email" :"[email protected]",
"admin" :true,
"confirmed" :true
},
{
"username" :"demo",
"email" :"[email protected]",
"admin" :false,
"membership" :"member",
"confirmed" :true
},
{
"username" :"user",
"email" :"[email protected]",
"admin" :false,
"membership" :"member",
"confirmed" :true
}
]
and Passport
:
[
{
"protocol":"local",
"password":"adminadmin",
"user": 1
},
{
"protocol":"local",
"password":"demodemo",
"user":2
},
{
"protocol":"local",
"password":"useruser",
"user":3
}
]
The code to populate the database is as follows:
var _ = require('lodash');
var Barrels = require('barrels');
var barrels = new Barrels();
var fixtures = _.keys(barrels.data);
barrels.populate(fixtures, next, false); //<== passing false here
I can see in the database that sometimes 'admin' user gets 'demo' passport, and in fact i can login to 'admin' account with 'demodemo' password.
I'm disabling auto-association because I have models with required:true
on associations, and this causes barrels to fail to load models.
This is more an idea I just had and would certainly be a bigger project, but it would be great to get faker support for automatic data generation.
So you could for example call var barrels = new Barrels({ faker: true, models: ['user', 'posts'] });
And then in the populate
function this would try to call the right faker mehtod. So for example if it finds an email
property it would create properties via faker.internet.email();
etc.
Furhtermore it should allow for custom calls, so
var barrels = new Barrels({ faker: true, models: [
'user': {
'username': 'internet.email',
'abstract': 'lorem.words'
},
'posts'
] });
Or something similar. I think that would be really awesome to get some populated tests ready within minutes. In fact this fakerToModel
function would probably even make a good standalone module now that I am writing this down.
In any case, I hope that I will get to this once I find some time myself, just wanted to note it down at an appropriate place.
I am trying to test both server and client code. So the obvious directory structure would be:
./myApp
├── api
├── assets
├── ...
├── test
│ ├── server
│ │ ├── unit
│ │ │ ├── controllers
│ │ │ │ └── UsersController.test.js
│ │ │ ├── models
│ │ │ │ └── Users.test.js
│ │ │ └── ...
│ │ ├── fixtures
│ │ ├── ...
│ │ ├── bootstrap.test.js
│ │ └── mocha.opts
│ └── client
│ ├── unit
│ ├── ...
│ ├── karma.conf.js
│ ├── test.main.js
│ └── mocha.opts
└── views
Is it currently possible? Barrels seems to want fixtures to be in ./myApp/test/fixtures
, and there is no documentation about how to change that.
EDIT: Not a big issue, as leaving the fixtures directory where it is expected to be and using
"test": "NODE_ENV=test mocha test/server -R spec -b --recursive"
in package.json
is enough to run npm test
successfully, at least for the server tests. It is just that I prefer to put things where they belong.
Within tests it would be great if we can use Barrels to populate specified models.
I'm trying to use the barrels fixtures, but I have a problem with fixture names - I have a model Foo with collection name myFoo, I have a fixture named myFoo.json in the fixtures directory. The barrels doesn't populate any data in the myFoo collection.
Is there a hidden way to do this? It would be nice if I can provide provide key - value pairs on populate - fixtureName: collectionName.
Cheers
Followed exactly your example and I'm getting this:
UsageError: Invalid criteria. Details: Cannot use this method (
destroy) with a criteria of
undefined. (This is just a simple failsafe to help protect your data: if you really want to destroy ALL records, no problem-- please just be explicit and provide a criteria of
{}`.)
at Deferred._.extend._WLModel [as _handleExec] (node_modules/waterline/lib/waterline/methods/destroy.js:173:17)
at Deferred.exec (node_modules/parley/lib/private/Deferred.js:191:10)
at node_modules/barrels/index.js:134:23
at node_modules/barrels/node_modules/async/lib/async.js:181:20
at Object.async.forEachOf.async.eachOf (node_modules/barrels/node_modules/async/lib/async.js:233:13)
at Object.async.forEach.async.each (node_modules/barrels/node_modules/async/lib/async.js:209:22)
at Barrels.populate (node_modules/barrels/index.js:130:51)
at test/lifecycle.test.js:30:13
at whenSailsIsReady (node_modules/sails/lib/app/lift.js:120:12)
at node_modules/async/dist/async.js:3679:13
at node_modules/async/dist/async.js:486:20
at replenish (node_modules/async/dist/async.js:879:29)
at iterateeCallback (node_modules/async/dist/async.js:869:21)
at node_modules/async/dist/async.js:847:20
at node_modules/async/dist/async.js:3676:17
at node_modules/async/dist/async.js:339:31
at node_modules/sails/lib/app/private/initialize.js:91:14
at node_modules/async/dist/async.js:952:25
at iteratorCallback (node_modules/async/dist/async.js:997:17)
at node_modules/async/dist/async.js:847:20
at expressListening (node_modules/sails/lib/hooks/http/start.js:169:14)
at node_modules/async/dist/async.js:486:20
at processQueue (node_modules/async/dist/async.js:1608:24)
at taskComplete (node_modules/async/dist/async.js:1630:13)
at node_modules/async/dist/async.js:1653:21
at node_modules/async/dist/async.js:339:31
at node_modules/async/dist/async.js:847:20
at async.auto.verify (node_modules/sails/lib/hooks/http/start.js:160:9)
at runTask (node_modules/async/dist/async.js:1660:17)
at node_modules/async/dist/async.js:1602:17
at processQueue (node_modules/async/dist/async.js:1612:17)
at taskComplete (node_modules/async/dist/async.js:1630:13)
at node_modules/async/dist/async.js:1653:21
at node_modules/async/dist/async.js:339:31
at node_modules/async/dist/async.js:847:20
at Server.<anonymous> (node_modules/sails/lib/hooks/http/start.js:38:20)
at emitListeningNT (net.js:1288:10)
at _combinedTickCallback (internal/process/next_tick.js:77:11)
at process._tickCallback (internal/process/next_tick.js:104:9)`
I'm having a bit of problem where the app
foreignKey isn't set when running barrels.populate(...)
, looks fine in the barrels.data
, any idea what I'm missing? Thanks for the help.
App.json
[
{
"id": "SsQbM0b10QCuWxMj11tnUIh0OJBDX64sttSsrR5U",
"name": "My App",
"createdBy": 1,
"ownedBy": 1,
"createdAt": "2015-10-30T22:19:58.921Z"
}
]
AuthStrategy.json
[
{
"type": "facebook",
"id": 1,
"ownedBy": 2,
"app": "SsQbM0b10QCuWxMj11tnUIh0OJBDX64sttSsrR5U",
"accessToken": "..."
}
]
Here is my user model:
/**
* User.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
schema: true,
attributes: {
name: {
type: 'string',
required: true
},
username: {
type: 'string',
required: true,
unique: true,
alphanumericdashed: true,
lowercase: true,
minLength: 2
},
email: {
type: 'string',
required: true,
unique: true,
email: true
},
password: {
type: 'string',
required: true,
//minLength: 8
},
admin: {
type: 'boolean',
defaultsTo: false
}
}
};
as you can see i comment out the minLength validation on password.
With this setting my tests works...
Here is the fixture file:
[
{
"name": "Tony",
"username": "tony",
"email": "[email protected]",
"password": "tony"
},
{
"name": "Tony2",
"username": "tony2",
"email": "[email protected]",
"password": "tony2"
}
]
And here is the test:
console.log("UserModel");
describe('UserModel', function() {
describe('#find()', function() {
it('should check find function', function (done) {
User.find()
.then(function(results) {
// some tests
console.log("========");
console.log(results);
console.log("========");
console.log(fixtures);
results.length.should.be.eql(fixtures['user'].length);
done();
})
.catch(done);
});
});
});
When i comment-in the minLength validation on password attribute - the test will stuck and will never reach the end (tested few times till 10 minutes - then manual canceled). It seems the populate method don't reach the callback (or something else...)???
I have used Barrels to populate my MongoDB Database ( via Waterline ORM )
Let's suppose that we have an association between my two models (Collections) via the attr "xattr".
While populating the DB using the prepared fixtures, i get the document "xattr" nulled when it's not capital,
but filled et converted into an ObjectId when it's capitalized ...
Is it a bug, or can i get more details about this problem ?
Thanx
when you test fixture contains Russian characters, it can't run test. the just goes into an endless loop and does not show anything
Run with
#!/usr/bin/env node
var Barrels = require("barrels")
var barrels = new Barrels()
barrels.populate(err => {
console.log(err)
})
Got this error
/Users/guten/a/sails/hello/node_modules/barrels/index.js:132
var Model = sails.models[modelName];
^
TypeError: Cannot read property 'users' of undefined
at /Users/guten/a/sails/hello/node_modules/barrels/index.js:132:29
at /Users/guten/a/sails/hello/node_modules/barrels/node_modules/async/lib/async.js:181:20
at Object.async.forEachOf.async.eachOf (/Users/guten/a/sails/hello/node_modules/barrels/node_modules/async/lib/async.js:233:13)
at Object.async.forEach.async.each (/Users/guten/a/sails/hello/node_modules/barrels/node_modules/async/lib/async.js:209:22)
at Barrels.populate (/Users/guten/a/sails/hello/node_modules/barrels/index.js:131:51)
at Object.<anonymous> (/Users/guten/a/sails/hello/fixtures.js:19:9)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (node.js:348:7)
at startup (node.js:140:9)
at node.js:463:3
Hi. I'm trying to use barrels to seed my db.
I have my JSON files inside <sails_app>/fixtures/.
I created a <sails_app>/seedDevelopment.js file with the following content:
var Barrels = require('barrels');
var barrels = new Barrels('./fixtures/');
var fixtures = barrels.data;
barrels.populate(function(err) {
if (err) {
return done(err);
}
done();
});
When I run
node seedDevelopment.js
I get the following error:
module.js:338
throw err;
^
Error: Cannot find module 'fixtures/Group.json'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at new Barrels (/Users/lcrespo/Projects/roloegol_backend/node_modules/barrels/index.js:42:30)
at Object. (/Users/lcrespo/Projects/roloegol_backend/seedDevelopment.js:2:15)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
What am I doing wrong?.
Fixture:
[
{
"owner": 1
}
]
Model "Listing":
var model = {
attributes: {
owner: {
model: 'User',
required: true
}
}
This doesn't work unless required is set to false.
Barrels version: 1.6.5
Sails: 1.2.3
Adapter: Sails-Disk
inMemoryOnly: true
So I have this sails project, and I added tests. Everything works fine when run separately, but when merged and tried to run all the tests, I'm having issues creating new records. when i checked barrels.data, I noticed that the records created on the previous tests are loaded instead of the one that should be read from the fixtures files which is causing issue as I'm trying to create records that were already created on the previous tests set.
How to solve or prevent this? Shouldn't it be that on new Barrels()
a new instance of barrels and a new read of the fixtures be made?
If defining a model with an alias of primary key, barrels doesn't work.
e.g.
attributes: {
"user_id": {
type: 'integer',
columnName: 'id',
autoIncrement: true,
primaryKey: true
},
...
}
Here's fix:
index.js
// ID mapping
that.idMap[modelName][itemIndex] = model.id;
Should be
// ID mapping
that.idMap[modelName][itemIndex] = model[Model.primaryKey]
So I have yet to really dig into it, but I'm seeing some weirdness with barrels-generated fixtures whereby their properties seem to be getting mutated by Sails. E.g. plaintext passwords being turned into hashed passwords within private data
variable in index.js
.
Is this intended, and how can I work around this behavior?
basically, as it stands (using your passport/user example) I have to populate Users first, and then everything else..
this requires you to explicitly define all of the other models, a bit of a pain if you're not used to it and just banging out new features.. such like..
barrels.populate(['user'], function(err) {
if (err)
return done(err); // Higher level callback
// Users will already be populated here, so the required association should work
barrels.populate(['passport', 'comment', 'location', 'log', 'tag'], function(err) {
if (err)
return done(err); // Higher level callback
// Do your thing...
done();
});
});
Is it possible to add some logic in, (if it already hasn't) that would allow something like this..
barrels.populate(['user'], function(err) {
if (err)
return done(err); // Higher level callback
// Users will already be populated here, so the required association should work
barrels.populate(function(err) {
if (err)
return done(err); // Higher level callback
// Do your thing...
done();
});
});
barrels would then look at whats already populated, and only populate everything else..
After updating all libraries, it seems like the many to many relations are no longer working for me. Do you happen to know if any lib-update might effect barrels?
These are my dependencies:
"dependencies": {
"async": "1.5.2",
"barrels": "1.6.4",
"bcryptjs": "2.3.0",
"bluebird": "3.2.2",
"include-all": "0.1.6",
"jsonwebtoken": "5.5.4",
"lodash": "4.3.0",
"moment-timezone": "0.5.0",
"passport": "0.3.2",
"passport-facebook": "2.1.0",
"passport-github": "1.1.0",
"passport-google": "0.3.0",
"passport-local": "1.0.0",
"passport-twitter": "1.0.4",
"passport-custom": "1.0.5",
"rc": "1.1.6",
"sails": "0.12.0",
"sails-disk": "0.10.9",
"sails-hook-apianalytics": "0.3.0",
"sails-mysql": "0.11.4",
"sails-fixtures": "1.0.8",
"ua-parser": "0.3.5",
"validator": "4.7.1",
"request": "2.69.0",
"request-promise": "2.0.0",
"winston": "^2.1.1",
"q": "1.4.1"
}
I populate all models before my 'main'-model is populated. This 'main'-model contains all references to the other models, e.g:
{ "id": 1, "title": "13In est risus, auctor sed,", "clearance": 1, "project": 13, "ipType": 0, "createdUser": 12, "authors": [ 10, 6 ], "published": "1997-01-25", "type": 5, "files": 627, "released": false },
My other json files (such as Project, Clearance, ...) do not contain any information about this 'main' model. I did not need it before the update.
One-To-One relations work fine, one-to-many as well. Only many-to-many don't seem to work anymore.
Do you have any workaround?
When I use this library to populate fixture data for my sails app, I got error as follows.
model[attr] = that.idMap[joined][item[attr]-1];
^
TypeError: Cannot read property '0' of undefined
Hello. Cool module :) Quick question...
Is it possible to specify the order in which the fixtures should be loaded? One of my associations has required: true
as a validation rule, which causes sails to complain. Sails validates that a certain model exists before associating the models, causing it to claim that my value is wrong. If I could load the other model first, it would exist and validation wouldn't fail.
As a newcomer to Sails and Barrels, I had a hard time to figure out in which format the fixtures should be. I kept thinking how should I create the fixtures, should I just wrote the files, in which format, et cetera. By consuming time to examine the files under test/fixtures/, I now know that they have a structure that is somehow related to the model attributes.
What do you think, is the documentation lacking in this matter? Even a tiny example.json fixture in the README.md with proper description might do the job.
Hi,
I have 2 models (let say User and Pet). Models are defined in User.js and Pet.js (in singular).
I have an association many-to-one. One user can have many pets but a pet can have only one user.
In User.js, the association is defined like that:
pets: {
notNull: true,
required: true,
collection: 'Pet',
via: 'pet_id'
},
The fixture for user is:
[
{
"id": "1",
"pets": [1,2]
}
]
I populate the db this way:
barrels.populate(['pet'], function(err) {
if (err) return reject(err);
barrels.populate(['user'], function(err) {
if (err) reject(err);
else resolve();
}, false);
}, false);
The association fails (sails don't lift and an error is thrown during before all hook). The association for pets cannot be done because 'pets.json' doesn't exist. The fixture filename is 'pet.json' and it is pet.json because the filename of my model is Pet.js.
I could rename the model filename, but it would affect all the blueprints handled by sails...
Would it be possible to mention in each fixture file to which model it is binding, without using the filename all the time?
https://github.com/bredikhin/barrels/blob/master/index.js#L19
populate() is opinionated in that it requires fixtures to exist in order to use Barrels. However, there are times when fixtures do not exist in a project (Such as when Barrels is part of a testing suite that acts as a template for more complex tests and, thus, does not contain models or fixtures) and never will, thus, checking for them and throwing an error when they do not exist is limiting.
Expose doPopulateSails so that we can bypass this requirement and not throw errors in the event of fixtures not existing.
I understand it is stated on the README that the fixture files are named after the model. However, it may still be confusing to some (at least to me) since the Sails guide name the model using singular form while some (may be most) people name their fixtures in plural form for obvious reason. In the README, you mentioned test/fixtures/products.json
(plural) but no body knows which form your models in.
Also in the example repo, the model files are in plural forms which is different than the official Sails convention.
It would be nice if the fixtures are in plural and Barrels would just work. In the mean time, I'd use singular form in the fixtures in the so it is consistent with what is stated in the README.
I already posted this on Stackoverflow but decided to open issue here too.
I have following fixtures defined:
Project.json
[
{
"name": "TestProject",
"integrations": 1
},
{
"name": "TestProjectWithPeople",
"integrations": 2,
"projectLeads": [2],
"members": [3]
}
]
Activity.json
[
{
"project": 1,
"content": {
"text": "Just random content in JSON format 1"
},
"source": "Some other service",
"userName": "Test user name",
"activityType": "OldestActivity",
"url": "http://www.example.com",
"priority": 0
},
{
"project": 1,
"content": {
"text": "Just random content in JSON format 2"
},
"source": "Some other service 2",
"userName": "Another test user",
"activityType": "Test2",
"url": "http://www.example.com",
"priority": 1
},
{
"project": 1,
"content": {
"text": "Just random content in JSON format 3"
},
"source": "Some other service 2",
"userName": "Another test user",
"activityType": "Test2",
"url": "http://www.example.com",
"priority": 1
}
]
The Activity model has required association to Project. After reading readme of Barrels I wrote the following code:
loadFixtures: function() {
return new Promise(function (resolve) {
var barrels = new Barrels(process.cwd() + '/test/fixtures');
barrels.populate(['project', 'integrations', 'user'], function(err) {
barrels.populate(['activity'], function(err) {
console.log(err)
resolve();
});
});
});
}
I keep getting validation error from second populate:
Invalid attributes sent to Activity:
• project
• "required" validation rule failed for input: null
What is the problem here? I tried switching off auto-association and it "works" meaning that it sets just bare numbers as association which works if they really represent correct model in association, but that seems to be fragile and will break if I ever use another test db other than sails-disk.
I have fixtures in /test/fixtures folder, everything works fine. I'm running fixtures like this:
var barrels = new Barrels();
I decided to populate another set of fixtures (for local dev environment) which are located in: /api/fixtures
which means I have to use barrels like this:
var barrels = new Barrels('./api/fixtures/');
however, when I do this I get this error:
error: Sent 500 ("Server Error") response
error: Error: Cannot find module 'api/fixtures/user.json'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at new Barrels (/Users/usenkanov/projects/xxx/node_modules/barrels/index.js:42:30)
at module.exports.populate (/Users/usenkanov/projects/xxx/api/controllers/DbController.js:10:23)
at routeTargetFnWrapper (/Users/usenkanov/projects/xxx/node_modules/sails/lib/router/bind.js:178:5)
at callbacks (/Users/usenkanov/projects/xxx/node_modules/sails/node_modules/express/lib/router/index.js:164:37)
at param (/Users/usenkanov/projects/xxx/node_modules/sails/node_modules/express/lib/router/index.js:138:11)
at pass (/Users/usenkanov/projects/xxx/node_modules/sails/node_modules/express/lib/router/index.js:145:5) { [Error: Cannot find module 'api/fixtures/user.json'] code: 'MODULE_NOT_FOUND' }
Hi.
I'm trying to fix up some fixtures for the User model. The User model uses the Passport model generated by https://github.com/kasperisager/sails-generate-auth
(https://gist.github.com/Industrial/e063603eef8d6a456d33).
This is the fixture data:
User.json
[
{
"id": "1",
"username": "BobGod",
"email": "[email protected]",
"postalCode": "0000AA",
"houseNumber": "1",
"group": 0,
"passports": [ 0 ],
"maxems": []
},
{
"id": "2",
"username": "SallyAdministrator",
"email": "[email protected]",
"postalCode": "0000AA",
"houseNumber": "1",
"group": 1,
"passports": [ 1 ],
"maxems": []
},
{
"id": "3",
"username": "PeterInstaller",
"email": "[email protected]",
"postalCode": "0000AA",
"houseNumber": "1",
"group": 2,
"passports": [ 2 ],
"maxems": []
},
{
"id": "4",
"username": "BernieUser",
"email": "[email protected]",
"postalCode": "0000AA",
"houseNumber": "1",
"group": 3,
"passports": [ 3 ],
"maxems": []
}
]
Passport.json
[
{
"id": "1",
"protocol": "local",
"password": "bobgod123",
"user": 0
},
{
"id": "2",
"protocol": "local",
"password": "sallyadministrator123",
"user": 1
},
{
"id": "3",
"protocol": "local",
"password": "peterinstaller123",
"user": 2
},
{
"id": "4",
"protocol": "local",
"password": "bernieuser123",
"user": 3
}
]
and the error:
There's a required: true
on the user field of the Passport model thaat is throwing this error: https://gist.github.com/Industrial/b7a2ee499a4a58387267
Did I make a mistake somewhere?
gr,
Tom
Problem:
Barrels files are in cwd/test/fixtures
Barrels is being required in a test that is located in cwd/test/api
Barrels presently scans cwd/test/fixtures(via new Barrels('./test/fixtures')) and finds the appropriate fixtures, but then tries to require them out of cwd/api/test/fixtures, meaning it starts looking for cwd/test/fixtures/fixture-a.json in the folder cwd/api/test/fixtures/fixture-a.json.
var files = fs.readdirSync(sourceFolder); // Read from cwd path.
this.data[modelName] = require(path.join(sourceFolder, files[i])); // Read from require path
I fixed this in a fork of mine, but didn't want to submit a pull request until someone more familiar with the library looks at the problem and doesn't come up with a better way of doing things first.
The reason I am trying to require Barrels out of my test instead of the test bootstrap function is that I am tearing down and setting up the memory store for each individual test.
#39 fixed the issue when fixtures needed to be loaded in particular order and they not always were with async.each
(see #31). However, in default case (no model list is passed to populate
), the order is not important and we can still perform the loading asynchronously. So, basically, we need to run async.each
if a list of models wasn't passed as the first parameter to populate
and async.eachSeries
if it was.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.