@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.
Files changed (224) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc +35 -0
  3. package/.travis.yml +32 -0
  4. package/CHANGELOG.md +24 -0
  5. package/Dockerfile +7 -0
  6. package/LICENSE.md +11 -0
  7. package/README.md +71 -2
  8. package/docker-compose.yml +32 -0
  9. package/features/autoIncrement/README.md +37 -0
  10. package/features/autoIncrement/core/autoIncrement.test.js +151 -0
  11. package/features/autoIncrement/sequential/autoIncrementSequential.test.js +104 -0
  12. package/features/autoIncrement/support/autoInc.fixture.js +25 -0
  13. package/features/compositePrimaryKey/core/compositePrimaryKey.test.js +67 -0
  14. package/features/compositePrimaryKey/support/fixture.js +24 -0
  15. package/features/compositeUnique/core/compositeUnique.test.js +67 -0
  16. package/features/compositeUnique/support/fixture.js +30 -0
  17. package/features/crossAdapter/core/crossAdapter.js +119 -0
  18. package/features/crossAdapter/support/bootstrap.js +106 -0
  19. package/features/sequences/core/sequences.test.js +110 -0
  20. package/features/sequences/support/mariadb.js +23 -0
  21. package/features/sequences/support/oracle.js +23 -0
  22. package/features/sequences/support/postgres.js +23 -0
  23. package/features/spatial/core/geojson.test.js +68 -0
  24. package/features/spatial/support/fixtures.js +82 -0
  25. package/features/spatial/support/models.js +45 -0
  26. package/features/unique/README.md +18 -0
  27. package/features/unique/core/unique.test.js +107 -0
  28. package/features/unique/support/unique.fixture.js +26 -0
  29. package/interfaces/associations/belongsTo/create.js +41 -0
  30. package/interfaces/associations/belongsTo/create.nested.customPK.js +61 -0
  31. package/interfaces/associations/belongsTo/create.nested.js +52 -0
  32. package/interfaces/associations/belongsTo/dynamicFinder.js +213 -0
  33. package/interfaces/associations/belongsTo/find.populate.js +145 -0
  34. package/interfaces/associations/belongsTo/findOne.populate.js +84 -0
  35. package/interfaces/associations/belongsTo/modifiers.js +275 -0
  36. package/interfaces/associations/belongsTo/multipleForeignKeys.js +70 -0
  37. package/interfaces/associations/belongsTo/update.nested.customPK.js +141 -0
  38. package/interfaces/associations/belongsTo/update.nested.js +174 -0
  39. package/interfaces/associations/deep.associations.test.js +437 -0
  40. package/interfaces/associations/find.associations.test.js +92 -0
  41. package/interfaces/associations/hasMany/add.js +106 -0
  42. package/interfaces/associations/hasMany/create.nested.customPK.js +113 -0
  43. package/interfaces/associations/hasMany/create.nested.js +96 -0
  44. package/interfaces/associations/hasMany/find.populate.customPK.js +75 -0
  45. package/interfaces/associations/hasMany/find.populate.js +219 -0
  46. package/interfaces/associations/hasMany/find.populate.where.js +148 -0
  47. package/interfaces/associations/hasMany/findOne.populate.js +88 -0
  48. package/interfaces/associations/hasMany/modifiers.js +560 -0
  49. package/interfaces/associations/hasMany/multipleForeignKeys.js +113 -0
  50. package/interfaces/associations/hasMany/remove.js +96 -0
  51. package/interfaces/associations/hasMany/update.nested.customPK.js +148 -0
  52. package/interfaces/associations/hasMany/update.nested.js +202 -0
  53. package/interfaces/associations/manyToMany/add.js +136 -0
  54. package/interfaces/associations/manyToMany/create.nested.customPK.js +109 -0
  55. package/interfaces/associations/manyToMany/create.nested.js +96 -0
  56. package/interfaces/associations/manyToMany/destroy.js +128 -0
  57. package/interfaces/associations/manyToMany/find.populate.js +109 -0
  58. package/interfaces/associations/manyToMany/find.populate.where.js +75 -0
  59. package/interfaces/associations/manyToMany/find.populate.withSchema.js +91 -0
  60. package/interfaces/associations/manyToMany/findOne.populate.js +86 -0
  61. package/interfaces/associations/manyToMany/modifiers.js +558 -0
  62. package/interfaces/associations/manyToMany/remove.js +103 -0
  63. package/interfaces/associations/manyToMany/update.js +105 -0
  64. package/interfaces/associations/manyToMany/update.nested.customPK.js +315 -0
  65. package/interfaces/associations/manyToMany/update.nested.js +355 -0
  66. package/interfaces/associations/manyToManyThrough/add.js +109 -0
  67. package/interfaces/associations/manyToManyThrough/create.nested.customPK.js +118 -0
  68. package/interfaces/associations/manyToManyThrough/create.nested.js +114 -0
  69. package/interfaces/associations/manyToManyThrough/find.populate.customPK.js +76 -0
  70. package/interfaces/associations/manyToManyThrough/find.populate.js +120 -0
  71. package/interfaces/associations/manyToManyThrough/find.populate.where.js +157 -0
  72. package/interfaces/associations/manyToManyThrough/findOne.populate.js +93 -0
  73. package/interfaces/associations/manyToManyThrough/modifiers.js +560 -0
  74. package/interfaces/associations/manyToManyThrough/multipleForeignKeys.js +118 -0
  75. package/interfaces/associations/manyToManyThrough/remove.js +98 -0
  76. package/interfaces/associations/manyToManyThrough/update.nested.customPK.js +150 -0
  77. package/interfaces/associations/manyToManyThrough/update.nested.js +202 -0
  78. package/interfaces/associations/oneToOne/create.js +41 -0
  79. package/interfaces/associations/oneToOne/create.nested.customPK.js +61 -0
  80. package/interfaces/associations/oneToOne/create.nested.js +52 -0
  81. package/interfaces/associations/oneToOne/dynamicFinder.js +68 -0
  82. package/interfaces/associations/oneToOne/find.populate.js +127 -0
  83. package/interfaces/associations/oneToOne/findOne.populate.js +83 -0
  84. package/interfaces/associations/oneToOne/modifiers.js +275 -0
  85. package/interfaces/associations/oneToOne/multipleForeignKeys.js +69 -0
  86. package/interfaces/associations/oneToOne/update.nested.customPK.js +141 -0
  87. package/interfaces/associations/oneToOne/update.nested.js +174 -0
  88. package/interfaces/associations/support/bootstrap.js +82 -0
  89. package/interfaces/associations/support/fixtures/belongsTo.child.customPK.fixture.js +25 -0
  90. package/interfaces/associations/support/fixtures/belongsTo.child.fixture.js +25 -0
  91. package/interfaces/associations/support/fixtures/belongsTo.parent.customPK.fixture.js +26 -0
  92. package/interfaces/associations/support/fixtures/belongsTo.parent.fixture.js +28 -0
  93. package/interfaces/associations/support/fixtures/crud.fixture.js +53 -0
  94. package/interfaces/associations/support/fixtures/deep.address.fixture.js +21 -0
  95. package/interfaces/associations/support/fixtures/deep.breakdown.fixture.js +23 -0
  96. package/interfaces/associations/support/fixtures/deep.company.fixture.js +29 -0
  97. package/interfaces/associations/support/fixtures/deep.country.fixture.js +25 -0
  98. package/interfaces/associations/support/fixtures/deep.departement.fixture.js +24 -0
  99. package/interfaces/associations/support/fixtures/deep.driver.fixture.js +32 -0
  100. package/interfaces/associations/support/fixtures/deep.ride.fixture.js +23 -0
  101. package/interfaces/associations/support/fixtures/deep.seller.fixture.js +33 -0
  102. package/interfaces/associations/support/fixtures/deep.taxi.fixture.js +36 -0
  103. package/interfaces/associations/support/fixtures/hasMany.child.fixture.js +33 -0
  104. package/interfaces/associations/support/fixtures/hasMany.customPK.fixture.js +22 -0
  105. package/interfaces/associations/support/fixtures/hasMany.parent.fixture.js +28 -0
  106. package/interfaces/associations/support/fixtures/hasManyThrough.child.customPK.fixture.js +32 -0
  107. package/interfaces/associations/support/fixtures/hasManyThrough.parent.customPK.fixture.js +23 -0
  108. package/interfaces/associations/support/fixtures/hasManyThrough.stadium.fixture.js +20 -0
  109. package/interfaces/associations/support/fixtures/hasManyThrough.team.fixture.js +35 -0
  110. package/interfaces/associations/support/fixtures/hasManyThrough.through.customPK.fixture.js +18 -0
  111. package/interfaces/associations/support/fixtures/hasManyThrough.venue.fixture.js +18 -0
  112. package/interfaces/associations/support/fixtures/manyToMany.driver.customPK.fixture.js +22 -0
  113. package/interfaces/associations/support/fixtures/manyToMany.driver.fixture.js +25 -0
  114. package/interfaces/associations/support/fixtures/manyToMany.driver.withSchema.fixture.js +25 -0
  115. package/interfaces/associations/support/fixtures/manyToMany.taxi.customPK.fixture.js +21 -0
  116. package/interfaces/associations/support/fixtures/manyToMany.taxi.fixture.js +30 -0
  117. package/interfaces/associations/support/fixtures/manyToMany.taxi.withSchema.fixture.js +24 -0
  118. package/interfaces/associations/support/fixtures/multipleAssociations.fixture.js +54 -0
  119. package/interfaces/associations/support/fixtures/multipleOneToOneAssociations.fixture.js +40 -0
  120. package/interfaces/associations/support/fixtures/multipleThroughAssociations.fixture.js +79 -0
  121. package/interfaces/associations/support/fixtures/oneToOne.customPK.fixture.js +47 -0
  122. package/interfaces/associations/support/fixtures/oneToOne.fixture.js +52 -0
  123. package/interfaces/associations/support/fixtures.js +41 -0
  124. package/interfaces/datastore/datastore.test.js +63 -0
  125. package/interfaces/migratable/definition.test.js +65 -0
  126. package/interfaces/migratable/migrate.alter.test.js +55 -0
  127. package/interfaces/migratable/migrate.create.test.js +120 -0
  128. package/interfaces/migratable/migrate.drop.test.js +47 -0
  129. package/interfaces/migratable/migrate.safe.test.js +25 -0
  130. package/interfaces/migratable/schema.test.js +117 -0
  131. package/interfaces/migratable/support/bootstrap.js +55 -0
  132. package/interfaces/migratable/support/bootstrapFn.js +54 -0
  133. package/interfaces/migratable/support/fixtures/alter.fixture.js +12 -0
  134. package/interfaces/migratable/support/fixtures/create.fixture.js +12 -0
  135. package/interfaces/migratable/support/fixtures/crud.fixture.js +53 -0
  136. package/interfaces/migratable/support/fixtures/custom.fixture.js +17 -0
  137. package/interfaces/migratable/support/fixtures/drop.fixture.js +12 -0
  138. package/interfaces/migratable/support/fixtures/safe.fixture.js +12 -0
  139. package/interfaces/migratable/support/fixtures/schema.fixture.js +23 -0
  140. package/interfaces/queryable/caseInsensitive.test.js +196 -0
  141. package/interfaces/queryable/count.test.js +51 -0
  142. package/interfaces/queryable/dynamicFinders.test.js +179 -0
  143. package/interfaces/queryable/findLike.test.js +34 -0
  144. package/interfaces/queryable/findOneLike.test.js +28 -0
  145. package/interfaces/queryable/modifiers/average.modifier.test.js +55 -0
  146. package/interfaces/queryable/modifiers/contains.modifier.test.js +82 -0
  147. package/interfaces/queryable/modifiers/endsWith.modifier.test.js +82 -0
  148. package/interfaces/queryable/modifiers/greaterThan.modifier.test.js +335 -0
  149. package/interfaces/queryable/modifiers/groupBy.modifier.test.js +123 -0
  150. package/interfaces/queryable/modifiers/in.modifier.test.js +76 -0
  151. package/interfaces/queryable/modifiers/lessThan.modifier.test.js +223 -0
  152. package/interfaces/queryable/modifiers/like.modifier.test.js +50 -0
  153. package/interfaces/queryable/modifiers/limit.modifier.test.js +60 -0
  154. package/interfaces/queryable/modifiers/max.modifier.test.js +68 -0
  155. package/interfaces/queryable/modifiers/min.modifier.test.js +68 -0
  156. package/interfaces/queryable/modifiers/not.modifier.test.js +80 -0
  157. package/interfaces/queryable/modifiers/notIn.modifier.test.js +69 -0
  158. package/interfaces/queryable/modifiers/or.modifier.test.js +142 -0
  159. package/interfaces/queryable/modifiers/select.modifier.test.js +118 -0
  160. package/interfaces/queryable/modifiers/skip.modifier.test.js +59 -0
  161. package/interfaces/queryable/modifiers/sort.modifier.test.js +160 -0
  162. package/interfaces/queryable/modifiers/startsWith.modifier.test.js +83 -0
  163. package/interfaces/queryable/modifiers/sum.modifier.test.js +68 -0
  164. package/interfaces/queryable/support/bootstrap.js +80 -0
  165. package/interfaces/queryable/support/fixtures/crud.fixture.js +54 -0
  166. package/interfaces/scalable/README.md +19 -0
  167. package/interfaces/scalable/crud.test.js +73 -0
  168. package/interfaces/scalable/queries.test.js +9 -0
  169. package/interfaces/scalable/support/crud.fixture.js +60 -0
  170. package/interfaces/semantic/create.test.js +110 -0
  171. package/interfaces/semantic/createEach.test.js +50 -0
  172. package/interfaces/semantic/destroy.js +147 -0
  173. package/interfaces/semantic/find.test.js +91 -0
  174. package/interfaces/semantic/findOne.test.js +60 -0
  175. package/interfaces/semantic/findOrCreate.test.js +91 -0
  176. package/interfaces/semantic/findOrCreateEach.test.js +75 -0
  177. package/interfaces/semantic/support/bootstrap.js +85 -0
  178. package/interfaces/semantic/support/fixtures/crud.fixture.js +66 -0
  179. package/interfaces/semantic/support/fixtures/validations.fixture.js +23 -0
  180. package/interfaces/semantic/types/array.type.js +28 -0
  181. package/interfaces/semantic/types/binary.type.js +34 -0
  182. package/interfaces/semantic/types/boolean.type.js +80 -0
  183. package/interfaces/semantic/types/date.type.js +53 -0
  184. package/interfaces/semantic/types/datetime.type.js +48 -0
  185. package/interfaces/semantic/types/float.type.js +40 -0
  186. package/interfaces/semantic/types/integer.type.js +40 -0
  187. package/interfaces/semantic/types/json.type.js +29 -0
  188. package/interfaces/semantic/types/string.type.js +40 -0
  189. package/interfaces/semantic/types/text.type.js +34 -0
  190. package/interfaces/semantic/types/time.type.js +52 -0
  191. package/interfaces/semantic/update.test.js +157 -0
  192. package/interfaces/sql/find.test.js +73 -0
  193. package/interfaces/sql/query.test.js +40 -0
  194. package/interfaces/sql/support/bootstrap.js +82 -0
  195. package/interfaces/sql/support/fixtures/crud.fixture.js +57 -0
  196. package/interfaces/transactable/commit.test.js +438 -0
  197. package/interfaces/transactable/crossAdapter.test.js +346 -0
  198. package/interfaces/transactable/deep.test.js +100 -0
  199. package/interfaces/transactable/rollback.test.js +221 -0
  200. package/interfaces/transactable/support/bootstrap.js +55 -0
  201. package/interfaces/transactable/support/bootstrapFn.js +51 -0
  202. package/interfaces/transactable/support/fixtures/customer.fixture.js +29 -0
  203. package/interfaces/transactable/support/fixtures/payment.fixture.js +24 -0
  204. package/interfaces/transactable/support/fixtures/receipt.fixture.js +20 -0
  205. package/interfaces/transactable/support/fixtures/store.fixture.js +22 -0
  206. package/interfaces/transactable/support/fixtures/storecustomer.fixture.js +14 -0
  207. package/lib/index.js +155 -0
  208. package/lib/utils.js +39 -0
  209. package/package.json +58 -4
  210. package/test/integration/README.md +26 -0
  211. package/test/integration/config/offshore-memory.js +8 -0
  212. package/test/integration/config/offshore-sql-mariadb.js +15 -0
  213. package/test/integration/config/offshore-sql-mysql.js +21 -0
  214. package/test/integration/config/offshore-sql-oracle.js +19 -0
  215. package/test/integration/config/offshore-sql-postgres.js +27 -0
  216. package/test/integration/config/offshore-sql-sqlite3.js +19 -0
  217. package/test/integration/runner.js +83 -0
  218. package/test/integration/runnerDispatcher.js +163 -0
  219. package/test/load/README.md +20 -0
  220. package/test/load/index.js +33 -0
  221. package/test/load/runner.js +160 -0
  222. package/test/load/support/bootstrap.js +69 -0
  223. package/test/load/support/fixtures/pet.js +8 -0
  224. package/test/load/support/fixtures/user.js +9 -0
@@ -0,0 +1,560 @@
1
+ var assert = require('assert'),
2
+ _ = require('lodash');
3
+
4
+ describe('Association Interface', function() {
5
+
6
+ describe('HasManyThrough Association', function() {
7
+ describe('Modifiers', function() {
8
+
9
+ /////////////////////////////////////////////////////
10
+ // TEST SETUP
11
+ ////////////////////////////////////////////////////
12
+
13
+ var names = ['modifier1', 'modifier2', 'modifier3', 'modifier4'];
14
+
15
+ before(function(done) {
16
+ // Check Stadium hasManytoMany Team through Venue
17
+ assert.strictEqual(Associations.Stadium.attributes.teams.collection, 'team');
18
+ assert.strictEqual(Associations.Team.attributes.stadiums.collection, 'stadium');
19
+ assert.strictEqual(Associations.Venue.attributes.stadium.model, 'stadium');
20
+ assert.strictEqual(Associations.Venue.attributes.team.model, 'team');
21
+
22
+ var Stadiums = [];
23
+
24
+ Stadiums.push({name: 'modifier1', budget: 10000, teams: []});
25
+ Stadiums.push({name: 'modifier2', budget: 25000, teams: []});
26
+ Stadiums.push({name: 'modifier3', budget: 32000, teams: []});
27
+ Stadiums.push({name: 'modifier4', budget: 25000, teams: []});
28
+
29
+ Stadiums[1].teams.push({followers: 150, mascot: 'aquaman', score: 20, league: 2 });
30
+ Stadiums[1].teams.push({followers: 350, mascot: 'batman', score: 10, league: 1});
31
+ Stadiums[1].teams.push({followers: 180, mascot: 'catwoman', score: 20, league: 2});
32
+ Stadiums[1].teams.push({followers: 180, mascot: 'daredevil', score: 10, league: 2});
33
+
34
+ Associations.Stadium.createEach(Stadiums, function(err) {
35
+ assert.ifError(err);
36
+ done();
37
+ });
38
+ });
39
+
40
+ /////////////////////////////////////////////////////
41
+ // TEST METHODS
42
+ ////////////////////////////////////////////////////
43
+
44
+ it('should sort with parent asc and child asc', function(done) {
45
+ Associations.Stadium.find({name: names, sort: 'name asc'})
46
+ .populate('teams', {sort: 'mascot asc'})
47
+ .exec(function(err, stadiums) {
48
+ assert.ifError(err);
49
+
50
+ assert(Array.isArray(stadiums));
51
+ assert.strictEqual(stadiums.length, 4);
52
+ assert.strictEqual(stadiums[0].name, 'modifier1');
53
+ assert.strictEqual(stadiums[1].name, 'modifier2');
54
+ assert.strictEqual(stadiums[2].name, 'modifier3');
55
+ assert.strictEqual(stadiums[3].name, 'modifier4');
56
+
57
+ assert(Array.isArray(stadiums[1].teams));
58
+ assert.strictEqual(stadiums[1].teams.length, 4);
59
+ assert.strictEqual(stadiums[1].teams[0].mascot, 'aquaman');
60
+ assert.strictEqual(stadiums[1].teams[1].mascot, 'batman');
61
+ assert.strictEqual(stadiums[1].teams[2].mascot, 'catwoman');
62
+ assert.strictEqual(stadiums[1].teams[3].mascot, 'daredevil');
63
+
64
+ done();
65
+ });
66
+ });
67
+
68
+ it('should sort with parent desc and child desc', function(done) {
69
+ Associations.Stadium.find({name: names, sort: 'name desc'})
70
+ .populate('teams', {sort: 'mascot desc'})
71
+ .exec(function(err, stadiums) {
72
+ assert.ifError(err);
73
+
74
+ assert(Array.isArray(stadiums));
75
+ assert.strictEqual(stadiums.length, 4);
76
+ assert.strictEqual(stadiums[3].name, 'modifier1');
77
+ assert.strictEqual(stadiums[2].name, 'modifier2');
78
+ assert.strictEqual(stadiums[1].name, 'modifier3');
79
+ assert.strictEqual(stadiums[0].name, 'modifier4');
80
+
81
+ assert(Array.isArray(stadiums[2].teams));
82
+ assert.strictEqual(stadiums[2].teams.length, 4);
83
+ assert.strictEqual(stadiums[2].teams[3].mascot, 'aquaman');
84
+ assert.strictEqual(stadiums[2].teams[2].mascot, 'batman');
85
+ assert.strictEqual(stadiums[2].teams[1].mascot, 'catwoman');
86
+ assert.strictEqual(stadiums[2].teams[0].mascot, 'daredevil');
87
+
88
+ done();
89
+ });
90
+ });
91
+
92
+ it('should sort with parent asc and child desc', function(done) {
93
+ Associations.Stadium.find({name: names, sort: 'name asc'})
94
+ .populate('teams', {sort: 'mascot desc'})
95
+ .exec(function(err, stadiums) {
96
+ assert.ifError(err);
97
+
98
+ assert(Array.isArray(stadiums));
99
+ assert.strictEqual(stadiums.length, 4);
100
+ assert.strictEqual(stadiums[0].name, 'modifier1');
101
+ assert.strictEqual(stadiums[1].name, 'modifier2');
102
+ assert.strictEqual(stadiums[2].name, 'modifier3');
103
+ assert.strictEqual(stadiums[3].name, 'modifier4');
104
+
105
+ assert(Array.isArray(stadiums[1].teams));
106
+ assert.strictEqual(stadiums[1].teams.length, 4);
107
+ assert.strictEqual(stadiums[1].teams[3].mascot, 'aquaman');
108
+ assert.strictEqual(stadiums[1].teams[2].mascot, 'batman');
109
+ assert.strictEqual(stadiums[1].teams[1].mascot, 'catwoman');
110
+ assert.strictEqual(stadiums[1].teams[0].mascot, 'daredevil');
111
+
112
+ done();
113
+ });
114
+ });
115
+
116
+ it('should sort with parent desc and child asc', function(done) {
117
+ Associations.Stadium.find({name: names, sort: 'name desc'})
118
+ .populate('teams', {sort: 'mascot asc'})
119
+ .exec(function(err, stadiums) {
120
+ assert.ifError(err);
121
+
122
+ assert(Array.isArray(stadiums));
123
+ assert.strictEqual(stadiums.length, 4);
124
+ assert.strictEqual(stadiums[3].name, 'modifier1');
125
+ assert.strictEqual(stadiums[2].name, 'modifier2');
126
+ assert.strictEqual(stadiums[1].name, 'modifier3');
127
+ assert.strictEqual(stadiums[0].name, 'modifier4');
128
+
129
+ assert(Array.isArray(stadiums[2].teams));
130
+ assert.strictEqual(stadiums[2].teams.length, 4);
131
+ assert.strictEqual(stadiums[2].teams[0].mascot, 'aquaman');
132
+ assert.strictEqual(stadiums[2].teams[1].mascot, 'batman');
133
+ assert.strictEqual(stadiums[2].teams[2].mascot, 'catwoman');
134
+ assert.strictEqual(stadiums[2].teams[3].mascot, 'daredevil');
135
+
136
+ done();
137
+ });
138
+ });
139
+
140
+ it('should sort skip limit with parent asc and child asc', function(done) {
141
+ Associations.Stadium.find({name: names, sort: 'name asc'})
142
+ .populate('teams', {sort: 'mascot asc', skip: 1, limit: 2})
143
+ .exec(function(err, stadiums) {
144
+ assert.ifError(err);
145
+
146
+ assert(Array.isArray(stadiums));
147
+ assert.strictEqual(stadiums.length, 4);
148
+ assert.strictEqual(stadiums[0].name, 'modifier1');
149
+ assert.strictEqual(stadiums[1].name, 'modifier2');
150
+ assert.strictEqual(stadiums[2].name, 'modifier3');
151
+ assert.strictEqual(stadiums[3].name, 'modifier4');
152
+
153
+ assert(Array.isArray(stadiums[1].teams));
154
+ assert.strictEqual(stadiums[1].teams.length, 2);
155
+ assert.strictEqual(stadiums[1].teams[0].mascot, 'batman');
156
+ assert.strictEqual(stadiums[1].teams[1].mascot, 'catwoman');
157
+
158
+ done();
159
+ });
160
+ });
161
+
162
+ it('should sort skip limit with parent desc and child desc', function(done) {
163
+ Associations.Stadium.find({name: names, sort: 'name desc'})
164
+ .populate('teams', {sort: 'mascot desc', skip: 1, limit: 2})
165
+ .exec(function(err, stadiums) {
166
+ assert.ifError(err);
167
+
168
+ assert(Array.isArray(stadiums));
169
+ assert.strictEqual(stadiums.length, 4);
170
+ assert.strictEqual(stadiums[3].name, 'modifier1');
171
+ assert.strictEqual(stadiums[2].name, 'modifier2');
172
+ assert.strictEqual(stadiums[1].name, 'modifier3');
173
+ assert.strictEqual(stadiums[0].name, 'modifier4');
174
+
175
+ assert(Array.isArray(stadiums[2].teams));
176
+ assert.strictEqual(stadiums[2].teams.length, 2);
177
+ assert.strictEqual(stadiums[2].teams[1].mascot, 'batman');
178
+ assert.strictEqual(stadiums[2].teams[0].mascot, 'catwoman');
179
+
180
+ done();
181
+ });
182
+ });
183
+
184
+ it('should sort skip limit with parent asc and child desc', function(done) {
185
+ Associations.Stadium.find({name: names, sort: 'name asc'})
186
+ .populate('teams', {sort: 'mascot desc', skip: 1, limit: 2})
187
+ .exec(function(err, stadiums) {
188
+ assert.ifError(err);
189
+
190
+ assert(Array.isArray(stadiums));
191
+ assert.strictEqual(stadiums.length, 4);
192
+ assert.strictEqual(stadiums[0].name, 'modifier1');
193
+ assert.strictEqual(stadiums[1].name, 'modifier2');
194
+ assert.strictEqual(stadiums[2].name, 'modifier3');
195
+ assert.strictEqual(stadiums[3].name, 'modifier4');
196
+
197
+ assert(Array.isArray(stadiums[1].teams));
198
+ assert.strictEqual(stadiums[1].teams.length, 2);
199
+ assert.strictEqual(stadiums[1].teams[1].mascot, 'batman');
200
+ assert.strictEqual(stadiums[1].teams[0].mascot, 'catwoman');
201
+
202
+ done();
203
+ });
204
+ });
205
+
206
+ it('should sort skip limit with parent desc and child asc', function(done) {
207
+ Associations.Stadium.find({name: names, sort: 'name desc'})
208
+ .populate('teams', {sort: 'mascot asc', skip: 1, limit: 2})
209
+ .exec(function(err, stadiums) {
210
+ assert.ifError(err);
211
+
212
+ assert(Array.isArray(stadiums));
213
+ assert.strictEqual(stadiums.length, 4);
214
+ assert.strictEqual(stadiums[3].name, 'modifier1');
215
+ assert.strictEqual(stadiums[2].name, 'modifier2');
216
+ assert.strictEqual(stadiums[1].name, 'modifier3');
217
+ assert.strictEqual(stadiums[0].name, 'modifier4');
218
+
219
+ assert(Array.isArray(stadiums[2].teams));
220
+ assert.strictEqual(stadiums[2].teams.length, 2);
221
+ assert.strictEqual(stadiums[2].teams[0].mascot, 'batman');
222
+ assert.strictEqual(stadiums[2].teams[1].mascot, 'catwoman');
223
+
224
+ done();
225
+ });
226
+ });
227
+
228
+ it('should return the correct average', function(done) {
229
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
230
+ .populate('teams', {average: ['followers'] })
231
+ .exec(function(err, Stadiums) {
232
+ assert.ifError(err);
233
+ assert(Array.isArray(Stadiums));
234
+ assert.strictEqual(Stadiums.length, 1);
235
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
236
+ assert(Array.isArray(Stadiums[0].teams));
237
+ assert.strictEqual(Stadiums[0].teams.length, 1);
238
+ assert.strictEqual(Stadiums[0].teams[0].followers, 215);
239
+ done();
240
+ });
241
+ });
242
+
243
+ it('should return the correct min', function(done) {
244
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
245
+ .populate('teams', {min: ['followers'] })
246
+ .exec(function(err, Stadiums) {
247
+ assert.ifError(err);
248
+ assert(Array.isArray(Stadiums));
249
+ assert.strictEqual(Stadiums.length, 1);
250
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
251
+ assert(Array.isArray(Stadiums[0].teams));
252
+ assert.strictEqual(Stadiums[0].teams.length, 1);
253
+ assert.strictEqual(Stadiums[0].teams[0].followers, 150);
254
+ done();
255
+ });
256
+ });
257
+
258
+ it('should return the correct max', function(done) {
259
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
260
+ .populate('teams', {max: ['followers'] })
261
+ .exec(function(err, Stadiums) {
262
+ assert.ifError(err);
263
+ assert(Array.isArray(Stadiums));
264
+ assert.strictEqual(Stadiums.length, 1);
265
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
266
+ assert(Array.isArray(Stadiums[0].teams));
267
+ assert.strictEqual(Stadiums[0].teams.length, 1);
268
+ assert.strictEqual(Stadiums[0].teams[0].followers, 350);
269
+ done();
270
+ });
271
+ });
272
+
273
+ it('should return the correct sum', function(done) {
274
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
275
+ .populate('teams', {sum: ['followers'] })
276
+ .exec(function(err, Stadiums) {
277
+ assert.ifError(err);
278
+ assert(Array.isArray(Stadiums));
279
+ assert.strictEqual(Stadiums.length, 1);
280
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
281
+ assert(Array.isArray(Stadiums[0].teams));
282
+ assert.strictEqual(Stadiums[0].teams.length, 1);
283
+ assert.strictEqual(Stadiums[0].teams[0].followers, 860);
284
+ done();
285
+ });
286
+ });
287
+
288
+ it('should return records with contains modifier', function(done) {
289
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
290
+ .populate('teams', {mascot: {contains: 'at'}, sort: 'mascot asc' })
291
+ .exec(function(err, Stadiums) {
292
+ assert.ifError(err);
293
+ assert(Array.isArray(Stadiums));
294
+ assert.strictEqual(Stadiums.length, 1);
295
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
296
+ assert(Array.isArray(Stadiums[0].teams));
297
+ assert.strictEqual(Stadiums[0].teams.length, 2);
298
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'batman');
299
+ assert.strictEqual(Stadiums[0].teams[1].mascot, 'catwoman');
300
+ done();
301
+ });
302
+ });
303
+
304
+ it('should return records with endsWith modifier', function(done) {
305
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
306
+ .populate('teams', {mascot: {endsWith: 'man'}, sort: 'mascot asc' })
307
+ .exec(function(err, Stadiums) {
308
+ assert.ifError(err);
309
+ assert(Array.isArray(Stadiums));
310
+ assert.strictEqual(Stadiums.length, 1);
311
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
312
+ assert(Array.isArray(Stadiums[0].teams));
313
+ assert.strictEqual(Stadiums[0].teams.length, 3);
314
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'aquaman');
315
+ assert.strictEqual(Stadiums[0].teams[1].mascot, 'batman');
316
+ assert.strictEqual(Stadiums[0].teams[2].mascot, 'catwoman');
317
+ done();
318
+ });
319
+ });
320
+
321
+ it('should return records with greaterThan modifier', function(done) {
322
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
323
+ .populate('teams', {followers: {greaterThan: 160}, sort: 'followers asc' })
324
+ .exec(function(err, Stadiums) {
325
+ assert.ifError(err);
326
+ assert(Array.isArray(Stadiums));
327
+ assert.strictEqual(Stadiums.length, 1);
328
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
329
+ assert(Array.isArray(Stadiums[0].teams));
330
+ assert.strictEqual(Stadiums[0].teams.length, 3);
331
+ assert.strictEqual(Stadiums[0].teams[0].followers, 180);
332
+ assert.strictEqual(Stadiums[0].teams[1].followers, 180);
333
+ assert.strictEqual(Stadiums[0].teams[2].followers, 350);
334
+ done();
335
+ });
336
+ });
337
+
338
+ it('should return records with multiple sort array notation', function(done) {
339
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
340
+ .populate('teams', {sort: ['followers asc', 'mascot desc'] })
341
+ .exec(function(err, Stadiums) {
342
+ assert.ifError(err);
343
+ assert(Array.isArray(Stadiums));
344
+ assert.strictEqual(Stadiums.length, 1);
345
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
346
+ assert(Array.isArray(Stadiums[0].teams));
347
+ assert.strictEqual(Stadiums[0].teams.length, 4);
348
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'aquaman');
349
+ assert.strictEqual(Stadiums[0].teams[1].mascot, 'daredevil');
350
+ assert.strictEqual(Stadiums[0].teams[2].mascot, 'catwoman');
351
+ assert.strictEqual(Stadiums[0].teams[3].mascot, 'batman');
352
+ done();
353
+ });
354
+ });
355
+
356
+ it('should return records with in modifier', function(done) {
357
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
358
+ .populate('teams', {mascot: ['aquaman', 'daredevil'], sort: 'mascot desc'})
359
+ .exec(function(err, Stadiums) {
360
+ assert.ifError(err);
361
+ assert(Array.isArray(Stadiums));
362
+ assert.strictEqual(Stadiums.length, 1);
363
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
364
+ assert(Array.isArray(Stadiums[0].teams));
365
+ assert.strictEqual(Stadiums[0].teams.length, 2);
366
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'daredevil');
367
+ assert.strictEqual(Stadiums[0].teams[1].mascot, 'aquaman');
368
+ done();
369
+ });
370
+ });
371
+
372
+ it('should return records with lessThan modifier', function(done) {
373
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
374
+ .populate('teams', {followers: {lessThan: 300}, sort: 'mascot desc' })
375
+ .exec(function(err, Stadiums) {
376
+ assert.ifError(err);
377
+ assert(Array.isArray(Stadiums));
378
+ assert.strictEqual(Stadiums.length, 1);
379
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
380
+ assert(Array.isArray(Stadiums[0].teams));
381
+ assert.strictEqual(Stadiums[0].teams.length, 3);
382
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'daredevil');
383
+ assert.strictEqual(Stadiums[0].teams[1].mascot, 'catwoman');
384
+ assert.strictEqual(Stadiums[0].teams[2].mascot, 'aquaman');
385
+ done();
386
+ });
387
+ });
388
+
389
+ it('should return records with like modifier', function(done) {
390
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
391
+ .populate('teams', {mascot: {like: '%at%man'}, sort: 'mascot desc' })
392
+ .exec(function(err, Stadiums) {
393
+ assert.ifError(err);
394
+ assert(Array.isArray(Stadiums));
395
+ assert.strictEqual(Stadiums.length, 1);
396
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
397
+ assert(Array.isArray(Stadiums[0].teams));
398
+ assert.strictEqual(Stadiums[0].teams.length, 2);
399
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'catwoman');
400
+ assert.strictEqual(Stadiums[0].teams[1].mascot, 'batman');
401
+ done();
402
+ });
403
+ });
404
+
405
+ it('should return records with limit modifier', function(done) {
406
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
407
+ .populate('teams', {followers: 180, limit: 1, sort: 'mascot desc'})
408
+ .exec(function(err, Stadiums) {
409
+ assert.ifError(err);
410
+ assert(Array.isArray(Stadiums));
411
+ assert.strictEqual(Stadiums.length, 1);
412
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
413
+ assert(Array.isArray(Stadiums[0].teams));
414
+ assert.strictEqual(Stadiums[0].teams.length, 1);
415
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'daredevil');
416
+ done();
417
+ });
418
+ });
419
+
420
+ it('should return records with not modifier', function(done) {
421
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
422
+ .populate('teams', {followers: {'!': 180}, sort: 'mascot desc'})
423
+ .exec(function(err, Stadiums) {
424
+ assert.ifError(err);
425
+ assert(Array.isArray(Stadiums));
426
+ assert.strictEqual(Stadiums.length, 1);
427
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
428
+ assert(Array.isArray(Stadiums[0].teams));
429
+ assert.strictEqual(Stadiums[0].teams.length, 2);
430
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'batman');
431
+ assert.strictEqual(Stadiums[0].teams[1].mascot, 'aquaman');
432
+ done();
433
+ });
434
+ });
435
+
436
+ it('should return records with notIn modifier', function(done) {
437
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
438
+ .populate('teams', {mascot: { '!': ['aquaman', 'daredevil']}, sort: 'mascot desc'})
439
+ .exec(function(err, Stadiums) {
440
+ assert.ifError(err);
441
+ assert(Array.isArray(Stadiums));
442
+ assert.strictEqual(Stadiums.length, 1);
443
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
444
+ assert(Array.isArray(Stadiums[0].teams));
445
+ assert.strictEqual(Stadiums[0].teams.length, 2);
446
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'catwoman');
447
+ assert.strictEqual(Stadiums[0].teams[1].mascot, 'batman');
448
+ done();
449
+ });
450
+ });
451
+
452
+ it('should return records with or modifier', function(done) {
453
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
454
+ .populate('teams', {where: { or: [{mascot:'batman'}, {followers: 150}]}, sort: 'mascot desc'})
455
+ .exec(function(err, Stadiums) {
456
+ assert.ifError(err);
457
+ assert(Array.isArray(Stadiums));
458
+ assert.strictEqual(Stadiums.length, 1);
459
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
460
+ assert(Array.isArray(Stadiums[0].teams));
461
+ assert.strictEqual(Stadiums[0].teams.length, 2);
462
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'batman');
463
+ assert.strictEqual(Stadiums[0].teams[1].mascot, 'aquaman');
464
+ done();
465
+ });
466
+ });
467
+
468
+ it('should return records with select modifier', function(done) {
469
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
470
+ .populate('teams', {followers: 180, select: ['mascot'], sort: 'mascot desc'})
471
+ .exec(function(err, Stadiums) {
472
+ assert.ifError(err);
473
+ assert(Array.isArray(Stadiums));
474
+ assert.strictEqual(Stadiums.length, 1);
475
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
476
+ assert(Array.isArray(Stadiums[0].teams));
477
+ assert.strictEqual(Stadiums[0].teams.length, 2);
478
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'daredevil');
479
+ assert.strictEqual(Stadiums[0].teams[0].followers, undefined);
480
+ assert.strictEqual(Stadiums[0].teams[1].mascot, 'catwoman');
481
+ assert.strictEqual(Stadiums[0].teams[1].followers, undefined);
482
+
483
+ done();
484
+ });
485
+ });
486
+
487
+ it('should return records with skip modifier', function(done) {
488
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
489
+ .populate('teams', {followers: 180, skip: 1, sort: 'mascot desc'})
490
+ .exec(function(err, Stadiums) {
491
+ assert.ifError(err);
492
+ assert(Array.isArray(Stadiums));
493
+ assert.strictEqual(Stadiums.length, 1);
494
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
495
+ assert(Array.isArray(Stadiums[0].teams));
496
+ assert.strictEqual(Stadiums[0].teams.length, 1);
497
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'catwoman');
498
+ done();
499
+ });
500
+ });
501
+
502
+ it('should return records with startsWith modifier', function(done) {
503
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
504
+ .populate('teams', {mascot: {startsWith: 'bat'}})
505
+ .exec(function(err, Stadiums) {
506
+ assert.ifError(err);
507
+ assert(Array.isArray(Stadiums));
508
+ assert.strictEqual(Stadiums.length, 1);
509
+ assert.strictEqual(Stadiums[0].name, 'modifier2');
510
+ assert(Array.isArray(Stadiums[0].teams));
511
+ assert.strictEqual(Stadiums[0].teams.length, 1);
512
+ assert.strictEqual(Stadiums[0].teams[0].mascot, 'batman');
513
+ done();
514
+ });
515
+ });
516
+
517
+ it('should return the correct records with skip, limit and sort', function(done) {
518
+ Associations.Stadium.find({ where: { name: {startsWith: 'modifier'}}, limit: 2, skip: 1, sort: {budget: 1, name: 0} })
519
+ .populate('teams', { limit: 2, skip: 1, sort: {followers: 1, mascot: 0} })
520
+ .exec(function(err, Stadiums) {
521
+ assert.ifError(err);
522
+ assert(Array.isArray(Stadiums));
523
+ assert.strictEqual(Stadiums.length, 2);
524
+ assert.strictEqual(Stadiums[0].name, 'modifier4');
525
+ assert.strictEqual(Stadiums[1].name, 'modifier2');
526
+ assert(Array.isArray(Stadiums[1].teams));
527
+ assert.strictEqual(Stadiums[1].teams.length, 2);
528
+ assert.strictEqual(Stadiums[1].teams[0].mascot, 'daredevil');
529
+ assert.strictEqual(Stadiums[1].teams[1].mascot, 'catwoman');
530
+ done();
531
+ });
532
+ });
533
+
534
+ it('should return the correct sum with groupBy', function(done) {
535
+ Associations.Stadium.find({ where: { name: 'modifier2' }})
536
+ .populate('teams', {sum: ['followers'], groupBy: ['score', 'league'], sort: ['score asc', 'league desc'] })
537
+ .exec(function(err, stadiums) {
538
+ assert.ifError(err);
539
+ assert(Array.isArray(stadiums));
540
+ assert.strictEqual(stadiums.length, 1);
541
+ assert.strictEqual(stadiums[0].name, 'modifier2');
542
+ assert(Array.isArray(stadiums[0].teams));
543
+ assert.strictEqual(stadiums[0].teams.length, 3);
544
+ assert.strictEqual(stadiums[0].teams[0].followers, 180);
545
+ assert.strictEqual(stadiums[0].teams[0].score, 10);
546
+ assert.strictEqual(stadiums[0].teams[0].league, 2);
547
+ assert.strictEqual(stadiums[0].teams[1].followers, 350);
548
+ assert.strictEqual(stadiums[0].teams[1].score, 10);
549
+ assert.strictEqual(stadiums[0].teams[1].league, 1);
550
+ assert.strictEqual(stadiums[0].teams[2].followers, 330);
551
+ assert.strictEqual(stadiums[0].teams[2].score, 20);
552
+ assert.strictEqual(stadiums[0].teams[2].league, 2);
553
+ done();
554
+ });
555
+ });
556
+
557
+
558
+ });
559
+ });
560
+ });
@@ -0,0 +1,118 @@
1
+ var assert = require('assert'),
2
+ _ = require('lodash');
3
+
4
+ describe('Association Interface', function() {
5
+
6
+ describe('Multiple Many to Many Through Associations', function() {
7
+ describe('association .add()', function() {
8
+
9
+ describe('with an object', function() {
10
+
11
+ /////////////////////////////////////////////////////
12
+ // TEST SETUP
13
+ ////////////////////////////////////////////////////
14
+
15
+ var stadiumRecord;
16
+
17
+ before(function(done) {
18
+ // Check Stadium hasManytoMany Team through Venue
19
+ assert.strictEqual(Associations.Stadiummany.attributes.teams.collection, 'teammany');
20
+ assert.strictEqual(Associations.Teammany.attributes.stadiums.collection, 'stadiummany');
21
+ assert.strictEqual(Associations.Venuemany.attributes.stadium.model, 'stadiummany');
22
+ assert.strictEqual(Associations.Venuemany.attributes.team.model, 'teammany');
23
+
24
+ assert.strictEqual(Associations.Stadiummany.attributes.nativeTeams.collection, 'teammany');
25
+ assert.strictEqual(Associations.Teammany.attributes.nativeStadiums.collection, 'stadiummany');
26
+ assert.strictEqual(Associations.Venuemany.attributes.nativeStadium.model, 'stadiummany');
27
+ assert.strictEqual(Associations.Venuemany.attributes.nativeTeam.model, 'teammany');
28
+
29
+ Associations.Stadiummany.create({ name: 'manyAssociations through uno hasMany add' }, function(err, model) {
30
+ assert.ifError(err);
31
+
32
+ stadiumRecord = model;
33
+ Associations.Teammany.create({ name: 'team many 1', stadiums: model.id }, done);
34
+ });
35
+ });
36
+
37
+ /////////////////////////////////////////////////////
38
+ // TEST METHODS
39
+ ////////////////////////////////////////////////////
40
+
41
+ it('should create a new team and nativeTeam through association', function(done) {
42
+ stadiumRecord.teams.add({ name: 'team many 2' });
43
+ stadiumRecord.nativeTeams.add({ name: 'nativeTeam many 1' });
44
+ stadiumRecord.save(function(err) {
45
+ assert.ifError(err);
46
+
47
+ // Look up the stadium again to be sure the team was added
48
+ Associations.Stadiummany.findOne(stadiumRecord.id)
49
+ .populate('teams', {sort: 'id asc'})
50
+ .populate('nativeTeams', {sort: 'id asc'})
51
+ .exec(function(err, stadium) {
52
+ assert.ifError(err);
53
+ assert.strictEqual(stadium.teams.length, 2);
54
+ assert.strictEqual(stadium.teams[0].name, 'team many 1');
55
+ assert.strictEqual(stadium.teams[1].name, 'team many 2');
56
+
57
+ assert.strictEqual(stadium.nativeTeams.length, 1, 'Expected stadium to have 1 nativeTeam, but actually it has '+stadium.nativeTeams.length+', see? \n'+require('util').inspect(stadium,false,null));
58
+ assert.strictEqual(stadium.nativeTeams[0].name, 'nativeTeam many 1');
59
+ done();
60
+ });
61
+ });
62
+ });
63
+ });
64
+
65
+ describe('with an id', function() {
66
+
67
+ /////////////////////////////////////////////////////
68
+ // TEST SETUP
69
+ ////////////////////////////////////////////////////
70
+
71
+ var stadiumRecord, teamRecord;
72
+
73
+ before(function(done) {
74
+
75
+ var records = [
76
+ { name: 'manyAssociations through hasMany 1' },
77
+ { name: 'manyAssociations through hasMany 2' }
78
+ ];
79
+
80
+ Associations.Stadiummany.createEach(records, function(err, models) {
81
+ assert.ifError(err);
82
+
83
+ stadiumRecord = models[0];
84
+ Associations.Teammany.create({ name: 'team many 3', stadiums: models[1].id }, function(err, teamModel) {
85
+ assert.ifError(err);
86
+
87
+ teamRecord = teamModel;
88
+ done();
89
+ });
90
+ });
91
+ });
92
+
93
+ /////////////////////////////////////////////////////
94
+ // TEST METHODS
95
+ ////////////////////////////////////////////////////
96
+
97
+ it('should link the team to another association', function(done) {
98
+ stadiumRecord.teams.add(teamRecord.id);
99
+ stadiumRecord.save(function(err) {
100
+ assert.ifError(err);
101
+
102
+ // Look up the stadium again to be sure the team was added
103
+ Associations.Stadiummany.findOne(stadiumRecord.id)
104
+ .populate('teams')
105
+ .exec(function(err, data) {
106
+ assert.ifError(err);
107
+
108
+ assert.strictEqual(data.teams.length, 1);
109
+ assert.strictEqual(data.teams[0].name, 'team many 3');
110
+ done();
111
+ });
112
+ });
113
+ });
114
+ });
115
+
116
+ });
117
+ });
118
+ });