@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,114 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var _ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Association Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Has Many Through Association', function() {
|
|
7
|
+
describe('create nested through associations when a custom primary key is used()', function() {
|
|
8
|
+
describe('with single level depth', function() {
|
|
9
|
+
|
|
10
|
+
describe('and objects', function() {
|
|
11
|
+
|
|
12
|
+
before(function(done) {
|
|
13
|
+
// Check Stadium hasManytoMany Team through Venue
|
|
14
|
+
assert.strictEqual(Associations.Stadium.attributes.teams.collection, 'team');
|
|
15
|
+
assert.strictEqual(Associations.Team.attributes.stadiums.collection, 'stadium');
|
|
16
|
+
assert.strictEqual(Associations.Venue.attributes.stadium.model, 'stadium');
|
|
17
|
+
assert.strictEqual(Associations.Venue.attributes.team.model, 'team');
|
|
18
|
+
done();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/////////////////////////////////////////////////////
|
|
22
|
+
// TEST METHODS
|
|
23
|
+
////////////////////////////////////////////////////
|
|
24
|
+
|
|
25
|
+
it('should create a new stadium and team through association', function(done) {
|
|
26
|
+
|
|
27
|
+
var data = {
|
|
28
|
+
name: 'has many through nested',
|
|
29
|
+
teams: [
|
|
30
|
+
{ name: 'Avengers', mascot: 'Hulk' },
|
|
31
|
+
{ name: 'Justice League', mascot: 'Batman' }
|
|
32
|
+
]
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
Associations.Stadium.create(data)
|
|
36
|
+
.exec(function(err, values) {
|
|
37
|
+
assert.ifError(err);
|
|
38
|
+
// Look up the stadium again to be sure the teams were added
|
|
39
|
+
Associations.Stadium.findOne({name: values.name})
|
|
40
|
+
.populate('teams', { sort: 'name ASC' })
|
|
41
|
+
.exec(function(err, model) {
|
|
42
|
+
assert.ifError(err);
|
|
43
|
+
|
|
44
|
+
assert(model, 'should find the parent');
|
|
45
|
+
assert.equal(model.teams.length, 2);
|
|
46
|
+
|
|
47
|
+
assert.equal(model.teams[0].name, 'Avengers');
|
|
48
|
+
assert.equal(model.teams[0].mascot, 'Hulk');
|
|
49
|
+
|
|
50
|
+
assert.equal(model.teams[1].name, 'Justice League');
|
|
51
|
+
assert.equal(model.teams[1].mascot, 'Batman');
|
|
52
|
+
|
|
53
|
+
done();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('and objects mixed with ids', function() {
|
|
61
|
+
var idTeam;
|
|
62
|
+
before(function(done) {
|
|
63
|
+
Associations.Team.create({ name: 'X-Men', mascot: 'Wolverine' })
|
|
64
|
+
.exec(function(err, team) {
|
|
65
|
+
assert.ifError(err);
|
|
66
|
+
idTeam = team.id;
|
|
67
|
+
done();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
/////////////////////////////////////////////////////
|
|
72
|
+
// TEST METHODS
|
|
73
|
+
////////////////////////////////////////////////////
|
|
74
|
+
|
|
75
|
+
it('should create a new stadium and payment association', function(done) {
|
|
76
|
+
|
|
77
|
+
var data = {
|
|
78
|
+
name: 'mixed custom through create',
|
|
79
|
+
teams: [
|
|
80
|
+
idTeam,
|
|
81
|
+
{ name : 'Fantastic Four', mascot: 'Dr Doom' }
|
|
82
|
+
]
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
Associations.Stadium.create(data)
|
|
86
|
+
.exec(function(err, values) {
|
|
87
|
+
assert.ifError(err);
|
|
88
|
+
|
|
89
|
+
// Look up the stadium again to be sure the teams were added
|
|
90
|
+
Associations.Stadium.findOne({name: values.name})
|
|
91
|
+
.populate('teams', { sort: 'name ASC' })
|
|
92
|
+
.exec(function(err, model) {
|
|
93
|
+
assert.ifError(err);
|
|
94
|
+
|
|
95
|
+
assert(model, 'should find the parent');
|
|
96
|
+
assert.equal(model.teams.length, 2);
|
|
97
|
+
|
|
98
|
+
assert.equal(model.teams[0].name, 'Fantastic Four');
|
|
99
|
+
assert.equal(model.teams[0].mascot, 'Dr Doom');
|
|
100
|
+
|
|
101
|
+
assert.equal(model.teams[1].name, 'X-Men');
|
|
102
|
+
assert.equal(model.teams[1].mascot, 'Wolverine');
|
|
103
|
+
|
|
104
|
+
done();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var util = require('util');
|
|
2
|
+
var assert = require('assert');
|
|
3
|
+
var _ = require('lodash');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describe('Association Interface', function() {
|
|
7
|
+
|
|
8
|
+
describe('Has Many Through Association with Custom Primary Keys', function() {
|
|
9
|
+
|
|
10
|
+
/////////////////////////////////////////////////////
|
|
11
|
+
// TEST SETUP
|
|
12
|
+
////////////////////////////////////////////////////
|
|
13
|
+
|
|
14
|
+
before(function(done) {
|
|
15
|
+
// Check Stadium hasManytoMany Team through Venue
|
|
16
|
+
assert.strictEqual(Associations.Stadiumcustom.attributes.teams.collection, 'teamcustom');
|
|
17
|
+
assert.strictEqual(Associations.Teamcustom.attributes.stadiums.collection, 'stadiumcustom');
|
|
18
|
+
assert.strictEqual(Associations.Venuecustom.attributes.stadium.model, 'stadiumcustom');
|
|
19
|
+
assert.strictEqual(Associations.Venuecustom.attributes.team.model, 'teamcustom');
|
|
20
|
+
|
|
21
|
+
var stadiumRecords = [
|
|
22
|
+
{ address: 'a00-A', name: 'hasManyThrough find customPK' },
|
|
23
|
+
{ address: 'b00-B', name: 'hasManyThrough find customPK' }
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
Associations.Stadiumcustom.createEach(stadiumRecords, function(err, stadiums) {
|
|
27
|
+
assert.ifError(err);
|
|
28
|
+
|
|
29
|
+
Associations.Stadiumcustom.find({ name: 'hasManyThrough find customPK' })
|
|
30
|
+
.sort('address asc')
|
|
31
|
+
.exec(function(err, stadiums) {
|
|
32
|
+
assert.ifError(err);
|
|
33
|
+
|
|
34
|
+
// Create 8 teams, 4 for one stadium, 4 for the other
|
|
35
|
+
var teams = [];
|
|
36
|
+
for(var i=0; i<8; i++) {
|
|
37
|
+
if(i < 4) teams.push({ location: 'team'+i, stadiums: stadiums[0].address });
|
|
38
|
+
if(i >= 4) teams.push({ location: 'team'+i, stadiums: stadiums[1].address });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Associations.Teamcustom.createEach(teams, function(err, teams) {
|
|
42
|
+
assert.ifError(err);
|
|
43
|
+
done();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('.find', function() {
|
|
50
|
+
|
|
51
|
+
/////////////////////////////////////////////////////
|
|
52
|
+
// TEST METHODS
|
|
53
|
+
////////////////////////////////////////////////////
|
|
54
|
+
|
|
55
|
+
it('should return teams when the populate criteria is added', function(done) {
|
|
56
|
+
Associations.Stadiumcustom.find({ name: 'hasManyThrough find customPK' })
|
|
57
|
+
.populate('teams')
|
|
58
|
+
.exec(function(err, stadiums) {
|
|
59
|
+
assert.ifError(err);
|
|
60
|
+
|
|
61
|
+
assert(Array.isArray(stadiums));
|
|
62
|
+
assert.strictEqual(stadiums.length, 2, 'expected 2 stadiums, got these stadiums:'+require('util').inspect(stadiums, false, null));
|
|
63
|
+
|
|
64
|
+
assert(Array.isArray(stadiums[0].teams));
|
|
65
|
+
assert(Array.isArray(stadiums[1].teams));
|
|
66
|
+
|
|
67
|
+
assert.strictEqual(stadiums[0].teams.length, 4);
|
|
68
|
+
assert.strictEqual(stadiums[1].teams.length, 4);
|
|
69
|
+
|
|
70
|
+
done();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Association Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Has Many Through Association', function() {
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////
|
|
9
|
+
// TEST SETUP
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
var stadiumRecord, stadiumRecord2, teamRecord, teamRecord2;
|
|
13
|
+
|
|
14
|
+
before(function(done) {
|
|
15
|
+
// Check Stadium hasManytoMany Team through Venue
|
|
16
|
+
assert.strictEqual(Associations.Stadium.attributes.teams.collection, 'team');
|
|
17
|
+
assert.strictEqual(Associations.Team.attributes.stadiums.collection, 'stadium');
|
|
18
|
+
assert.strictEqual(Associations.Venue.attributes.stadium.model, 'stadium');
|
|
19
|
+
assert.strictEqual(Associations.Venue.attributes.team.model, 'team');
|
|
20
|
+
|
|
21
|
+
Associations.Stadium.create({ name: 'hasManyThrough find stadium'}, function(err, stadium) {
|
|
22
|
+
assert.ifError(err);
|
|
23
|
+
stadiumRecord = stadium;
|
|
24
|
+
Associations.Stadium.create({ name: 'hasManyThrough find stadium2'}, function(err, stadium2) {
|
|
25
|
+
assert.ifError(err);
|
|
26
|
+
stadiumRecord2 = stadium2;
|
|
27
|
+
Associations.Stadium.create({ name: 'find stadium hasManyThrough no child'}, function(err, stadium3) {
|
|
28
|
+
assert.ifError(err);
|
|
29
|
+
|
|
30
|
+
Associations.Team.create({ name: 'hasManyThrough team1', mascot: 'elephant' }, function(err, team) {
|
|
31
|
+
assert.ifError(err);
|
|
32
|
+
teamRecord = team;
|
|
33
|
+
|
|
34
|
+
Associations.Team.create({ name: 'hasManyThrough team1', mascot: 'fox' }, function(err, team2) {
|
|
35
|
+
assert.ifError(err);
|
|
36
|
+
teamRecord2 = team2;
|
|
37
|
+
|
|
38
|
+
Associations.Venue.create({ seats: 200, stadium: stadium.id, team: team.id }, function(err, venue) {
|
|
39
|
+
assert.ifError(err);
|
|
40
|
+
|
|
41
|
+
Associations.Venue.create({ seats: 200, stadium: stadium2.id, team: team2.id }, function(err, venue) {
|
|
42
|
+
assert.ifError(err);
|
|
43
|
+
done();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('.find', function() {
|
|
54
|
+
|
|
55
|
+
/////////////////////////////////////////////////////
|
|
56
|
+
// TEST METHODS
|
|
57
|
+
////////////////////////////////////////////////////
|
|
58
|
+
|
|
59
|
+
it('should return teams when the populate criteria is added', function(done) {
|
|
60
|
+
Associations.Stadium.find({name: {startsWith: 'hasManyThrough find stadium'}})
|
|
61
|
+
.populate('teams')
|
|
62
|
+
.exec(function(err, stadiums) {
|
|
63
|
+
assert.ifError(err);
|
|
64
|
+
assert(Array.isArray(stadiums));
|
|
65
|
+
assert.strictEqual(stadiums.length, 2);
|
|
66
|
+
assert(Array.isArray(stadiums[0].teams));
|
|
67
|
+
assert.strictEqual(stadiums[0].teams.length, 1);
|
|
68
|
+
assert(Array.isArray(stadiums[1].teams));
|
|
69
|
+
assert.strictEqual(stadiums[1].teams.length, 1);
|
|
70
|
+
done();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should not return a teams object when the populate is not added', function(done) {
|
|
75
|
+
Associations.Stadium.find()
|
|
76
|
+
.exec(function(err, stadiums) {
|
|
77
|
+
assert.ifError(err);
|
|
78
|
+
|
|
79
|
+
var obj = stadiums[0].toJSON();
|
|
80
|
+
assert(!obj.teams);
|
|
81
|
+
|
|
82
|
+
done();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should call toJSON on all associated records if available', function(done) {
|
|
87
|
+
Associations.Stadium.find({ name: 'hasManyThrough find stadium' })
|
|
88
|
+
.populate('teams')
|
|
89
|
+
.exec(function(err, stadiums) {
|
|
90
|
+
assert.ifError(err);
|
|
91
|
+
|
|
92
|
+
assert(Array.isArray(stadiums));
|
|
93
|
+
assert.strictEqual(stadiums.length, 1);
|
|
94
|
+
var obj = stadiums[0].toJSON();
|
|
95
|
+
|
|
96
|
+
assert(Array.isArray(obj.teams));
|
|
97
|
+
assert.strictEqual(obj.teams.length, 1);
|
|
98
|
+
assert(!obj.teams[0].mascot);
|
|
99
|
+
|
|
100
|
+
done();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('populate should be an empty array if id refer to an undefined child', function(done) {
|
|
105
|
+
Associations.Stadium.find({name: 'find stadium hasManyThrough no child'})
|
|
106
|
+
.populate('teams')
|
|
107
|
+
.exec(function(err, stadiums) {
|
|
108
|
+
assert.ifError(err);
|
|
109
|
+
|
|
110
|
+
assert.strictEqual(stadiums.length, 1);
|
|
111
|
+
assert(!_.isUndefined(stadiums[0].teams), 'Child should not be undefined');
|
|
112
|
+
assert(_.isArray(stadiums[0].teams), 'Child should be an array');
|
|
113
|
+
assert.strictEqual(stadiums[0].teams.length, 0);
|
|
114
|
+
done();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var _ = require('lodash');
|
|
3
|
+
var util = require('util');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
describe('Association Interface', function() {
|
|
10
|
+
|
|
11
|
+
describe('Many to Many Through Association', function() {
|
|
12
|
+
|
|
13
|
+
var Stadium;
|
|
14
|
+
|
|
15
|
+
/////////////////////////////////////////////////////
|
|
16
|
+
// TEST SETUP
|
|
17
|
+
////////////////////////////////////////////////////
|
|
18
|
+
|
|
19
|
+
before(function(done) {
|
|
20
|
+
// Check Stadium hasManytoMany Team through Venue
|
|
21
|
+
assert.strictEqual(Associations.Stadium.attributes.teams.collection, 'team');
|
|
22
|
+
assert.strictEqual(Associations.Team.attributes.stadiums.collection, 'stadium');
|
|
23
|
+
assert.strictEqual(Associations.Venue.attributes.stadium.model, 'stadium');
|
|
24
|
+
assert.strictEqual(Associations.Venue.attributes.team.model, 'team');
|
|
25
|
+
|
|
26
|
+
Associations.Stadium.createEach([
|
|
27
|
+
{ name: 'hasMany find where 1' },
|
|
28
|
+
{ name: 'hasMany find where 2' }
|
|
29
|
+
],
|
|
30
|
+
function(err, stadiums) {
|
|
31
|
+
assert.ifError(err);
|
|
32
|
+
|
|
33
|
+
Associations.Stadium.find({ name: {startsWith: 'hasMany find where'}})
|
|
34
|
+
.sort('name asc')
|
|
35
|
+
.exec(function(err, stadiums) {
|
|
36
|
+
assert.ifError(err);
|
|
37
|
+
|
|
38
|
+
assert(Array.isArray(stadiums));
|
|
39
|
+
assert.strictEqual(stadiums.length, 2);
|
|
40
|
+
|
|
41
|
+
Stadium = stadiums[0];
|
|
42
|
+
var teams = [];
|
|
43
|
+
|
|
44
|
+
for(var i=0; i<8; i++) {
|
|
45
|
+
if(i < 4) {
|
|
46
|
+
if (i < 2) {
|
|
47
|
+
teams.push({ name: 'teamWhere'+i, mascot: 'Platypus', stadiums: stadiums[0].id });
|
|
48
|
+
} else {
|
|
49
|
+
teams.push({ name: 'teamWhere'+i, mascot: 'Bison', stadiums: stadiums[0].id });
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
teams.push({ name: 'teamWhere'+i, mascot: 'Tapir', stadiums: stadiums[1].id });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
Associations.Team.createEach(teams, function(err, teams) {
|
|
57
|
+
assert.ifError(err);
|
|
58
|
+
done();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('.find', function() {
|
|
65
|
+
|
|
66
|
+
/////////////////////////////////////////////////////
|
|
67
|
+
// TEST METHODS
|
|
68
|
+
////////////////////////////////////////////////////
|
|
69
|
+
|
|
70
|
+
it('should return only payments less than or equal to 2', function(done) {
|
|
71
|
+
Associations.Stadium.find({ name: {startsWith: 'hasMany find where'}, sort: 'name asc'})
|
|
72
|
+
.populate('teams', { mascot:'Platypus' , limit: 2, sort: { name: 1 }})
|
|
73
|
+
.sort('name asc')
|
|
74
|
+
.exec(function(err, stadiums) {
|
|
75
|
+
assert.ifError(err);
|
|
76
|
+
|
|
77
|
+
assert(Array.isArray(stadiums));
|
|
78
|
+
assert.strictEqual(stadiums.length, 2);
|
|
79
|
+
|
|
80
|
+
assert(Array.isArray(stadiums[0].teams));
|
|
81
|
+
assert(Array.isArray(stadiums[1].teams));
|
|
82
|
+
|
|
83
|
+
assert(stadiums[0].teams.length === 2,
|
|
84
|
+
'expecting stadiums[0] to have 2 teams, but actually it looks like: \n'+util.inspect(stadiums[0],false, null));
|
|
85
|
+
|
|
86
|
+
assert.strictEqual(stadiums[0].teams[0].name, 'teamWhere0');
|
|
87
|
+
assert.strictEqual(stadiums[0].teams[1].name, 'teamWhere1');
|
|
88
|
+
|
|
89
|
+
assert.strictEqual(stadiums[1].teams.length, 0);
|
|
90
|
+
|
|
91
|
+
done();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should return payments using skip and limit', function(done) {
|
|
96
|
+
Associations.Stadium.find({ name: {startsWith: 'hasMany find where'}})
|
|
97
|
+
.populate('teams', { skip: 1, limit: 2, sort: { name: 1 } })
|
|
98
|
+
.sort('name asc')
|
|
99
|
+
.exec(function(err, stadiums) {
|
|
100
|
+
assert.ifError(err);
|
|
101
|
+
|
|
102
|
+
assert(Array.isArray(stadiums));
|
|
103
|
+
assert.strictEqual(stadiums.length, 2);
|
|
104
|
+
|
|
105
|
+
assert(Array.isArray(stadiums[0].teams));
|
|
106
|
+
assert(Array.isArray(stadiums[1].teams));
|
|
107
|
+
|
|
108
|
+
assert.strictEqual(stadiums[0].teams.length, 2);
|
|
109
|
+
assert.strictEqual(stadiums[0].teams[0].name, 'teamWhere1');
|
|
110
|
+
assert.strictEqual(stadiums[0].teams[1].name, 'teamWhere2');
|
|
111
|
+
|
|
112
|
+
assert(
|
|
113
|
+
stadiums[1].teams.length === 2,
|
|
114
|
+
'expected stadiums[1] to have 2 payments but instead it looks like:\n'+
|
|
115
|
+
util.inspect(stadiums[1].teams, false, null)
|
|
116
|
+
);
|
|
117
|
+
assert(
|
|
118
|
+
stadiums[1].teams[0].name === 'teamWhere5',
|
|
119
|
+
'expected stadiums[1].teams[0].name === 5, but stadiums[1] ==>\n'+
|
|
120
|
+
util.inspect(stadiums[1], false, null)
|
|
121
|
+
);
|
|
122
|
+
assert.strictEqual(stadiums[1].teams[1].name, 'teamWhere6');
|
|
123
|
+
|
|
124
|
+
done();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should allow filtering by primary key', function(done) {
|
|
129
|
+
|
|
130
|
+
// Find the teams
|
|
131
|
+
Associations.Team.findOne({ name: 'teamWhere1'}).exec(function(err, teams) {
|
|
132
|
+
assert.ifError(err);
|
|
133
|
+
|
|
134
|
+
Associations.Stadium.find({ name: {startsWith: 'hasMany find where'}})
|
|
135
|
+
.populate('teams', {where : { id: teams.id }, sort : {name : 1}})
|
|
136
|
+
.sort('name asc')
|
|
137
|
+
.exec(function(err, stadiums) {
|
|
138
|
+
assert.ifError(err);
|
|
139
|
+
|
|
140
|
+
assert(Array.isArray(stadiums));
|
|
141
|
+
assert.strictEqual(stadiums.length, 2);
|
|
142
|
+
|
|
143
|
+
assert(Array.isArray(stadiums[0].teams));
|
|
144
|
+
assert(Array.isArray(stadiums[1].teams));
|
|
145
|
+
|
|
146
|
+
assert.strictEqual(stadiums[0].teams.length, 1);
|
|
147
|
+
assert.strictEqual(stadiums[0].teams[0].name, 'teamWhere1');
|
|
148
|
+
assert.strictEqual(stadiums[1].teams.length, 0);
|
|
149
|
+
done();
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Association Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Has Many Through Association', function() {
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////
|
|
9
|
+
// TEST SETUP
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
var customerRecord;
|
|
13
|
+
|
|
14
|
+
before(function(done) {
|
|
15
|
+
// Check Stadium hasManytoMany Team through Venue
|
|
16
|
+
assert.strictEqual(Associations.Stadium.attributes.teams.collection, 'team');
|
|
17
|
+
assert.strictEqual(Associations.Team.attributes.stadiums.collection, 'stadium');
|
|
18
|
+
assert.strictEqual(Associations.Venue.attributes.stadium.model, 'stadium');
|
|
19
|
+
assert.strictEqual(Associations.Venue.attributes.team.model, 'team');
|
|
20
|
+
|
|
21
|
+
Associations.Stadium.create({ name: 'hasMany findOne' }, function(err, stadium) {
|
|
22
|
+
assert.ifError(err);
|
|
23
|
+
|
|
24
|
+
stadiumRecord = stadium;
|
|
25
|
+
|
|
26
|
+
var teams = [];
|
|
27
|
+
|
|
28
|
+
for(var i=0; i<4; i++) {
|
|
29
|
+
teams.push({ name: 'teamFindOne'+i, stadiums: stadium.id });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Associations.Team.createEach(teams, function(err) {
|
|
33
|
+
assert.ifError(err);
|
|
34
|
+
done();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('.findOne', function() {
|
|
40
|
+
|
|
41
|
+
/////////////////////////////////////////////////////
|
|
42
|
+
// TEST METHODS
|
|
43
|
+
////////////////////////////////////////////////////
|
|
44
|
+
|
|
45
|
+
it('should return teams when the populate criteria is added', function(done) {
|
|
46
|
+
Associations.Stadium.findOne({ id: stadiumRecord.id })
|
|
47
|
+
.populate('teams')
|
|
48
|
+
.exec(function(err, stadium) {
|
|
49
|
+
assert.ifError(err);
|
|
50
|
+
|
|
51
|
+
assert.strictEqual(stadium.id, stadiumRecord.id);
|
|
52
|
+
assert(Array.isArray(stadium.teams));
|
|
53
|
+
assert.strictEqual(stadium.teams.length, 4);
|
|
54
|
+
done();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should add a flag to not serialize association object when the populate is not added', function(done) {
|
|
59
|
+
Associations.Stadium.findOne({ id: stadiumRecord.id })
|
|
60
|
+
.exec(function(err, stadium) {
|
|
61
|
+
assert.ifError(err);
|
|
62
|
+
|
|
63
|
+
assert.strictEqual(stadium.id, stadiumRecord.id);
|
|
64
|
+
var obj = stadium.toJSON();
|
|
65
|
+
assert(!obj.teams);
|
|
66
|
+
|
|
67
|
+
done();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should call toJSON on all associated records if available', function(done) {
|
|
72
|
+
Associations.Stadium.findOne({ id: stadiumRecord.id })
|
|
73
|
+
.populate('teams')
|
|
74
|
+
.exec(function(err, stadium) {
|
|
75
|
+
assert.ifError(err);
|
|
76
|
+
|
|
77
|
+
var obj = stadium.toJSON();
|
|
78
|
+
|
|
79
|
+
assert.strictEqual(stadium.id, stadiumRecord.id);
|
|
80
|
+
assert(Array.isArray(obj.teams));
|
|
81
|
+
assert.strictEqual(obj.teams.length, 4);
|
|
82
|
+
assert(!obj.teams[0].hasOwnProperty('type'));
|
|
83
|
+
assert(!obj.teams[1].hasOwnProperty('type'));
|
|
84
|
+
assert(!obj.teams[2].hasOwnProperty('type'));
|
|
85
|
+
assert(!obj.teams[3].hasOwnProperty('type'));
|
|
86
|
+
|
|
87
|
+
done();
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|