@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,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module Dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
var bootstrapFn = require('./bootstrapFn');
|
|
6
|
+
var asynk = require('asynk');
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////
|
|
9
|
+
// TEST SETUP
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
var offshore, ontology;
|
|
13
|
+
|
|
14
|
+
before(function(done) {
|
|
15
|
+
|
|
16
|
+
bootstrapFn(function(err, obj) {
|
|
17
|
+
|
|
18
|
+
ontology = obj.ontology;
|
|
19
|
+
offshore = obj.offshore;
|
|
20
|
+
|
|
21
|
+
Object.keys(ontology.collections).forEach(function(key) {
|
|
22
|
+
var globalName = key.charAt(0).toUpperCase() + key.slice(1);
|
|
23
|
+
global.Migratable[globalName] = ontology.collections[key];
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Store the Offshore object as a global so it can be used in the tests
|
|
27
|
+
global.Migratable.offshore = offshore;
|
|
28
|
+
|
|
29
|
+
done();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
after(function(done) {
|
|
34
|
+
|
|
35
|
+
function dropCollection(item, next) {
|
|
36
|
+
if (!Adapter.hasOwnProperty('drop')) {
|
|
37
|
+
return next();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
ontology.collections[item].drop(function(err) {
|
|
41
|
+
if (err) {
|
|
42
|
+
return next(err);
|
|
43
|
+
}
|
|
44
|
+
next();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
asynk.each(Object.keys(ontology.collections), dropCollection).serie().asCallback(function(err) {
|
|
49
|
+
if (err) {
|
|
50
|
+
return done(err);
|
|
51
|
+
}
|
|
52
|
+
offshore.teardown(done);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module Dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
var Offshore = require(process.env.offshorePath || 'offshore');
|
|
6
|
+
var _ = require('lodash');
|
|
7
|
+
|
|
8
|
+
// Require Fixtures
|
|
9
|
+
var fixtures = {
|
|
10
|
+
UserFixture: require('./fixtures/crud.fixture'),
|
|
11
|
+
ProjectFixture: require('./fixtures/schema.fixture'),
|
|
12
|
+
AlterFixture: require('./fixtures/alter.fixture'),
|
|
13
|
+
CreateFixture: require('./fixtures/create.fixture'),
|
|
14
|
+
CustomFixture: require('./fixtures/custom.fixture'),
|
|
15
|
+
DropFixture: require('./fixtures/drop.fixture'),
|
|
16
|
+
SafeFixture: require('./fixtures/safe.fixture')
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
module.exports = function(newFixtures, cb) {
|
|
21
|
+
if(!cb){
|
|
22
|
+
cb = newFixtures;
|
|
23
|
+
newFixtures = undefined;
|
|
24
|
+
}
|
|
25
|
+
newFixtures = newFixtures || {};
|
|
26
|
+
fixtures = _.defaults(newFixtures, fixtures);
|
|
27
|
+
|
|
28
|
+
var offshore = new Offshore();
|
|
29
|
+
|
|
30
|
+
Object.keys(fixtures).forEach(function(key) {
|
|
31
|
+
var collection = fixtures[key];
|
|
32
|
+
_.keys(collection.attributes).forEach(function(attr) {
|
|
33
|
+
// skip collection
|
|
34
|
+
if (collection.attributes[attr].collection) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// skip functions
|
|
38
|
+
if (_.isFunction(collection.attributes[attr])) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
// add columnName
|
|
42
|
+
collection.attributes[attr].columnName = collection.identity + _.capitalize(attr);
|
|
43
|
+
});
|
|
44
|
+
offshore.loadCollection(Offshore.Collection.extend(collection));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
var connections = { migratable: _.clone(Connections.test) };
|
|
48
|
+
|
|
49
|
+
offshore.initialize({ adapters: { wl_tests: Adapter }, connections: connections }, function(err, _ontology) {
|
|
50
|
+
if(err) return cb(err);
|
|
51
|
+
cb(null, { offshore: offshore, ontology: _ontology });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
|
|
3
|
+
identity: 'user',
|
|
4
|
+
connection: 'migratable',
|
|
5
|
+
|
|
6
|
+
attributes: {
|
|
7
|
+
first_name: {
|
|
8
|
+
type: 'string'
|
|
9
|
+
},
|
|
10
|
+
last_name: {
|
|
11
|
+
type: 'string'
|
|
12
|
+
},
|
|
13
|
+
email: {
|
|
14
|
+
type: 'string'
|
|
15
|
+
},
|
|
16
|
+
title: {
|
|
17
|
+
type: 'string'
|
|
18
|
+
},
|
|
19
|
+
phone: {
|
|
20
|
+
type: 'string'
|
|
21
|
+
},
|
|
22
|
+
type: {
|
|
23
|
+
type: 'string'
|
|
24
|
+
},
|
|
25
|
+
favoriteFruit: {
|
|
26
|
+
defaultsTo: 'blueberry',
|
|
27
|
+
type: 'string'
|
|
28
|
+
},
|
|
29
|
+
age: {
|
|
30
|
+
type: 'integer'
|
|
31
|
+
}, // integer field that's not auto-incrementable
|
|
32
|
+
dob: {
|
|
33
|
+
type: 'datetime'
|
|
34
|
+
},
|
|
35
|
+
status: {
|
|
36
|
+
type: 'boolean',
|
|
37
|
+
defaultsTo: false
|
|
38
|
+
},
|
|
39
|
+
percent: {
|
|
40
|
+
type: 'float'
|
|
41
|
+
},
|
|
42
|
+
list: {
|
|
43
|
+
type: 'array'
|
|
44
|
+
},
|
|
45
|
+
obj: {
|
|
46
|
+
type: 'json'
|
|
47
|
+
},
|
|
48
|
+
fullName: function() {
|
|
49
|
+
return this.first_name + ' ' + this.last_name;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
|
|
3
|
+
tableName: 'document',
|
|
4
|
+
connection: 'migratable',
|
|
5
|
+
|
|
6
|
+
attributes: {
|
|
7
|
+
title: {
|
|
8
|
+
type: 'string',
|
|
9
|
+
primaryKey: true
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
number: {
|
|
13
|
+
type: 'integer',
|
|
14
|
+
autoIncrement: true
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
serialNumber: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
unique: true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
};
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Queryable Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('case sensitivity', function() {
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////
|
|
9
|
+
// TEST SETUP
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
before(function(done) {
|
|
13
|
+
|
|
14
|
+
var usersArray = [
|
|
15
|
+
{ first_name: 'tHeTest', type: 'case sensitivity', age : 10 },
|
|
16
|
+
{ first_name: 'thetest', type: 'case sensitivity' , age : 11},
|
|
17
|
+
{ first_name: 'THETEST', type: 'case sensitivity' , age : 12},
|
|
18
|
+
{ first_name: 'tHeOtherTest', type: 'case sensitivity' , age : 13}
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
Queryable.User.createEach(usersArray, function(err, users) {
|
|
22
|
+
if(err) return done(err);
|
|
23
|
+
done();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('.findOne()', function() {
|
|
28
|
+
|
|
29
|
+
/////////////////////////////////////////////////////
|
|
30
|
+
// TEST METHODS
|
|
31
|
+
////////////////////////////////////////////////////
|
|
32
|
+
|
|
33
|
+
it('should work in a case insensitve fashion by default', function(done) {
|
|
34
|
+
Queryable.User.findOne({where:{ first_name: 'theothertest', type: 'case sensitivity'}, sort:{age : 1}}, function(err, user) {
|
|
35
|
+
assert(user.id);
|
|
36
|
+
assert.equal(user.first_name, 'tHeOtherTest');
|
|
37
|
+
assert.equal(toString.call(user.createdAt), '[object Date]');
|
|
38
|
+
assert.equal(toString.call(user.updatedAt), '[object Date]');
|
|
39
|
+
done();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should work with findOneBy*()', function(done) {
|
|
44
|
+
Queryable.User.findOneByFirst_name('theothertest', function(err, user) {
|
|
45
|
+
assert(user.id);
|
|
46
|
+
assert.equal(user.first_name, 'tHeOtherTest');
|
|
47
|
+
assert.equal(toString.call(user.createdAt), '[object Date]');
|
|
48
|
+
assert.equal(toString.call(user.updatedAt), '[object Date]');
|
|
49
|
+
done();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('.find()', function() {
|
|
56
|
+
|
|
57
|
+
/////////////////////////////////////////////////////
|
|
58
|
+
// TEST METHODS
|
|
59
|
+
////////////////////////////////////////////////////
|
|
60
|
+
|
|
61
|
+
it('should work in a case insensitve fashion by default', function(done) {
|
|
62
|
+
Queryable.User.find({where : { first_name: 'thetest', type: 'case sensitivity'}, sort:{age : 1}}, function(err, users) {
|
|
63
|
+
assert.strictEqual(users.length, 3);
|
|
64
|
+
assert(users[0].id);
|
|
65
|
+
assert.equal(users[0].first_name, 'tHeTest');
|
|
66
|
+
done();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should work with findBy*()', function(done) {
|
|
71
|
+
Queryable.User.findByFirst_name('thetest').sort({age : 1}).exec( function(err, users) {
|
|
72
|
+
assert.strictEqual(users.length, 3);
|
|
73
|
+
assert(users[0].id);
|
|
74
|
+
assert.equal(users[0].first_name, 'tHeTest');
|
|
75
|
+
done();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('special classified queries', function() {
|
|
82
|
+
|
|
83
|
+
/////////////////////////////////////////////////////
|
|
84
|
+
// TEST SETUP
|
|
85
|
+
////////////////////////////////////////////////////
|
|
86
|
+
|
|
87
|
+
before(function(done) {
|
|
88
|
+
|
|
89
|
+
var usersArray = [
|
|
90
|
+
{ first_name: 'OTHER THINGS 0', type: 'case sensitivity', age : 10 },
|
|
91
|
+
{ first_name: 'OTHER THINGS 1', type: 'case sensitivity', age : 11 },
|
|
92
|
+
{ first_name: 'AR)H$daxx', type: 'case sensitivity', age : 12 },
|
|
93
|
+
{ first_name: 'AR)H$daxxy', type: 'case sensitivity', age : 13 },
|
|
94
|
+
{ first_name: '0n3 m0r3 est', type: 'case sensitivity', age : 14 }
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
Queryable.User.createEach(usersArray, function(err, users) {
|
|
98
|
+
if(err) return done(err);
|
|
99
|
+
done();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
/////////////////////////////////////////////////////
|
|
104
|
+
// TEST METHODS
|
|
105
|
+
////////////////////////////////////////////////////
|
|
106
|
+
|
|
107
|
+
it('contains should work in a case insensitive fashion by default', function(done) {
|
|
108
|
+
Queryable.User.find({where : { first_name: { contains: 'hete'}, type: 'case sensitivity' },sort:{age : 1}}, function(err, users) {
|
|
109
|
+
assert.strictEqual(users.length, 3);
|
|
110
|
+
assert(users[0].id);
|
|
111
|
+
assert.equal(users[0].first_name, 'tHeTest');
|
|
112
|
+
done();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('startsWith should work in a case insensitive fashion by default', function(done) {
|
|
117
|
+
Queryable.User.find({where : { first_name: { startsWith: 'the'}, type: 'case sensitivity' },sort:{age : 1}}, function(err, users) {
|
|
118
|
+
assert.strictEqual(users.length, 4);
|
|
119
|
+
assert(users[0].id);
|
|
120
|
+
assert.equal(users[0].first_name, 'tHeTest');
|
|
121
|
+
done();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('endsWith should work in a case insensitive fashion by default', function(done) {
|
|
126
|
+
Queryable.User.find({where : { first_name: { endsWith: 'est'}, type: 'case sensitivity' },sort:{age : 1}}, function(err, users) {
|
|
127
|
+
assert.strictEqual(users.length, 5);
|
|
128
|
+
assert(users[0].id);
|
|
129
|
+
assert.equal(users[0].first_name, 'tHeTest');
|
|
130
|
+
done();
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('like should work in a case insensitive fashion by default', function(done) {
|
|
135
|
+
Queryable.User.find({where : { first_name: { like: '%hete%'}, type: 'case sensitivity' },sort:{age : 1}}, function(err, users) {
|
|
136
|
+
assert.strictEqual(users.length, 3);
|
|
137
|
+
assert(users[0].id);
|
|
138
|
+
assert.equal(users[0].first_name, 'tHeTest');
|
|
139
|
+
done();
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('endsWith should actually enforce endswith', function(done) {
|
|
144
|
+
Queryable.User.find({where : { first_name: { endsWith: 'AR)H$daxx'}, type: 'case sensitivity' },sort:{age : 1}}, function(err, users) {
|
|
145
|
+
assert.strictEqual(users.length, 1);
|
|
146
|
+
assert(users[0].id);
|
|
147
|
+
assert.equal(users[0].first_name, 'AR)H$daxx');
|
|
148
|
+
done();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe('special characters', function() {
|
|
155
|
+
|
|
156
|
+
/////////////////////////////////////////////////////
|
|
157
|
+
// TEST SETUP
|
|
158
|
+
////////////////////////////////////////////////////
|
|
159
|
+
|
|
160
|
+
before(function(done) {
|
|
161
|
+
|
|
162
|
+
var usersArray = [
|
|
163
|
+
{ first_name: '****Awesome****', type: 'case sensitivity' }
|
|
164
|
+
];
|
|
165
|
+
|
|
166
|
+
Queryable.User.createEach(usersArray, function(err, users) {
|
|
167
|
+
if(err) return done(err);
|
|
168
|
+
done();
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
/////////////////////////////////////////////////////
|
|
173
|
+
// TEST METHODS
|
|
174
|
+
////////////////////////////////////////////////////
|
|
175
|
+
|
|
176
|
+
it('should escape stars', function(done) {
|
|
177
|
+
Queryable.User.find({ first_name: '****Awesome****', type: 'case sensitivity' }, function(err, users) {
|
|
178
|
+
assert.strictEqual(users.length, 1);
|
|
179
|
+
assert(users[0].id);
|
|
180
|
+
assert.equal(users[0].first_name, '****Awesome****');
|
|
181
|
+
done();
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('contains should work with stars in the name', function(done) {
|
|
186
|
+
Queryable.User.find({ first_name: { contains: '**Awesome**'}, type: 'case sensitivity' }, function(err, users) {
|
|
187
|
+
assert.strictEqual(users.length, 1);
|
|
188
|
+
assert(users[0].id);
|
|
189
|
+
assert.equal(users[0].first_name, '****Awesome****');
|
|
190
|
+
done();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
});
|
|
196
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Queryable Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('count()', function() {
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////
|
|
9
|
+
// TEST SETUP
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
// Start with an known database state to accurately test count
|
|
13
|
+
before(function(done) {
|
|
14
|
+
Queryable.User.destroy(function(err) {
|
|
15
|
+
if(err) return done(err);
|
|
16
|
+
|
|
17
|
+
// Insert 10 Users
|
|
18
|
+
var users = [];
|
|
19
|
+
for(var i=0; i<10; i++) {
|
|
20
|
+
users.push({first_name: 'count_user' + i, type: 'count'});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
Queryable.User.createEach(users, function(err, users) {
|
|
24
|
+
if(err) return done(err);
|
|
25
|
+
done();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/////////////////////////////////////////////////////
|
|
31
|
+
// TEST METHODS
|
|
32
|
+
////////////////////////////////////////////////////
|
|
33
|
+
|
|
34
|
+
it('should accurately count records', function(done) {
|
|
35
|
+
Queryable.User.count({ type: 'count' }, function(err, count) {
|
|
36
|
+
assert.ifError(err);
|
|
37
|
+
assert.strictEqual(count, 10);
|
|
38
|
+
done();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should work with dynamic finders', function(done) {
|
|
43
|
+
Queryable.User.countByType('count', function(err, count) {
|
|
44
|
+
assert.ifError(err);
|
|
45
|
+
assert.strictEqual(count, 10);
|
|
46
|
+
done();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
});
|
|
51
|
+
});
|