@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.
- package/.eslintignore +1 -0
- package/.eslintrc +35 -0
- package/.travis.yml +32 -0
- package/CHANGELOG.md +24 -0
- package/Dockerfile +7 -0
- package/LICENSE.md +11 -0
- package/README.md +71 -2
- package/docker-compose.yml +32 -0
- package/features/autoIncrement/README.md +37 -0
- package/features/autoIncrement/core/autoIncrement.test.js +151 -0
- package/features/autoIncrement/sequential/autoIncrementSequential.test.js +104 -0
- package/features/autoIncrement/support/autoInc.fixture.js +25 -0
- package/features/compositePrimaryKey/core/compositePrimaryKey.test.js +67 -0
- package/features/compositePrimaryKey/support/fixture.js +24 -0
- package/features/compositeUnique/core/compositeUnique.test.js +67 -0
- package/features/compositeUnique/support/fixture.js +30 -0
- package/features/crossAdapter/core/crossAdapter.js +119 -0
- package/features/crossAdapter/support/bootstrap.js +106 -0
- package/features/sequences/core/sequences.test.js +110 -0
- package/features/sequences/support/mariadb.js +23 -0
- package/features/sequences/support/oracle.js +23 -0
- package/features/sequences/support/postgres.js +23 -0
- package/features/spatial/core/geojson.test.js +68 -0
- package/features/spatial/support/fixtures.js +82 -0
- package/features/spatial/support/models.js +45 -0
- package/features/unique/README.md +18 -0
- package/features/unique/core/unique.test.js +107 -0
- package/features/unique/support/unique.fixture.js +26 -0
- package/interfaces/associations/belongsTo/create.js +41 -0
- package/interfaces/associations/belongsTo/create.nested.customPK.js +61 -0
- package/interfaces/associations/belongsTo/create.nested.js +52 -0
- package/interfaces/associations/belongsTo/dynamicFinder.js +213 -0
- package/interfaces/associations/belongsTo/find.populate.js +145 -0
- package/interfaces/associations/belongsTo/findOne.populate.js +84 -0
- package/interfaces/associations/belongsTo/modifiers.js +275 -0
- package/interfaces/associations/belongsTo/multipleForeignKeys.js +70 -0
- package/interfaces/associations/belongsTo/update.nested.customPK.js +141 -0
- package/interfaces/associations/belongsTo/update.nested.js +174 -0
- package/interfaces/associations/deep.associations.test.js +437 -0
- package/interfaces/associations/find.associations.test.js +92 -0
- package/interfaces/associations/hasMany/add.js +106 -0
- package/interfaces/associations/hasMany/create.nested.customPK.js +113 -0
- package/interfaces/associations/hasMany/create.nested.js +96 -0
- package/interfaces/associations/hasMany/find.populate.customPK.js +75 -0
- package/interfaces/associations/hasMany/find.populate.js +219 -0
- package/interfaces/associations/hasMany/find.populate.where.js +148 -0
- package/interfaces/associations/hasMany/findOne.populate.js +88 -0
- package/interfaces/associations/hasMany/modifiers.js +560 -0
- package/interfaces/associations/hasMany/multipleForeignKeys.js +113 -0
- package/interfaces/associations/hasMany/remove.js +96 -0
- package/interfaces/associations/hasMany/update.nested.customPK.js +148 -0
- package/interfaces/associations/hasMany/update.nested.js +202 -0
- package/interfaces/associations/manyToMany/add.js +136 -0
- package/interfaces/associations/manyToMany/create.nested.customPK.js +109 -0
- package/interfaces/associations/manyToMany/create.nested.js +96 -0
- package/interfaces/associations/manyToMany/destroy.js +128 -0
- package/interfaces/associations/manyToMany/find.populate.js +109 -0
- package/interfaces/associations/manyToMany/find.populate.where.js +75 -0
- package/interfaces/associations/manyToMany/find.populate.withSchema.js +91 -0
- package/interfaces/associations/manyToMany/findOne.populate.js +86 -0
- package/interfaces/associations/manyToMany/modifiers.js +558 -0
- package/interfaces/associations/manyToMany/remove.js +103 -0
- package/interfaces/associations/manyToMany/update.js +105 -0
- package/interfaces/associations/manyToMany/update.nested.customPK.js +315 -0
- package/interfaces/associations/manyToMany/update.nested.js +355 -0
- package/interfaces/associations/manyToManyThrough/add.js +109 -0
- package/interfaces/associations/manyToManyThrough/create.nested.customPK.js +118 -0
- package/interfaces/associations/manyToManyThrough/create.nested.js +114 -0
- package/interfaces/associations/manyToManyThrough/find.populate.customPK.js +76 -0
- package/interfaces/associations/manyToManyThrough/find.populate.js +120 -0
- package/interfaces/associations/manyToManyThrough/find.populate.where.js +157 -0
- package/interfaces/associations/manyToManyThrough/findOne.populate.js +93 -0
- package/interfaces/associations/manyToManyThrough/modifiers.js +560 -0
- package/interfaces/associations/manyToManyThrough/multipleForeignKeys.js +118 -0
- package/interfaces/associations/manyToManyThrough/remove.js +98 -0
- package/interfaces/associations/manyToManyThrough/update.nested.customPK.js +150 -0
- package/interfaces/associations/manyToManyThrough/update.nested.js +202 -0
- package/interfaces/associations/oneToOne/create.js +41 -0
- package/interfaces/associations/oneToOne/create.nested.customPK.js +61 -0
- package/interfaces/associations/oneToOne/create.nested.js +52 -0
- package/interfaces/associations/oneToOne/dynamicFinder.js +68 -0
- package/interfaces/associations/oneToOne/find.populate.js +127 -0
- package/interfaces/associations/oneToOne/findOne.populate.js +83 -0
- package/interfaces/associations/oneToOne/modifiers.js +275 -0
- package/interfaces/associations/oneToOne/multipleForeignKeys.js +69 -0
- package/interfaces/associations/oneToOne/update.nested.customPK.js +141 -0
- package/interfaces/associations/oneToOne/update.nested.js +174 -0
- package/interfaces/associations/support/bootstrap.js +82 -0
- package/interfaces/associations/support/fixtures/belongsTo.child.customPK.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/belongsTo.child.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/belongsTo.parent.customPK.fixture.js +26 -0
- package/interfaces/associations/support/fixtures/belongsTo.parent.fixture.js +28 -0
- package/interfaces/associations/support/fixtures/crud.fixture.js +53 -0
- package/interfaces/associations/support/fixtures/deep.address.fixture.js +21 -0
- package/interfaces/associations/support/fixtures/deep.breakdown.fixture.js +23 -0
- package/interfaces/associations/support/fixtures/deep.company.fixture.js +29 -0
- package/interfaces/associations/support/fixtures/deep.country.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/deep.departement.fixture.js +24 -0
- package/interfaces/associations/support/fixtures/deep.driver.fixture.js +32 -0
- package/interfaces/associations/support/fixtures/deep.ride.fixture.js +23 -0
- package/interfaces/associations/support/fixtures/deep.seller.fixture.js +33 -0
- package/interfaces/associations/support/fixtures/deep.taxi.fixture.js +36 -0
- package/interfaces/associations/support/fixtures/hasMany.child.fixture.js +33 -0
- package/interfaces/associations/support/fixtures/hasMany.customPK.fixture.js +22 -0
- package/interfaces/associations/support/fixtures/hasMany.parent.fixture.js +28 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.child.customPK.fixture.js +32 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.parent.customPK.fixture.js +23 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.stadium.fixture.js +20 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.team.fixture.js +35 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.through.customPK.fixture.js +18 -0
- package/interfaces/associations/support/fixtures/hasManyThrough.venue.fixture.js +18 -0
- package/interfaces/associations/support/fixtures/manyToMany.driver.customPK.fixture.js +22 -0
- package/interfaces/associations/support/fixtures/manyToMany.driver.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/manyToMany.driver.withSchema.fixture.js +25 -0
- package/interfaces/associations/support/fixtures/manyToMany.taxi.customPK.fixture.js +21 -0
- package/interfaces/associations/support/fixtures/manyToMany.taxi.fixture.js +30 -0
- package/interfaces/associations/support/fixtures/manyToMany.taxi.withSchema.fixture.js +24 -0
- package/interfaces/associations/support/fixtures/multipleAssociations.fixture.js +54 -0
- package/interfaces/associations/support/fixtures/multipleOneToOneAssociations.fixture.js +40 -0
- package/interfaces/associations/support/fixtures/multipleThroughAssociations.fixture.js +79 -0
- package/interfaces/associations/support/fixtures/oneToOne.customPK.fixture.js +47 -0
- package/interfaces/associations/support/fixtures/oneToOne.fixture.js +52 -0
- package/interfaces/associations/support/fixtures.js +41 -0
- package/interfaces/datastore/datastore.test.js +63 -0
- package/interfaces/migratable/definition.test.js +65 -0
- package/interfaces/migratable/migrate.alter.test.js +55 -0
- package/interfaces/migratable/migrate.create.test.js +120 -0
- package/interfaces/migratable/migrate.drop.test.js +47 -0
- package/interfaces/migratable/migrate.safe.test.js +25 -0
- package/interfaces/migratable/schema.test.js +117 -0
- package/interfaces/migratable/support/bootstrap.js +55 -0
- package/interfaces/migratable/support/bootstrapFn.js +54 -0
- package/interfaces/migratable/support/fixtures/alter.fixture.js +12 -0
- package/interfaces/migratable/support/fixtures/create.fixture.js +12 -0
- package/interfaces/migratable/support/fixtures/crud.fixture.js +53 -0
- package/interfaces/migratable/support/fixtures/custom.fixture.js +17 -0
- package/interfaces/migratable/support/fixtures/drop.fixture.js +12 -0
- package/interfaces/migratable/support/fixtures/safe.fixture.js +12 -0
- package/interfaces/migratable/support/fixtures/schema.fixture.js +23 -0
- package/interfaces/queryable/caseInsensitive.test.js +196 -0
- package/interfaces/queryable/count.test.js +51 -0
- package/interfaces/queryable/dynamicFinders.test.js +179 -0
- package/interfaces/queryable/findLike.test.js +34 -0
- package/interfaces/queryable/findOneLike.test.js +28 -0
- package/interfaces/queryable/modifiers/average.modifier.test.js +55 -0
- package/interfaces/queryable/modifiers/contains.modifier.test.js +82 -0
- package/interfaces/queryable/modifiers/endsWith.modifier.test.js +82 -0
- package/interfaces/queryable/modifiers/greaterThan.modifier.test.js +335 -0
- package/interfaces/queryable/modifiers/groupBy.modifier.test.js +123 -0
- package/interfaces/queryable/modifiers/in.modifier.test.js +76 -0
- package/interfaces/queryable/modifiers/lessThan.modifier.test.js +223 -0
- package/interfaces/queryable/modifiers/like.modifier.test.js +50 -0
- package/interfaces/queryable/modifiers/limit.modifier.test.js +60 -0
- package/interfaces/queryable/modifiers/max.modifier.test.js +68 -0
- package/interfaces/queryable/modifiers/min.modifier.test.js +68 -0
- package/interfaces/queryable/modifiers/not.modifier.test.js +80 -0
- package/interfaces/queryable/modifiers/notIn.modifier.test.js +69 -0
- package/interfaces/queryable/modifiers/or.modifier.test.js +142 -0
- package/interfaces/queryable/modifiers/select.modifier.test.js +118 -0
- package/interfaces/queryable/modifiers/skip.modifier.test.js +59 -0
- package/interfaces/queryable/modifiers/sort.modifier.test.js +160 -0
- package/interfaces/queryable/modifiers/startsWith.modifier.test.js +83 -0
- package/interfaces/queryable/modifiers/sum.modifier.test.js +68 -0
- package/interfaces/queryable/support/bootstrap.js +80 -0
- package/interfaces/queryable/support/fixtures/crud.fixture.js +54 -0
- package/interfaces/scalable/README.md +19 -0
- package/interfaces/scalable/crud.test.js +73 -0
- package/interfaces/scalable/queries.test.js +9 -0
- package/interfaces/scalable/support/crud.fixture.js +60 -0
- package/interfaces/semantic/create.test.js +110 -0
- package/interfaces/semantic/createEach.test.js +50 -0
- package/interfaces/semantic/destroy.js +147 -0
- package/interfaces/semantic/find.test.js +91 -0
- package/interfaces/semantic/findOne.test.js +60 -0
- package/interfaces/semantic/findOrCreate.test.js +91 -0
- package/interfaces/semantic/findOrCreateEach.test.js +75 -0
- package/interfaces/semantic/support/bootstrap.js +85 -0
- package/interfaces/semantic/support/fixtures/crud.fixture.js +66 -0
- package/interfaces/semantic/support/fixtures/validations.fixture.js +23 -0
- package/interfaces/semantic/types/array.type.js +28 -0
- package/interfaces/semantic/types/binary.type.js +34 -0
- package/interfaces/semantic/types/boolean.type.js +80 -0
- package/interfaces/semantic/types/date.type.js +53 -0
- package/interfaces/semantic/types/datetime.type.js +48 -0
- package/interfaces/semantic/types/float.type.js +40 -0
- package/interfaces/semantic/types/integer.type.js +40 -0
- package/interfaces/semantic/types/json.type.js +29 -0
- package/interfaces/semantic/types/string.type.js +40 -0
- package/interfaces/semantic/types/text.type.js +34 -0
- package/interfaces/semantic/types/time.type.js +52 -0
- package/interfaces/semantic/update.test.js +157 -0
- package/interfaces/sql/find.test.js +73 -0
- package/interfaces/sql/query.test.js +40 -0
- package/interfaces/sql/support/bootstrap.js +82 -0
- package/interfaces/sql/support/fixtures/crud.fixture.js +57 -0
- package/interfaces/transactable/commit.test.js +438 -0
- package/interfaces/transactable/crossAdapter.test.js +346 -0
- package/interfaces/transactable/deep.test.js +100 -0
- package/interfaces/transactable/rollback.test.js +221 -0
- package/interfaces/transactable/support/bootstrap.js +55 -0
- package/interfaces/transactable/support/bootstrapFn.js +51 -0
- package/interfaces/transactable/support/fixtures/customer.fixture.js +29 -0
- package/interfaces/transactable/support/fixtures/payment.fixture.js +24 -0
- package/interfaces/transactable/support/fixtures/receipt.fixture.js +20 -0
- package/interfaces/transactable/support/fixtures/store.fixture.js +22 -0
- package/interfaces/transactable/support/fixtures/storecustomer.fixture.js +14 -0
- package/lib/index.js +155 -0
- package/lib/utils.js +39 -0
- package/package.json +58 -4
- package/test/integration/README.md +26 -0
- package/test/integration/config/offshore-memory.js +8 -0
- package/test/integration/config/offshore-sql-mariadb.js +15 -0
- package/test/integration/config/offshore-sql-mysql.js +21 -0
- package/test/integration/config/offshore-sql-oracle.js +19 -0
- package/test/integration/config/offshore-sql-postgres.js +27 -0
- package/test/integration/config/offshore-sql-sqlite3.js +19 -0
- package/test/integration/runner.js +83 -0
- package/test/integration/runnerDispatcher.js +163 -0
- package/test/load/README.md +20 -0
- package/test/load/index.js +33 -0
- package/test/load/runner.js +160 -0
- package/test/load/support/bootstrap.js +69 -0
- package/test/load/support/fixtures/pet.js +8 -0
- package/test/load/support/fixtures/user.js +9 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Queryable Interface', function() {
|
|
5
|
+
|
|
6
|
+
/////////////////////////////////////////////////////
|
|
7
|
+
// TEST SETUP
|
|
8
|
+
////////////////////////////////////////////////////
|
|
9
|
+
|
|
10
|
+
var userRecords;
|
|
11
|
+
|
|
12
|
+
before(function(done) {
|
|
13
|
+
var users = [
|
|
14
|
+
{ first_name: 'dynamic finders bar', last_name: 'smith'},
|
|
15
|
+
{ first_name: 'dynamic finders foobar', last_name: 'smith' },
|
|
16
|
+
{ first_name: 'dynamic finders foo', last_name: 'john' }
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
Queryable.User.createEach(users, function(err, users) {
|
|
20
|
+
assert.ifError(err);
|
|
21
|
+
|
|
22
|
+
// Cache user
|
|
23
|
+
userRecords = users;
|
|
24
|
+
done();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('dynamic finders', function() {
|
|
29
|
+
|
|
30
|
+
/////////////////////////////////////////////////////
|
|
31
|
+
// TEST METHODS
|
|
32
|
+
////////////////////////////////////////////////////
|
|
33
|
+
|
|
34
|
+
it('should return customer when the dynamic finder method is used for findOne', function(done) {
|
|
35
|
+
Queryable.User.findOneByFirst_name(userRecords[0].first_name)
|
|
36
|
+
.exec(function(err, user) {
|
|
37
|
+
assert.ifError(err);
|
|
38
|
+
|
|
39
|
+
assert(user);
|
|
40
|
+
assert.equal(user.id, userRecords[0].id);
|
|
41
|
+
|
|
42
|
+
done();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should return customer when the dynamic finder method is used for findOneIn', function(done) {
|
|
47
|
+
Queryable.User.findOneByFirst_nameIn([userRecords[0].first_name, userRecords[1].first_name]).sort('first_name asc')
|
|
48
|
+
.exec(function(err, user) {
|
|
49
|
+
assert.ifError(err);
|
|
50
|
+
|
|
51
|
+
assert(user);
|
|
52
|
+
assert.equal(user.id, userRecords[0].id);
|
|
53
|
+
|
|
54
|
+
done();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should return customer when the dynamic finder method is used for findOneLike', function(done) {
|
|
59
|
+
Queryable.User.findOneByFirst_nameLike('%bar').sort('first_name asc')
|
|
60
|
+
.exec(function(err, user) {
|
|
61
|
+
assert.ifError(err);
|
|
62
|
+
|
|
63
|
+
assert(user);
|
|
64
|
+
assert.equal(user.id, userRecords[0].id);
|
|
65
|
+
|
|
66
|
+
done();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should return customer when the dynamic finder method is used for find', function(done) {
|
|
71
|
+
Queryable.User.findByFirst_name(userRecords[0].first_name)
|
|
72
|
+
.exec(function(err, users) {
|
|
73
|
+
assert.ifError(err);
|
|
74
|
+
|
|
75
|
+
assert.strictEqual(users.length, 1);
|
|
76
|
+
assert.equal(users[0].id, userRecords[0].id);
|
|
77
|
+
|
|
78
|
+
done();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should return customer when the dynamic finder method is used for findIn', function(done) {
|
|
83
|
+
Queryable.User.findByFirst_nameIn([userRecords[0].first_name, userRecords[1].first_name]).sort('first_name asc')
|
|
84
|
+
.exec(function(err, users) {
|
|
85
|
+
assert.ifError(err);
|
|
86
|
+
|
|
87
|
+
assert.strictEqual(users.length, 2);
|
|
88
|
+
assert.equal(users[0].id, userRecords[0].id);
|
|
89
|
+
assert.equal(users[1].id, userRecords[1].id);
|
|
90
|
+
|
|
91
|
+
done();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should return customer when the dynamic finder method is used for findLike', function(done) {
|
|
96
|
+
Queryable.User.findByFirst_nameLike('%bar').sort('first_name asc')
|
|
97
|
+
.exec(function(err, users) {
|
|
98
|
+
assert.ifError(err);
|
|
99
|
+
|
|
100
|
+
assert.strictEqual(users.length, 2);
|
|
101
|
+
assert.equal(users[0].id, userRecords[0].id);
|
|
102
|
+
assert.equal(users[1].id, userRecords[1].id);
|
|
103
|
+
|
|
104
|
+
done();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should return customer when the dynamic finder method is used for count', function(done) {
|
|
109
|
+
Queryable.User.countByLast_name('smith')
|
|
110
|
+
.exec(function(err, userCount) {
|
|
111
|
+
assert.ifError(err);
|
|
112
|
+
|
|
113
|
+
assert.strictEqual(userCount, 2);
|
|
114
|
+
done();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should return customer when the dynamic finder method is used for countIn', function(done) {
|
|
119
|
+
Queryable.User.countByLast_nameIn(['smith', 'john'])
|
|
120
|
+
.exec(function(err, userCount) {
|
|
121
|
+
assert.ifError(err);
|
|
122
|
+
|
|
123
|
+
assert.strictEqual(userCount, 3);
|
|
124
|
+
done();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should return customer when the dynamic finder method is used for countLike', function(done) {
|
|
129
|
+
Queryable.User.countByFirst_nameLike('%bar')
|
|
130
|
+
.exec(function(err, userCount) {
|
|
131
|
+
assert.ifError(err);
|
|
132
|
+
|
|
133
|
+
assert.strictEqual(userCount, 2);
|
|
134
|
+
done();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should return customer when the dynamic finder method is used for startsWith', function(done) {
|
|
139
|
+
Queryable.User.first_nameStartsWith('dynamic').sort('first_name asc')
|
|
140
|
+
.exec(function(err, users) {
|
|
141
|
+
assert.ifError(err);
|
|
142
|
+
|
|
143
|
+
assert.strictEqual(users.length, 3);
|
|
144
|
+
assert.equal(users[0].id, userRecords[0].id);
|
|
145
|
+
assert.equal(users[1].id, userRecords[2].id);
|
|
146
|
+
assert.equal(users[2].id, userRecords[1].id);
|
|
147
|
+
|
|
148
|
+
done();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('should return customer when the dynamic finder method is used for startsWith', function(done) {
|
|
153
|
+
Queryable.User.first_nameContains('bar').sort('first_name asc')
|
|
154
|
+
.exec(function(err, users) {
|
|
155
|
+
assert.ifError(err);
|
|
156
|
+
|
|
157
|
+
assert.strictEqual(users.length, 2);
|
|
158
|
+
assert.equal(users[0].id, userRecords[0].id);
|
|
159
|
+
assert.equal(users[1].id, userRecords[1].id);
|
|
160
|
+
|
|
161
|
+
done();
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('should return customer when the dynamic finder method is used for startsWith', function(done) {
|
|
166
|
+
Queryable.User.first_nameEndsWith('bar').sort('first_name asc')
|
|
167
|
+
.exec(function(err, users) {
|
|
168
|
+
assert.ifError(err);
|
|
169
|
+
|
|
170
|
+
assert.strictEqual(users.length, 2);
|
|
171
|
+
assert.equal(users[0].id, userRecords[0].id);
|
|
172
|
+
assert.equal(users[1].id, userRecords[1].id);
|
|
173
|
+
|
|
174
|
+
done();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
});
|
|
179
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var util = require('util');
|
|
3
|
+
var _ = require('lodash');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describe('Queryable Interface', function() {
|
|
7
|
+
|
|
8
|
+
describe('.findLike()', function() {
|
|
9
|
+
|
|
10
|
+
/////////////////////////////////////////////////////
|
|
11
|
+
// TEST METHODS
|
|
12
|
+
////////////////////////////////////////////////////
|
|
13
|
+
|
|
14
|
+
it('should return all the users with the given name', function(done) {
|
|
15
|
+
var part = '%findLike%',
|
|
16
|
+
testName = 'zz 340ajsdha test_findLike -- aw40gasdha',
|
|
17
|
+
testName2 = 'zz zzbjfk test_findLike2../haer-h';
|
|
18
|
+
|
|
19
|
+
Queryable.User.createEach([{ first_name: testName }, { first_name: testName2 }], function(err) {
|
|
20
|
+
if (err) return done(err);
|
|
21
|
+
|
|
22
|
+
Queryable.User.findLike({ first_name: part }, function(err, users) {
|
|
23
|
+
assert.ifError(err);
|
|
24
|
+
assert(Array.isArray(users));
|
|
25
|
+
assert.strictEqual(users.length, 2, util.format('expected 2 users, but got %s, see?\n%s', users.length, util.inspect(users, false, null) ));
|
|
26
|
+
assert((users[0].first_name === testName && users[1].first_name === testName2) ||
|
|
27
|
+
(users[0].first_name === testName2 && users[1].first_name === testName))
|
|
28
|
+
done();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Queryable Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('.findOneLike()', function() {
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////
|
|
9
|
+
// TEST METHODS
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
it('should return the user with the given name', function(done) {
|
|
13
|
+
var part = '%findOneLike%',
|
|
14
|
+
testName = 'asdgah4 test_findOneLike asg';
|
|
15
|
+
|
|
16
|
+
Queryable.User.create({ first_name: testName }, function(err) {
|
|
17
|
+
if (err) return done(err);
|
|
18
|
+
|
|
19
|
+
Queryable.User.findOneLike({ first_name: part }, function(err, user) {
|
|
20
|
+
assert.ifError(err);
|
|
21
|
+
assert.equal(user.first_name, testName);
|
|
22
|
+
done();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Queryable Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('AVERAGE Query Modifier', function() {
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////
|
|
9
|
+
// TEST SETUP
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
before(function(done) {
|
|
13
|
+
|
|
14
|
+
// Insert 10 Users
|
|
15
|
+
var users = [],
|
|
16
|
+
date;
|
|
17
|
+
|
|
18
|
+
for(var i=0; i<10; i++) {
|
|
19
|
+
users.push({
|
|
20
|
+
first_name: 'average_user' + i,
|
|
21
|
+
type: 'average test',
|
|
22
|
+
age: i,
|
|
23
|
+
percent: i/2
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
Queryable.User.createEach(users, function(err, users) {
|
|
28
|
+
if(err) return done(err);
|
|
29
|
+
done();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/////////////////////////////////////////////////////
|
|
34
|
+
// TEST METHODS
|
|
35
|
+
////////////////////////////////////////////////////
|
|
36
|
+
|
|
37
|
+
it('should average by key and only return that key with the average value', function(done) {
|
|
38
|
+
Queryable.User.find({ where:{type: 'average test'}, average: ['age'] }, function(err, averages) {
|
|
39
|
+
assert(!err,err);
|
|
40
|
+
assert.strictEqual(averages[0].age, 4.5, 'expected averages[0].age to === 4.5, instead averages ==='+require('util').inspect(averages, false, null));
|
|
41
|
+
done();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should average by multiple keys and return averages per key', function(done) {
|
|
46
|
+
Queryable.User.find({ where:{type: 'average test'}, average: ['age', 'percent'] }, function(err, averages) {
|
|
47
|
+
assert(!err,err);
|
|
48
|
+
assert.strictEqual(averages[0].age, 4.5, 'expected averages[0].age to === 4.5, instead averages[0] ==='+require('util').inspect(averages[0], false, null));
|
|
49
|
+
assert.strictEqual(averages[0].percent, 2.25);
|
|
50
|
+
done();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Queryable Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Modifiers', function() {
|
|
7
|
+
describe('contains', function() {
|
|
8
|
+
describe('shorthand', function() {
|
|
9
|
+
|
|
10
|
+
/////////////////////////////////////////////////////
|
|
11
|
+
// TEST METHODS
|
|
12
|
+
////////////////////////////////////////////////////
|
|
13
|
+
|
|
14
|
+
it('should return the user with the correct name', function(done) {
|
|
15
|
+
var part = 'short_xx3ah4aj8xrxh!!!r',
|
|
16
|
+
testName = 'short_xx3ah4aj8xrxh!!!r contains query test';
|
|
17
|
+
|
|
18
|
+
Queryable.User.create({ first_name: testName }, function(err) {
|
|
19
|
+
if(err) return done(err);
|
|
20
|
+
|
|
21
|
+
Queryable.User.contains({ first_name: part }, function(err, users) {
|
|
22
|
+
assert.ifError(err);
|
|
23
|
+
assert(Array.isArray(users));
|
|
24
|
+
assert.equal(users.length, 1);
|
|
25
|
+
assert.equal(users[0].first_name, testName);
|
|
26
|
+
done();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('full where criteria', function() {
|
|
33
|
+
|
|
34
|
+
/////////////////////////////////////////////////////
|
|
35
|
+
// TEST METHODS
|
|
36
|
+
////////////////////////////////////////////////////
|
|
37
|
+
|
|
38
|
+
it('should return the user with the correct name', function(done) {
|
|
39
|
+
var part = 'long_xx3ah4aj8xrxh!!!r',
|
|
40
|
+
testName = 'long_xx3ah4aj8xrxh!!!r contains query test';
|
|
41
|
+
|
|
42
|
+
Queryable.User.create({ first_name: testName }, function(err) {
|
|
43
|
+
if(err) return done(err);
|
|
44
|
+
|
|
45
|
+
Queryable.User.where({ first_name: { contains: part }}, function(err, users) {
|
|
46
|
+
assert.ifError(err);
|
|
47
|
+
assert(Array.isArray(users));
|
|
48
|
+
assert.equal(users.length, 1);
|
|
49
|
+
assert.equal(users[0].first_name, testName);
|
|
50
|
+
done();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('dynamic attribute', function() {
|
|
57
|
+
|
|
58
|
+
/////////////////////////////////////////////////////
|
|
59
|
+
// TEST METHODS
|
|
60
|
+
////////////////////////////////////////////////////
|
|
61
|
+
|
|
62
|
+
it('should have [attribute]contains() method', function(done) {
|
|
63
|
+
var part = 'xxx',
|
|
64
|
+
testType = 'Dynamic Contains test' + part + 'test';
|
|
65
|
+
|
|
66
|
+
Queryable.User.create({ type: testType }, function(err) {
|
|
67
|
+
if(err) return done(err);
|
|
68
|
+
|
|
69
|
+
Queryable.User.typeContains(part, function(err, users) {
|
|
70
|
+
assert.ifError(err);
|
|
71
|
+
assert(Array.isArray(users));
|
|
72
|
+
assert.equal(users.length, 1);
|
|
73
|
+
assert.equal(users[0].type, testType);
|
|
74
|
+
done();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Queryable Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Modifiers', function() {
|
|
7
|
+
describe('endsWith', function() {
|
|
8
|
+
describe('shorthand', function() {
|
|
9
|
+
|
|
10
|
+
/////////////////////////////////////////////////////
|
|
11
|
+
// TEST METHODS
|
|
12
|
+
////////////////////////////////////////////////////
|
|
13
|
+
|
|
14
|
+
it('should return the user with the correct name', function(done) {
|
|
15
|
+
var part = 'xxj8xa4hPFDH_short',
|
|
16
|
+
testName = 'endsWith query test xxj8xa4hPFDH_short';
|
|
17
|
+
|
|
18
|
+
Queryable.User.create({ first_name: testName }, function(err) {
|
|
19
|
+
if(err) return done(err);
|
|
20
|
+
|
|
21
|
+
Queryable.User.endsWith({ first_name: part }, function(err, users) {
|
|
22
|
+
assert.ifError(err);
|
|
23
|
+
assert(Array.isArray(users));
|
|
24
|
+
assert.equal(users.length, 1);
|
|
25
|
+
assert.equal(users[0].first_name, testName);
|
|
26
|
+
done();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('full where criteria', function() {
|
|
33
|
+
|
|
34
|
+
/////////////////////////////////////////////////////
|
|
35
|
+
// TEST METHODS
|
|
36
|
+
////////////////////////////////////////////////////
|
|
37
|
+
|
|
38
|
+
it('should return the user with the correct name', function(done) {
|
|
39
|
+
var part = 'xxj8xa4hPFDH_long',
|
|
40
|
+
testName = 'endsWith query test xxj8xa4hPFDH_long';
|
|
41
|
+
|
|
42
|
+
Queryable.User.create({ first_name: testName }, function(err) {
|
|
43
|
+
if(err) return done(err);
|
|
44
|
+
|
|
45
|
+
Queryable.User.where({ first_name: { endsWith: part }}, function(err, users) {
|
|
46
|
+
assert.ifError(err);
|
|
47
|
+
assert(Array.isArray(users));
|
|
48
|
+
assert.equal(users.length, 1);
|
|
49
|
+
assert.equal(users[0].first_name, testName);
|
|
50
|
+
done();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('dynamic attribute', function() {
|
|
57
|
+
|
|
58
|
+
/////////////////////////////////////////////////////
|
|
59
|
+
// TEST METHODS
|
|
60
|
+
////////////////////////////////////////////////////
|
|
61
|
+
|
|
62
|
+
it('should have [attribute]EndsWith() method', function(done) {
|
|
63
|
+
var part = 'xxj8xrxh!!!r',
|
|
64
|
+
testType = 'Dynamic EndsWith test' + part;
|
|
65
|
+
|
|
66
|
+
Queryable.User.create({ type: testType }, function(err) {
|
|
67
|
+
if(err) return done(err);
|
|
68
|
+
|
|
69
|
+
Queryable.User.typeEndsWith(part, function(err, users) {
|
|
70
|
+
assert.ifError(err);
|
|
71
|
+
assert(Array.isArray(users));
|
|
72
|
+
assert.equal(users.length, 1);
|
|
73
|
+
assert.equal(users[0].type, testType);
|
|
74
|
+
done();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|