@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,67 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var _ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('compositeUnique feature', function () {
|
|
5
|
+
var Offshore = require(process.env.offshorePath || 'offshore');
|
|
6
|
+
var defaults = { migrate: 'alter' };
|
|
7
|
+
var offshore;
|
|
8
|
+
|
|
9
|
+
var Fixture = require('./../support/fixture.js');
|
|
10
|
+
var Model;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
before(function(done) {
|
|
14
|
+
offshore = new Offshore();
|
|
15
|
+
offshore.loadCollection(Fixture);
|
|
16
|
+
|
|
17
|
+
var connections = { compositeUniqueConnection: _.clone(Connections.test) };
|
|
18
|
+
|
|
19
|
+
Adapter.teardown('compositeUniqueConnection', function adapterTeardown(){
|
|
20
|
+
offshore.initialize({ adapters: { wl_tests: Adapter }, connections: connections, defaults: defaults }, function(err, ontology) {
|
|
21
|
+
if(err) return done(err);
|
|
22
|
+
Model = ontology.collections['compositeunique'];
|
|
23
|
+
done();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
after(function(done) {
|
|
28
|
+
if(!Adapter.hasOwnProperty('drop')) {
|
|
29
|
+
offshore.teardown(done);
|
|
30
|
+
} else {
|
|
31
|
+
Model.drop(function(err1) {
|
|
32
|
+
offshore.teardown(function(err2) {
|
|
33
|
+
return done(err1 || err2);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should insert unique values', function (done) {
|
|
40
|
+
var records = [
|
|
41
|
+
{ name: '1st', uniqueOne: 'foo', uniqueTwo: 'bar' },
|
|
42
|
+
{ name: '2nd', uniqueOne: 'foo', uniqueTwo: 'baz' },
|
|
43
|
+
{ name: '3rd', uniqueOne: 'bar', uniqueTwo: 'bar' },
|
|
44
|
+
{ name: '4th', uniqueOne: 'bar', uniqueTwo: 'baz' }
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
Model.create(records)
|
|
48
|
+
.then(function (records) {
|
|
49
|
+
assert(records.length, 4);
|
|
50
|
+
done();
|
|
51
|
+
})
|
|
52
|
+
.catch(done)
|
|
53
|
+
})
|
|
54
|
+
it('should enforce composite uniqueness', function (done) {
|
|
55
|
+
var records = [
|
|
56
|
+
{ name: '5th', uniqueOne: 'foo', uniqueTwo: 'bar' }
|
|
57
|
+
];
|
|
58
|
+
Model.create(records)
|
|
59
|
+
.then(function (records) {
|
|
60
|
+
done(new Error('should not have inserted unique records, but did anyway'));
|
|
61
|
+
})
|
|
62
|
+
.catch(function (err) {
|
|
63
|
+
assert(err)
|
|
64
|
+
done();
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var Offshore = require(process.env.offshorePath || 'offshore');
|
|
2
|
+
|
|
3
|
+
module.exports = Offshore.Collection.extend({
|
|
4
|
+
|
|
5
|
+
identity: 'compositeUnique',
|
|
6
|
+
tableName: 'compositeUniqueTable',
|
|
7
|
+
connection: 'compositeUniqueConnection',
|
|
8
|
+
|
|
9
|
+
attributes: {
|
|
10
|
+
name: {
|
|
11
|
+
type: 'string'
|
|
12
|
+
},
|
|
13
|
+
uniqueOne: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
unique: {
|
|
16
|
+
unique: false,
|
|
17
|
+
composite: [ 'uniqueTwo' ]
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
uniqueTwo: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
unique: {
|
|
24
|
+
unique: false,
|
|
25
|
+
composite: [ 'uniqueOne' ]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multiple Connections tests re-use the Associations interface tests so we need to
|
|
3
|
+
* run them in a separe Mocha runner.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Dependencies
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var Path = require('path');
|
|
11
|
+
var _ = require('lodash');
|
|
12
|
+
var utils = require('../../../lib/utils');
|
|
13
|
+
var mocha = require('mocha');
|
|
14
|
+
var memoryAdapter = require('offshore-memory');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Test Runner
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} options
|
|
20
|
+
* @api public
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
module.exports = CrossAdapter;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function CrossAdapter(options, cb) {
|
|
27
|
+
|
|
28
|
+
this.adapter = options.adapter;
|
|
29
|
+
this.config = options.config || {};
|
|
30
|
+
// The associationTypes must match the folder names in interfaces/associations
|
|
31
|
+
this.associationTypes = ['belongsTo', 'hasMany', 'manyToMany', 'manyToManyThrough', 'oneToOne'];
|
|
32
|
+
|
|
33
|
+
// Attach config to adapter
|
|
34
|
+
// this.adapter.config = this.config;
|
|
35
|
+
global.Connections = {
|
|
36
|
+
'test': this.config,
|
|
37
|
+
'test2': { schema: false }
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
global.Connections.test.adapter = 'wl_tests';
|
|
41
|
+
global.Connections.test2.adapter = 'wl_tests2';
|
|
42
|
+
|
|
43
|
+
// Globalize Adapter
|
|
44
|
+
global.Adapter = this.adapter;
|
|
45
|
+
global.MemoryAdapter = memoryAdapter;
|
|
46
|
+
|
|
47
|
+
// Build an array of files to test
|
|
48
|
+
var filter = '\\.(' + ['js'].join('|') + ')$';
|
|
49
|
+
|
|
50
|
+
var files = [];
|
|
51
|
+
|
|
52
|
+
var bootstrapPath = Path.resolve(__dirname,'../support');
|
|
53
|
+
files = files.concat(utils.fileLookup(bootstrapPath, filter, true));
|
|
54
|
+
|
|
55
|
+
this.associationTypes.forEach(function(type) {
|
|
56
|
+
var interfacePath = Path.resolve(__dirname,'../../../interfaces/associations/' + type);
|
|
57
|
+
files = files.concat(utils.fileLookup(interfacePath, filter, true));
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Build a Mocha Runner
|
|
61
|
+
var test = new mocha(_.merge({
|
|
62
|
+
timeout: 6000
|
|
63
|
+
}, options.mocha||{}));
|
|
64
|
+
|
|
65
|
+
if (options.mochaChainableMethods){
|
|
66
|
+
_.forEach(options.mochaChainableMethods, function(arg, method){
|
|
67
|
+
test[method](arg);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Set Global Placeholders for Ontologies
|
|
72
|
+
global.Associations = {};
|
|
73
|
+
|
|
74
|
+
// Allow Adapter to be a global without warning about a leak
|
|
75
|
+
test.globals([Adapter, MemoryAdapter, Associations]);
|
|
76
|
+
test.files = files;
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
console.info('\nTesting Cross Adapter interface...\n');
|
|
80
|
+
|
|
81
|
+
console.time('time elapsed');
|
|
82
|
+
var runner = test.run(function(err) {
|
|
83
|
+
console.timeEnd('time elapsed');
|
|
84
|
+
cb(err);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
if (options.childProcess) {
|
|
88
|
+
runner.on('pass', function (test) {
|
|
89
|
+
process.send({
|
|
90
|
+
file: test.file,
|
|
91
|
+
title: test.title,
|
|
92
|
+
state: test.state,
|
|
93
|
+
duration: test.duration
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
runner.on('fail', function (test, error) {
|
|
98
|
+
console.error(test.err);
|
|
99
|
+
process.send({
|
|
100
|
+
file: test.file,
|
|
101
|
+
title: test.title,
|
|
102
|
+
state: test.state,
|
|
103
|
+
duration: test.duration,
|
|
104
|
+
err: test.err
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Mocha keeps the test files cached through require, we need to clean them in order to not
|
|
112
|
+
* repeat the tests
|
|
113
|
+
* @param {Object} files
|
|
114
|
+
*/
|
|
115
|
+
CrossAdapter.cleanTestCache = function(files){
|
|
116
|
+
files.forEach(function(val){
|
|
117
|
+
delete require.cache[val];
|
|
118
|
+
});
|
|
119
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module Dependencies
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
var Offshore = require(process.env.offshorePath || 'offshore');
|
|
6
|
+
var _ = require('lodash');
|
|
7
|
+
var asynk = require('asynk');
|
|
8
|
+
|
|
9
|
+
// Require Fixtures
|
|
10
|
+
var fixtures = require('../../../interfaces/associations/support/fixtures');
|
|
11
|
+
|
|
12
|
+
// Divide models connection on `associations` and `associations2` by relations
|
|
13
|
+
var Cnx = {};
|
|
14
|
+
_.keys(fixtures).forEach(function(key) {
|
|
15
|
+
|
|
16
|
+
var fixture = fixtures[key];
|
|
17
|
+
var collectionName = fixture.identity.toLowerCase();
|
|
18
|
+
|
|
19
|
+
_.keys(fixture.attributes).forEach(function(attrKey) {
|
|
20
|
+
if (Cnx[collectionName]) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
var attr = fixtures[key].attributes[attrKey];
|
|
24
|
+
var relation = attr.model || attr.collection;
|
|
25
|
+
if (relation && Cnx[relation.toLowerCase()] === 'associations') {
|
|
26
|
+
Cnx[collectionName] = fixture.connection = 'associations2';
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (!Cnx[collectionName]) {
|
|
31
|
+
Cnx[collectionName] = fixture.connection = 'associations';
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/////////////////////////////////////////////////////
|
|
36
|
+
// TEST SETUP
|
|
37
|
+
////////////////////////////////////////////////////
|
|
38
|
+
|
|
39
|
+
var offshore, ontology;
|
|
40
|
+
|
|
41
|
+
before(function(done) {
|
|
42
|
+
this.timeout(60000);
|
|
43
|
+
offshore = new Offshore();
|
|
44
|
+
|
|
45
|
+
// create all collection and load them
|
|
46
|
+
Object.keys(fixtures).forEach(function(key) {
|
|
47
|
+
var collection = fixtures[key];
|
|
48
|
+
_.keys(collection.attributes).forEach(function(attr) {
|
|
49
|
+
// skip collection
|
|
50
|
+
if (collection.attributes[attr].collection) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// skip functions
|
|
54
|
+
if (_.isFunction(collection.attributes[attr])) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
// add columnName
|
|
58
|
+
collection.attributes[attr].columnName = collection.identity + _.capitalize(attr);
|
|
59
|
+
});
|
|
60
|
+
offshore.loadCollection(Offshore.Collection.extend(collection));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
var connections = { associations: _.clone(Connections.test), associations2: _.clone(Connections.test2) };
|
|
64
|
+
|
|
65
|
+
// in case previous teardown failed
|
|
66
|
+
Adapter.teardown('associations', function adapterTeardown(){
|
|
67
|
+
|
|
68
|
+
offshore.initialize({ adapters: { wl_tests: Adapter, wl_tests2: MemoryAdapter }, connections: connections }, function(err, _ontology) {
|
|
69
|
+
if(err) return done(err);
|
|
70
|
+
|
|
71
|
+
ontology = _ontology;
|
|
72
|
+
|
|
73
|
+
Object.keys(_ontology.collections).forEach(function(key) {
|
|
74
|
+
var globalName = key.charAt(0).toUpperCase() + key.slice(1);
|
|
75
|
+
global.Associations[globalName] = _ontology.collections[key];
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
done();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
after(function(done) {
|
|
85
|
+
this.timeout(60000);
|
|
86
|
+
function dropCollection(item, next) {
|
|
87
|
+
if (!Adapter.hasOwnProperty('drop')) {
|
|
88
|
+
return next();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
ontology.collections[item].drop(function(err) {
|
|
92
|
+
if (err) {
|
|
93
|
+
return next(err);
|
|
94
|
+
}
|
|
95
|
+
next();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
asynk.each(Object.keys(ontology.collections), dropCollection).serie().asCallback(function(err) {
|
|
100
|
+
if (err) {
|
|
101
|
+
return done(err);
|
|
102
|
+
}
|
|
103
|
+
offshore.teardown(done);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
|
|
2
|
+
var assert = require('assert');
|
|
3
|
+
var _ = require('lodash');
|
|
4
|
+
|
|
5
|
+
describe('Sequences feature', function() {
|
|
6
|
+
|
|
7
|
+
var connectionName = 'sequencesTest';
|
|
8
|
+
var sequenceName = 'OFFSHORE_ADAPTER_TEST_SEQ';
|
|
9
|
+
var sequenceCreated = false;
|
|
10
|
+
var sequenceSupport;
|
|
11
|
+
|
|
12
|
+
before(function(done) {
|
|
13
|
+
var connection = _.clone(Connections.test);
|
|
14
|
+
connection.identity = connectionName;
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
sequenceSupport = require('./support/' + connection.dbType);
|
|
18
|
+
} catch (err) {
|
|
19
|
+
return done(new Error(
|
|
20
|
+
'Sequence tests are not configured for ' + connection.dbType
|
|
21
|
+
));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
Adapter.registerConnection(connection, {}, function(err) {
|
|
25
|
+
if (err) return done(err);
|
|
26
|
+
|
|
27
|
+
sequenceSupport.create(
|
|
28
|
+
Adapter,
|
|
29
|
+
connectionName,
|
|
30
|
+
sequenceName,
|
|
31
|
+
function(err) {
|
|
32
|
+
if (err) return done(err);
|
|
33
|
+
|
|
34
|
+
sequenceCreated = true;
|
|
35
|
+
done();
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
after(function(done) {
|
|
42
|
+
function teardown(err) {
|
|
43
|
+
Adapter.teardown(connectionName, function(teardownErr) {
|
|
44
|
+
done(err || teardownErr);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!sequenceCreated) {
|
|
49
|
+
return teardown();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
sequenceSupport.drop(
|
|
53
|
+
Adapter,
|
|
54
|
+
connectionName,
|
|
55
|
+
sequenceName,
|
|
56
|
+
teardown
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('getNextSequence', function() {
|
|
61
|
+
|
|
62
|
+
it('should return the next sequence value', function(done) {
|
|
63
|
+
Adapter.getNextSequence(
|
|
64
|
+
connectionName,
|
|
65
|
+
sequenceName,
|
|
66
|
+
function(err, value) {
|
|
67
|
+
assert.ifError(err);
|
|
68
|
+
assert.strictEqual(typeof value, 'string');
|
|
69
|
+
assert(Number(value) > 0);
|
|
70
|
+
done();
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should return increasing sequence values', function(done) {
|
|
76
|
+
Adapter.getNextSequence(
|
|
77
|
+
connectionName,
|
|
78
|
+
sequenceName,
|
|
79
|
+
function(err, firstValue) {
|
|
80
|
+
if (err) return done(err);
|
|
81
|
+
|
|
82
|
+
Adapter.getNextSequence(
|
|
83
|
+
connectionName,
|
|
84
|
+
sequenceName,
|
|
85
|
+
function(err, secondValue) {
|
|
86
|
+
if (err) return done(err);
|
|
87
|
+
|
|
88
|
+
assert(Number(secondValue) > Number(firstValue));
|
|
89
|
+
done();
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should return an error for an unknown sequence', function(done) {
|
|
97
|
+
Adapter.getNextSequence(
|
|
98
|
+
connectionName,
|
|
99
|
+
'OFFSHORE_UNKNOWN_SEQUENCE',
|
|
100
|
+
function(err, value) {
|
|
101
|
+
assert(err);
|
|
102
|
+
assert.strictEqual(value, undefined);
|
|
103
|
+
done();
|
|
104
|
+
}
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = {
|
|
3
|
+
|
|
4
|
+
create: function(Adapter, connectionName, sequenceName, cb) {
|
|
5
|
+
Adapter.query(
|
|
6
|
+
connectionName,
|
|
7
|
+
null,
|
|
8
|
+
'CREATE SEQUENCE `' + sequenceName +
|
|
9
|
+
'` START WITH 1 INCREMENT BY 1',
|
|
10
|
+
cb
|
|
11
|
+
);
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
drop: function(Adapter, connectionName, sequenceName, cb) {
|
|
15
|
+
Adapter.query(
|
|
16
|
+
connectionName,
|
|
17
|
+
null,
|
|
18
|
+
'DROP SEQUENCE `' + sequenceName + '`',
|
|
19
|
+
cb
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = {
|
|
3
|
+
|
|
4
|
+
create: function(Adapter, connectionName, sequenceName, cb) {
|
|
5
|
+
Adapter.query(
|
|
6
|
+
connectionName,
|
|
7
|
+
null,
|
|
8
|
+
'CREATE SEQUENCE "' + sequenceName +
|
|
9
|
+
'" START WITH 1 INCREMENT BY 1',
|
|
10
|
+
cb
|
|
11
|
+
);
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
drop: function(Adapter, connectionName, sequenceName, cb) {
|
|
15
|
+
Adapter.query(
|
|
16
|
+
connectionName,
|
|
17
|
+
null,
|
|
18
|
+
'DROP SEQUENCE "' + sequenceName + '"',
|
|
19
|
+
cb
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
module.exports = {
|
|
3
|
+
|
|
4
|
+
create: function(Adapter, connectionName, sequenceName, cb) {
|
|
5
|
+
Adapter.query(
|
|
6
|
+
connectionName,
|
|
7
|
+
null,
|
|
8
|
+
'CREATE SEQUENCE "' + sequenceName +
|
|
9
|
+
'" START WITH 1 INCREMENT BY 1',
|
|
10
|
+
cb
|
|
11
|
+
);
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
drop: function(Adapter, connectionName, sequenceName, cb) {
|
|
15
|
+
Adapter.query(
|
|
16
|
+
connectionName,
|
|
17
|
+
null,
|
|
18
|
+
'DROP SEQUENCE "' + sequenceName + '"',
|
|
19
|
+
cb
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var assert = require('assert');
|
|
2
|
+
var _ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('spatial feature', function () {
|
|
5
|
+
var Offshore = require(process.env.offshorePath || 'offshore');
|
|
6
|
+
var defaults = { migrate: 'alter' };
|
|
7
|
+
var offshore;
|
|
8
|
+
|
|
9
|
+
var Models = require('../support/models.js');
|
|
10
|
+
var Fixtures = require('../support/fixtures.js');
|
|
11
|
+
var Model;
|
|
12
|
+
|
|
13
|
+
describe('geojson', function () {
|
|
14
|
+
|
|
15
|
+
it('shoud create geometries', function (done) {
|
|
16
|
+
Model.create({
|
|
17
|
+
name: 'pointA',
|
|
18
|
+
prop1: 'foo',
|
|
19
|
+
marker: Fixtures.point
|
|
20
|
+
})
|
|
21
|
+
.then(function (model) {
|
|
22
|
+
assert(_.isObject(model.marker));
|
|
23
|
+
assert.equal(model.marker.type, 'Point');
|
|
24
|
+
assert(model.id);
|
|
25
|
+
|
|
26
|
+
done();
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('should return geojson features if queried normally', function (done) {
|
|
31
|
+
Model.find().then(function (models) {
|
|
32
|
+
assert(models);
|
|
33
|
+
assert(models.length)
|
|
34
|
+
done();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
before(function(done) {
|
|
41
|
+
offshore = new Offshore();
|
|
42
|
+
offshore.loadCollection(Models);
|
|
43
|
+
|
|
44
|
+
var connections = { geoConnection: _.clone(Connections.test) };
|
|
45
|
+
Adapter.teardown('geoConnection', function adapterTeardown(){
|
|
46
|
+
offshore.initialize({ adapters: { wl_tests: Adapter }, connections: connections, defaults: defaults }, function(err, ontology) {
|
|
47
|
+
if(err) return done(err);
|
|
48
|
+
Model = ontology.collections['geomodel'];
|
|
49
|
+
done();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
after(function(done) {
|
|
54
|
+
done()
|
|
55
|
+
if(!Adapter.hasOwnProperty('drop')) {
|
|
56
|
+
offshore.teardown(done);
|
|
57
|
+
done()
|
|
58
|
+
} else {
|
|
59
|
+
Model.drop(function(err1) {
|
|
60
|
+
done()
|
|
61
|
+
offshore.teardown(function(err2) {
|
|
62
|
+
return done(err1 || err2);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
});;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
point: {
|
|
3
|
+
"type": "Feature",
|
|
4
|
+
"properties": {},
|
|
5
|
+
"geometry": {
|
|
6
|
+
"type": "Point",
|
|
7
|
+
"coordinates": [
|
|
8
|
+
-76.29215240478516,
|
|
9
|
+
36.85067669846314
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
shape: {
|
|
15
|
+
"type": "Feature",
|
|
16
|
+
"properties": {},
|
|
17
|
+
"geometry": {
|
|
18
|
+
"type": "Polygon",
|
|
19
|
+
"crs": {
|
|
20
|
+
"type":"name",
|
|
21
|
+
"properties":{
|
|
22
|
+
"name":"EPSG:4326"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"coordinates": [
|
|
26
|
+
[
|
|
27
|
+
[
|
|
28
|
+
-76.2956714630127,
|
|
29
|
+
36.85943312934033
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
-76.3020658493042,
|
|
33
|
+
36.859467466310285
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
-76.29648685455322,
|
|
37
|
+
36.8519473016299
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
-76.29069328308105,
|
|
41
|
+
36.854625801280235
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
-76.29137992858887,
|
|
45
|
+
36.858437350500914
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
-76.2956714630127,
|
|
49
|
+
36.85943312934033
|
|
50
|
+
]
|
|
51
|
+
]
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
line: {
|
|
56
|
+
"type": "Feature",
|
|
57
|
+
"properties": {},
|
|
58
|
+
"geometry": {
|
|
59
|
+
"type": "LineString",
|
|
60
|
+
"crs": {
|
|
61
|
+
"type":"name",
|
|
62
|
+
"properties":{
|
|
63
|
+
"name":"EPSG:4326"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"coordinates": [
|
|
67
|
+
[
|
|
68
|
+
-76.3046407699585,
|
|
69
|
+
36.85438542694001
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
-76.28833293914795,
|
|
73
|
+
36.846555678014376
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
-76.28687381744385,
|
|
77
|
+
36.85325222344018
|
|
78
|
+
]
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var Offshore = require(process.env.offshorePath || 'offshore');
|
|
2
|
+
|
|
3
|
+
module.exports = Offshore.Collection.extend({
|
|
4
|
+
identity: 'geomodel',
|
|
5
|
+
tableName: 'geomodelTable',
|
|
6
|
+
connection: 'geoConnection',
|
|
7
|
+
|
|
8
|
+
attributes: {
|
|
9
|
+
name: {
|
|
10
|
+
type: 'string'
|
|
11
|
+
},
|
|
12
|
+
prop1: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
columnName: 'geomodelProp1'
|
|
15
|
+
},
|
|
16
|
+
marker: {
|
|
17
|
+
type: 'geometry',
|
|
18
|
+
geometry: {
|
|
19
|
+
nativeSrid: 4326,
|
|
20
|
+
wktType: 'POINT'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
line: {
|
|
24
|
+
type: 'geometry',
|
|
25
|
+
geometry: {
|
|
26
|
+
nativeSrid: 4326,
|
|
27
|
+
wktType: 'LINESTRING'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
shape: {
|
|
31
|
+
type: 'geometry',
|
|
32
|
+
geometry: {
|
|
33
|
+
nativeSrid: 4326,
|
|
34
|
+
wktType: 'POLYGON'
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
genericGeometry: {
|
|
38
|
+
type: 'geometry',
|
|
39
|
+
geometry: {
|
|
40
|
+
nativeSrid: 4326,
|
|
41
|
+
wktType: 'GEOMETRY'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|