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