@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,142 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Queryable Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('OR Query Modifier', function() {
|
|
7
|
+
|
|
8
|
+
describe('with a record', function() {
|
|
9
|
+
|
|
10
|
+
/////////////////////////////////////////////////////
|
|
11
|
+
// TEST SETUP
|
|
12
|
+
////////////////////////////////////////////////////
|
|
13
|
+
|
|
14
|
+
before(function(done) {
|
|
15
|
+
|
|
16
|
+
// Insert 3 Users
|
|
17
|
+
var users = [];
|
|
18
|
+
|
|
19
|
+
for(var i=0; i<4; i++) {
|
|
20
|
+
users.push({
|
|
21
|
+
first_name: 'OR_user' + i,
|
|
22
|
+
last_name: 'contains_user' + i,
|
|
23
|
+
title: 'contains_title' + i,
|
|
24
|
+
type: 'or test',
|
|
25
|
+
age: i
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Queryable.User.createEach(users, function(err, users) {
|
|
30
|
+
if(err) return done(err);
|
|
31
|
+
done();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/////////////////////////////////////////////////////
|
|
36
|
+
// TEST METHODS
|
|
37
|
+
////////////////////////////////////////////////////
|
|
38
|
+
|
|
39
|
+
it('should return the correct users', function(done) {
|
|
40
|
+
Queryable.User.find({ where: { or: [{ first_name: 'OR_user0' }, { first_name: 'OR_user1' }]}})
|
|
41
|
+
.sort('first_name')
|
|
42
|
+
.exec(function(err, users) {
|
|
43
|
+
if(err) return done(err);
|
|
44
|
+
|
|
45
|
+
assert(Array.isArray(users));
|
|
46
|
+
assert.strictEqual(users.length, 2);
|
|
47
|
+
assert.equal(users[0].first_name, 'OR_user0');
|
|
48
|
+
assert.equal(users[1].first_name, 'OR_user1');
|
|
49
|
+
done();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should return a model instances', function(done) {
|
|
54
|
+
Queryable.User.find({ where: { or: [{ first_name: 'OR_user0' }, { first_name: 'OR_user1' }]}})
|
|
55
|
+
.exec(function(err, users) {
|
|
56
|
+
assert(users[0].id);
|
|
57
|
+
assert.equal(typeof users[0].fullName, 'function');
|
|
58
|
+
assert.equal(toString.call(users[0].createdAt), '[object Date]');
|
|
59
|
+
assert.equal(toString.call(users[0].updatedAt), '[object Date]');
|
|
60
|
+
done();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should work with multi-level criteria options inside the OR criteria', function(done) {
|
|
65
|
+
Queryable.User.find({
|
|
66
|
+
or: [
|
|
67
|
+
{ first_name: { contains: 'user0' }, type: 'or test' },
|
|
68
|
+
{ first_name: { endsWith: 'user1' }, age: { '>': 0 }, type: 'or test' }
|
|
69
|
+
]
|
|
70
|
+
})
|
|
71
|
+
.sort('first_name')
|
|
72
|
+
.exec(function(err, users) {
|
|
73
|
+
if(err) return done(err);
|
|
74
|
+
|
|
75
|
+
assert(Array.isArray(users));
|
|
76
|
+
assert.strictEqual(users.length, 2);
|
|
77
|
+
assert.equal(users[0].first_name, 'OR_user0');
|
|
78
|
+
assert.equal(users[1].first_name, 'OR_user1');
|
|
79
|
+
done();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should work correctly when OR is used with AND', function(done) {
|
|
84
|
+
Queryable.User.find({
|
|
85
|
+
type: 'or test',
|
|
86
|
+
or: [
|
|
87
|
+
{ first_name: { contains: 'user1' } },
|
|
88
|
+
{ first_name: { endsWith: 'user2' } }
|
|
89
|
+
]
|
|
90
|
+
})
|
|
91
|
+
.sort('first_name')
|
|
92
|
+
.exec(function(err, users) {
|
|
93
|
+
if(err) return done(err);
|
|
94
|
+
|
|
95
|
+
assert(Array.isArray(users));
|
|
96
|
+
assert.strictEqual(users.length, 2);
|
|
97
|
+
assert.equal(users[0].first_name, 'OR_user1');
|
|
98
|
+
assert.equal(users[1].first_name, 'OR_user2');
|
|
99
|
+
done();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should work correctly when OR is used with multiple contains modifiers', function(done) {
|
|
104
|
+
Queryable.User.find({
|
|
105
|
+
type: 'or test',
|
|
106
|
+
or: [
|
|
107
|
+
{ first_name: { contains: 'user0' } },
|
|
108
|
+
{ last_name: { contains: 'user1' } },
|
|
109
|
+
{ title: { contains: 'title2' } }
|
|
110
|
+
]
|
|
111
|
+
})
|
|
112
|
+
.sort('first_name')
|
|
113
|
+
.exec(function(err, users) {
|
|
114
|
+
if(err) return done(err);
|
|
115
|
+
|
|
116
|
+
assert(Array.isArray(users));
|
|
117
|
+
assert.strictEqual(users.length, 3);
|
|
118
|
+
assert.equal(users[0].first_name, 'OR_user0');
|
|
119
|
+
assert.equal(users[1].last_name, 'contains_user1');
|
|
120
|
+
assert.equal(users[2].title, 'contains_title2');
|
|
121
|
+
done();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('without a record', function() {
|
|
127
|
+
|
|
128
|
+
/////////////////////////////////////////////////////
|
|
129
|
+
// TEST METHODS
|
|
130
|
+
////////////////////////////////////////////////////
|
|
131
|
+
|
|
132
|
+
it('should return an empty array', function(done) {
|
|
133
|
+
Queryable.User.find({ where: { or: [{ first_name: 'OR_user10' }, { first_name: 'OR_user11' }]}})
|
|
134
|
+
.exec(function(err, users) {
|
|
135
|
+
assert.strictEqual(users.length, 0);
|
|
136
|
+
done();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
function assertNotProperty(obj, prop){
|
|
5
|
+
assert(prop in obj === false, 'property [' + prop + '] should not exist, but it exists and has value: ' + obj[prop]);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
describe('Queryable Interface', function() {
|
|
9
|
+
|
|
10
|
+
describe('SELECT Query Modifier', function() {
|
|
11
|
+
|
|
12
|
+
/////////////////////////////////////////////////////
|
|
13
|
+
// TEST SETUP
|
|
14
|
+
////////////////////////////////////////////////////
|
|
15
|
+
|
|
16
|
+
before(function(done) {
|
|
17
|
+
|
|
18
|
+
// Insert 1 Users
|
|
19
|
+
var users = [];
|
|
20
|
+
for (var i = 0; i < 10; i++) {
|
|
21
|
+
users.push({
|
|
22
|
+
first_name: 'select_user',
|
|
23
|
+
last_name: 'select_name_' + i,
|
|
24
|
+
email: 'select_email',
|
|
25
|
+
title: 'select_title',
|
|
26
|
+
age: 30 + i,
|
|
27
|
+
type: 'select test'
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Queryable.User.create(users, function(err, model) {
|
|
32
|
+
if(err) return done(err);
|
|
33
|
+
done();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/////////////////////////////////////////////////////
|
|
38
|
+
// TEST METHODS
|
|
39
|
+
////////////////////////////////////////////////////
|
|
40
|
+
|
|
41
|
+
it('should return a record with a single field first_name', function(done) {
|
|
42
|
+
Queryable.User.find({ where: { type: 'select test' }, select: ['first_name'], sort: 'age' }, function(err, users) {
|
|
43
|
+
assert.ifError(err);
|
|
44
|
+
var user = users[0];
|
|
45
|
+
assert.equal(user.first_name, 'select_user');
|
|
46
|
+
assertNotProperty(user, 'last_name');
|
|
47
|
+
assertNotProperty(user, 'email');
|
|
48
|
+
assertNotProperty(user, 'title');
|
|
49
|
+
assertNotProperty(user, 'age');
|
|
50
|
+
assertNotProperty(user, 'type');
|
|
51
|
+
assertNotProperty(user, 'dob');
|
|
52
|
+
done();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should return multiples records with a single field first_name', function(done) {
|
|
57
|
+
Queryable.User.find({ where: {}, select: ['first_name'], sort: 'age' }, function(err, users) {
|
|
58
|
+
assert.ifError(err);
|
|
59
|
+
assert(users.length > 1);
|
|
60
|
+
for(var i=0; i<users.length; i++){
|
|
61
|
+
var user = users[i];
|
|
62
|
+
assert('first_name' in user);
|
|
63
|
+
assertNotProperty(user, 'last_name');
|
|
64
|
+
assertNotProperty(user, 'email');
|
|
65
|
+
assertNotProperty(user, 'title');
|
|
66
|
+
assertNotProperty(user, 'age');
|
|
67
|
+
assertNotProperty(user, 'type');
|
|
68
|
+
assertNotProperty(user, 'dob');
|
|
69
|
+
}
|
|
70
|
+
done();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should return a record with a single field first_name (findOne)', function(done) {
|
|
75
|
+
Queryable.User.findOne({ where: { type: 'select test' }, select: ['first_name'] }, function(err, user) {
|
|
76
|
+
assert.ifError(err);
|
|
77
|
+
assert.equal(user.first_name, 'select_user');
|
|
78
|
+
assertNotProperty(user, 'last_name');
|
|
79
|
+
assertNotProperty(user, 'email');
|
|
80
|
+
assertNotProperty(user, 'title');
|
|
81
|
+
assertNotProperty(user, 'age');
|
|
82
|
+
assertNotProperty(user, 'type');
|
|
83
|
+
assertNotProperty(user, 'dob');
|
|
84
|
+
done();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should return a record with multiple fields', function(done) {
|
|
89
|
+
Queryable.User.find({ where: { type: 'select test' }, select: ['first_name', 'age'], sort: 'age' }, function(err, users) {
|
|
90
|
+
assert.ifError(err);
|
|
91
|
+
var user = users[0];
|
|
92
|
+
assert.equal(user.first_name, 'select_user');
|
|
93
|
+
assertNotProperty(user, 'last_name');
|
|
94
|
+
assertNotProperty(user, 'email');
|
|
95
|
+
assertNotProperty(user, 'title');
|
|
96
|
+
assert.strictEqual(user.age, 30);
|
|
97
|
+
assertNotProperty(user, 'type');
|
|
98
|
+
assertNotProperty(user, 'dob');
|
|
99
|
+
done();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('in absence of SELECT modifier should return a record with all fields', function(done) {
|
|
104
|
+
Queryable.User.find({ where: { type: 'select test' }, sort: 'age' }, function(err, users) {
|
|
105
|
+
assert.ifError(err);
|
|
106
|
+
var user = users[0];
|
|
107
|
+
assert.equal(user.first_name, 'select_user');
|
|
108
|
+
assert.equal(user.last_name, 'select_name_0');
|
|
109
|
+
assert.equal(user.email, 'select_email');
|
|
110
|
+
assert.equal(user.title, 'select_title');
|
|
111
|
+
assert.strictEqual(user.age, 30);
|
|
112
|
+
assert.equal(user.type, 'select test');
|
|
113
|
+
done();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Queryable Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('SKIP Query Modifier', function() {
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////
|
|
9
|
+
// TEST SETUP
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
before(function(done) {
|
|
13
|
+
|
|
14
|
+
// Insert 10 Users
|
|
15
|
+
var users = [];
|
|
16
|
+
|
|
17
|
+
for(var i=0; i<10; i++) {
|
|
18
|
+
users.push({first_name: 'skip_user' + i, type: 'skip test'});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Queryable.User.createEach(users, function(err, users) {
|
|
22
|
+
if(err) return done(err);
|
|
23
|
+
done();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/////////////////////////////////////////////////////
|
|
28
|
+
// TEST METHODS
|
|
29
|
+
////////////////////////////////////////////////////
|
|
30
|
+
|
|
31
|
+
it('should return the correct amount of records', function(done) {
|
|
32
|
+
Queryable.User.find({ where: { type: 'skip test' }, skip: 3 }, function(err, users) {
|
|
33
|
+
assert.ifError(err);
|
|
34
|
+
assert(Array.isArray(users));
|
|
35
|
+
assert.strictEqual(users.length, 7);
|
|
36
|
+
done();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('dynamic finder usage should return the correct amount of records', function(done) {
|
|
41
|
+
Queryable.User.findByType('skip test', { skip: 3 }, function(err, users) {
|
|
42
|
+
assert.ifError(err);
|
|
43
|
+
assert(Array.isArray(users));
|
|
44
|
+
assert.strictEqual(users.length, 7);
|
|
45
|
+
done();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('as an option should return correct amount of records', function(done) {
|
|
50
|
+
Queryable.User.find({ where: { type: 'skip test' } }, { skip: 3 }, function(err, users) {
|
|
51
|
+
assert.ifError(err);
|
|
52
|
+
assert(Array.isArray(users));
|
|
53
|
+
assert.strictEqual(users.length, 7);
|
|
54
|
+
done();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Queryable Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('SORT 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
|
+
date = new Date();
|
|
20
|
+
date.setDate(date.getDate() + i);
|
|
21
|
+
|
|
22
|
+
users.push({
|
|
23
|
+
first_name: 'sort_user' + i,
|
|
24
|
+
type: 'sort test',
|
|
25
|
+
dob: date
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Queryable.User.createEach(users, function(err, users) {
|
|
30
|
+
if(err) return done(err);
|
|
31
|
+
done();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/////////////////////////////////////////////////////
|
|
36
|
+
// TEST METHODS
|
|
37
|
+
////////////////////////////////////////////////////
|
|
38
|
+
|
|
39
|
+
it('should sort records using binary notation for asc', function(done) {
|
|
40
|
+
Queryable.User.find({ where: { type: 'sort test' }, sort: { dob: 1 } }, function(err, users) {
|
|
41
|
+
assert.ifError(err);
|
|
42
|
+
assert.strictEqual(users.length, 10);
|
|
43
|
+
assert.equal(users[0].first_name, 'sort_user0');
|
|
44
|
+
done();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should sort records using binary notation desc', function(done) {
|
|
49
|
+
Queryable.User.find({ where: { type: 'sort test' }, sort: { dob: 0 } }, function(err, users) {
|
|
50
|
+
assert.ifError(err);
|
|
51
|
+
assert.strictEqual(users.length, 10);
|
|
52
|
+
assert.equal(users[0].first_name, 'sort_user9');
|
|
53
|
+
done();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should sort records using string notation for asc', function(done) {
|
|
58
|
+
Queryable.User.find({ where: { type: 'sort test' }, sort: 'dob asc' }, function(err, users) {
|
|
59
|
+
assert.ifError(err);
|
|
60
|
+
assert.strictEqual(users.length, 10);
|
|
61
|
+
assert.equal(users[0].first_name, 'sort_user0');
|
|
62
|
+
done();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should sort records using string notation for desc', function(done) {
|
|
67
|
+
Queryable.User.find({ where: { type: 'sort test' }, sort: 'dob desc' }, function(err, users) {
|
|
68
|
+
assert.ifError(err);
|
|
69
|
+
assert.strictEqual(users.length, 10);
|
|
70
|
+
assert.equal(users[0].first_name, 'sort_user9');
|
|
71
|
+
done();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should sort when sort is an option', function(done) {
|
|
76
|
+
Queryable.User.find({ where: { type: 'sort test' } }, { sort: { dob: 0 } }, function(err, users) {
|
|
77
|
+
assert.ifError(err);
|
|
78
|
+
assert.strictEqual(users.length, 10);
|
|
79
|
+
assert.equal(users[0].first_name, 'sort_user9');
|
|
80
|
+
done();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
describe('Multiple SORT criteria searches', function() {
|
|
88
|
+
|
|
89
|
+
/////////////////////////////////////////////////////
|
|
90
|
+
// TEST SETUP
|
|
91
|
+
////////////////////////////////////////////////////
|
|
92
|
+
|
|
93
|
+
before(function(done) {
|
|
94
|
+
|
|
95
|
+
// Insert 3 Users
|
|
96
|
+
var users = [
|
|
97
|
+
|
|
98
|
+
{ first_name: 'foo', last_name: 'smith', type: 'sort test multi' },
|
|
99
|
+
{ first_name: 'joe', last_name: 'smith', type: 'sort test multi' },
|
|
100
|
+
{ first_name: 'bob', last_name: 'foo', type: 'sort test multi' }
|
|
101
|
+
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
Queryable.User.createEach(users, function(err, users) {
|
|
105
|
+
if(err) return done(err);
|
|
106
|
+
done();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/////////////////////////////////////////////////////
|
|
111
|
+
// TEST METHODS
|
|
112
|
+
////////////////////////////////////////////////////
|
|
113
|
+
|
|
114
|
+
it('should sort records using multiple sort criteria, with first name desc', function(done) {
|
|
115
|
+
Queryable.User.find({ where: { type: 'sort test multi' }, sort: { last_name: 1, first_name: 0 } }, function(err, users) {
|
|
116
|
+
assert.ifError(err);
|
|
117
|
+
|
|
118
|
+
// check the smith's are together and ordered by first_name
|
|
119
|
+
assert.equal(users[0].first_name, 'bob');
|
|
120
|
+
assert.equal(users[1].last_name, 'smith');
|
|
121
|
+
assert.equal(users[2].last_name, 'smith');
|
|
122
|
+
|
|
123
|
+
assert.equal(users[1].first_name, 'joe');
|
|
124
|
+
assert.equal(users[2].first_name, 'foo');
|
|
125
|
+
done();
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should sort records using multiple sort criteria, with first name asc', function(done) {
|
|
130
|
+
Queryable.User.find({ where: { type: 'sort test multi' }, sort: { last_name: 1, first_name: 1 } }, function(err, users) {
|
|
131
|
+
assert.ifError(err);
|
|
132
|
+
|
|
133
|
+
// check the smith's are together and ordered by first_name
|
|
134
|
+
assert.equal(users[0].first_name, 'bob');
|
|
135
|
+
assert.equal(users[1].last_name, 'smith');
|
|
136
|
+
assert.equal(users[2].last_name, 'smith');
|
|
137
|
+
|
|
138
|
+
assert.equal(users[1].first_name, 'foo');
|
|
139
|
+
assert.equal(users[2].first_name, 'joe');
|
|
140
|
+
done();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('should sort records using multiple sort criteria (array notation), with first name asc', function(done) {
|
|
145
|
+
Queryable.User.find({ where: { type: 'sort test multi' }, sort: [ 'last_name asc', 'first_name asc'] }, function(err, users) {
|
|
146
|
+
assert.ifError(err);
|
|
147
|
+
|
|
148
|
+
// check the smith's are together and ordered by first_name
|
|
149
|
+
assert.equal(users[0].first_name, 'bob');
|
|
150
|
+
assert.equal(users[1].last_name, 'smith');
|
|
151
|
+
assert.equal(users[2].last_name, 'smith');
|
|
152
|
+
|
|
153
|
+
assert.equal(users[1].first_name, 'foo');
|
|
154
|
+
assert.equal(users[2].first_name, 'joe');
|
|
155
|
+
done();
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
});
|
|
160
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Queryable Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Modifiers', function() {
|
|
7
|
+
describe('startsWith', function() {
|
|
8
|
+
|
|
9
|
+
describe('shorthand', function() {
|
|
10
|
+
|
|
11
|
+
/////////////////////////////////////////////////////
|
|
12
|
+
// TEST METHODS
|
|
13
|
+
////////////////////////////////////////////////////
|
|
14
|
+
|
|
15
|
+
it('should return the user with the correct name', function(done) {
|
|
16
|
+
var part = 'short_xxj8xrxh!!!r',
|
|
17
|
+
testName = 'short_xxj8xrxh!!!r startsWith query test';
|
|
18
|
+
|
|
19
|
+
Queryable.User.create({ first_name: testName }, function(err) {
|
|
20
|
+
if (err) return done(err);
|
|
21
|
+
|
|
22
|
+
Queryable.User.startsWith({ first_name: part }, function(err, users) {
|
|
23
|
+
assert.ifError(err);
|
|
24
|
+
assert(Array.isArray(users));
|
|
25
|
+
assert.equal(users.length, 1);
|
|
26
|
+
assert.equal(users[0].first_name, testName);
|
|
27
|
+
done();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('full where criteria', function() {
|
|
34
|
+
|
|
35
|
+
/////////////////////////////////////////////////////
|
|
36
|
+
// TEST METHODS
|
|
37
|
+
////////////////////////////////////////////////////
|
|
38
|
+
|
|
39
|
+
it('should return the user with the correct name', function(done) {
|
|
40
|
+
var part = 'long_xxj8xrxh!!!r',
|
|
41
|
+
testName = 'long_xxj8xrxh!!!r startsWith query test';
|
|
42
|
+
|
|
43
|
+
Queryable.User.create({ first_name: testName }, function(err) {
|
|
44
|
+
if (err) return done(err);
|
|
45
|
+
|
|
46
|
+
Queryable.User.where({ first_name: { startsWith: part }}, function(err, users) {
|
|
47
|
+
assert.ifError(err);
|
|
48
|
+
assert(Array.isArray(users));
|
|
49
|
+
assert.equal(users.length, 1);
|
|
50
|
+
assert.equal(users[0].first_name, testName);
|
|
51
|
+
done();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('dynamic attribute', function() {
|
|
58
|
+
|
|
59
|
+
/////////////////////////////////////////////////////
|
|
60
|
+
// TEST METHODS
|
|
61
|
+
////////////////////////////////////////////////////
|
|
62
|
+
|
|
63
|
+
it('should have [attribute]StartsWith() method', function(done) {
|
|
64
|
+
var part = 'xxj8xrxh!!!r',
|
|
65
|
+
testType = part + 'Dynamic StartsWith test';
|
|
66
|
+
|
|
67
|
+
Queryable.User.create({ type: testType }, function(err) {
|
|
68
|
+
if(err) return done(err);
|
|
69
|
+
|
|
70
|
+
Queryable.User.typeStartsWith(part, function(err, users) {
|
|
71
|
+
assert.ifError(err);
|
|
72
|
+
assert(Array.isArray(users));
|
|
73
|
+
assert.equal(users.length, 1);
|
|
74
|
+
assert.equal(users[0].type, testType);
|
|
75
|
+
done();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Queryable Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('SUM 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: 'sum_user' + i,
|
|
21
|
+
type: 'sum 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 sum by key and only return that key with the sum value', function(done) {
|
|
38
|
+
Queryable.User.find({ where:{type: 'sum test'}, sum: ['age'] }, function(err, summed) {
|
|
39
|
+
assert.ifError(err);
|
|
40
|
+
assert.strictEqual(summed[0].age, 45);
|
|
41
|
+
done();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should sum by multiple keys and return sums of all keys', function(done) {
|
|
46
|
+
Queryable.User.find({ where:{type: 'sum test'}, sum: ['age', 'percent'] }, function(err, summed) {
|
|
47
|
+
assert.ifError(err);
|
|
48
|
+
assert.strictEqual(summed[0].age, 45);
|
|
49
|
+
assert.strictEqual(summed[0].percent, 22.5);
|
|
50
|
+
done();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should sum and average in the same query', function(done) {
|
|
55
|
+
Queryable.User.find({
|
|
56
|
+
where:{type: 'sum test'},
|
|
57
|
+
sum: ['age'],
|
|
58
|
+
average: ['percent']
|
|
59
|
+
}, function(err, summed) {
|
|
60
|
+
assert.ifError(err);
|
|
61
|
+
assert.strictEqual(summed[0].age, 45);
|
|
62
|
+
assert.strictEqual(summed[0].percent, 2.25);
|
|
63
|
+
done();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
});
|
|
68
|
+
});
|