@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,47 @@
1
+ module.exports.user_resource = {
2
+
3
+ tableName: 'user_resourceCustomTable',
4
+ identity: 'user_resourceCustom',
5
+
6
+ autoPk: false,
7
+
8
+ attributes: {
9
+ number: {
10
+ type: 'integer',
11
+ primaryKey: true
12
+ },
13
+ name: {
14
+ type: 'string'
15
+ },
16
+ quantity: {
17
+ type: 'integer'
18
+ },
19
+ profile: {
20
+ model: 'profileCustom'
21
+ }
22
+ }
23
+
24
+ };
25
+
26
+ module.exports.profile = {
27
+
28
+ tableName: 'profileCustomTable',
29
+ identity: 'profileCustom',
30
+ connection: 'associations',
31
+
32
+ autoPk: false,
33
+
34
+ attributes: {
35
+ name: {
36
+ type: 'string',
37
+ primaryKey: true
38
+ },
39
+ level : {
40
+ type: 'integer'
41
+ },
42
+ user: {
43
+ model: 'user_resourceCustom'
44
+ }
45
+ }
46
+
47
+ };
@@ -0,0 +1,52 @@
1
+ module.exports.user_resource = {
2
+
3
+ tableName: 'user_resourceTable',
4
+ identity: 'user_resource',
5
+
6
+ attributes: {
7
+ name: {
8
+ type: 'string'
9
+ },
10
+ quantity: {
11
+ type: 'integer'
12
+ },
13
+ profile: {
14
+ model: 'profile'
15
+ },
16
+
17
+
18
+ toJSON: function() {
19
+ var obj = this.toObject();
20
+ delete obj.name;
21
+ return obj;
22
+ }
23
+ }
24
+
25
+
26
+ };
27
+
28
+ module.exports.profile = {
29
+
30
+ tableName: 'profileTable',
31
+ identity: 'profile',
32
+
33
+ attributes: {
34
+ name: {
35
+ type: 'string'
36
+ },
37
+ level : {
38
+ type: 'integer'
39
+ },
40
+ user: {
41
+ model: 'user_resource'
42
+ },
43
+
44
+
45
+ toJSON: function() {
46
+ var obj = this.toObject();
47
+ delete obj.level;
48
+ return obj;
49
+ }
50
+ }
51
+
52
+ };
@@ -0,0 +1,41 @@
1
+ module.exports = {
2
+ PaymentBelongsFixture: require('./fixtures/belongsTo.child.fixture'),
3
+ PaymentBelongsCustomFixture: require('./fixtures/belongsTo.child.customPK.fixture'),
4
+ CustomerBelongsFixture: require('./fixtures/belongsTo.parent.fixture'),
5
+ CustomerBelongsCustomFixture: require('./fixtures/belongsTo.parent.customPK.fixture'),
6
+ PaymentHasManyFixture: require('./fixtures/hasMany.child.fixture'),
7
+ CustomerHasManyFixture: require('./fixtures/hasMany.parent.fixture'),
8
+ ApartmentHasManyFixture: require('./fixtures/hasMany.customPK.fixture'),
9
+ PaymentManyFixture: require('./fixtures/multipleAssociations.fixture').payment,
10
+ CustomerManyFixture: require('./fixtures/multipleAssociations.fixture').customer,
11
+ StadiumManyFixture: require('./fixtures/multipleThroughAssociations.fixture').stadium,
12
+ TeamManyFixture: require('./fixtures/multipleThroughAssociations.fixture').team,
13
+ VenueManyFixture: require('./fixtures/multipleThroughAssociations.fixture').venue,
14
+ StadiumFixture: require('./fixtures/hasManyThrough.stadium.fixture'),
15
+ TeamFixture: require('./fixtures/hasManyThrough.team.fixture'),
16
+ StadiumCustomFixture: require('./fixtures/hasManyThrough.parent.customPK.fixture'),
17
+ TeamCustomFixture: require('./fixtures/hasManyThrough.child.customPK.fixture'),
18
+ VenueCustomFixture: require('./fixtures/hasManyThrough.through.customPK.fixture'),
19
+ VenueFixture: require('./fixtures/hasManyThrough.venue.fixture'),
20
+ TaxiFixture: require('./fixtures/manyToMany.taxi.fixture'),
21
+ DriverFixture: require('./fixtures/manyToMany.driver.fixture'),
22
+ TaxiWithSchemaFixture: require('./fixtures/manyToMany.taxi.withSchema.fixture'),
23
+ DriverWithSchemaFixture: require('./fixtures/manyToMany.driver.withSchema.fixture'),
24
+ TaxiCustomFixture: require('./fixtures/manyToMany.taxi.customPK.fixture'),
25
+ DriverCustomFixture: require('./fixtures/manyToMany.driver.customPK.fixture'),
26
+ UserOneFixture: require('./fixtures/oneToOne.fixture').user_resource,
27
+ ProfileOneFixture: require('./fixtures/oneToOne.fixture').profile,
28
+ UserOneCustomFixture: require('./fixtures/oneToOne.customPK.fixture').user_resource,
29
+ ProfileOneCustomFixture: require('./fixtures/oneToOne.customPK.fixture').profile,
30
+ UserOneManyFixture: require('./fixtures/multipleOneToOneAssociations.fixture').user_resource,
31
+ ProfileOneManyFixture: require('./fixtures/multipleOneToOneAssociations.fixture').profile,
32
+ AddressDeepFixture: require('./fixtures/deep.address.fixture'),
33
+ BreakdownDeepFixture: require('./fixtures/deep.breakdown.fixture'),
34
+ CompanyDeepFixture: require('./fixtures/deep.company.fixture'),
35
+ SellerDeepFixture: require('./fixtures/deep.seller.fixture'),
36
+ CountryDeepFixture: require('./fixtures/deep.country.fixture'),
37
+ DepartementDeepFixture: require('./fixtures/deep.departement.fixture'),
38
+ DriverDeepFixture: require('./fixtures/deep.driver.fixture'),
39
+ RideDeepFixture: require('./fixtures/deep.ride.fixture'),
40
+ TaxiDeepFixture: require('./fixtures/deep.taxi.fixture')
41
+ };
@@ -0,0 +1,63 @@
1
+ var assert = require('assert');
2
+ var _ = require('lodash');
3
+
4
+ describe('Datastore Interface', function() {
5
+
6
+ var Datastore;
7
+
8
+ describe('.get()', function() {
9
+
10
+ /////////////////////////////////////////////////////
11
+ // TEST SETUP
12
+ ////////////////////////////////////////////////////
13
+
14
+ before(function(done) {
15
+ Adapter.getDatastore({}, function(err, datastore) {
16
+ Datastore = datastore;
17
+ Datastore.set('user_1', {first_name: 'user1', type: 'test1', age: 10 }, function() {
18
+ Datastore.set('user_2', {first_name: 'user2', type: 'test2', age: 20 }, function() {
19
+ Datastore.set('user_3', {first_name: 'user3', type: 'test3', age: 30 }, function() {
20
+ done();
21
+ });
22
+ });
23
+ });
24
+ });
25
+ });
26
+
27
+ /////////////////////////////////////////////////////
28
+ // TEST METHODS
29
+ ////////////////////////////////////////////////////
30
+
31
+
32
+ it('should get the value from key', function(done) {
33
+ Datastore.get('user_2', function(err, data) {
34
+ assert.ifError(err);
35
+ assert.equal(data.first_name, 'user2');
36
+ assert.equal(data.type, 'test2');
37
+ assert.equal(data.age, 20);
38
+ done();
39
+ });
40
+ });
41
+
42
+ it('should return a 404 error if key doesn\'t exist', function(done) {
43
+ Datastore.get('user_36', function(err, data) {
44
+ assert.equal(err.message,'404');
45
+ done();
46
+ });
47
+ });
48
+
49
+ });
50
+
51
+ describe('.remove()', function() {
52
+
53
+ it('should remove a key/value pair', function(done) {
54
+ Datastore.remove('user_2', function() {
55
+ Datastore.get('user_2', function(err, data) {
56
+ assert.equal(err.message,'404');
57
+ done();
58
+ });
59
+ });
60
+ });
61
+
62
+ });
63
+ });
@@ -0,0 +1,65 @@
1
+ var assert = require('assert');
2
+
3
+ describe('Migratable Interface', function() {
4
+
5
+ describe('definitions', function() {
6
+
7
+ describe('autoCreatedAt', function() {
8
+
9
+ /////////////////////////////////////////////////////
10
+ // TEST METHODS
11
+ ////////////////////////////////////////////////////
12
+
13
+ it('should be on by default', function() {
14
+ assert(Migratable.User.autoCreatedAt);
15
+ });
16
+
17
+ it('should cause new schema to have a createdAt attribute', function(done) {
18
+ Migratable.User.describe(function (err, user) {
19
+ assert.ifError(err);
20
+ assert(user.createdAt);
21
+ done();
22
+ });
23
+ });
24
+ });
25
+
26
+ describe('autoUpdatedAt', function() {
27
+
28
+ /////////////////////////////////////////////////////
29
+ // TEST METHODS
30
+ ////////////////////////////////////////////////////
31
+
32
+ it('should be on by default', function() {
33
+ assert(Migratable.User.autoUpdatedAt);
34
+ });
35
+
36
+ it('should cause new schema to have an updatedAt attribute', function(done) {
37
+ Migratable.User.describe(function (err, user) {
38
+ assert.ifError(err);
39
+ assert(user.updatedAt);
40
+ done();
41
+ });
42
+ });
43
+ });
44
+
45
+ describe('autoPK', function() {
46
+
47
+ /////////////////////////////////////////////////////
48
+ // TEST METHODS
49
+ ////////////////////////////////////////////////////
50
+
51
+ it('should be set to use id by default', function() {
52
+ assert(Migratable.User.autoPK);
53
+ });
54
+
55
+ it('should cause new schema to have an id attribute', function(done) {
56
+ Migratable.User.describe(function (err, user) {
57
+ assert.ifError(err);
58
+ assert(user.id);
59
+ done();
60
+ });
61
+ });
62
+ });
63
+
64
+ });
65
+ });
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Module dependencies
3
+ */
4
+
5
+ var assert = require('assert'),
6
+ bootstrapFn = require('./support/bootstrapFn');
7
+
8
+ describe('Migratable Interface', function() {
9
+
10
+ describe('migrate: "alter"', function() {
11
+ runTests("Alter");
12
+ });
13
+
14
+ describe('migrate: "alter" with custom table and column names', function() {
15
+ runTests("Custom");
16
+ });
17
+
18
+ function runTests(collectionName) {
19
+
20
+ it('should have the proper migrate setting when bootstrapping', function() {
21
+ assert.equal(Migratable[collectionName].migrate, 'alter');
22
+ });
23
+
24
+ it('should have tables', function(done) {
25
+ Migratable[collectionName].describe(function(err, schema) {
26
+ assert.ifError(err);
27
+ assert(schema);
28
+ done();
29
+ });
30
+ });
31
+
32
+
33
+ describe('teardown and migrate existing data', function() {
34
+
35
+ before(function(done) {
36
+ Migratable[collectionName].create({ name: 'blackbeard' }, done);
37
+ });
38
+
39
+ it('should retain the data when bootstrapped the second time', function(done) {
40
+ Migratable.offshore.teardown(function(err) {
41
+ bootstrapFn(function(err, obj) {
42
+ assert.ifError(err);
43
+ var ontology = obj.ontology;
44
+ ontology.collections[collectionName.toLowerCase()].count().exec(function(err, numOfPirates) {
45
+ assert.ifError(err);
46
+ assert.strictEqual(numOfPirates, 1);
47
+ done();
48
+ });
49
+ });
50
+ });
51
+ });
52
+ });
53
+
54
+ }
55
+ });
@@ -0,0 +1,120 @@
1
+ /*
2
+ * Module dependencies
3
+ */
4
+
5
+ var Offshore = require(process.env.offshorePath || 'offshore');
6
+ var assert = require('assert');
7
+ var bootstrapFn = require('./support/bootstrapFn');
8
+
9
+ var newFixture = {
10
+ CreateFixture : Offshore.Collection.extend({
11
+
12
+ tableName : 'create',
13
+ connection : 'migratable',
14
+ migrate : 'create',
15
+
16
+ attributes : {
17
+ name : 'string',
18
+ age : 'integer',
19
+ gender : 'string'
20
+ }
21
+ })
22
+ };
23
+
24
+
25
+ describe('Migratable Interface', function() {
26
+
27
+ describe('migrate: "create"', function() {
28
+ runTests("Create");
29
+ });
30
+
31
+ function runTests(collectionName) {
32
+
33
+ it('should have the proper migrate setting when bootstrapping', function() {
34
+ assert(Migratable[collectionName].migrate === 'create');
35
+ });
36
+
37
+ it('should have tables', function(done) {
38
+ Migratable[collectionName].describe(function(err, schema) {
39
+ assert.ifError(err);
40
+ assert(schema);
41
+ done();
42
+ });
43
+ });
44
+
45
+
46
+ describe('teardown and migrate existing data', function() {
47
+
48
+ before(function(done) {
49
+ Migratable[collectionName].create({ name: 'blackbeard' }, done);
50
+ });
51
+
52
+ it('should retain the data when bootstrapped the second time', function(done) {
53
+ Migratable.offshore.teardown(function(err) {
54
+ bootstrapFn(function(err, obj) {
55
+ assert.ifError(err);
56
+ var ontology = obj.ontology;
57
+ ontology.collections[collectionName.toLowerCase()].findOne({name: 'blackbeard'})
58
+ .exec(function(err, pirate) {
59
+ assert.ifError(err);
60
+ assert.equal(pirate.name, 'blackbeard');
61
+ done();
62
+ });
63
+ });
64
+ });
65
+ });
66
+ });
67
+
68
+
69
+ describe('teardown and migrate existing data after adding property', function() {
70
+
71
+ var collection;
72
+
73
+ before(function(done) {
74
+ Migratable[collectionName].create({ name : 'bluebeard' }, function(err) {
75
+ if(err) { return done(err); }
76
+ Migratable.offshore.teardown(function(err) {
77
+ bootstrapFn(newFixture, function(err, obj) {
78
+ assert.ifError(err);
79
+ var ontology = obj.ontology;
80
+ ontology.collections[collectionName.toLowerCase()].findOne({name: 'bluebeard'});
81
+ collection = ontology.collections[collectionName.toLowerCase()];
82
+ done();
83
+ });
84
+ });
85
+ });
86
+ });
87
+
88
+ it('should retain the data when bootstrapped the second time', function(done) {
89
+ collection.findOne({name: 'bluebeard'})
90
+ .exec(function(err, pirate) {
91
+ assert.ifError(err);
92
+ assert.equal(pirate.name, 'bluebeard');
93
+ done();
94
+ });
95
+ });
96
+
97
+ it('should have new attribute', function(done) {
98
+ collection.describe(function(err, schema) {
99
+ assert.ifError(err);
100
+ assert(schema);
101
+ assert(schema.name);
102
+ assert(schema.gender);
103
+ done();
104
+ });
105
+ });
106
+
107
+
108
+ it('should be able to record data using new attribute', function(done) {
109
+ collection.create({ name: 'whitebeard', gender: 'male' })
110
+ .exec(function(err, newPirate) {
111
+ assert.ifError(err);
112
+ assert.equal(newPirate.name, 'whitebeard');
113
+ assert.equal(newPirate.gender, 'male'); // requires addAttribute
114
+ done();
115
+ });
116
+ });
117
+
118
+ });
119
+ }
120
+ });
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Module dependencies
3
+ */
4
+
5
+ var assert = require('assert'),
6
+ bootstrapFn = require('./support/bootstrapFn');
7
+
8
+ describe('Migratable Interface', function() {
9
+
10
+ describe('migrate: "drop"', function() {
11
+
12
+ it('should have the proper migrate setting when bootstrapping', function() {
13
+ assert.equal(Migratable.Drop.migrate, 'drop');
14
+ });
15
+
16
+ it('should have tables', function(done) {
17
+ Migratable.Drop.describe(function(err, schema) {
18
+ assert.ifError(err);
19
+ assert(schema);
20
+ done();
21
+ });
22
+ });
23
+
24
+ describe('teardown and drop existing data', function() {
25
+
26
+ before(function(done) {
27
+ Migratable.Drop.create({ name: 'blackbeard' }, done);
28
+ });
29
+
30
+ it('should not retain the data when bootstrapped the second time', function(done) {
31
+ Migratable.offshore.teardown(function(err) {
32
+ bootstrapFn(function(err, obj) {
33
+
34
+ var ontology = obj.ontology;
35
+
36
+ ontology.collections.drop.count().exec(function(err, numOfPirates) {
37
+ assert.ifError(err);
38
+ assert.strictEqual(numOfPirates, 0);
39
+ done();
40
+ });
41
+ });
42
+ });
43
+ });
44
+ });
45
+
46
+ });
47
+ });
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Module dependencies
3
+ */
4
+
5
+ var assert = require('assert'),
6
+ bootstrapFn = require('./support/bootstrapFn');
7
+
8
+ describe('Migratable Interface', function() {
9
+
10
+ describe('migrate: "safe"', function() {
11
+
12
+ it('should have the proper migrate setting when bootstrapping', function() {
13
+ assert.equal(Migratable.Safe.migrate, 'safe');
14
+ });
15
+
16
+ it('should have NOT have tables', function(done) {
17
+ Migratable.Safe.describe(function(err, schema) {
18
+ assert.ifError(err);
19
+ assert(!schema);
20
+ done();
21
+ });
22
+ });
23
+
24
+ });
25
+ });
@@ -0,0 +1,117 @@
1
+ var assert = require('assert');
2
+
3
+ describe('Migratable Interface', function() {
4
+
5
+ describe('Schema', function() {
6
+
7
+ describe('primaryKey', function() {
8
+
9
+ /////////////////////////////////////////////////////
10
+ // TEST METHODS
11
+ ////////////////////////////////////////////////////
12
+
13
+ it('should disable autoPK', function(done) {
14
+ Migratable.Document.describe(function (err, user) {
15
+ assert(!user.id);
16
+ done();
17
+ });
18
+ });
19
+
20
+ it('should set attribute as primary key', function(done) {
21
+ Migratable.Document.describe(function (err, user) {
22
+ assert.strictEqual(user.title.primaryKey, true);
23
+ done();
24
+ });
25
+ });
26
+ });
27
+
28
+ describe('autoIncrement', function() {
29
+
30
+ /////////////////////////////////////////////////////
31
+ // TEST METHODS
32
+ ////////////////////////////////////////////////////
33
+
34
+ //
35
+ // TODO:
36
+ // pull auto-increment tests into a different interface
37
+ //
38
+
39
+ // it('should set autoIncrement on schema attribute', function(done) {
40
+ // Document.describe(function (err, user) {
41
+
42
+ // // Some databases like MySQL don't allow multiple autoIncrement values
43
+ // if(!user.number.autoIncrement) {
44
+ // console.log('Auto Increment was not set on the non primary-key attribute. If your ' +
45
+ // 'database supports it you should look into this. Some databases like MySQL dont ' +
46
+ // 'support multiple auto increment values');
47
+ // return done();
48
+ // }
49
+
50
+ // assert.strictEqual(user.number.autoIncrement, true);
51
+ // done();
52
+ // });
53
+ // });
54
+
55
+ // it('should increment an ID on insert', function(done) {
56
+ // Document.describe(function (err, user) {
57
+
58
+ // // Some databases like MySQL don't allow multiple autoIncrement values
59
+ // if(!user.number.autoIncrement) {
60
+ // console.log('Auto Increment was not set on the non primary-key attribute. If your ' +
61
+ // 'database supports it you should look into this. Some databases like MySQL dont ' +
62
+ // 'support multiple auto increment values');
63
+ // return done();
64
+ // }
65
+
66
+ // Document.create({ title: 'autoincrement 1' }, function(err, record) {
67
+ // assert.strictEqual(record.number, 1);
68
+ // Document.create({ title: 'autoincrement 2' }, function(err, record) {
69
+ // assert.strictEqual(record.number, 2);
70
+ // done();
71
+ // });
72
+ // });
73
+ // });
74
+ // });
75
+
76
+ it('should not allow multiple records with the same PK', function(done) {
77
+ Migratable.Document.create({ title: '100' }, function(err, record) {
78
+ assert.equal(record.title, '100');
79
+ Migratable.Document.create({ title: '100' }, function(err, record) {
80
+ assert(err);
81
+ assert(!record);
82
+ done();
83
+ });
84
+ });
85
+ });
86
+
87
+ });
88
+
89
+ describe('uniqueness', function() {
90
+
91
+ /////////////////////////////////////////////////////
92
+ // TEST METHODS
93
+ ////////////////////////////////////////////////////
94
+
95
+ it('should set unique on schema attribute', function(done) {
96
+ Migratable.Document.describe(function (err, user) {
97
+ assert.strictEqual(user.serialNumber.unique, true);
98
+ done();
99
+ });
100
+ });
101
+
102
+ it('should return an error if unique constraint fails', function(done) {
103
+ Migratable.Document.create({ title: 'uniqueConstraint 1', serialNumber: 'test' }, function(err, record) {
104
+ assert.ifError(err);
105
+ assert.equal(record.serialNumber, 'test');
106
+
107
+ Migratable.Document.create({ title: 'uniqueConstraint 2', serialNumber: 'test' }, function(err, record) {
108
+ assert(!record);
109
+ assert(err);
110
+ done();
111
+ });
112
+ });
113
+ });
114
+ });
115
+
116
+ });
117
+ });