@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,98 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Association Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Has Many Association', function() {
|
|
7
|
+
describe('association .remove()', function() {
|
|
8
|
+
|
|
9
|
+
describe('with an id', function() {
|
|
10
|
+
|
|
11
|
+
/////////////////////////////////////////////////////
|
|
12
|
+
// TEST SETUP
|
|
13
|
+
////////////////////////////////////////////////////
|
|
14
|
+
|
|
15
|
+
var stadiumRecord, teamRecord;
|
|
16
|
+
|
|
17
|
+
// Create a Customer and a payment
|
|
18
|
+
before(function(done) {
|
|
19
|
+
// Check Stadium hasManytoMany Team through Venue
|
|
20
|
+
assert.strictEqual(Associations.Stadium.attributes.teams.collection, 'team');
|
|
21
|
+
assert.strictEqual(Associations.Team.attributes.stadiums.collection, 'stadium');
|
|
22
|
+
assert.strictEqual(Associations.Venue.attributes.stadium.model, 'stadium');
|
|
23
|
+
assert.strictEqual(Associations.Venue.attributes.team.model, 'team');
|
|
24
|
+
|
|
25
|
+
Associations.Stadium.create({ name: 'hasManyThrough remove' }, function(err, stadium) {
|
|
26
|
+
assert.ifError(err);
|
|
27
|
+
|
|
28
|
+
stadiumRecord = stadium;
|
|
29
|
+
|
|
30
|
+
Associations.Team.create({ name: 'team remove 1', stadiums: stadium.id }, function(err, team) {
|
|
31
|
+
assert.ifError(err);
|
|
32
|
+
|
|
33
|
+
teamRecord = team;
|
|
34
|
+
|
|
35
|
+
done();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
/////////////////////////////////////////////////////
|
|
41
|
+
// TEST METHODS
|
|
42
|
+
////////////////////////////////////////////////////
|
|
43
|
+
|
|
44
|
+
it('should remove the stadiums foreign key from the team', function(done) {
|
|
45
|
+
stadiumRecord.teams.remove(teamRecord.id);
|
|
46
|
+
stadiumRecord.save(function(err) {
|
|
47
|
+
assert.ifError(err);
|
|
48
|
+
|
|
49
|
+
// Look up the customer again to be sure the payment was added
|
|
50
|
+
Associations.Stadium.findOne(stadiumRecord.id)
|
|
51
|
+
.populate('teams')
|
|
52
|
+
.exec(function(err, data) {
|
|
53
|
+
assert.ifError(err);
|
|
54
|
+
|
|
55
|
+
assert.strictEqual(data.teams.length, 0);
|
|
56
|
+
done();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('with an object', function() {
|
|
63
|
+
|
|
64
|
+
/////////////////////////////////////////////////////
|
|
65
|
+
// TEST SETUP
|
|
66
|
+
////////////////////////////////////////////////////
|
|
67
|
+
|
|
68
|
+
// var stadiumRecord;
|
|
69
|
+
//
|
|
70
|
+
// before(function(done) {
|
|
71
|
+
// Associations.Stadium.create({ name: 'hasMany add' }, function(err, model) {
|
|
72
|
+
// assert.ifError(err);
|
|
73
|
+
// customerRecord = model;
|
|
74
|
+
// done();
|
|
75
|
+
// });
|
|
76
|
+
// });
|
|
77
|
+
|
|
78
|
+
/////////////////////////////////////////////////////
|
|
79
|
+
// TEST METHODS
|
|
80
|
+
////////////////////////////////////////////////////
|
|
81
|
+
|
|
82
|
+
it('should error when an object is passed in', function(done) {
|
|
83
|
+
stadiumRecord.teams.remove({ name: 'team remove 1' });
|
|
84
|
+
stadiumRecord.save(function(err) {
|
|
85
|
+
assert(err);
|
|
86
|
+
assert(err.failedTransactions)
|
|
87
|
+
assert(Array.isArray(err.failedTransactions));
|
|
88
|
+
assert.strictEqual(err.failedTransactions.length, 1);
|
|
89
|
+
assert.equal(err.failedTransactions[0].type, 'remove');
|
|
90
|
+
|
|
91
|
+
done();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Association Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('1:m through association :: .update()', function() {
|
|
7
|
+
describe('update nested through associations with custom primary keys()', function() {
|
|
8
|
+
describe('with single level depth', function() {
|
|
9
|
+
|
|
10
|
+
describe('when association doesn\'t exist', function() {
|
|
11
|
+
|
|
12
|
+
/////////////////////////////////////////////////////
|
|
13
|
+
// TEST SETUP
|
|
14
|
+
////////////////////////////////////////////////////
|
|
15
|
+
|
|
16
|
+
var stadiumRecord;
|
|
17
|
+
|
|
18
|
+
before(function(done) {
|
|
19
|
+
// Check Stadium hasManytoMany Team through Venue
|
|
20
|
+
assert.strictEqual(Associations.Stadiumcustom.attributes.teams.collection, 'teamcustom');
|
|
21
|
+
assert.strictEqual(Associations.Teamcustom.attributes.stadiums.collection, 'stadiumcustom');
|
|
22
|
+
assert.strictEqual(Associations.Venuecustom.attributes.stadium.model, 'stadiumcustom');
|
|
23
|
+
assert.strictEqual(Associations.Venuecustom.attributes.team.model, 'teamcustom');
|
|
24
|
+
|
|
25
|
+
var data = {
|
|
26
|
+
address: 'address has many nested custom 1',
|
|
27
|
+
name: 'has many nested custom update 1'
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
Associations.Stadiumcustom.create(data)
|
|
31
|
+
.exec(function(err, values) {
|
|
32
|
+
assert.ifError(err);
|
|
33
|
+
stadiumRecord = values;
|
|
34
|
+
done();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
/////////////////////////////////////////////////////
|
|
41
|
+
// TEST METHODS
|
|
42
|
+
////////////////////////////////////////////////////
|
|
43
|
+
|
|
44
|
+
it('should create new teams', function(done) {
|
|
45
|
+
|
|
46
|
+
var data = {
|
|
47
|
+
name: '1:m update nested custom 1 - updated',
|
|
48
|
+
teams: [
|
|
49
|
+
{ location: 'location has many nested custom 1', name: 'nested team 1' }
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
Associations.Stadiumcustom.update({ address: stadiumRecord.address })
|
|
54
|
+
.set(data)
|
|
55
|
+
.exec(function(err, values) {
|
|
56
|
+
assert.ifError(err);
|
|
57
|
+
|
|
58
|
+
// Look up the stadium again to be sure the teams were added
|
|
59
|
+
Associations.Stadiumcustom.findOne(values[0].address)
|
|
60
|
+
.populate('teams')
|
|
61
|
+
.exec(function(err, model) {
|
|
62
|
+
assert.ifError(err);
|
|
63
|
+
assert.equal(model.name, '1:m update nested custom 1 - updated');
|
|
64
|
+
assert.equal(model.teams.length, 1);
|
|
65
|
+
assert.equal(model.teams[0].location, 'location has many nested custom 1');
|
|
66
|
+
assert.equal(model.teams[0].name, 'nested team 1');
|
|
67
|
+
done();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
describe('when associations already exist', function() {
|
|
76
|
+
|
|
77
|
+
/////////////////////////////////////////////////////
|
|
78
|
+
// TEST SETUP
|
|
79
|
+
////////////////////////////////////////////////////
|
|
80
|
+
|
|
81
|
+
var stadiumRecord;
|
|
82
|
+
|
|
83
|
+
before(function(done) {
|
|
84
|
+
|
|
85
|
+
var data = {
|
|
86
|
+
address: 'address has many nested custom 2',
|
|
87
|
+
name: 'has many nested custom update 2',
|
|
88
|
+
teams: [
|
|
89
|
+
{ location: 'location has many nested custom 2', name: 'nested team 2' },
|
|
90
|
+
{ location: 'location has many nested custom 3', name: 'nested team 3' }
|
|
91
|
+
]
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
Associations.Stadiumcustom.create(data)
|
|
95
|
+
.exec(function(err, stadium) {
|
|
96
|
+
assert.ifError(err);
|
|
97
|
+
stadiumRecord = stadium;
|
|
98
|
+
done();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
/////////////////////////////////////////////////////
|
|
105
|
+
// TEST METHODS
|
|
106
|
+
////////////////////////////////////////////////////
|
|
107
|
+
|
|
108
|
+
it('should reset associations with the updated associations', function(done) {
|
|
109
|
+
|
|
110
|
+
var data = {
|
|
111
|
+
name: '1:m update nested custom 2 - updated',
|
|
112
|
+
teams: [
|
|
113
|
+
{ location: 'location has many nested custom 4', name: 'nested team 4' },
|
|
114
|
+
{ location: 'location has many nested custom 5', name: 'nested team 5' },
|
|
115
|
+
{ location: 'location has many nested custom 6', name: 'nested team 6' }
|
|
116
|
+
]
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
Associations.Stadiumcustom.update({ address: stadiumRecord.address })
|
|
120
|
+
.set(data)
|
|
121
|
+
.exec(function(err, values) {
|
|
122
|
+
assert.ifError(err);
|
|
123
|
+
|
|
124
|
+
// Look up the stadium again to be sure the teams were added
|
|
125
|
+
Associations.Stadiumcustom.findOne(values[0].address)
|
|
126
|
+
.populate('teams', { sort: 'name ASC' })
|
|
127
|
+
.exec(function(err, model) {
|
|
128
|
+
assert.ifError(err);
|
|
129
|
+
assert.equal(model.name, '1:m update nested custom 2 - updated');
|
|
130
|
+
assert.equal(model.teams.length, 3);
|
|
131
|
+
|
|
132
|
+
assert.equal(model.teams[0].location, 'location has many nested custom 4');
|
|
133
|
+
assert.equal(model.teams[0].name, 'nested team 4');
|
|
134
|
+
|
|
135
|
+
assert.equal(model.teams[1].location, 'location has many nested custom 5');
|
|
136
|
+
assert.equal(model.teams[1].name, 'nested team 5');
|
|
137
|
+
|
|
138
|
+
assert.equal(model.teams[2].location, 'location has many nested custom 6');
|
|
139
|
+
assert.equal(model.teams[2].name, 'nested team 6');
|
|
140
|
+
done();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Association Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('1:m through association :: .update()', function() {
|
|
7
|
+
describe('update nested through associations()', function() {
|
|
8
|
+
describe('with single level depth', function() {
|
|
9
|
+
|
|
10
|
+
describe('when association doesn\'t exist', function() {
|
|
11
|
+
|
|
12
|
+
/////////////////////////////////////////////////////
|
|
13
|
+
// TEST SETUP
|
|
14
|
+
////////////////////////////////////////////////////
|
|
15
|
+
|
|
16
|
+
var stadiumRecord;
|
|
17
|
+
|
|
18
|
+
before(function(done) {
|
|
19
|
+
// Check Stadium hasManytoMany Team through Venue
|
|
20
|
+
assert.strictEqual(Associations.Stadium.attributes.teams.collection, 'team');
|
|
21
|
+
assert.strictEqual(Associations.Team.attributes.stadiums.collection, 'stadium');
|
|
22
|
+
assert.strictEqual(Associations.Venue.attributes.stadium.model, 'stadium');
|
|
23
|
+
assert.strictEqual(Associations.Venue.attributes.team.model, 'team');
|
|
24
|
+
|
|
25
|
+
var data = {
|
|
26
|
+
name: 'has many nested update'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
Associations.Stadium.create(data).exec(function(err, values) {
|
|
30
|
+
assert.ifError(err);
|
|
31
|
+
stadiumRecord = values;
|
|
32
|
+
done();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
/////////////////////////////////////////////////////
|
|
39
|
+
// TEST METHODS
|
|
40
|
+
////////////////////////////////////////////////////
|
|
41
|
+
|
|
42
|
+
it('should create new teams', function(done) {
|
|
43
|
+
|
|
44
|
+
var data = {
|
|
45
|
+
name: '1:m update nested - updated',
|
|
46
|
+
teams: [
|
|
47
|
+
{ name: 'nested team' }
|
|
48
|
+
]
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
Associations.Stadium.update({ id: stadiumRecord.id }, data).exec(function(err, values) {
|
|
52
|
+
assert.ifError(err);
|
|
53
|
+
|
|
54
|
+
// Look up the customer again to be sure the payments were added
|
|
55
|
+
Associations.Stadium.findOne(values[0].id)
|
|
56
|
+
.populate('teams')
|
|
57
|
+
.exec(function(err, model) {
|
|
58
|
+
assert.ifError(err);
|
|
59
|
+
assert.equal(model.name, '1:m update nested - updated');
|
|
60
|
+
assert.strictEqual(model.teams.length, 1);
|
|
61
|
+
assert.strictEqual(model.teams[0].name, 'nested team');
|
|
62
|
+
done();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
describe('when associations already exist', function() {
|
|
70
|
+
|
|
71
|
+
/////////////////////////////////////////////////////
|
|
72
|
+
// TEST SETUP
|
|
73
|
+
////////////////////////////////////////////////////
|
|
74
|
+
|
|
75
|
+
var stadiumRecord;
|
|
76
|
+
|
|
77
|
+
before(function(done) {
|
|
78
|
+
|
|
79
|
+
var data = {
|
|
80
|
+
name: '1:m update nested 1',
|
|
81
|
+
payments: [
|
|
82
|
+
{ name: 'nested team 1' },
|
|
83
|
+
{ name: 'nested team 2' }
|
|
84
|
+
]
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
Associations.Stadium.create(data).exec(function(err, stadium) {
|
|
88
|
+
assert.ifError(err);
|
|
89
|
+
stadiumRecord = stadium;
|
|
90
|
+
done();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
/////////////////////////////////////////////////////
|
|
96
|
+
// TEST METHODS
|
|
97
|
+
////////////////////////////////////////////////////
|
|
98
|
+
|
|
99
|
+
it('should reset associations with the updated associations', function(done) {
|
|
100
|
+
|
|
101
|
+
var data = {
|
|
102
|
+
name: '1:m update nested 1 - updated',
|
|
103
|
+
teams: [
|
|
104
|
+
{ name: 'nested team 3' },
|
|
105
|
+
{ name: 'nested team 4' },
|
|
106
|
+
{ name: 'nested team 5' }
|
|
107
|
+
]
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
Associations.Stadium.update({ id: stadiumRecord.id }, data).exec(function(err, values) {
|
|
111
|
+
assert.ifError(err);
|
|
112
|
+
|
|
113
|
+
// Look up the stadium again to be sure the teams were added
|
|
114
|
+
Associations.Stadium.findOne(values[0].id)
|
|
115
|
+
.populate('teams', { sort: 'name ASC' })
|
|
116
|
+
.exec(function(err, model) {
|
|
117
|
+
assert.ifError(err);
|
|
118
|
+
assert.equal(model.name, '1:m update nested 1 - updated');
|
|
119
|
+
assert.strictEqual(model.teams.length, 3);
|
|
120
|
+
assert.strictEqual(model.teams[0].name, 'nested team 3');
|
|
121
|
+
assert.strictEqual(model.teams[1].name, 'nested team 4');
|
|
122
|
+
assert.strictEqual(model.teams[2].name, 'nested team 5');
|
|
123
|
+
done();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('when associations have primary keys', function() {
|
|
131
|
+
|
|
132
|
+
/////////////////////////////////////////////////////
|
|
133
|
+
// TEST SETUP
|
|
134
|
+
////////////////////////////////////////////////////
|
|
135
|
+
|
|
136
|
+
var stadiumRecord, teamsRecord;
|
|
137
|
+
|
|
138
|
+
before(function(done) {
|
|
139
|
+
|
|
140
|
+
var teamData = [
|
|
141
|
+
{ name: 'nested team 1' },
|
|
142
|
+
{ name: 'nested team 2' }
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
var data = {
|
|
146
|
+
name: '1:m update nested 2',
|
|
147
|
+
payments: [
|
|
148
|
+
{ name: 'nested team 3' },
|
|
149
|
+
{ name: 'nested team 4' }
|
|
150
|
+
]
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
Associations.Team.create(teamData).exec(function(err, teams) {
|
|
154
|
+
assert.ifError(err);
|
|
155
|
+
teamsRecord = teams;
|
|
156
|
+
|
|
157
|
+
Associations.Stadium.create(data).exec(function(err, stadium) {
|
|
158
|
+
assert.ifError(err);
|
|
159
|
+
stadiumRecord = stadium;
|
|
160
|
+
done();
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
/////////////////////////////////////////////////////
|
|
167
|
+
// TEST METHODS
|
|
168
|
+
////////////////////////////////////////////////////
|
|
169
|
+
|
|
170
|
+
it('should update association values', function(done) {
|
|
171
|
+
|
|
172
|
+
var data = {
|
|
173
|
+
name: '1:m update nested 2 - updated',
|
|
174
|
+
teams: teamsRecord.map(function(team) { return team.toObject(); })
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
Associations.Stadium.update({ id: stadiumRecord.id }, data).exec(function(err, values) {
|
|
178
|
+
assert.ifError(err);
|
|
179
|
+
|
|
180
|
+
// Look up the stadium again to be sure the teams were added
|
|
181
|
+
Associations.Stadium.findOne(values[0].id)
|
|
182
|
+
.populate('teams',{sort:{name : 1}})
|
|
183
|
+
.exec(function(err, model) {
|
|
184
|
+
assert.ifError(err);
|
|
185
|
+
assert.equal(model.name, '1:m update nested 2 - updated');
|
|
186
|
+
assert.strictEqual(model.teams.length, 2);
|
|
187
|
+
|
|
188
|
+
// Ensure association values were updated
|
|
189
|
+
assert.strictEqual(model.teams[0].name, 'nested team 1');
|
|
190
|
+
assert.strictEqual(model.teams[1].name, 'nested team 2');
|
|
191
|
+
|
|
192
|
+
done();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Association Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('1:1 Association', function() {
|
|
7
|
+
describe('create', function() {
|
|
8
|
+
|
|
9
|
+
/////////////////////////////////////////////////////
|
|
10
|
+
// TEST SETUP
|
|
11
|
+
////////////////////////////////////////////////////
|
|
12
|
+
|
|
13
|
+
var userId;
|
|
14
|
+
|
|
15
|
+
before(function(done) {
|
|
16
|
+
// Check User_resource and Profile have a oneToOne association
|
|
17
|
+
assert.strictEqual(Associations.Profile.attributes.user.model, 'user_resource');
|
|
18
|
+
assert.strictEqual(Associations.User_resource.attributes.profile.model, 'profile');
|
|
19
|
+
|
|
20
|
+
Associations.User_resource.create({ name: 'oneToOne add' }).exec(function(err, user) {
|
|
21
|
+
assert.ifError(err);
|
|
22
|
+
userId = user.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.Profile.create({ level: 1, user: userId }).exec(function(err, profile) {
|
|
33
|
+
assert.ifError(err);
|
|
34
|
+
assert.equal(profile.user.toString(), userId.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('1:1 Association', function() {
|
|
8
|
+
|
|
9
|
+
before(function(done) {
|
|
10
|
+
// Check User_resourcecustom and Profilecustom have a oneToOne association
|
|
11
|
+
assert.strictEqual(Associations.Profilecustom.attributes.user.model, 'user_resourcecustom');
|
|
12
|
+
assert.strictEqual(Associations.User_resourcecustom.attributes.profile.model, 'profilecustom');
|
|
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
|
+
number: 1000,
|
|
25
|
+
quantity: 200,
|
|
26
|
+
profile: {
|
|
27
|
+
name: 'oneToOne',
|
|
28
|
+
level: 30
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Create the Parent and Child records
|
|
33
|
+
Associations.User_resourcecustom.create(data)
|
|
34
|
+
.exec(function(err, user) {
|
|
35
|
+
assert.ifError(err);
|
|
36
|
+
|
|
37
|
+
// Ensure the foreignKey get set
|
|
38
|
+
assert.equal(user.profile.name, 'oneToOne');
|
|
39
|
+
assert.equal(user.profile.level, 30);
|
|
40
|
+
|
|
41
|
+
// Look up the values and test that populate works on the custom values
|
|
42
|
+
Associations.User_resourcecustom.findOne(user.number)
|
|
43
|
+
.populate('profile')
|
|
44
|
+
.exec(function(err, _user) {
|
|
45
|
+
assert.ifError(err);
|
|
46
|
+
|
|
47
|
+
// Test the parent is correct
|
|
48
|
+
assert.equal(_user.number, 1000);
|
|
49
|
+
|
|
50
|
+
// Test the child is correct
|
|
51
|
+
assert.equal(_user.profile.name, 'oneToOne');
|
|
52
|
+
assert.equal(_user.profile.level, 30);
|
|
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('1:1 Association', function() {
|
|
10
|
+
|
|
11
|
+
before(function(done) {
|
|
12
|
+
// Check User_resource and Profile have a oneToOne association
|
|
13
|
+
assert.strictEqual(Associations.Profile.attributes.user.model, 'user_resource');
|
|
14
|
+
assert.strictEqual(Associations.User_resource.attributes.profile.model, 'profile');
|
|
15
|
+
done();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('create nested association', function() {
|
|
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
|
+
quantity: 200,
|
|
27
|
+
profile: {
|
|
28
|
+
name: 'oneToOne nested create'
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
Associations.User_resource.create(data).exec(function(err, user) {
|
|
33
|
+
assert.ifError(err);
|
|
34
|
+
assert(user.profile);
|
|
35
|
+
|
|
36
|
+
Associations.User_resource.findOne(user.id)
|
|
37
|
+
.populate('profile')
|
|
38
|
+
.exec(function(err, _user) {
|
|
39
|
+
assert(!err,'Tried to execute .findOne() with criteria:\n'+
|
|
40
|
+
util.inspect(_user.id, false, null)+'\nBut got error:\n'+
|
|
41
|
+
util.inspect(err, false, null));
|
|
42
|
+
assert(_user.profile.name === 'oneToOne nested create',
|
|
43
|
+
'Expecting `_user.profile.name`==="oneToOne nested create", but instead `_user` ==>'+
|
|
44
|
+
util.inspect(_user, false, null));
|
|
45
|
+
done();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
});
|
|
52
|
+
});
|