@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,80 @@
1
+ /**
2
+ * Module Dependencies
3
+ */
4
+
5
+ var Offshore = require(process.env.offshorePath || 'offshore');
6
+ var _ = require('lodash');
7
+ var asynk = require('asynk');
8
+
9
+ // Require Fixtures
10
+ var fixtures = {
11
+ UserFixture: require('./fixtures/crud.fixture')
12
+ };
13
+
14
+
15
+ /////////////////////////////////////////////////////
16
+ // TEST SETUP
17
+ ////////////////////////////////////////////////////
18
+
19
+ var offshore, ontology;
20
+
21
+ before(function(done) {
22
+
23
+ offshore = new Offshore();
24
+
25
+ Object.keys(fixtures).forEach(function(key) {
26
+ var collection = fixtures[key];
27
+ _.keys(collection.attributes).forEach(function(attr) {
28
+ // skip collection
29
+ if (collection.attributes[attr].collection) {
30
+ return;
31
+ }
32
+ // skip functions
33
+ if (_.isFunction(collection.attributes[attr])) {
34
+ return;
35
+ }
36
+ // add columnName
37
+ collection.attributes[attr].columnName = collection.identity + _.capitalize(attr);
38
+ });
39
+ offshore.loadCollection(Offshore.Collection.extend(collection));
40
+ });
41
+
42
+ var connections = { queryable: _.clone(Connections.test) };
43
+
44
+ offshore.initialize({ adapters: { wl_tests: Adapter }, connections: connections }, function(err, _ontology) {
45
+ if(err) return done(err);
46
+
47
+ ontology = _ontology;
48
+
49
+ Object.keys(_ontology.collections).forEach(function(key) {
50
+ var globalName = key.charAt(0).toUpperCase() + key.slice(1);
51
+ global.Queryable[globalName] = _ontology.collections[key];
52
+ });
53
+
54
+ done();
55
+ });
56
+ });
57
+
58
+ after(function(done) {
59
+
60
+ function dropCollection(item, next) {
61
+ if (!Adapter.hasOwnProperty('drop')) {
62
+ return next();
63
+ }
64
+
65
+ ontology.collections[item].drop(function(err) {
66
+ if (err) {
67
+ return next(err);
68
+ }
69
+ next();
70
+ });
71
+ }
72
+
73
+ asynk.each(Object.keys(ontology.collections), dropCollection).serie().asCallback(function(err) {
74
+ if (err) {
75
+ return done(err);
76
+ }
77
+ offshore.teardown(done);
78
+ });
79
+
80
+ });
@@ -0,0 +1,54 @@
1
+ module.exports = {
2
+
3
+ tableName: 'userTable2',
4
+ identity: 'user',
5
+ connection: 'queryable',
6
+
7
+ attributes: {
8
+ first_name: {
9
+ type: 'string'
10
+ },
11
+ last_name: {
12
+ type: 'string'
13
+ },
14
+ email: {
15
+ type: 'string'
16
+ },
17
+ title: {
18
+ type: 'string'
19
+ },
20
+ phone: {
21
+ type: 'string'
22
+ },
23
+ type: {
24
+ type: 'string'
25
+ },
26
+ favoriteFruit: {
27
+ defaultsTo: 'blueberry',
28
+ type: 'string'
29
+ },
30
+ age: {
31
+ type: 'integer'
32
+ }, // integer field that's not auto-incrementable
33
+ dob: {
34
+ type: 'date'
35
+ },
36
+ status: {
37
+ type: 'boolean',
38
+ defaultsTo: false
39
+ },
40
+ percent: {
41
+ type: 'float'
42
+ },
43
+ list: {
44
+ type: 'array'
45
+ },
46
+ obj: {
47
+ type: 'json'
48
+ },
49
+ fullName: function() {
50
+ return this.first_name + ' ' + this.last_name;
51
+ }
52
+ }
53
+
54
+ };
@@ -0,0 +1,19 @@
1
+ # Benchmarks
2
+
3
+ Currently, the goal with the `scalable` interface is to test that a reasonable bar for performance/memory usage is met, for the `semantic` (CRUD) and `queryable` (searching using criteria) interfaces.
4
+
5
+ We're standardizing to “Benchmark.js](https://github.com/bestiejs/benchmark.js) across all the sails/offshore projects.
6
+
7
+
8
+ ###### Writing good benchmarks
9
+ + Pick what you want to test.
10
+ + Whatever you choose does not have to be atomic (see examples above)-- in an ideal world, we would have benchmarks for every single function in our apps, but that is not how things work today.
11
+ + Write a benchmark test that isolates that functionality. (the hard part)
12
+ + Then see how many miliseconds it takes. (easy)
13
+
14
+ > **Advice from Felix Geisendörfer ([@felixge](https://github.com/felixge))**
15
+ >
16
+ > + First of all, keep in mind our problems are definitely not the same as Felix's, and we must remember to follow [his own advice](https://github.com/felixge/faster-than-c#taking-performance-advice-from-strangers): `[What]...does not work is taking performance advise (euro-sic) from strangers...` That said, he's got some great ideas.
17
+ > + [Benchmark-Driven Optimization](https://github.com/felixge/faster-than-c#benchmark-driven-development)
18
+ > + I also highly recommend this [talk on optimization and benchmarking](http://2012.jsconf.eu/speaker/2012/09/05/faster-than-c-parsing-node-js-streams-.html) ([slides](https://github.com/felixge/faster-than-c)).
19
+
@@ -0,0 +1,73 @@
1
+ // TODO: test basic CRUD functionality (semantic interface) at high concurrency
2
+
3
+ // TODO: measure memory usage
4
+ // TODO: measure execution time
5
+ // TODO: track any failures/errors
6
+
7
+
8
+ var Offshore = require(process.env.offshorePath || 'offshore');
9
+ var Model = require('./support/crud.fixture');
10
+ var assert = require('assert');
11
+ var asynk = require('asynk');
12
+
13
+ var CONNECTIONS = 10;
14
+
15
+ describe('Load Testing', function() {
16
+ this.timeout(60000);
17
+
18
+
19
+ // TODO: try out `benchmark` library
20
+
21
+
22
+ /////////////////////////////////////////////////////
23
+ // TEST SETUP
24
+ ////////////////////////////////////////////////////
25
+
26
+
27
+ var User;
28
+
29
+ before(function(done) {
30
+ var offshore = new Offshore();
31
+ offshore.loadCollection(Model);
32
+
33
+ Events.emit('fixture', Model);
34
+
35
+ offshore.initialize({ adapters: { test: Adapter }}, function(err, colls) {
36
+ if(err) return done(err);
37
+ User = colls.loadtest;
38
+ done();
39
+ });
40
+ });
41
+
42
+
43
+ /////////////////////////////////////////////////////
44
+ // TEST METHODS
45
+ ////////////////////////////////////////////////////
46
+
47
+
48
+ describe('create with x connection', function() {
49
+
50
+ it('should not error', function(done) {
51
+
52
+ // generate x users
53
+ var users = [];
54
+ for (var i = 0; i < CONNECTIONS; ++i) {
55
+ users.push({
56
+ first_name: Math.floor((Math.random()*100000)+1),
57
+ last_name: Math.floor((Math.random()*100000)+1),
58
+ email: Math.floor((Math.random()*100000)+1)
59
+ });
60
+ }
61
+
62
+
63
+ asynk.each(users, function(user, next){
64
+ User.create(user, next);
65
+ }).serie().asCallback(function(err, users) {
66
+ assert.ifError(err);
67
+ assert.strictEqual(users.length, CONNECTIONS);
68
+ done();
69
+ });
70
+ });
71
+ });
72
+
73
+ });
@@ -0,0 +1,9 @@
1
+
2
+
3
+ // TODO: test functionality for the queryable interface at high concurrency
4
+
5
+ // TODO: measure memory usage
6
+ // TODO: measure execution time
7
+ // TODO: track any failures/errors
8
+
9
+
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Dependencies
3
+ */
4
+
5
+ var Offshore = require(process.env.offshorePath || 'offshore');
6
+
7
+ module.exports = Offshore.Collection.extend({
8
+
9
+ identity: 'loadtest',
10
+ tableName: 'loadTestTable',
11
+ adapter: 'test',
12
+
13
+ attributes: {
14
+ first_name: {
15
+ type: 'string'
16
+ },
17
+ last_name: {
18
+ type: 'string'
19
+ },
20
+ email: {
21
+ type: 'string'
22
+ },
23
+ title: {
24
+ type: 'string'
25
+ },
26
+ phone: {
27
+ type: 'string'
28
+ },
29
+ type: {
30
+ type: 'string'
31
+ },
32
+ favoriteFruit: {
33
+ defaultsTo: 'blueberry',
34
+ type: 'string'
35
+ },
36
+ age: {
37
+ type: 'string'
38
+ }, // integer field that's not auto-incrementable
39
+ dob: {
40
+ type: 'datetime'
41
+ },
42
+ status: {
43
+ type: 'boolean',
44
+ defaultsTo: false
45
+ },
46
+ percent: {
47
+ type: 'float'
48
+ },
49
+ list: {
50
+ type: 'array'
51
+ },
52
+ obj: {
53
+ type: 'json'
54
+ },
55
+ fullName: function() {
56
+ return this.first_name + ' ' + this.last_name;
57
+ }
58
+ }
59
+
60
+ });
@@ -0,0 +1,110 @@
1
+ var assert = require('assert'),
2
+ _ = require('lodash');
3
+
4
+ describe('Semantic Interface', function() {
5
+
6
+ describe('.create()', function() {
7
+
8
+ /////////////////////////////////////////////////////
9
+ // TEST METHODS
10
+ ////////////////////////////////////////////////////
11
+
12
+ it('should create a new record', function(done) {
13
+ Semantic.User.create({ first_name: 'Foo' }, function(err, record) {
14
+ if (err) { console.error(err); }
15
+ assert.ifError(err);
16
+ assert.equal(record.first_name, 'Foo');
17
+ done();
18
+ });
19
+ });
20
+
21
+ it('should return a generated PK', function(done) {
22
+ Semantic.User.create({ first_name: 'FooBar' }, function(err, user) {
23
+ if (err) { console.error(err); }
24
+ assert.ifError(err);
25
+ assert.equal(user.first_name, 'FooBar');
26
+ assert(user.id);
27
+ done();
28
+ });
29
+ });
30
+
31
+ it('should return generated timestamps', function(done) {
32
+ Semantic.User.create({ first_name: 'Foo', last_name: 'Bar' }, function(err, user) {
33
+ if (err) { console.error(err); }
34
+ assert.ifError(err);
35
+ assert.equal(toString.call(user.createdAt), '[object Date]');
36
+ assert.equal(toString.call(user.updatedAt), '[object Date]');
37
+ done();
38
+ });
39
+ });
40
+
41
+ it('should return a model instance', function(done) {
42
+ Semantic.User.create({ first_name: 'Foo', last_name: 'Bar' }, function(err, user) {
43
+ if (err) { console.error(err); }
44
+ assert.ifError(err);
45
+ assert.equal(user.fullName(), 'Foo Bar');
46
+ done();
47
+ });
48
+ });
49
+
50
+ it('should normalize undefined values to null', function(done) {
51
+ Semantic.User.create({ first_name: 'Yezy', last_name: undefined }, function(err, user) {
52
+ assert.ifError(err);
53
+ assert.equal(user.last_name, null);
54
+ done();
55
+ });
56
+ });
57
+
58
+ it('should return rows in the correct order when creating multiple rows', function(done) {
59
+ var testName = '.create() with a list, returning values';
60
+ var users = [];
61
+
62
+ for(var i=0; i<30; i++) {
63
+ users.push({ first_name: 'test_' + i, type: testName });
64
+ }
65
+ Semantic.User.create(users, function(err, users) {
66
+ assert.ifError(err);
67
+ users.forEach(function(val, idx){
68
+ assert.equal(users[idx].first_name, 'test_' + idx);
69
+ });
70
+ assert.equal(users.length, 30, 'Expecting 30 "users", but actually got '+users.length+': '+require('util').inspect(users, false, null));
71
+ done();
72
+ });
73
+ });
74
+
75
+ describe('overloaded usage of create', function() {
76
+
77
+ /////////////////////////////////////////////////////
78
+ // TEST SETUP
79
+ ////////////////////////////////////////////////////
80
+
81
+ var testName = '.create() test create a list';
82
+
83
+ before(function(done) {
84
+ var users = [];
85
+
86
+ for(var i=0; i<4; i++) {
87
+ users.push({ first_name: 'test_' + i, type: testName });
88
+ }
89
+
90
+ Semantic.User.create(users, done);
91
+ });
92
+
93
+
94
+ /////////////////////////////////////////////////////
95
+ // TEST METHODS
96
+ ////////////////////////////////////////////////////
97
+
98
+ it('should have saved the proper values (with auto-increment values)', function(done) {
99
+ Semantic.User.find({where : { type: testName }, sort : {first_name : 1}}, function(err, users) {
100
+ if (err) return done(err);
101
+ assert.ifError(err);
102
+ assert.equal(users.length, 4, 'Expecting 4 "users", but actually got '+users.length+': '+require('util').inspect(users, false, null));
103
+ assert.equal(users[0].first_name, 'test_0' );
104
+ done();
105
+ });
106
+ });
107
+ });
108
+
109
+ });
110
+ });
@@ -0,0 +1,50 @@
1
+ var assert = require('assert'),
2
+ _ = require('lodash');
3
+
4
+ describe('Semantic Interface', function() {
5
+
6
+ describe('.createEach()', function() {
7
+
8
+ /////////////////////////////////////////////////////
9
+ // TEST METHODS
10
+ ////////////////////////////////////////////////////
11
+
12
+ it('should create a set of users', function(done) {
13
+ var usersArray = [
14
+ { first_name: 'createEach_1', type: 'createEach' },
15
+ { first_name: 'createEach_2', type: 'createEach' }
16
+ ];
17
+
18
+ Semantic.User.createEach(usersArray, function(err, users) {
19
+ assert.ifError(err);
20
+ assert(Array.isArray(users));
21
+ assert.strictEqual(users.length, 2);
22
+ done();
23
+ });
24
+ });
25
+
26
+ it('should insert 2 records verififed by find', function(done) {
27
+ Semantic.User.find({ type: 'createEach' }, function(err, users) {
28
+ assert.ifError(err);
29
+ assert.strictEqual(users.length, 2);
30
+ done();
31
+ });
32
+ });
33
+
34
+ it('should return model instances', function(done) {
35
+ var usersArray = [
36
+ { first_name: 'createEach_3', type: 'createEach' },
37
+ { first_name: 'createEach_4', type: 'createEach' }
38
+ ];
39
+
40
+ Semantic.User.createEach(usersArray, function(err, users) {
41
+ assert(users[0].id);
42
+ assert.equal(typeof users[0].fullName, 'function');
43
+ assert.equal(toString.call(users[0].createdAt), '[object Date]');
44
+ assert.equal(toString.call(users[0].updatedAt), '[object Date]');
45
+ done();
46
+ });
47
+ });
48
+
49
+ });
50
+ });
@@ -0,0 +1,147 @@
1
+ var assert = require('assert'),
2
+ _ = require('lodash');
3
+
4
+ describe('Semantic Interface', function() {
5
+
6
+ describe('.destroy()', function() {
7
+
8
+ describe('a single record', function() {
9
+
10
+ /////////////////////////////////////////////////////
11
+ // TEST SETUP
12
+ ////////////////////////////////////////////////////
13
+
14
+ before(function(done) {
15
+ Semantic.User.create({ first_name: 'Destroy', last_name: 'Test' }, function(err) {
16
+ if(err) return done(err);
17
+ done();
18
+ });
19
+ });
20
+
21
+ /////////////////////////////////////////////////////
22
+ // TEST METHODS
23
+ ////////////////////////////////////////////////////
24
+
25
+ it('should destroy a record', function(done) {
26
+ Semantic.User.destroy({ first_name: 'Destroy' }, function(err, records) {
27
+ assert.ifError(err);
28
+ assert(Array.isArray(records));
29
+ assert.strictEqual(records.length, 1);
30
+ assert.equal(records[0].first_name, 'Destroy');
31
+ assert.equal(records[0].last_name, 'Test');
32
+ done();
33
+ });
34
+ });
35
+
36
+ it('should return an empty array when searched for', function(done) {
37
+ Semantic.User.find({ first_name: 'Destroy' }, function(err, users) {
38
+ assert.strictEqual(users.length, 0);
39
+ done();
40
+ });
41
+ });
42
+
43
+ });
44
+
45
+ describe('with numeric ID', function() {
46
+
47
+ /////////////////////////////////////////////////////
48
+ // TEST SETUP
49
+ ////////////////////////////////////////////////////
50
+
51
+ var user;
52
+
53
+ // Create a user to test destroy on
54
+ before(function(done) {
55
+ Semantic.User.create({ first_name: 'Destroy', last_name: 'Test' }, function(err, record) {
56
+ if(err) return done(err);
57
+ user = record;
58
+ done();
59
+ });
60
+ });
61
+
62
+ /////////////////////////////////////////////////////
63
+ // TEST METHODS
64
+ ////////////////////////////////////////////////////
65
+
66
+ it('should destroy a record', function(done) {
67
+ Semantic.User.destroy(user.id, function(err, status) {
68
+ assert.ifError(err);
69
+ done();
70
+ });
71
+ });
72
+
73
+ it('should return an empty array when searched for', function(done) {
74
+ Semantic.User.find({ first_name: 'Destroy' }, function(err, users) {
75
+ assert.strictEqual(users.length, 0);
76
+ done();
77
+ });
78
+ });
79
+ });
80
+
81
+ describe('multiple records', function() {
82
+
83
+ /////////////////////////////////////////////////////
84
+ // TEST SETUP
85
+ ////////////////////////////////////////////////////
86
+
87
+ beforeEach(function(done) {
88
+ Semantic.User.createEach([
89
+ { first_name: 'dummy_test' },
90
+ { first_name: 'dummy_test' },
91
+ { first_name: 'dummy_test' }
92
+ ], done);
93
+ });
94
+
95
+ /////////////////////////////////////////////////////
96
+ // TEST METHODS
97
+ ////////////////////////////////////////////////////
98
+
99
+ it('should destroy all the records', function(done) {
100
+ Semantic.User.destroy(function(err, users) {
101
+ assert.ifError(err);
102
+ done();
103
+ });
104
+ });
105
+
106
+ it('should return an empty array when searched for', function(done) {
107
+ Semantic.User.find({ first_name: 'Destroy' }, function(err, users) {
108
+ assert.strictEqual(users.length, 0);
109
+ done();
110
+ });
111
+ });
112
+ });
113
+
114
+ describe('IN query', function() {
115
+
116
+ /////////////////////////////////////////////////////
117
+ // TEST SETUP
118
+ ////////////////////////////////////////////////////
119
+
120
+ beforeEach(function(done) {
121
+ Semantic.User.createEach([
122
+ { first_name: 'dummy_test_in' },
123
+ { first_name: 'dummy_test_in' },
124
+ { first_name: 'dummy_test_in' }
125
+ ], done);
126
+ });
127
+
128
+ /////////////////////////////////////////////////////
129
+ // TEST METHODS
130
+ ////////////////////////////////////////////////////
131
+
132
+ it('should not destroy any records', function(done) {
133
+ Semantic.User.destroy({ id: [] }, function(err, users) {
134
+ assert.ifError(err);
135
+ assert.strictEqual(users.length, 0);
136
+
137
+ Semantic.User.find({ first_name: 'dummy_test_in' }, function(err, users) {
138
+ assert.ifError(err);
139
+ assert.strictEqual(users.length, 3);
140
+ done();
141
+ });
142
+ });
143
+ });
144
+
145
+ });
146
+ });
147
+ });