@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,84 @@
1
+ var _ = require('lodash'),
2
+ assert = require('assert');
3
+
4
+ describe('Association Interface', function() {
5
+
6
+ describe('Belongs To Association', function() {
7
+
8
+ /////////////////////////////////////////////////////
9
+ // TEST SETUP
10
+ ////////////////////////////////////////////////////
11
+
12
+ var customerRecord, paymentRecord;
13
+
14
+ before(function(done) {
15
+ // Check Payment belongsTo Customer
16
+ assert.strictEqual(Associations.Payment.attributes.a_customer.model, 'customer');
17
+ assert.strictEqual(Associations.Customer.attributes.payments.collection, 'payment');
18
+
19
+ Associations.Customer.create({ name: 'foobar' }, function(err, customer) {
20
+ assert.ifError(err);
21
+
22
+ Associations.Payment.create({ amount: 1, a_customer: customer.id }, function(err, payment) {
23
+ assert.ifError(err);
24
+
25
+ // Cache customer and payment
26
+ customerRecord = customer;
27
+ paymentRecord = payment;
28
+
29
+ done();
30
+ });
31
+ });
32
+ });
33
+
34
+ describe('.findOne()', function() {
35
+
36
+ /////////////////////////////////////////////////////
37
+ // TEST METHODS
38
+ ////////////////////////////////////////////////////
39
+
40
+ it('should return customer when the populate criteria is added', function(done) {
41
+ Associations.Payment.findOne({ id: paymentRecord.id })
42
+ .populate('a_customer')
43
+ .exec(function(err, payment) {
44
+ assert.ifError(err);
45
+
46
+ assert(payment.a_customer);
47
+ assert.equal(payment.a_customer.id, customerRecord.id);
48
+ assert.equal(payment.a_customer.name, 'foobar');
49
+
50
+ done();
51
+ });
52
+ });
53
+
54
+ it('should not return a customer object when the populate is not added', function(done) {
55
+ Associations.Payment.findOne({ id: paymentRecord.id })
56
+ .exec(function(err, payment) {
57
+ assert.ifError(err);
58
+
59
+ assert(!_.isPlainObject(payment.a_customer));
60
+
61
+ done();
62
+ });
63
+ });
64
+
65
+ it('should call toJSON on associated record', function(done) {
66
+ Associations.Payment.findOne({ id: paymentRecord.id })
67
+ .populate('a_customer')
68
+ .exec(function(err, payment) {
69
+ assert.ifError(err);
70
+
71
+ var obj = payment.toJSON();
72
+
73
+ assert(!obj.type);
74
+ assert(obj.a_customer);
75
+ assert(obj.a_customer.createdAt);
76
+ assert(!obj.a_customer.name);
77
+
78
+ done();
79
+ });
80
+ });
81
+ });
82
+
83
+ });
84
+ });
@@ -0,0 +1,275 @@
1
+ var assert = require('assert'),
2
+ _ = require('lodash');
3
+
4
+ describe('Association Interface', function() {
5
+
6
+ describe('BelongsTo Association', function() {
7
+ describe('Modifiers', function() {
8
+
9
+ /////////////////////////////////////////////////////
10
+ // TEST SETUP
11
+ ////////////////////////////////////////////////////
12
+
13
+ before(function(done) {
14
+ // Check Payment belongsTo Customer
15
+ assert.strictEqual(Associations.Payment.attributes.a_customer.model, 'customer');
16
+ assert.strictEqual(Associations.Customer.attributes.payments.collection, 'payment');
17
+
18
+ var Payments = [];
19
+
20
+ Payments.push({type: 'modifier1', amount: 10000});
21
+ Payments.push({type: 'modifier2', amount: 25000, a_customer: {capital: 150, name: 'batman'}});
22
+ Payments.push({type: 'modifier3', amount: 32000});
23
+ Payments.push({type: 'modifier4', amount: 25000});
24
+
25
+ Associations.Payment.createEach(Payments, function(err) {
26
+ assert.ifError(err);
27
+ done();
28
+ });
29
+ });
30
+
31
+ /////////////////////////////////////////////////////
32
+ // TEST METHODS
33
+ ////////////////////////////////////////////////////
34
+
35
+ it('should return the correct average', function(done) {
36
+ Associations.Payment.find({ where: { type: 'modifier2' }})
37
+ .populate('a_customer', {average: ['capital'] })
38
+ .exec(function(err, payments) {
39
+ assert.ifError(err);
40
+ assert(Array.isArray(payments));
41
+ assert.strictEqual(payments.length, 1);
42
+ assert.strictEqual(payments[0].type, 'modifier2');
43
+ assert(_.isObject(payments[0].a_customer));
44
+ assert.strictEqual(payments[0].a_customer.capital, 150);
45
+ done();
46
+ });
47
+ });
48
+
49
+ it('should return the correct min', function(done) {
50
+ Associations.Payment.find({ where: { type: 'modifier2' }})
51
+ .populate('a_customer', {min: ['capital'] })
52
+ .exec(function(err, payments) {
53
+ assert.ifError(err);
54
+ assert(Array.isArray(payments));
55
+ assert.strictEqual(payments.length, 1);
56
+ assert.strictEqual(payments[0].type, 'modifier2');
57
+ assert(_.isObject(payments[0].a_customer));
58
+ assert.strictEqual(payments[0].a_customer.capital, 150);
59
+ done();
60
+ });
61
+ });
62
+
63
+ it('should return the correct max', function(done) {
64
+ Associations.Payment.find({ where: { type: 'modifier2' }})
65
+ .populate('a_customer', {max: ['capital'] })
66
+ .exec(function(err, payments) {
67
+ assert.ifError(err);
68
+ assert(Array.isArray(payments));
69
+ assert.strictEqual(payments.length, 1);
70
+ assert.strictEqual(payments[0].type, 'modifier2');
71
+ assert(_.isObject(payments[0].a_customer));
72
+ assert.strictEqual(payments[0].a_customer.capital, 150);
73
+ done();
74
+ });
75
+ });
76
+
77
+ it('should return the correct sum', function(done) {
78
+ Associations.Payment.find({ where: { type: 'modifier2' }})
79
+ .populate('a_customer', {sum: ['capital'] })
80
+ .exec(function(err, payments) {
81
+ assert.ifError(err);
82
+ assert(Array.isArray(payments));
83
+ assert.strictEqual(payments.length, 1);
84
+ assert.strictEqual(payments[0].type, 'modifier2');
85
+ assert(_.isObject(payments[0].a_customer));
86
+ assert.strictEqual(payments[0].a_customer.capital, 150);
87
+ done();
88
+ });
89
+ });
90
+
91
+ it('should return records with contains modifier', function(done) {
92
+ Associations.Payment.find({ where: { type: 'modifier2' }})
93
+ .populate('a_customer', {name: {contains: 'at'}})
94
+ .exec(function(err, payments) {
95
+ assert.ifError(err);
96
+ assert(Array.isArray(payments));
97
+ assert.strictEqual(payments.length, 1);
98
+ assert.strictEqual(payments[0].type, 'modifier2');
99
+ assert(_.isObject(payments[0].a_customer));
100
+ assert.strictEqual(payments[0].a_customer.name, 'batman');
101
+ done();
102
+ });
103
+ });
104
+
105
+ it('should return records with endsWith modifier', function(done) {
106
+ Associations.Payment.find({ where: { type: 'modifier2' }})
107
+ .populate('a_customer', {name: {endsWith: 'man'}})
108
+ .exec(function(err, payments) {
109
+ assert.ifError(err);
110
+ assert(Array.isArray(payments));
111
+ assert.strictEqual(payments.length, 1);
112
+ assert.strictEqual(payments[0].type, 'modifier2');
113
+ assert(_.isObject(payments[0].a_customer));
114
+ assert.strictEqual(payments[0].a_customer.name, 'batman');
115
+ done();
116
+ });
117
+ });
118
+
119
+ it('should return records with greaterThan modifier', function(done) {
120
+ Associations.Payment.find({ where: { type: 'modifier2' }})
121
+ .populate('a_customer', {capital: {greaterThan: 120}})
122
+ .exec(function(err, payments) {
123
+ assert.ifError(err);
124
+ assert(Array.isArray(payments));
125
+ assert.strictEqual(payments.length, 1);
126
+ assert.strictEqual(payments[0].type, 'modifier2');
127
+ assert(_.isObject(payments[0].a_customer));
128
+ assert.strictEqual(payments[0].a_customer.capital, 150);
129
+ done();
130
+ });
131
+ });
132
+
133
+ it('should return records with in modifier', function(done) {
134
+ Associations.Payment.find({ where: { type: 'modifier2' }})
135
+ .populate('a_customer', {name: ['batman', 'daredevil']})
136
+ .exec(function(err, payments) {
137
+ assert.ifError(err);
138
+ assert(Array.isArray(payments));
139
+ assert.strictEqual(payments.length, 1);
140
+ assert.strictEqual(payments[0].type, 'modifier2');
141
+ assert(_.isObject(payments[0].a_customer));
142
+ assert.strictEqual(payments[0].a_customer.name, 'batman');
143
+ done();
144
+ });
145
+ });
146
+
147
+ it('should return records with lessThan modifier', function(done) {
148
+ Associations.Payment.find({ where: { type: 'modifier2' }})
149
+ .populate('a_customer', {capital: {lessThan: 300}})
150
+ .exec(function(err, payments) {
151
+ assert.ifError(err);
152
+ assert(Array.isArray(payments));
153
+ assert.strictEqual(payments.length, 1);
154
+ assert.strictEqual(payments[0].type, 'modifier2');
155
+ assert(_.isObject(payments[0].a_customer));
156
+ assert.strictEqual(payments[0].a_customer.name, 'batman');
157
+ done();
158
+ });
159
+ });
160
+
161
+ it('should return records with like modifier', function(done) {
162
+ Associations.Payment.find({ where: { type: 'modifier2' }})
163
+ .populate('a_customer', {name: {like: '%at%man'}})
164
+ .exec(function(err, payments) {
165
+ assert.ifError(err);
166
+ assert(Array.isArray(payments));
167
+ assert.strictEqual(payments.length, 1);
168
+ assert.strictEqual(payments[0].type, 'modifier2');
169
+ assert(_.isObject(payments[0].a_customer));
170
+ assert.strictEqual(payments[0].a_customer.name, 'batman');
171
+ done();
172
+ });
173
+ });
174
+
175
+ it('should return records with limit modifier', function(done) {
176
+ Associations.Payment.find({ where: { type: 'modifier2' }})
177
+ .populate('a_customer', {capital: 150, limit: 1})
178
+ .exec(function(err, payments) {
179
+ assert.ifError(err);
180
+ assert(Array.isArray(payments));
181
+ assert.strictEqual(payments.length, 1);
182
+ assert.strictEqual(payments[0].type, 'modifier2');
183
+ assert(_.isObject(payments[0].a_customer));
184
+ assert.strictEqual(payments[0].a_customer.name, 'batman');
185
+ done();
186
+ });
187
+ });
188
+
189
+ it('should return records with not modifier', function(done) {
190
+ Associations.Payment.find({ where: { type: 'modifier2' }})
191
+ .populate('a_customer', {capital: {'!': 180}})
192
+ .exec(function(err, payments) {
193
+ assert.ifError(err);
194
+ assert(Array.isArray(payments));
195
+ assert.strictEqual(payments.length, 1);
196
+ assert.strictEqual(payments[0].type, 'modifier2');
197
+ assert(_.isObject(payments[0].a_customer));
198
+ assert.strictEqual(payments[0].a_customer.name, 'batman');
199
+ done();
200
+ });
201
+ });
202
+
203
+ it('should return records with notIn modifier', function(done) {
204
+ Associations.Payment.find({ where: { type: 'modifier2' }})
205
+ .populate('a_customer', {name: { '!': ['aquaman', 'daredevil']}})
206
+ .exec(function(err, payments) {
207
+ assert.ifError(err);
208
+ assert(Array.isArray(payments));
209
+ assert.strictEqual(payments.length, 1);
210
+ assert.strictEqual(payments[0].type, 'modifier2');
211
+ assert(_.isObject(payments[0].a_customer));
212
+ assert.strictEqual(payments[0].a_customer.name, 'batman');
213
+ done();
214
+ });
215
+ });
216
+
217
+ it('should return records with or modifier', function(done) {
218
+ Associations.Payment.find({ where: { type: 'modifier2' }})
219
+ .populate('a_customer', {where: { or: [{name:'batman'}, {capital: 230}]}})
220
+ .exec(function(err, payments) {
221
+ assert.ifError(err);
222
+ assert(Array.isArray(payments));
223
+ assert.strictEqual(payments.length, 1);
224
+ assert.strictEqual(payments[0].type, 'modifier2');
225
+ assert(_.isObject(payments[0].a_customer));
226
+ assert.strictEqual(payments[0].a_customer.name, 'batman');
227
+ done();
228
+ });
229
+ });
230
+
231
+ it('should return records with select modifier', function(done) {
232
+ Associations.Payment.find({ where: { type: 'modifier2' }})
233
+ .populate('a_customer', {capital: 150, select: ['name']})
234
+ .exec(function(err, payments) {
235
+ assert.ifError(err);
236
+ assert(Array.isArray(payments));
237
+ assert.strictEqual(payments.length, 1);
238
+ assert.strictEqual(payments[0].type, 'modifier2');
239
+ assert(_.isObject(payments[0].a_customer));
240
+ assert.strictEqual(payments[0].a_customer.name, 'batman');
241
+ assert.strictEqual(payments[0].a_customer.capital, undefined);
242
+ done();
243
+ });
244
+ });
245
+
246
+ it('should return records with skip modifier', function(done) {
247
+ Associations.Payment.find({ where: { type: 'modifier2' }})
248
+ .populate('a_customer', {capital: 150, skip: 1})
249
+ .exec(function(err, payments) {
250
+ assert.ifError(err);
251
+ assert(Array.isArray(payments));
252
+ assert.strictEqual(payments.length, 1);
253
+ assert.strictEqual(payments[0].type, 'modifier2');
254
+ assert.strictEqual(payments[0].a_customer, null, 'customer should be null');
255
+ done();
256
+ });
257
+ });
258
+
259
+ it('should return records with startsWith modifier', function(done) {
260
+ Associations.Payment.find({ where: { type: 'modifier2' }})
261
+ .populate('a_customer', {name: {startsWith: 'bat'}})
262
+ .exec(function(err, payments) {
263
+ assert.ifError(err);
264
+ assert(Array.isArray(payments));
265
+ assert.strictEqual(payments.length, 1);
266
+ assert.strictEqual(payments[0].type, 'modifier2');
267
+ assert(_.isObject(payments[0].a_customer));
268
+ assert.strictEqual(payments[0].a_customer.name, 'batman');
269
+ done();
270
+ });
271
+ });
272
+
273
+ });
274
+ });
275
+ });
@@ -0,0 +1,70 @@
1
+ var assert = require('assert'),
2
+ _ = require('lodash');
3
+
4
+ describe('Association Interface', function() {
5
+
6
+ describe('Multiple Belongs To Association', function() {
7
+ describe('create', function() {
8
+
9
+ /////////////////////////////////////////////////////
10
+ // TEST SETUP
11
+ ////////////////////////////////////////////////////
12
+
13
+ var customer_1_id, customer_2_id;
14
+
15
+ before(function(done) {
16
+ // Check Payment belongsTo Customer
17
+ assert.strictEqual(Associations.Payment_many.attributes.customer.model, 'customer_many');
18
+ assert.strictEqual(Associations.Payment_many.attributes.patron.model, 'customer_many');
19
+ assert.strictEqual(Associations.Customer_many.attributes.payments.collection, 'payment_many');
20
+ assert.strictEqual(Associations.Customer_many.attributes.transactions.collection, 'payment_many');
21
+
22
+ Associations.Customer_many.create({ name: 'manyAssociations uno add' }).exec(function(err, cust) {
23
+ assert.ifError(err);
24
+ customer_1_id = cust.id;
25
+
26
+ Associations.Customer_many.create({ name: 'manyAssociations dos add' }).exec(function(err, cust) {
27
+ assert.ifError(err);
28
+ customer_2_id = cust.id;
29
+ done();
30
+ });
31
+ });
32
+ });
33
+
34
+ /////////////////////////////////////////////////////
35
+ // TEST METHODS
36
+ ////////////////////////////////////////////////////
37
+
38
+ it('should create multiple foreign key values when passed association keys', function(done) {
39
+ Associations.Payment_many.create({ amount: 1, customer: customer_1_id, patron: customer_2_id }).exec(function(err, payment) {
40
+ assert.ifError(err);
41
+ assert.equal(payment.customer.toString(), customer_1_id.toString());
42
+ assert.equal(payment.patron.toString(), customer_2_id.toString());
43
+ done();
44
+ });
45
+ });
46
+
47
+ it('should populate values only for specified keys', function(done) {
48
+
49
+ Associations.Payment_many.create({ amount: 10, customer: customer_1_id, patron: customer_2_id }).exec(function(err) {
50
+ assert.ifError(err);
51
+
52
+ Associations.Payment_many.findOne({ amount: 10 })
53
+ .populate('patron')
54
+ .exec(function(err, payment) {
55
+ assert.ifError(err);
56
+
57
+ var obj = payment.toJSON();
58
+
59
+ assert(obj.patron);
60
+ assert.equal(obj.patron.id.toString(), customer_2_id.toString());
61
+ assert.equal(obj.customer.toString(), customer_1_id.toString());
62
+
63
+ done();
64
+ });
65
+ });
66
+ });
67
+ });
68
+ });
69
+
70
+ });
@@ -0,0 +1,141 @@
1
+ var assert = require('assert'),
2
+ _ = require('lodash');
3
+
4
+ describe('Association Interface', function() {
5
+
6
+ describe('Belongs To Association', function() {
7
+ describe('update nested 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 Payment;
17
+
18
+ before(function(done) {
19
+ // Check Payment belongsTo Customer
20
+ assert.strictEqual(Associations.Paymentbelongscustom.attributes.customer.model, 'customerbelongscustom');
21
+ assert.strictEqual(Associations.Customerbelongscustom.attributes.payments.collection, 'paymentbelongscustom');
22
+
23
+ var data = {
24
+ invoice: 100,
25
+ amount: 200
26
+ };
27
+
28
+ Associations.Paymentbelongscustom.create(data)
29
+ .exec(function(err, values) {
30
+ assert.ifError(err);
31
+ Payment = values;
32
+ done();
33
+ });
34
+
35
+ });
36
+
37
+
38
+ /////////////////////////////////////////////////////
39
+ // TEST METHODS
40
+ ////////////////////////////////////////////////////
41
+
42
+ it('should create a new customer', function(done) {
43
+
44
+ var data = {
45
+ amount: 200,
46
+ customer: {
47
+ username: 'belongsTo nested',
48
+ name: 'belongsTo nested update'
49
+ }
50
+ };
51
+
52
+ Associations.Paymentbelongscustom.update({ invoice: Payment.invoice })
53
+ .set(data)
54
+ .exec(function(err, payment) {
55
+ assert.ifError(err);
56
+
57
+ // Check that the foreign key was set
58
+ assert.equal(payment[0].customer, 'belongsTo nested');
59
+
60
+ Associations.Paymentbelongscustom.findOne(payment[0].invoice)
61
+ .populate('customer')
62
+ .exec(function(err, _payment) {
63
+ assert.ifError(err);
64
+ assert.equal(_payment.customer.username, 'belongsTo nested');
65
+ assert.equal(_payment.customer.name, 'belongsTo nested update');
66
+ done();
67
+ });
68
+ });
69
+ });
70
+ });
71
+
72
+ describe('when association already exist', function() {
73
+
74
+ /////////////////////////////////////////////////////
75
+ // TEST SETUP
76
+ ////////////////////////////////////////////////////
77
+
78
+ var Payment;
79
+
80
+ before(function(done) {
81
+
82
+ var data = {
83
+ invoice: 101,
84
+ amount: 200,
85
+ customer: {
86
+ username: 'belongsTo nested update',
87
+ name: 'belongsTo nested update'
88
+ }
89
+ };
90
+
91
+ Associations.Paymentbelongscustom.create(data)
92
+ .exec(function(err, values) {
93
+ assert.ifError(err);
94
+ Payment = values;
95
+ done();
96
+ });
97
+
98
+ });
99
+
100
+
101
+ /////////////////////////////////////////////////////
102
+ // TEST METHODS
103
+ ////////////////////////////////////////////////////
104
+
105
+ it('should reset associations with the updated associations', function(done) {
106
+
107
+ var data = {
108
+ amount: 100,
109
+ customer: {
110
+ username: 'belongsTo nested update - updated',
111
+ name: 'belongsTo nested update - updated'
112
+ }
113
+ };
114
+
115
+ Associations.Paymentbelongscustom.update({ invoice: Payment.invoice })
116
+ .set(data)
117
+ .exec(function(err, payments) {
118
+ assert.ifError(err);
119
+
120
+ // Check that the foreign key was set
121
+ assert.equal(payments[0].customer, 'belongsTo nested update - updated');
122
+
123
+ // Look up the payment again to be sure the new customer was added
124
+ Associations.Paymentbelongscustom.findOne(Payment.invoice)
125
+ .populate('customer')
126
+ .exec(function(err, _payment) {
127
+ assert.ifError(err);
128
+ assert.equal(_payment.amount, 100);
129
+ assert.equal(_payment.customer.username, 'belongsTo nested update - updated');
130
+ assert.equal(_payment.customer.name, 'belongsTo nested update - updated');
131
+ done();
132
+ });
133
+
134
+ });
135
+ });
136
+ });
137
+
138
+ });
139
+ });
140
+ });
141
+ });