@na1647/offshore-adapter-tests 0.0.0-stage → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc +35 -0
- package/.travis.yml +32 -0
- package/CHANGELOG.md +24 -0
- package/Dockerfile +7 -0
- package/LICENSE.md +11 -0
- package/README.md +71 -2
- package/docker-compose.yml +32 -0
- package/features/autoIncrement/README.md +37 -0
- package/features/autoIncrement/core/autoIncrement.test.js +151 -0
- package/features/autoIncrement/sequential/autoIncrementSequential.test.js +104 -0
- package/features/autoIncrement/support/autoInc.fixture.js +25 -0
- package/features/compositePrimaryKey/core/compositePrimaryKey.test.js +67 -0
- package/features/compositePrimaryKey/support/fixture.js +24 -0
- package/features/compositeUnique/core/compositeUnique.test.js +67 -0
- package/features/compositeUnique/support/fixture.js +30 -0
- package/features/crossAdapter/core/crossAdapter.js +119 -0
- package/features/crossAdapter/support/bootstrap.js +106 -0
- package/features/sequences/core/sequences.test.js +110 -0
- package/features/sequences/support/mariadb.js +23 -0
- package/features/sequences/support/oracle.js +23 -0
- package/features/sequences/support/postgres.js +23 -0
- package/features/spatial/core/geojson.test.js +68 -0
- package/features/spatial/support/fixtures.js +82 -0
- package/features/spatial/support/models.js +45 -0
- package/features/unique/README.md +18 -0
- package/features/unique/core/unique.test.js +107 -0
- package/features/unique/support/unique.fixture.js +26 -0
- package/interfaces/associations/belongsTo/create.js +41 -0
- package/interfaces/associations/belongsTo/create.nested.customPK.js +61 -0
- package/interfaces/associations/belongsTo/create.nested.js +52 -0
- package/interfaces/associations/belongsTo/dynamicFinder.js +213 -0
- package/interfaces/associations/belongsTo/find.populate.js +145 -0
- package/interfaces/associations/belongsTo/findOne.populate.js +84 -0
- package/interfaces/associations/belongsTo/modifiers.js +275 -0
- package/interfaces/associations/belongsTo/multipleForeignKeys.js +70 -0
- package/interfaces/associations/belongsTo/update.nested.customPK.js +141 -0
- package/interfaces/associations/belongsTo/update.nested.js +174 -0
- package/interfaces/associations/deep.associations.test.js +437 -0
- package/interfaces/associations/find.associations.test.js +92 -0
- package/interfaces/associations/hasMany/add.js +106 -0
- package/interfaces/associations/hasMany/create.nested.customPK.js +113 -0
- package/interfaces/associations/hasMany/create.nested.js +96 -0
- package/interfaces/associations/hasMany/find.populate.customPK.js +75 -0
- package/interfaces/associations/hasMany/find.populate.js +219 -0
- package/interfaces/associations/hasMany/find.populate.where.js +148 -0
- package/interfaces/associations/hasMany/findOne.populate.js +88 -0
- package/interfaces/associations/hasMany/modifiers.js +560 -0
- package/interfaces/associations/hasMany/multipleForeignKeys.js +113 -0
- package/interfaces/associations/hasMany/remove.js +96 -0
- package/interfaces/associations/hasMany/update.nested.customPK.js +148 -0
- package/interfaces/associations/hasMany/update.nested.js +202 -0
- package/interfaces/associations/manyToMany/add.js +136 -0
- package/interfaces/associations/manyToMany/create.nested.customPK.js +109 -0
- package/interfaces/associations/manyToMany/create.nested.js +96 -0
- package/interfaces/associations/manyToMany/destroy.js +128 -0
- package/interfaces/associations/manyToMany/find.populate.js +109 -0
- package/interfaces/associations/manyToMany/find.populate.where.js +75 -0
- package/interfaces/associations/manyToMany/find.populate.withSchema.js +91 -0
- package/interfaces/associations/manyToMany/findOne.populate.js +86 -0
- package/interfaces/associations/manyToMany/modifiers.js +558 -0
- package/interfaces/associations/manyToMany/remove.js +103 -0
- package/interfaces/associations/manyToMany/update.js +105 -0
- package/interfaces/associations/manyToMany/update.nested.customPK.js +315 -0
- package/interfaces/associations/manyToMany/update.nested.js +355 -0
- package/interfaces/associations/manyToManyThrough/add.js +109 -0
- package/interfaces/associations/manyToManyThrough/create.nested.customPK.js +118 -0
- package/interfaces/associations/manyToManyThrough/create.nested.js +114 -0
- package/interfaces/associations/manyToManyThrough/find.populate.customPK.js +76 -0
- package/interfaces/associations/manyToManyThrough/find.populate.js +120 -0
- package/interfaces/associations/manyToManyThrough/find.populate.where.js +157 -0
- package/interfaces/associations/manyToManyThrough/findOne.populate.js +93 -0
- package/interfaces/associations/manyToManyThrough/modifiers.js +560 -0
- package/interfaces/associations/manyToManyThrough/multipleForeignKeys.js +118 -0
- package/interfaces/associations/manyToManyThrough/remove.js +98 -0
- package/interfaces/associations/manyToManyThrough/update.nested.customPK.js +150 -0
- package/interfaces/associations/manyToManyThrough/update.nested.js +202 -0
- package/interfaces/associations/oneToOne/create.js +41 -0
- package/interfaces/associations/oneToOne/create.nested.customPK.js +61 -0
- package/interfaces/associations/oneToOne/create.nested.js +52 -0
- package/interfaces/associations/oneToOne/dynamicFinder.js +68 -0
- package/interfaces/associations/oneToOne/find.populate.js +127 -0
- package/interfaces/associations/oneToOne/findOne.populate.js +83 -0
- package/interfaces/associations/oneToOne/modifiers.js +275 -0
- package/interfaces/associations/oneToOne/multipleForeignKeys.js +69 -0
- package/interfaces/associations/oneToOne/update.nested.customPK.js +141 -0
- package/interfaces/associations/oneToOne/update.nested.js +174 -0
- package/interfaces/associations/support/bootstrap.js +82 -0
- package/interfaces/associations/support/fixtures/belongsTo.child.customPK.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/belongsTo.child.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/belongsTo.parent.customPK.fixture.js +26 -0
- package/interfaces/associations/support/fixtures/belongsTo.parent.fixture.js +28 -0
- package/interfaces/associations/support/fixtures/crud.fixture.js +53 -0
- package/interfaces/associations/support/fixtures/deep.address.fixture.js +21 -0
- package/interfaces/associations/support/fixtures/deep.breakdown.fixture.js +23 -0
- package/interfaces/associations/support/fixtures/deep.company.fixture.js +29 -0
- package/interfaces/associations/support/fixtures/deep.country.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/deep.departement.fixture.js +24 -0
- package/interfaces/associations/support/fixtures/deep.driver.fixture.js +32 -0
- package/interfaces/associations/support/fixtures/deep.ride.fixture.js +23 -0
- package/interfaces/associations/support/fixtures/deep.seller.fixture.js +33 -0
- package/interfaces/associations/support/fixtures/deep.taxi.fixture.js +36 -0
- package/interfaces/associations/support/fixtures/hasMany.child.fixture.js +33 -0
- package/interfaces/associations/support/fixtures/hasMany.customPK.fixture.js +22 -0
- package/interfaces/associations/support/fixtures/hasMany.parent.fixture.js +28 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.child.customPK.fixture.js +32 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.parent.customPK.fixture.js +23 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.stadium.fixture.js +20 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.team.fixture.js +35 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.through.customPK.fixture.js +18 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.venue.fixture.js +18 -0
- package/interfaces/associations/support/fixtures/manyToMany.driver.customPK.fixture.js +22 -0
- package/interfaces/associations/support/fixtures/manyToMany.driver.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/manyToMany.driver.withSchema.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/manyToMany.taxi.customPK.fixture.js +21 -0
- package/interfaces/associations/support/fixtures/manyToMany.taxi.fixture.js +30 -0
- package/interfaces/associations/support/fixtures/manyToMany.taxi.withSchema.fixture.js +24 -0
- package/interfaces/associations/support/fixtures/multipleAssociations.fixture.js +54 -0
- package/interfaces/associations/support/fixtures/multipleOneToOneAssociations.fixture.js +40 -0
- package/interfaces/associations/support/fixtures/multipleThroughAssociations.fixture.js +79 -0
- package/interfaces/associations/support/fixtures/oneToOne.customPK.fixture.js +47 -0
- package/interfaces/associations/support/fixtures/oneToOne.fixture.js +52 -0
- package/interfaces/associations/support/fixtures.js +41 -0
- package/interfaces/datastore/datastore.test.js +63 -0
- package/interfaces/migratable/definition.test.js +65 -0
- package/interfaces/migratable/migrate.alter.test.js +55 -0
- package/interfaces/migratable/migrate.create.test.js +120 -0
- package/interfaces/migratable/migrate.drop.test.js +47 -0
- package/interfaces/migratable/migrate.safe.test.js +25 -0
- package/interfaces/migratable/schema.test.js +117 -0
- package/interfaces/migratable/support/bootstrap.js +55 -0
- package/interfaces/migratable/support/bootstrapFn.js +54 -0
- package/interfaces/migratable/support/fixtures/alter.fixture.js +12 -0
- package/interfaces/migratable/support/fixtures/create.fixture.js +12 -0
- package/interfaces/migratable/support/fixtures/crud.fixture.js +53 -0
- package/interfaces/migratable/support/fixtures/custom.fixture.js +17 -0
- package/interfaces/migratable/support/fixtures/drop.fixture.js +12 -0
- package/interfaces/migratable/support/fixtures/safe.fixture.js +12 -0
- package/interfaces/migratable/support/fixtures/schema.fixture.js +23 -0
- package/interfaces/queryable/caseInsensitive.test.js +196 -0
- package/interfaces/queryable/count.test.js +51 -0
- package/interfaces/queryable/dynamicFinders.test.js +179 -0
- package/interfaces/queryable/findLike.test.js +34 -0
- package/interfaces/queryable/findOneLike.test.js +28 -0
- package/interfaces/queryable/modifiers/average.modifier.test.js +55 -0
- package/interfaces/queryable/modifiers/contains.modifier.test.js +82 -0
- package/interfaces/queryable/modifiers/endsWith.modifier.test.js +82 -0
- package/interfaces/queryable/modifiers/greaterThan.modifier.test.js +335 -0
- package/interfaces/queryable/modifiers/groupBy.modifier.test.js +123 -0
- package/interfaces/queryable/modifiers/in.modifier.test.js +76 -0
- package/interfaces/queryable/modifiers/lessThan.modifier.test.js +223 -0
- package/interfaces/queryable/modifiers/like.modifier.test.js +50 -0
- package/interfaces/queryable/modifiers/limit.modifier.test.js +60 -0
- package/interfaces/queryable/modifiers/max.modifier.test.js +68 -0
- package/interfaces/queryable/modifiers/min.modifier.test.js +68 -0
- package/interfaces/queryable/modifiers/not.modifier.test.js +80 -0
- package/interfaces/queryable/modifiers/notIn.modifier.test.js +69 -0
- package/interfaces/queryable/modifiers/or.modifier.test.js +142 -0
- package/interfaces/queryable/modifiers/select.modifier.test.js +118 -0
- package/interfaces/queryable/modifiers/skip.modifier.test.js +59 -0
- package/interfaces/queryable/modifiers/sort.modifier.test.js +160 -0
- package/interfaces/queryable/modifiers/startsWith.modifier.test.js +83 -0
- package/interfaces/queryable/modifiers/sum.modifier.test.js +68 -0
- package/interfaces/queryable/support/bootstrap.js +80 -0
- package/interfaces/queryable/support/fixtures/crud.fixture.js +54 -0
- package/interfaces/scalable/README.md +19 -0
- package/interfaces/scalable/crud.test.js +73 -0
- package/interfaces/scalable/queries.test.js +9 -0
- package/interfaces/scalable/support/crud.fixture.js +60 -0
- package/interfaces/semantic/create.test.js +110 -0
- package/interfaces/semantic/createEach.test.js +50 -0
- package/interfaces/semantic/destroy.js +147 -0
- package/interfaces/semantic/find.test.js +91 -0
- package/interfaces/semantic/findOne.test.js +60 -0
- package/interfaces/semantic/findOrCreate.test.js +91 -0
- package/interfaces/semantic/findOrCreateEach.test.js +75 -0
- package/interfaces/semantic/support/bootstrap.js +85 -0
- package/interfaces/semantic/support/fixtures/crud.fixture.js +66 -0
- package/interfaces/semantic/support/fixtures/validations.fixture.js +23 -0
- package/interfaces/semantic/types/array.type.js +28 -0
- package/interfaces/semantic/types/binary.type.js +34 -0
- package/interfaces/semantic/types/boolean.type.js +80 -0
- package/interfaces/semantic/types/date.type.js +53 -0
- package/interfaces/semantic/types/datetime.type.js +48 -0
- package/interfaces/semantic/types/float.type.js +40 -0
- package/interfaces/semantic/types/integer.type.js +40 -0
- package/interfaces/semantic/types/json.type.js +29 -0
- package/interfaces/semantic/types/string.type.js +40 -0
- package/interfaces/semantic/types/text.type.js +34 -0
- package/interfaces/semantic/types/time.type.js +52 -0
- package/interfaces/semantic/update.test.js +157 -0
- package/interfaces/sql/find.test.js +73 -0
- package/interfaces/sql/query.test.js +40 -0
- package/interfaces/sql/support/bootstrap.js +82 -0
- package/interfaces/sql/support/fixtures/crud.fixture.js +57 -0
- package/interfaces/transactable/commit.test.js +438 -0
- package/interfaces/transactable/crossAdapter.test.js +346 -0
- package/interfaces/transactable/deep.test.js +100 -0
- package/interfaces/transactable/rollback.test.js +221 -0
- package/interfaces/transactable/support/bootstrap.js +55 -0
- package/interfaces/transactable/support/bootstrapFn.js +51 -0
- package/interfaces/transactable/support/fixtures/customer.fixture.js +29 -0
- package/interfaces/transactable/support/fixtures/payment.fixture.js +24 -0
- package/interfaces/transactable/support/fixtures/receipt.fixture.js +20 -0
- package/interfaces/transactable/support/fixtures/store.fixture.js +22 -0
- package/interfaces/transactable/support/fixtures/storecustomer.fixture.js +14 -0
- package/lib/index.js +155 -0
- package/lib/utils.js +39 -0
- package/package.json +58 -4
- package/test/integration/README.md +26 -0
- package/test/integration/config/offshore-memory.js +8 -0
- package/test/integration/config/offshore-sql-mariadb.js +15 -0
- package/test/integration/config/offshore-sql-mysql.js +21 -0
- package/test/integration/config/offshore-sql-oracle.js +19 -0
- package/test/integration/config/offshore-sql-postgres.js +27 -0
- package/test/integration/config/offshore-sql-sqlite3.js +19 -0
- package/test/integration/runner.js +83 -0
- package/test/integration/runnerDispatcher.js +163 -0
- package/test/load/README.md +20 -0
- package/test/load/index.js +33 -0
- package/test/load/runner.js +160 -0
- package/test/load/support/bootstrap.js +69 -0
- package/test/load/support/fixtures/pet.js +8 -0
- package/test/load/support/fixtures/user.js +9 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Feature: unique
|
|
2
|
+
===============
|
|
3
|
+
|
|
4
|
+
Enable this test in `package.json` with: `"features": ["unique"]`
|
|
5
|
+
|
|
6
|
+
Ensures no two records will be allowed with the same value. This is a database level constraint
|
|
7
|
+
so in most cases a unique index will be created in the underlying data-store.
|
|
8
|
+
|
|
9
|
+
Usage on Offshore models:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
attributes: {
|
|
13
|
+
username: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
unique: true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
```
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var _ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('unique attribute feature', function() {
|
|
5
|
+
|
|
6
|
+
/////////////////////////////////////////////////////
|
|
7
|
+
// TEST SETUP
|
|
8
|
+
////////////////////////////////////////////////////
|
|
9
|
+
|
|
10
|
+
var Offshore = require(process.env.offshorePath || 'offshore');
|
|
11
|
+
var defaults = { migrate: 'alter' };
|
|
12
|
+
var offshore;
|
|
13
|
+
|
|
14
|
+
var UniqueFixture = require('../support/unique.fixture.js')
|
|
15
|
+
var UniqueModel;
|
|
16
|
+
|
|
17
|
+
var id0, id1, email0;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
before(function(done) {
|
|
21
|
+
offshore = new Offshore();
|
|
22
|
+
offshore.loadCollection(UniqueFixture);
|
|
23
|
+
|
|
24
|
+
var connections = { uniqueConn: _.clone(Connections.test) };
|
|
25
|
+
|
|
26
|
+
offshore.initialize({ adapters: { wl_tests: Adapter }, connections: connections, defaults: defaults }, function(err, ontology) {
|
|
27
|
+
if(err) return done(err);
|
|
28
|
+
UniqueModel = ontology.collections['unique'];
|
|
29
|
+
|
|
30
|
+
// Insert 3 Records
|
|
31
|
+
var records = [];
|
|
32
|
+
for(var i=0; i<3; i++) {
|
|
33
|
+
records.push({name: 'testUnique' + i, email: 'email' + i, type: 'unique'});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
UniqueModel.createEach(records, function(err, records) {
|
|
37
|
+
if(err) return done(err);
|
|
38
|
+
id0 = records[0].id;
|
|
39
|
+
id1 = records[1].id;
|
|
40
|
+
email0 = records[0].email.toString();
|
|
41
|
+
done();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
after(function(done) {
|
|
47
|
+
if(!Adapter.hasOwnProperty('drop')) {
|
|
48
|
+
offshore.teardown(done);
|
|
49
|
+
} else {
|
|
50
|
+
UniqueModel.drop(function(err1) {
|
|
51
|
+
offshore.teardown(function(err2) {
|
|
52
|
+
return done(err1 || err2);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
/////////////////////////////////////////////////////
|
|
60
|
+
// TEST METHODS
|
|
61
|
+
////////////////////////////////////////////////////
|
|
62
|
+
|
|
63
|
+
it('should error when creating with a duplicate value', function(done) {
|
|
64
|
+
UniqueModel.create({ email: email0, type: 'unique' }, function(err, records) {
|
|
65
|
+
assert(err);
|
|
66
|
+
assert(!records);
|
|
67
|
+
UniqueModel.find({type: 'unique'}).exec(function(err, records) {
|
|
68
|
+
assert.ifError(err);
|
|
69
|
+
assert.equal(records.length, 3);
|
|
70
|
+
done();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should error when updating with a duplicate value', function(done) {
|
|
76
|
+
UniqueModel.update(id1, { email: email0 }).exec(function(err, records) {
|
|
77
|
+
assert(err);
|
|
78
|
+
assert(!records);
|
|
79
|
+
UniqueModel.findOne(id1).exec(function(err, record) {
|
|
80
|
+
assert.ifError(err);
|
|
81
|
+
assert.notEqual(record.email, email0);
|
|
82
|
+
done();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should work (do nothing) when updating the field of an existing record to the same value', function(done) {
|
|
88
|
+
UniqueModel.update(id0, { id: id0, name: 'testUnique0', email: email0, type: 'unique' }).exec(function(err, records) {
|
|
89
|
+
assert(!err, 'Expected no error when updating to the same value');
|
|
90
|
+
assert.equal(records.length, 1);
|
|
91
|
+
assert.equal(records[0].id, id0);
|
|
92
|
+
assert.equal(records[0].email, email0);
|
|
93
|
+
done();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should work when updating a unique field to the same value based on search parameters', function(done) {
|
|
98
|
+
UniqueModel.update({email: email0}, { email: email0 }).exec(function(err, records) {
|
|
99
|
+
assert(!err, 'Expected no error when updating to the same value on searched records');
|
|
100
|
+
assert.equal(records.length, 1);
|
|
101
|
+
assert.equal(records[0].id, id0);
|
|
102
|
+
assert.equal(records[0].email, email0);
|
|
103
|
+
done();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
var Offshore = require(process.env.offshorePath || 'offshore');
|
|
6
|
+
|
|
7
|
+
module.exports = Offshore.Collection.extend({
|
|
8
|
+
|
|
9
|
+
identity: 'unique',
|
|
10
|
+
tableName: 'uniqueTable',
|
|
11
|
+
connection: 'uniqueConn',
|
|
12
|
+
|
|
13
|
+
attributes: {
|
|
14
|
+
name: {
|
|
15
|
+
type: 'string'
|
|
16
|
+
},
|
|
17
|
+
email: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
unique: true
|
|
20
|
+
},
|
|
21
|
+
type: {
|
|
22
|
+
type: 'string'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Association Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Belongs To Associations', function() {
|
|
7
|
+
describe('create', function() {
|
|
8
|
+
|
|
9
|
+
/////////////////////////////////////////////////////
|
|
10
|
+
// TEST SETUP
|
|
11
|
+
////////////////////////////////////////////////////
|
|
12
|
+
|
|
13
|
+
var customerId;
|
|
14
|
+
|
|
15
|
+
before(function(done) {
|
|
16
|
+
// Check payment belongsTo Customer
|
|
17
|
+
assert.strictEqual(Associations.Payment.attributes.a_customer.model, 'customer');
|
|
18
|
+
assert.strictEqual(Associations.Customer.attributes.payments.collection, 'payment');
|
|
19
|
+
|
|
20
|
+
Associations.Customer.create({ name: 'belongsTo add' }).exec(function(err, cust) {
|
|
21
|
+
assert.ifError(err);
|
|
22
|
+
customerId = cust.id;
|
|
23
|
+
done();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/////////////////////////////////////////////////////
|
|
28
|
+
// TEST METHODS
|
|
29
|
+
////////////////////////////////////////////////////
|
|
30
|
+
|
|
31
|
+
it('should create a foreign key value when passed an association key', function(done) {
|
|
32
|
+
Associations.Payment.create({ amount: 1, a_customer: customerId }).exec(function(err, payment) {
|
|
33
|
+
assert.ifError(err);
|
|
34
|
+
assert.equal(payment.a_customer.toString(), customerId.toString());
|
|
35
|
+
done();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var _ = require('lodash');
|
|
3
|
+
var util = require('util');
|
|
4
|
+
|
|
5
|
+
describe('Association Interface', function() {
|
|
6
|
+
|
|
7
|
+
describe('Belongs To Associations', function() {
|
|
8
|
+
|
|
9
|
+
before(function(done) {
|
|
10
|
+
// Check Payment belongsTo Customer
|
|
11
|
+
assert.strictEqual(Associations.Paymentbelongscustom.attributes.customer.model, 'customerbelongscustom');
|
|
12
|
+
assert.strictEqual(Associations.Customerbelongscustom.attributes.payments.collection, 'paymentbelongscustom');
|
|
13
|
+
done();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('create nested association when a custom primary key is used', function() {
|
|
17
|
+
|
|
18
|
+
/////////////////////////////////////////////////////
|
|
19
|
+
// TEST METHODS
|
|
20
|
+
////////////////////////////////////////////////////
|
|
21
|
+
|
|
22
|
+
it('should create a parent and child record and store the foreign key on the parent', function(done) {
|
|
23
|
+
var data = {
|
|
24
|
+
invoice: 1000,
|
|
25
|
+
amount: 200,
|
|
26
|
+
customer: {
|
|
27
|
+
username: 'belongsTo',
|
|
28
|
+
title: 'belongsTo nested create'
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Create the Parent and Child records
|
|
33
|
+
Associations.Paymentbelongscustom.create(data)
|
|
34
|
+
.exec(function(err, payment) {
|
|
35
|
+
assert.ifError(err);
|
|
36
|
+
|
|
37
|
+
// Ensure the foreignKey get set
|
|
38
|
+
assert.equal(payment.customer.username, 'belongsTo');
|
|
39
|
+
assert.equal(payment.customer.title, 'belongsTo nested create');
|
|
40
|
+
|
|
41
|
+
// Look up the values and test that populate works on the custom values
|
|
42
|
+
Associations.Paymentbelongscustom.findOne(payment.invoice)
|
|
43
|
+
.populate('customer')
|
|
44
|
+
.exec(function(err, _payment) {
|
|
45
|
+
assert.ifError(err);
|
|
46
|
+
|
|
47
|
+
// Test the parent is correct
|
|
48
|
+
assert.equal(_payment.invoice, 1000);
|
|
49
|
+
|
|
50
|
+
// Test the child is correct
|
|
51
|
+
assert.equal(_payment.customer.username, 'belongsTo');
|
|
52
|
+
assert.equal(_payment.customer.title, 'belongsTo nested create');
|
|
53
|
+
|
|
54
|
+
done();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var _ = require('lodash');
|
|
3
|
+
var util = require('util');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
describe('Association Interface', function() {
|
|
8
|
+
|
|
9
|
+
describe('Belongs To Associations', function() {
|
|
10
|
+
|
|
11
|
+
describe('create nested association', function() {
|
|
12
|
+
|
|
13
|
+
before(function(done) {
|
|
14
|
+
// Check Payment belongsTo Customer
|
|
15
|
+
assert.strictEqual(Associations.Paymentbelongs.attributes.customer.model, 'customerbelongs');
|
|
16
|
+
assert.strictEqual(Associations.Customerbelongs.attributes.payments.collection, 'paymentbelongs');
|
|
17
|
+
done();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
/////////////////////////////////////////////////////
|
|
21
|
+
// TEST METHODS
|
|
22
|
+
////////////////////////////////////////////////////
|
|
23
|
+
|
|
24
|
+
it('should create a parent and child record and store the foreign key on the parent', function(done) {
|
|
25
|
+
var data = {
|
|
26
|
+
amount: 200,
|
|
27
|
+
customer: {
|
|
28
|
+
title: 'belongsTo nested create'
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
Associations.Paymentbelongs.create(data).exec(function(err, payment) {
|
|
33
|
+
assert.ifError(err);
|
|
34
|
+
assert(payment.customer);
|
|
35
|
+
|
|
36
|
+
Associations.Paymentbelongs.findOne(payment.id)
|
|
37
|
+
.populate('customer')
|
|
38
|
+
.exec(function(err, _paymnt) {
|
|
39
|
+
assert(!err,'Tried to execute .findOne() with criteria:\n'+
|
|
40
|
+
util.inspect(payment.id, false, null)+'\nBut got error:\n'+
|
|
41
|
+
util.inspect(err, false, null));
|
|
42
|
+
assert(_paymnt.customer.title === 'belongsTo nested create',
|
|
43
|
+
'Expecting `_paymnt.customer.title`==="belongsTo nested create", but instead `_paymnt` ==>'+
|
|
44
|
+
util.inspect(_paymnt, false, null));
|
|
45
|
+
done();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Association Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Belongs To Association', function() {
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////
|
|
9
|
+
// TEST SETUP
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
var customerRecord, paymentRecord, customerCustomRecord, paymentCustomRecord;
|
|
13
|
+
|
|
14
|
+
before(function(done) {
|
|
15
|
+
// Check Payment belongsTo Customer
|
|
16
|
+
assert.strictEqual(Associations.Payment.attributes.a_customer.model, 'customer');
|
|
17
|
+
assert.strictEqual(Associations.Customer.attributes.payments.collection, 'payment');
|
|
18
|
+
assert.strictEqual(Associations.Paymentbelongscustom.attributes.customer.model, 'customerbelongscustom');
|
|
19
|
+
assert.strictEqual(Associations.Customerbelongscustom.attributes.payments.collection, 'paymentbelongscustom');
|
|
20
|
+
|
|
21
|
+
var customers = [{ name: 'foo' }, { name: 'bar' }, { name: 'foobar' }];
|
|
22
|
+
Associations.Customer.create(customers, function(err, customers) {
|
|
23
|
+
assert.ifError(err);
|
|
24
|
+
|
|
25
|
+
var payments = [
|
|
26
|
+
{ type: 'dynamic finders belongs bar', amount: 200, a_customer: customers[0].id},
|
|
27
|
+
{ type: 'dynamic finders belongs foobar', amount: 200, a_customer: customers[1].id },
|
|
28
|
+
{ type: 'dynamic finders belongs foo', amount: 250, a_customer: customers[2].id }
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
Associations.Payment.createEach(payments, function(err, payments) {
|
|
32
|
+
assert.ifError(err);
|
|
33
|
+
|
|
34
|
+
var customerCustoms = [{ username: 'dynamic finder belongs foo' }, { username: 'dynamic finder belongs bar' }, { username: 'dynamic finder belongs foobar' }];
|
|
35
|
+
Associations.Customerbelongscustom.create(customerCustoms, function(err, customerCustoms) {
|
|
36
|
+
assert.ifError(err);
|
|
37
|
+
|
|
38
|
+
var paymentCustoms = [
|
|
39
|
+
{ invoice: 700, type: 'dynamic finders belongs custom foo', amount: 400, customer: customerCustoms[0].username },
|
|
40
|
+
{ invoice: 701, type: 'dynamic finders belongs custom bar', amount: 400, customer: customerCustoms[1].username },
|
|
41
|
+
{ invoice: 702, type: 'dynamic finders belongs custom foobar', amount: 450, customer: customerCustoms[2].username }
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
Associations.Paymentbelongscustom.createEach(paymentCustoms, function(err, paymentCustoms) {
|
|
45
|
+
assert.ifError(err);
|
|
46
|
+
|
|
47
|
+
// Cache customer and payment
|
|
48
|
+
customerRecords = customers;
|
|
49
|
+
paymentRecords = payments;
|
|
50
|
+
customerCustomRecords = customerCustoms;
|
|
51
|
+
paymentCustomRecords = paymentCustoms;
|
|
52
|
+
|
|
53
|
+
done();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('dynamic finders', function() {
|
|
61
|
+
|
|
62
|
+
/////////////////////////////////////////////////////
|
|
63
|
+
// TEST METHODS
|
|
64
|
+
////////////////////////////////////////////////////
|
|
65
|
+
|
|
66
|
+
it('should return customer when the dynamic finder method is used for findOne', function(done) {
|
|
67
|
+
Associations.Payment.findOneByA_customer(customerRecords[0].id)
|
|
68
|
+
.exec(function(err, payment) {
|
|
69
|
+
assert.ifError(err);
|
|
70
|
+
|
|
71
|
+
assert(payment.a_customer);
|
|
72
|
+
assert.equal(payment.a_customer, customerRecords[0].id);
|
|
73
|
+
|
|
74
|
+
done();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should return customer when the dynamic finder method is used for findOneIn', function(done) {
|
|
79
|
+
Associations.Payment.findOneByA_customerIn([customerRecords[0].id])
|
|
80
|
+
.exec(function(err, payment) {
|
|
81
|
+
assert.ifError(err);
|
|
82
|
+
|
|
83
|
+
assert(payment.a_customer);
|
|
84
|
+
assert.equal(payment.a_customer, customerRecords[0].id);
|
|
85
|
+
|
|
86
|
+
done();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should return customer when the dynamic finder method is used for findOneLike', function(done) {
|
|
91
|
+
Associations.Paymentbelongscustom.findOneByCustomerLike('%bar').sort('invoice asc')
|
|
92
|
+
.exec(function(err, payment) {
|
|
93
|
+
assert.ifError(err);
|
|
94
|
+
|
|
95
|
+
assert(payment);
|
|
96
|
+
assert.equal(payment.customer, customerCustomRecords[1].username);
|
|
97
|
+
|
|
98
|
+
done();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should return customer when the dynamic finder method is used for find', function(done) {
|
|
103
|
+
Associations.Payment.findByA_customer(customerRecords[0].id)
|
|
104
|
+
.exec(function(err, payments) {
|
|
105
|
+
assert.ifError(err);
|
|
106
|
+
|
|
107
|
+
assert.equal(payments.length, 1);
|
|
108
|
+
assert(payments[0].a_customer);
|
|
109
|
+
assert.equal(payments[0].a_customer, customerRecords[0].id);
|
|
110
|
+
|
|
111
|
+
done();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should return customer when the dynamic finder method is used for findIn', function(done) {
|
|
116
|
+
Associations.Payment.findByA_customerIn([customerRecords[0].id, customerRecords[1].id])
|
|
117
|
+
.exec(function(err, payments) {
|
|
118
|
+
assert.ifError(err);
|
|
119
|
+
assert.strictEqual(payments.length, 2);
|
|
120
|
+
var customer1 = payments[0].a_customer;
|
|
121
|
+
var customer2 = payments[1].a_customer;
|
|
122
|
+
assert(customer1 === customerRecords[0].id || customer1 === customerRecords[1].id, 'customer not in find range');
|
|
123
|
+
assert(customer2 === customerRecords[0].id || customer2 === customerRecords[1].id, 'customer not in find range');
|
|
124
|
+
done();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should return customer when the dynamic finder method is used for findLike', function(done) {
|
|
129
|
+
Associations.Paymentbelongscustom.findByCustomerLike('%bar').sort('invoice asc')
|
|
130
|
+
.exec(function(err, payments) {
|
|
131
|
+
assert.ifError(err);
|
|
132
|
+
|
|
133
|
+
assert.strictEqual(payments.length, 2);
|
|
134
|
+
assert.equal(payments[0].customer, customerCustomRecords[1].username);
|
|
135
|
+
assert.equal(payments[1].customer, customerCustomRecords[2].username);
|
|
136
|
+
|
|
137
|
+
done();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should return customer when the dynamic finder method is used for count', function(done) {
|
|
142
|
+
Associations.Payment.countByA_customer(customerRecords[0].id)
|
|
143
|
+
.exec(function(err, paymentsCount) {
|
|
144
|
+
assert.ifError(err);
|
|
145
|
+
|
|
146
|
+
assert.strictEqual(paymentsCount, 1);
|
|
147
|
+
done();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('should return customer when the dynamic finder method is used for countIn', function(done) {
|
|
152
|
+
Associations.Payment.countByA_customerIn([customerRecords[0].id, customerRecords[1].id, 5000])
|
|
153
|
+
.exec(function(err, paymentsCount) {
|
|
154
|
+
assert.ifError(err);
|
|
155
|
+
|
|
156
|
+
assert.strictEqual(paymentsCount, 2);
|
|
157
|
+
done();
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('should return customer when the dynamic finder method is used for countLike', function(done) {
|
|
162
|
+
Associations.Paymentbelongscustom.countByCustomerLike('%bar')
|
|
163
|
+
.exec(function(err, paymentsCount) {
|
|
164
|
+
assert.ifError(err);
|
|
165
|
+
|
|
166
|
+
assert.strictEqual(paymentsCount, 2);
|
|
167
|
+
done();
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('should return customer when the dynamic finder method is used for startsWith', function(done) {
|
|
172
|
+
Associations.Paymentbelongscustom.customerStartsWith('dynamic').sort('invoice asc')
|
|
173
|
+
.exec(function(err, payments) {
|
|
174
|
+
assert.ifError(err);
|
|
175
|
+
|
|
176
|
+
assert.strictEqual(payments.length, 3);
|
|
177
|
+
assert.equal(payments[0].customer, customerCustomRecords[0].username);
|
|
178
|
+
assert.equal(payments[1].customer, customerCustomRecords[1].username);
|
|
179
|
+
assert.equal(payments[2].customer, customerCustomRecords[2].username);
|
|
180
|
+
|
|
181
|
+
done();
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should return customer when the dynamic finder method is used for contains', function(done) {
|
|
186
|
+
Associations.Paymentbelongscustom.customerContains('foo').sort('invoice asc')
|
|
187
|
+
.exec(function(err, payments) {
|
|
188
|
+
assert.ifError(err);
|
|
189
|
+
|
|
190
|
+
assert.strictEqual(payments.length, 2);
|
|
191
|
+
assert.equal(payments[0].customer, customerCustomRecords[0].username);
|
|
192
|
+
assert.equal(payments[1].customer, customerCustomRecords[2].username);
|
|
193
|
+
|
|
194
|
+
done();
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should return customer when the dynamic finder method is used for endsWith', function(done) {
|
|
199
|
+
Associations.Paymentbelongscustom.customerEndsWith('bar').sort('invoice asc')
|
|
200
|
+
.exec(function(err, payments) {
|
|
201
|
+
assert.ifError(err);
|
|
202
|
+
|
|
203
|
+
assert.strictEqual(payments.length, 2);
|
|
204
|
+
assert.equal(payments[0].customer, customerCustomRecords[1].username);
|
|
205
|
+
assert.equal(payments[1].customer, customerCustomRecords[2].username);
|
|
206
|
+
|
|
207
|
+
done();
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
var _ = require('lodash'),
|
|
2
|
+
assert = require('assert');
|
|
3
|
+
|
|
4
|
+
describe('Association Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Belongs To Association', function() {
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////
|
|
9
|
+
// TEST SETUP
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
var customers, payments;
|
|
13
|
+
|
|
14
|
+
before(function(done) {
|
|
15
|
+
|
|
16
|
+
// Check Payment belongsTo Customer
|
|
17
|
+
assert.strictEqual(Associations.Payment.attributes.a_customer.model, 'customer');
|
|
18
|
+
assert.strictEqual(Associations.Customer.attributes.payments.collection, 'payment');
|
|
19
|
+
|
|
20
|
+
Associations.Customer.createEach([{
|
|
21
|
+
name: 'foo'
|
|
22
|
+
}, {
|
|
23
|
+
name: 'bar'
|
|
24
|
+
}], function(err, _customers) {
|
|
25
|
+
assert.ifError(err);
|
|
26
|
+
|
|
27
|
+
// Expose results for examination below
|
|
28
|
+
customers = _customers;
|
|
29
|
+
|
|
30
|
+
Associations.Payment.createEach([{
|
|
31
|
+
amount: 1,
|
|
32
|
+
type: 'belongsTo find',
|
|
33
|
+
a_customer: customers[0].id
|
|
34
|
+
}, {
|
|
35
|
+
amount: 2,
|
|
36
|
+
type: 'belongsTo find',
|
|
37
|
+
a_customer: customers[1].id
|
|
38
|
+
}, {
|
|
39
|
+
amount: 3,
|
|
40
|
+
type: 'belongsTo find no child',
|
|
41
|
+
a_customer: 1000
|
|
42
|
+
}], function(err, _payments) {
|
|
43
|
+
assert.ifError(err);
|
|
44
|
+
|
|
45
|
+
// Expose results for examination below
|
|
46
|
+
payments = _payments;
|
|
47
|
+
done();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('.find()', function() {
|
|
53
|
+
|
|
54
|
+
/////////////////////////////////////////////////////
|
|
55
|
+
// TEST METHODS
|
|
56
|
+
////////////////////////////////////////////////////
|
|
57
|
+
|
|
58
|
+
it('should return a customer when the populate criteria is added', function(done) {
|
|
59
|
+
Associations.Payment.find({ type: 'belongsTo find', sort: 'amount ASC' })
|
|
60
|
+
.populate('a_customer')
|
|
61
|
+
.exec(function(err, _payments) {
|
|
62
|
+
assert(!err, err);
|
|
63
|
+
|
|
64
|
+
assert(Array.isArray(_payments));
|
|
65
|
+
assert.strictEqual(_payments.length, 2, 'expected 2 payments, but got '+_payments.length+': '+require('util').inspect(_payments, false, null));
|
|
66
|
+
|
|
67
|
+
assert(_payments[0].a_customer);
|
|
68
|
+
assert.equal(_payments[0].a_customer.id, customers[0].id);
|
|
69
|
+
assert(_payments[0].a_customer.name === 'foo',
|
|
70
|
+
'Expected `payments[0].a_customer.name`==="foo", instead payments[0].customer ===> '+ require('util').inspect(_payments[0].a_customer, false, null));
|
|
71
|
+
|
|
72
|
+
assert(_payments[1].a_customer);
|
|
73
|
+
assert(_payments[1].a_customer.id === customers[1].id,
|
|
74
|
+
'Expected `payments[1].a_customer.id` === '+customers[1].id+', instead payments[1].a_customer ===> '+ require('util').inspect(_payments[1].a_customer, false, null));
|
|
75
|
+
assert(_payments[1].a_customer.name === 'bar',
|
|
76
|
+
'Expected `payments[1].a_customer.name` === "bar", instead payments[1].a_customer ===> '+ require('util').inspect(_payments[1].a_customer, false, null)
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
assert(!_payments[0].toJSON().a_customer.name,
|
|
80
|
+
'Expected payments[0] to have `a_customer` populated with a `name`, but instead it looks like: '+require('util').inspect(_payments[0], false, null)
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
done();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should not return a customer object when the populate is not added', function(done) {
|
|
88
|
+
Associations.Payment.find()
|
|
89
|
+
.exec(function(err, payments) {
|
|
90
|
+
assert.ifError(err);
|
|
91
|
+
|
|
92
|
+
assert(!_.isPlainObject(payments[0].a_customer));
|
|
93
|
+
assert(!_.isPlainObject(payments[1].a_customer));
|
|
94
|
+
|
|
95
|
+
done();
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('should call toJSON on associated record', function(done) {
|
|
100
|
+
Associations.Payment.find()
|
|
101
|
+
.populate('a_customer')
|
|
102
|
+
.exec(function(err, payments) {
|
|
103
|
+
assert.ifError(err);
|
|
104
|
+
|
|
105
|
+
var obj = payments[0].toJSON();
|
|
106
|
+
|
|
107
|
+
assert(!obj.type);
|
|
108
|
+
assert(obj.a_customer);
|
|
109
|
+
assert(obj.a_customer.createdAt);
|
|
110
|
+
assert(!obj.a_customer.name);
|
|
111
|
+
|
|
112
|
+
done();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should find association key in parent model', function(done) {
|
|
117
|
+
Associations.Payment.find({where: {a_customer: customers[0].id}})
|
|
118
|
+
.populate('a_customer')
|
|
119
|
+
.exec(function(err, payments) {
|
|
120
|
+
assert.ifError(err);
|
|
121
|
+
assert.strictEqual(payments.length, 1);
|
|
122
|
+
assert.strictEqual(payments[0].a_customer.id, customers[0].id);
|
|
123
|
+
|
|
124
|
+
done();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('populate should be null if id refer to an undefined child', function(done) {
|
|
129
|
+
Associations.Payment.find({where: {amount: 3}})
|
|
130
|
+
.populate('a_customer')
|
|
131
|
+
.exec(function(err, payments) {
|
|
132
|
+
assert.ifError(err);
|
|
133
|
+
assert.strictEqual(payments.length, 1);
|
|
134
|
+
assert.strictEqual(payments[0].amount, 3);
|
|
135
|
+
assert(!_.isUndefined(payments[0].a_customer), 'Child should not be undefined');
|
|
136
|
+
assert(_.isNull(payments[0].a_customer), 'Child should be null, but is actually : ', payments[0].a_customer);
|
|
137
|
+
|
|
138
|
+
done();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
});
|
|
145
|
+
});
|