@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
package/.eslintignore ADDED
@@ -0,0 +1 @@
1
+ test/
package/.eslintrc ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "parserOptions": {
3
+ "ecmaVersion": 6,
4
+ "sourceType": "module"
5
+ },
6
+ "extends": "eslint:recommended",
7
+ "env": {
8
+ "node": true
9
+ },
10
+ "globals": {
11
+ "describe": true,
12
+ "it": true,
13
+ "before": true,
14
+ "beforeEach": true,
15
+ "after": true,
16
+ "afterEach": true
17
+ },
18
+ "rules": {
19
+ "indent": [1, 2, { "SwitchCase": 1 }],
20
+ "no-undef": 1,
21
+ "no-console": 1,
22
+ "keyword-spacing": 1,
23
+ "no-trailing-spaces": 1,
24
+ "no-unused-vars": 1,
25
+ "no-redeclare": 1,
26
+ "no-unused-labels": 1,
27
+ "no-unreachable": 1,
28
+ "semi": [1, "always"],
29
+ "no-extra-semi": 1,
30
+ "no-fallthrough": 1,
31
+ "no-constant-condition": 1,
32
+ "no-mixed-spaces-and-tabs": 1,
33
+ "no-case-declarations": 1
34
+ }
35
+ }
package/.travis.yml ADDED
@@ -0,0 +1,32 @@
1
+ language: node_js
2
+ sudo: required
3
+
4
+ node_js:
5
+ - '6'
6
+ - '8'
7
+
8
+ before_install:
9
+ - wget https://raw.githubusercontent.com/Vincit/travis-oracledb-xe/master/accept_the_license_agreement_for_oracledb_xe_11g_and_install.sh
10
+ - bash ./accept_the_license_agreement_for_oracledb_xe_11g_and_install.sh
11
+ - npm install oracledb
12
+ - npm install mysql
13
+ - npm install pg
14
+ - npm install sqlite3
15
+
16
+ before_script:
17
+ - psql -c 'create database offshorepg;' -U postgres
18
+ - mysql -e 'create database offshoresql;'
19
+
20
+ env:
21
+ - CXX=g++-4.8 KNEX_TEST_TIMEOUT=60000 ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe PATH=$ORACLE_HOME/bin:$PATH ORACLE_SID=XE OCI_LIB_DIR=/u01/app/oracle/product/11.2.0/xe/lib LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/xe/lib
22
+
23
+ addons:
24
+ postgresql: '9.4'
25
+ apt:
26
+ sources:
27
+ - ubuntu-toolchain-r-test
28
+ packages:
29
+ - g++-4.8
30
+ - gcc-4.8
31
+
32
+ after_success: npm run coveralls
package/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # Waterline Adapter Tests Changelog
2
+
3
+ ### 0.11.0
4
+
5
+ * [UPGRADE] Add test that checks the new function signature of `.save()` in Waterline 0.11.0
6
+ * [ENHANCEMENT] Add a Docker config for getting all the various databases installed and configured to run the tests.
7
+
8
+ ### 0.10.19
9
+
10
+ * [BUG] Fix previous date test that only checked CST
11
+
12
+ ### 0.10.18
13
+
14
+ * [ENHANCEMENT] Add a test for querying dates when they are a string. See [#100](https://github.com/balderdashy/waterline-adapter-tests/pull/100) for more details.
15
+
16
+ ### 0.10.17
17
+
18
+ * [STABILITY] Skip failing binary test that isn't compatible with Waterline feature set. This was hiding actual patches that break core or another adapter. See [#98](https://github.com/balderdashy/waterline-adapter-tests/pull/98) for more details.
19
+
20
+ * [STABILITY] Skip incorrect auto-increment test. See [#99](https://github.com/balderdashy/waterline-adapter-tests/pull/99) for more details.
21
+
22
+ * [ENHANCEMENT] Update Travis config to add Node 4.0 and 5.0. See [#97](https://github.com/balderdashy/waterline-adapter-tests/pull/97) for more details.
23
+
24
+ * [ENHANCEMENT] Added test for `migrate: 'create'` in the migratable interface. See [#34](https://github.com/balderdashy/waterline-adapter-tests/pull/34) for more details. Thanks [@dmarcelino](https://github.com/dmarcelino)!
package/Dockerfile ADDED
@@ -0,0 +1,7 @@
1
+ FROM nodesource/node:4.2
2
+
3
+ ADD package.json package.json
4
+ RUN npm install
5
+ ADD . .
6
+
7
+ CMD ["npm","test"]
package/LICENSE.md ADDED
@@ -0,0 +1,11 @@
1
+ The MIT License (MIT)
2
+ --
3
+
4
+ Copyright © 2012 Balderdash Design Co.
5
+ Copyright © 2015 Atlantis Software.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,72 @@
1
- # Temporary Holding Version
1
+ Offshore Adapter Tests
2
+ ==========================
2
3
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
4
+ A set of integration tests that can be included in your Offshore Adapter module and used to test
5
+ your adapter against the current Offshore API.
6
+
7
+ [![npm version](https://badge.fury.io/js/offshore-adapter-tests.svg)](https://www.npmjs.com/offshore-adapter-tests)
8
+ [![Build Status](https://travis-ci.org/Atlantis-Software/offshore-adapter-tests.svg?branch=master)](https://travis-ci.org/Atlantis-Software/offshore-adapter-tests)
9
+ [![Coverage Status](https://coveralls.io/repos/github/Atlantis-Software/offshore-adapter-tests/badge.svg?branch=master)](https://coveralls.io/github/Atlantis-Software/offshore-adapter-tests?branch=master)
10
+ [![NSP Status](https://nodesecurity.io/orgs/atlantis/projects/30ec60e6-5fe3-4546-9d4d-52be60ef5fa3/badge)](https://nodesecurity.io/orgs/atlantis/projects/30ec60e6-5fe3-4546-9d4d-52be60ef5fa3)
11
+ [![Dependencies Status](https://david-dm.org/Atlantis-Software/offshore-adapter-tests.svg)](https://david-dm.org/Atlantis-Software/offshore-adapter-tests)
12
+
13
+ ## Adapter Interface Specification
14
+
15
+
16
+ ## Usage
17
+
18
+ #### Write a test runner
19
+
20
+ > i.e. `runner.js`
21
+
22
+ ```javascript
23
+ /**
24
+ * Test runner dependencies
25
+ */
26
+ var mocha = require('mocha');
27
+ var TestRunner = require('offshore-adapter-tests');
28
+
29
+
30
+ /**
31
+ * Integration Test Runner
32
+ *
33
+ * Uses the `offshore-adapter-tests` module to
34
+ * run mocha tests against the specified interfaces
35
+ * of the currently-implemented Offshore adapter API.
36
+ */
37
+ new TestRunner({
38
+
39
+ // Load the adapter module.
40
+ adapter: require('./relative/path/to/your/adapter'),
41
+
42
+ // Default adapter config to use.
43
+ config: {
44
+ schema: false
45
+ },
46
+
47
+ // The set of adapter interfaces to test against.
48
+ interfaces: ['semantic', 'queryable']
49
+ });
50
+ ```
51
+
52
+ #### Run the tests
53
+
54
+ ```sh
55
+ $ node runner.js
56
+ ```
57
+
58
+
59
+ ## Running Tests in a Vagrant VM
60
+
61
+ Since it is not necessarily desirable to install all the databases on the local host
62
+ where this package is tested a [Vagrant](https://www.vagrantup.com) configuration for
63
+ a fully configured virtual host is provided. To run the tests using this virtual host
64
+ follow [these steps](.puppet/README.md).
65
+
66
+ Using Vagrant is entirely optional. If you prefer to just run the test on your host
67
+ directly just ensure the various databases being tested are installed.
68
+
69
+
70
+ ## MIT License
71
+
72
+ See LICENSE.md.
@@ -0,0 +1,32 @@
1
+ adapter:
2
+ build: .
3
+ volumes:
4
+ - .:/usr/src/app
5
+ links:
6
+ - postgres
7
+ - mysql
8
+ - mongo
9
+ - redis
10
+ environment:
11
+ - NODE_ENV=test
12
+
13
+ mysql:
14
+ image: mysql
15
+ environment:
16
+ - MYSQL_DATABASE=offshoreSql
17
+ - MYSQL_USER=offshore
18
+ - MYSQL_PASSWORD=offshore
19
+ - MYSQL_ROOT_PASSWORD=offshore
20
+
21
+ postgres:
22
+ image: postgres:9.4
23
+ environment:
24
+ - POSTGRES_PASSWORD=offshore
25
+ - POSTGRES_USER=offshore
26
+ - POSTGRES_DB=offshorepg
27
+
28
+ mongo:
29
+ image: mongo
30
+
31
+ redis:
32
+ image: redis
@@ -0,0 +1,37 @@
1
+ Feature: autoIncrement
2
+ ======================
3
+
4
+ Enable this test in `package.json` with: `"features": ["autoIncrement"]`
5
+
6
+ When autoIncrement is set to true on an attribute and no value is provided for it a new unique value
7
+ will be assigned by the adapter before the record is created. It is guaranteed that the adapter will
8
+ assign a unique value not present on any existing record. The values assigned automatically will not
9
+ necessarily be sequential, which accommodates the use of UUIDs. If a value for the attribute is
10
+ present in the data provided for a new record it will be saved as-is without any guarantee of uniqueness.
11
+ The autoIncrement option has no effect when updating existing records.
12
+
13
+ Usage on Offshore models:
14
+
15
+ ```
16
+ attributes: {
17
+ id: {
18
+ type: "integer", // or "string"
19
+ autoIncrement: true
20
+ }
21
+ }
22
+ ```
23
+
24
+ ## Sub-Features
25
+
26
+ ### autoIncrement.sequential
27
+
28
+ Enable this test in `package.json` with: `"features": ["autoIncrement.sequential"]`
29
+
30
+ If the adapter will provide sequential unique values, for example increasing integers, then it is
31
+ further guaranteed that the next value will be the last saved value plus one increment. If a value
32
+ is provided and is larger than the current auto-inc counter the counter will be bumped to the
33
+ provided value. If a provided value is less than or equal to the auto-inc counter value the
34
+ counter will remain unchanged, and again there will be no guaranteed that this value is unique.
35
+
36
+ This sub-feature is a special case/implementation detail of the `autoIncrement` attribute by
37
+ selected adapters and is not configured explicitly.
@@ -0,0 +1,151 @@
1
+ var assert = require('assert');
2
+ var _ = require('lodash');
3
+
4
+ /**
5
+ * When `autoIncrement` is set to `true` on an attribute and no value is provided for it a
6
+ * new unique value will be assigned by the adapter before the record is created. It is
7
+ * guaranteed that the adapter will assign a unique value not present on any existing record.
8
+ * The values assigned automatically will not necessarily be sequential, which accommodates
9
+ * the use of UUIDs. If a value for the attribute is present in the data provided for a new
10
+ * record it will be saved as-is without any guarantee of uniqueness. The `autoIncrement`
11
+ * option has no effect when updating existing records. The feature flag is `autoIncrement`.
12
+ */
13
+ describe('autoIncrement attribute feature', function() {
14
+
15
+ /////////////////////////////////////////////////////
16
+ // TEST SETUP
17
+ ////////////////////////////////////////////////////
18
+
19
+ var Offshore = require(process.env.offshorePath || 'offshore');
20
+ var defaults = { migrate: 'alter' };
21
+ var offshore;
22
+
23
+ var AutoIncFixture = require('./../support/autoInc.fixture.js');
24
+ var AutoIncModel;
25
+
26
+
27
+ before(function(done) {
28
+ offshore = new Offshore();
29
+ offshore.loadCollection(AutoIncFixture);
30
+ done();
31
+ });
32
+
33
+ beforeEach(function(done) {
34
+ var connections = { autoIncConn: _.clone(Connections.test) };
35
+
36
+ Adapter.teardown('autoIncConn', function adapterTeardown(){
37
+ offshore.initialize({ adapters: { wl_tests: Adapter }, connections: connections, defaults: defaults }, function(err, ontology) {
38
+ if(err) return done(err);
39
+ AutoIncModel = ontology.collections['autoinc'];
40
+ done();
41
+ });
42
+ });
43
+ });
44
+
45
+ afterEach(function(done) {
46
+ if(!Adapter.hasOwnProperty('drop')) {
47
+ offshore.teardown(done);
48
+ } else {
49
+ AutoIncModel.drop(function(err1) {
50
+ offshore.teardown(function(err2) {
51
+ return done(err1 || err2);
52
+ });
53
+ });
54
+ }
55
+ });
56
+
57
+
58
+ /////////////////////////////////////////////////////
59
+ // TEST METHODS
60
+ ////////////////////////////////////////////////////
61
+
62
+ var testName = '.create() test autoInc unique values';
63
+ var lastIds;
64
+
65
+
66
+ it('should auto generate unique values', function(done) {
67
+ var records = [];
68
+ for(var i=0; i<10; i++) {
69
+ records.push({ name: 'ai_' + i, type: testName });
70
+ }
71
+
72
+ AutoIncModel.create(records, function(err) {
73
+ if (err) return done(err);
74
+
75
+ AutoIncModel.find({where : { type: testName }, sort : {name : 1}}, function(err, records) {
76
+ if (err) return done(err);
77
+ assert.ifError(err);
78
+ assert.equal(records.length, 10, 'Expecting 10 records, but got '+records.length);
79
+
80
+ assert(records[0].id);
81
+ assert.equal(records[0].name, 'ai_0');
82
+ assert(records[0].normalField === null || records[0].normalField === undefined);
83
+
84
+ var ids = lastIds = _.map(records, 'id');
85
+ assert.equal(ids.length, 10);
86
+ assert.equal(_.uniq(ids).length, 10, 'Generated ids are not unique: '+ids.join(', '));
87
+
88
+ done();
89
+ });
90
+
91
+ });
92
+ });
93
+
94
+
95
+ it('should auto generate unique values even when values have been set', function(done) {
96
+ // Create some initial records with auto inc values already set. Type matches are ensured by using the
97
+ // values generated in the previous test, also ensuring that if there is a fixed sequence of values being
98
+ // used the first values are already taken.
99
+ var records = [];
100
+ for(var i=0; i<5; i++) {
101
+ records.push({ id: lastIds[i], name: 'ai_' + i, normalField: 10, type: testName });
102
+ }
103
+
104
+ AutoIncModel.create(records, function(err) {
105
+ if (err) return done(err);
106
+
107
+ AutoIncModel.find({where : { type: testName }, sort : {name : 1}}, function(err, records) {
108
+ if (err) return done(err);
109
+ assert.ifError(err);
110
+ assert.equal(records.length, 5, 'Expecting 5 records, but got '+records.length);
111
+
112
+ assert.equal(records[0].name, 'ai_0');
113
+ assert.equal(records[0].normalField, 10);
114
+
115
+ var ids = _.map(records, 'id');
116
+ assert.equal(ids.length, 5)
117
+ assert.equal(_.uniq(ids).length, 5)
118
+
119
+ // Create another set of records without auto inc values set. The generated values should be
120
+ // unique, even when compared to those set explicitly.
121
+ var records = [];
122
+ for(var i=5; i<10; i++) {
123
+ records.push({ name: 'ai_' + i, type: testName });
124
+ }
125
+
126
+ AutoIncModel.create(records, function(err) {
127
+ if (err) return done(err);
128
+
129
+ AutoIncModel.find({where : { type: testName }, sort : {name : 1}}, function(err, records) {
130
+ if (err) return done(err);
131
+ assert.ifError(err);
132
+ assert.equal(records.length, 10, 'Expecting 10 records, but got '+records.length);
133
+
134
+ assert.equal(records[0].name, 'ai_0');
135
+
136
+ assert(records[5].id);
137
+ assert.equal(records[5].name, 'ai_5');
138
+
139
+ var ids = _.map(records, 'id');
140
+ assert.equal(ids.length, 10);
141
+ assert.equal(_.uniq(ids).length, 10, 'Preset and generated ids are not unique: '+ids.join(', '));
142
+
143
+ done();
144
+ });
145
+ });
146
+
147
+ });
148
+ });
149
+
150
+ });
151
+ });
@@ -0,0 +1,104 @@
1
+ var assert = require('assert');
2
+ var _ = require('lodash');
3
+
4
+ /**
5
+ * If the adapter will provide sequential unique values, for example increasing integers,
6
+ * then it is further guaranteed that the next value will be the last saved value plus one
7
+ * increment. If a value is provided and is larger than the current auto-inc counter the
8
+ * counter will be bumped to the provided value. If a provided value is less than or equal
9
+ * to the auto-inc counter value the counter will remain unchanged, and again there will
10
+ * be no guaranteed that this value is unique. This extended feature is indicated with
11
+ * the `autoIncrementSequential` feature flag.
12
+ */
13
+ describe('autoIncrement attribute Sequential feature', function() {
14
+
15
+ /////////////////////////////////////////////////////
16
+ // TEST SETUP
17
+ ////////////////////////////////////////////////////
18
+
19
+ var Offshore = require(process.env.offshorePath || 'offshore');
20
+ var defaults = { migrate: 'alter' };
21
+ var offshore;
22
+
23
+ var AutoIncFixture = require('../support/autoInc.fixture.js');
24
+ var AutoIncModel;
25
+
26
+
27
+ before(function(done) {
28
+ offshore = new Offshore();
29
+ offshore.loadCollection(AutoIncFixture);
30
+
31
+ var connections = { autoIncConn: _.clone(Connections.test) };
32
+
33
+ Adapter.teardown('autoIncConn', function adapterTeardown(){
34
+ offshore.initialize({ adapters: { wl_tests: Adapter }, connections: connections, defaults: defaults }, function(err, ontology) {
35
+ if(err) return done(err);
36
+ AutoIncModel = ontology.collections['autoinc'];
37
+ done();
38
+ });
39
+ });
40
+ });
41
+
42
+ after(function(done) {
43
+ if(!Adapter.hasOwnProperty('drop')) {
44
+ offshore.teardown(done);
45
+ } else {
46
+ AutoIncModel.drop(function(err1) {
47
+ offshore.teardown(function(err2) {
48
+ return done(err1 || err2);
49
+ });
50
+ });
51
+ }
52
+ });
53
+
54
+
55
+ /////////////////////////////////////////////////////
56
+ // TEST METHODS
57
+ ////////////////////////////////////////////////////
58
+
59
+ var lastValue;
60
+
61
+
62
+ it('should generate sequential values', function(done) {
63
+ var records = [];
64
+ for(var i=0; i<3; i++) {
65
+ records.push({ name: 'ais_' + i });
66
+ }
67
+
68
+ AutoIncModel.create(records, function(err, records) {
69
+ if (err) return done(err);
70
+ assert(records[0].id < records[1].id);
71
+ assert(records[1].id < records[2].id);
72
+
73
+ lastValue = records[2].id;
74
+ done();
75
+ });
76
+ });
77
+
78
+ it('should continue auto-incrementing from the last provided larger value', function(done) {
79
+ AutoIncModel.create({ id: lastValue + 20, name: 'FooBar+20' }, function(err, record) {
80
+ if (err) return done(err);
81
+ assert.equal(record.id, lastValue + 20, 'Create item with a given larger than last id');
82
+
83
+ AutoIncModel.create({ name: 'FooBar+21' }, function(err, user) {
84
+ if (err) return done(err);
85
+ assert.equal(user.id, lastValue + 21, 'AutoInc id should follow the previous given value');
86
+ done();
87
+ });
88
+ });
89
+ });
90
+
91
+ it('should not update the auto-incrementing counter on smaller values', function(done) {
92
+ AutoIncModel.create({ id: lastValue + 10, name: 'FooBar+10' }, function(err, user) {
93
+ if (err) return done(err);
94
+ assert.equal(user.id, lastValue + 10, 'Create item with a given smaller than last id');
95
+
96
+ AutoIncModel.create({ name: 'FooBar+22' }, function(err, user) {
97
+ if (err) return done(err);
98
+ assert.equal(user.id, lastValue + 22, 'AutoInc should continue from the largest id to avoid clashing later');
99
+ done();
100
+ });
101
+ });
102
+ });
103
+
104
+ });
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Dependencies
3
+ */
4
+
5
+ var Offshore = require(process.env.offshorePath || 'offshore');
6
+
7
+ module.exports = Offshore.Collection.extend({
8
+
9
+ identity: 'autoInc',
10
+ tableName: 'autoIncTable',
11
+ connection: 'autoIncConn',
12
+
13
+ attributes: {
14
+ name: {
15
+ type: 'string'
16
+ },
17
+ normalField: {
18
+ type: 'integer'
19
+ },
20
+ type: {
21
+ type: 'string'
22
+ },
23
+ }
24
+
25
+ });
@@ -0,0 +1,67 @@
1
+ var assert = require('assert');
2
+ var _ = require('lodash');
3
+
4
+ describe('compositePrimaryKey feature', function () {
5
+ var Offshore = require(process.env.offshorePath || 'offshore');
6
+ var defaults = { migrate: 'alter' };
7
+ var offshore;
8
+
9
+ var Fixture = require('../support/fixture.js');
10
+ var Model;
11
+
12
+ before(function(done) {
13
+ offshore = new Offshore();
14
+ offshore.loadCollection(Fixture);
15
+
16
+ var connections = { compositePrimaryKeyConnection: _.clone(Connections.test) };
17
+
18
+ Adapter.teardown('compositePrimaryKeyConnection', function adapterTeardown(){
19
+ offshore.initialize({ adapters: { wl_tests: Adapter }, connections: connections, defaults: defaults }, function(err, ontology) {
20
+ if(err) return done(err);
21
+ Model = ontology.collections['compositeprimarykey'];
22
+ done();
23
+ });
24
+ });
25
+ });
26
+ after(function(done) {
27
+ if(!Adapter.hasOwnProperty('drop')) {
28
+ offshore.teardown(done);
29
+ } else {
30
+ Model.drop(function(err1) {
31
+ offshore.teardown(function(err2) {
32
+ return done(err1 || err2);
33
+ });
34
+ });
35
+ }
36
+ done()
37
+ });
38
+
39
+ it('should insert unique records', function (done) {
40
+ var records = [
41
+ { name: '1st', pkOne: 1, pkTwo: 'bar' },
42
+ { name: '2nd', pkOne: 2, pkTwo: 'baz' },
43
+ { name: '3rd', pkOne: 3, pkTwo: 'bar' },
44
+ { name: '4th', pkOne: 4, pkTwo: 'baz' }
45
+ ];
46
+
47
+ Model.create(records)
48
+ .then(function (records) {
49
+ assert(records.length, 4);
50
+ done();
51
+ })
52
+ .catch(done)
53
+ })
54
+ it('should enforce composite uniqueness', function (done) {
55
+ var records = [
56
+ { name: '5th', pkOne: 1, pkTwo: 'bar' }
57
+ ];
58
+ Model.create(records)
59
+ .then(function (records) {
60
+ done(new Error('should not have inserted unique records, but did anyway'));
61
+ })
62
+ .catch(function (err) {
63
+ assert(err)
64
+ done();
65
+ })
66
+ })
67
+ })
@@ -0,0 +1,24 @@
1
+ var Offshore = require(process.env.offshorePath || 'offshore');
2
+
3
+ module.exports = Offshore.Collection.extend({
4
+
5
+ identity: 'compositePrimaryKey',
6
+ tableName: 'compositePrimaryKeyTable',
7
+ connection: 'compositePrimaryKeyConnection',
8
+ autoPK: false,
9
+
10
+ attributes: {
11
+ name: {
12
+ type: 'string'
13
+ },
14
+ pkOne: {
15
+ type: 'integer',
16
+ primaryKey: true
17
+ },
18
+ pkTwo: {
19
+ type: 'string',
20
+ primaryKey: true
21
+ }
22
+ }
23
+
24
+ });