@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,53 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Semantic Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Date Type', function() {
|
|
7
|
+
describe('with valid data', function() {
|
|
8
|
+
|
|
9
|
+
/////////////////////////////////////////////////////
|
|
10
|
+
// TEST METHODS
|
|
11
|
+
////////////////////////////////////////////////////
|
|
12
|
+
|
|
13
|
+
var dateId;
|
|
14
|
+
var date = new Date(1970,0,1);
|
|
15
|
+
var parsedDate = '1970-0-1';
|
|
16
|
+
|
|
17
|
+
it.skip('should store proper date value', function(done) {
|
|
18
|
+
Semantic.User.create({ birthday: date }, function(err, createdRecord) {
|
|
19
|
+
assert.ifError(err);
|
|
20
|
+
createdDate = createdRecord.birthday.getFullYear() + '-' +
|
|
21
|
+
createdRecord.birthday.getMonth() + '-' +
|
|
22
|
+
createdRecord.birthday.getDate();
|
|
23
|
+
assert.strictEqual(parsedDate, createdDate);
|
|
24
|
+
dateId = createdRecord.id;
|
|
25
|
+
Semantic.User.findOne({id: createdRecord.id}, function (err, record) {
|
|
26
|
+
assert.ifError(err);
|
|
27
|
+
// Convert both dates to unix timestamps
|
|
28
|
+
var resultDate = record.birthday.getFullYear() + '-' +
|
|
29
|
+
record.birthday.getMonth() + '-' +
|
|
30
|
+
record.birthday.getDate();
|
|
31
|
+
assert.strictEqual(parsedDate, resultDate, 'date should correspond');
|
|
32
|
+
done();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it.skip('should find record by date criteria', function(done) {
|
|
38
|
+
var findDate = new Date(3600*1000*5.5);
|
|
39
|
+
|
|
40
|
+
Semantic.User.find({ birthday: findDate }, function (err, record) {
|
|
41
|
+
assert.ifError(err);
|
|
42
|
+
assert.strictEqual(record.length, 1, 'should have 1 result');
|
|
43
|
+
|
|
44
|
+
// Convert both dates to unix timestamps
|
|
45
|
+
var resultDate = Date.parse(new Date(record[0].birthday));
|
|
46
|
+
assert.strictEqual(dateId, record[0].id, 'id should correspond');
|
|
47
|
+
done();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Semantic Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Datetime Type', function() {
|
|
7
|
+
describe('with valid data', function() {
|
|
8
|
+
|
|
9
|
+
/////////////////////////////////////////////////////
|
|
10
|
+
// TEST METHODS
|
|
11
|
+
////////////////////////////////////////////////////
|
|
12
|
+
|
|
13
|
+
var dateId;
|
|
14
|
+
var date = new Date(2010, 10, 05, 10, 03, 40);
|
|
15
|
+
var origDate = date.getTime();
|
|
16
|
+
|
|
17
|
+
it('should store proper datetime value', function(done) {
|
|
18
|
+
Semantic.User.create({ dob: date }, function(err, createdRecord) {
|
|
19
|
+
assert.ifError(err);
|
|
20
|
+
createdDate = createdRecord.dob.getTime();
|
|
21
|
+
assert.strictEqual(origDate, createdDate);
|
|
22
|
+
dateId = createdRecord.id;
|
|
23
|
+
Semantic.User.findOne({id: createdRecord.id}, function (err, record) {
|
|
24
|
+
assert.ifError(err);
|
|
25
|
+
// Convert both dates to unix timestamps
|
|
26
|
+
var resultDate = record.dob.getTime();
|
|
27
|
+
assert.strictEqual(origDate, resultDate, 'datetime should correspond');
|
|
28
|
+
done();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should find record by datetime criteria', function(done) {
|
|
34
|
+
Semantic.User.find({dob: date}, function (err, record) {
|
|
35
|
+
assert.ifError(err);
|
|
36
|
+
assert.strictEqual(record.length, 1, 'should have 1 result');
|
|
37
|
+
|
|
38
|
+
// Convert both dates to unix timestamps
|
|
39
|
+
var resultDate = record[0].dob.getTime();
|
|
40
|
+
assert.strictEqual(dateId, record[0].id, 'id should correspond');
|
|
41
|
+
assert.strictEqual(origDate, resultDate, 'datetime should correspond');
|
|
42
|
+
done();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Semantic Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Float Type', function() {
|
|
7
|
+
describe('with valid data', function() {
|
|
8
|
+
|
|
9
|
+
/////////////////////////////////////////////////////
|
|
10
|
+
// TEST METHODS
|
|
11
|
+
////////////////////////////////////////////////////
|
|
12
|
+
|
|
13
|
+
var floatId;
|
|
14
|
+
|
|
15
|
+
it('should store proper float value', function(done) {
|
|
16
|
+
Semantic.User.create({ percent: 0.001 }, function(err, createdRecord) {
|
|
17
|
+
assert.ifError(err);
|
|
18
|
+
assert.strictEqual(createdRecord.percent, 0.001);
|
|
19
|
+
floatId = createdRecord.id;
|
|
20
|
+
Semantic.User.findOne({id: createdRecord.id}, function(err, record) {
|
|
21
|
+
assert.ifError(err);
|
|
22
|
+
assert.strictEqual(record.percent, 0.001, 'percent should correspond');
|
|
23
|
+
done();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should find record by float criteria', function(done) {
|
|
29
|
+
Semantic.User.find({percent: 0.001}, function(err, record) {
|
|
30
|
+
assert.ifError(err);
|
|
31
|
+
assert.strictEqual(record.length, 1, 'should have 1 result');
|
|
32
|
+
assert.strictEqual(record[0].id, floatId, 'id should correspond');
|
|
33
|
+
assert.strictEqual(record[0].percent, 0.001, 'percent should correspond');
|
|
34
|
+
done();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Semantic Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Integer Type', function() {
|
|
7
|
+
describe('with valid data', function() {
|
|
8
|
+
|
|
9
|
+
/////////////////////////////////////////////////////
|
|
10
|
+
// TEST METHODS
|
|
11
|
+
////////////////////////////////////////////////////
|
|
12
|
+
|
|
13
|
+
var integerId;
|
|
14
|
+
|
|
15
|
+
it('should store proper integer', function(done) {
|
|
16
|
+
Semantic.User.create({ age: 27 }, function (err, createdRecord) {
|
|
17
|
+
assert.ifError(err);
|
|
18
|
+
assert.strictEqual(createdRecord.age, 27);
|
|
19
|
+
integerId = createdRecord.id;
|
|
20
|
+
Semantic.User.findOne({id: createdRecord.id}, function (err, record) {
|
|
21
|
+
assert.ifError(err);
|
|
22
|
+
assert.strictEqual(record.age, 27, 'age should correspond');
|
|
23
|
+
done();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should find record by integer criteria', function(done) {
|
|
29
|
+
Semantic.User.find({age: 27}, function (err, record) {
|
|
30
|
+
assert.ifError(err);
|
|
31
|
+
assert.strictEqual(record.length, 1, 'should have 1 result');
|
|
32
|
+
assert.strictEqual(record[0].id, integerId, 'id should correspond');
|
|
33
|
+
assert.strictEqual(record[0].age, 27, 'age should correspond');
|
|
34
|
+
done();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Semantic Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('JSON Type', function() {
|
|
7
|
+
describe('with valid data', function() {
|
|
8
|
+
|
|
9
|
+
/////////////////////////////////////////////////////
|
|
10
|
+
// TEST METHODS
|
|
11
|
+
////////////////////////////////////////////////////
|
|
12
|
+
|
|
13
|
+
it('should store proper object value', function(done) {
|
|
14
|
+
Semantic.User.create({ obj: {foo: 'bar'} }, function(err, createdRecord) {
|
|
15
|
+
assert.ifError(err);
|
|
16
|
+
assert.strictEqual(createdRecord.obj, Object(createdRecord.obj));
|
|
17
|
+
assert.equal(createdRecord.obj.foo, 'bar');
|
|
18
|
+
Semantic.User.findOne({id: createdRecord.id}, function (err, record) {
|
|
19
|
+
assert.ifError(err);
|
|
20
|
+
assert.strictEqual(record.obj, Object(record.obj));
|
|
21
|
+
assert.equal(record.obj.foo, 'bar');
|
|
22
|
+
done();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Semantic Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('String Type', function() {
|
|
7
|
+
describe('with valid data', function() {
|
|
8
|
+
|
|
9
|
+
/////////////////////////////////////////////////////
|
|
10
|
+
// TEST METHODS
|
|
11
|
+
////////////////////////////////////////////////////
|
|
12
|
+
|
|
13
|
+
var stringId;
|
|
14
|
+
|
|
15
|
+
it('should store proper string value', function(done) {
|
|
16
|
+
Semantic.User.create({ first_name: 'Foo' }, function(err, createdRecord) {
|
|
17
|
+
assert.ifError(err);
|
|
18
|
+
assert.equal(createdRecord.first_name, 'Foo');
|
|
19
|
+
stringId = createdRecord.id;
|
|
20
|
+
Semantic.User.findOne({id: createdRecord.id}, function (err, record) {
|
|
21
|
+
assert.ifError(err);
|
|
22
|
+
assert.equal(record.first_name, 'Foo');
|
|
23
|
+
done();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should find record by string criteria', function(done) {
|
|
29
|
+
Semantic.User.find({first_name: 'Foo'}, function (err, record) {
|
|
30
|
+
assert.ifError(err);
|
|
31
|
+
assert.strictEqual(record.length, 1, 'should have 1 result');
|
|
32
|
+
assert.strictEqual(record[0].id, stringId, 'id should correspond');
|
|
33
|
+
assert.strictEqual(record[0].first_name, 'Foo', 'first_name should correspond');
|
|
34
|
+
done();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Semantic Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Text Type', function() {
|
|
7
|
+
describe('with valid data', function() {
|
|
8
|
+
|
|
9
|
+
/////////////////////////////////////////////////////
|
|
10
|
+
// TEST METHODS
|
|
11
|
+
////////////////////////////////////////////////////
|
|
12
|
+
|
|
13
|
+
var textId;
|
|
14
|
+
var description = 'a';
|
|
15
|
+
for(var i = 0; i < 1000; ++i) {
|
|
16
|
+
description += 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb';
|
|
17
|
+
}
|
|
18
|
+
description += 'c';
|
|
19
|
+
it('should store proper text value', function(done) {
|
|
20
|
+
Semantic.User.create({ description: description }, function(err, createdRecord) {
|
|
21
|
+
assert.ifError(err);
|
|
22
|
+
assert.equal(createdRecord.description, description);
|
|
23
|
+
textId = createdRecord.id;
|
|
24
|
+
Semantic.User.findOne({id: createdRecord.id}, function (err, record) {
|
|
25
|
+
assert.ifError(err);
|
|
26
|
+
assert(record.description === description, 'text should match');
|
|
27
|
+
done();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Semantic Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('Time Type', function() {
|
|
7
|
+
describe('with valid data', function() {
|
|
8
|
+
|
|
9
|
+
/////////////////////////////////////////////////////
|
|
10
|
+
// TEST METHODS
|
|
11
|
+
////////////////////////////////////////////////////
|
|
12
|
+
|
|
13
|
+
var timeId;
|
|
14
|
+
var deliveryTime = new Date();
|
|
15
|
+
var time = deliveryTime.getHours() + ':' + deliveryTime.getMinutes() + ':' + deliveryTime.getSeconds();
|
|
16
|
+
|
|
17
|
+
it.skip('should store proper time value', function(done) {
|
|
18
|
+
Semantic.User.create({ dailyDelivery: deliveryTime }, function(err, createdRecord) {
|
|
19
|
+
assert.ifError(err);
|
|
20
|
+
createdTime = createdRecord.dailyDelivery.getHours() + ':' + createdRecord.dailyDelivery.getMinutes() + ':' + createdRecord.dailyDelivery.getSeconds();
|
|
21
|
+
assert.strictEqual(time, createdTime);
|
|
22
|
+
timeId = createdRecord.id;
|
|
23
|
+
Semantic.User.findOne({id: createdRecord.id}, function (err, record) {
|
|
24
|
+
assert.ifError(err);
|
|
25
|
+
|
|
26
|
+
assert(record);
|
|
27
|
+
assert(_.isDate(record.dailyDelivery), 'should be a date object');
|
|
28
|
+
var resultTime = record.dailyDelivery.getHours() + ':' + record.dailyDelivery.getMinutes() + ':' + record.dailyDelivery.getSeconds();
|
|
29
|
+
assert.strictEqual(time, resultTime, 'time should correspond');
|
|
30
|
+
done();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it.skip('should find record by time criteria', function(done) {
|
|
36
|
+
var findTime = _.clone(deliveryTime);
|
|
37
|
+
//findTime.setFullYear(2000);
|
|
38
|
+
Semantic.User.find({dailyDelivery: findTime}, function (err, record) {
|
|
39
|
+
assert.ifError(err);
|
|
40
|
+
assert.strictEqual(record.length, 1, 'should have 1 result');
|
|
41
|
+
assert(_.isDate(record[0].dailyDelivery), 'should be a date object');
|
|
42
|
+
var resultTime = record[0].dailyDelivery.getHours() + ':' + record[0].dailyDelivery.getMinutes() + ':' + record[0].dailyDelivery.getSeconds();
|
|
43
|
+
assert.strictEqual(timeId, record[0].id, 'id should correspond');
|
|
44
|
+
assert.strictEqual(time, resultTime, 'time should correspond');
|
|
45
|
+
|
|
46
|
+
done();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('Semantic Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('.update()', function() {
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////
|
|
9
|
+
// TEST SETUP
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
before(function(done) {
|
|
13
|
+
|
|
14
|
+
// Wipe database to ensure a clean result set
|
|
15
|
+
Semantic.User.destroy(function(err) {
|
|
16
|
+
if(err) return done(err);
|
|
17
|
+
done();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('attributes', function() {
|
|
23
|
+
|
|
24
|
+
/////////////////////////////////////////////////////
|
|
25
|
+
// TEST SETUP
|
|
26
|
+
////////////////////////////////////////////////////
|
|
27
|
+
|
|
28
|
+
var id, thingId;
|
|
29
|
+
|
|
30
|
+
before(function(done) {
|
|
31
|
+
|
|
32
|
+
// Insert 10 Users
|
|
33
|
+
var users = [];
|
|
34
|
+
|
|
35
|
+
for(var i=0; i<10; i++) {
|
|
36
|
+
users.push({first_name: 'update_user' + i, last_name: 'update', type: 'update'});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Semantic.User.createEach(users, function(err, users) {
|
|
40
|
+
if(err) return done(err);
|
|
41
|
+
id = users[0].id.toString();
|
|
42
|
+
Semantic.Thing.create({ name: 'The Thing', description: 'A thing', age: 10 }, function(err, thing) {
|
|
43
|
+
if(err) return done(err);
|
|
44
|
+
thingId = thing.id;
|
|
45
|
+
done();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/////////////////////////////////////////////////////
|
|
52
|
+
// TEST METHODS
|
|
53
|
+
////////////////////////////////////////////////////
|
|
54
|
+
|
|
55
|
+
it('should update model attributes', function(done) {
|
|
56
|
+
Semantic.User.update({ type: 'update' }, { last_name: 'updated' }, function(err, users) {
|
|
57
|
+
assert.ifError(err);
|
|
58
|
+
assert(Array.isArray(users));
|
|
59
|
+
assert.strictEqual(users.length, 10);
|
|
60
|
+
assert.equal(users[0].last_name, 'updated');
|
|
61
|
+
done();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should return model instances', function(done) {
|
|
66
|
+
Semantic. User.update({ type: 'update' }, { last_name: 'updated again' }).exec(function(err, users) {
|
|
67
|
+
assert.ifError(err);
|
|
68
|
+
assert(users[0].id);
|
|
69
|
+
assert.strictEqual(users[0].first_name.indexOf('update_user'), 0);
|
|
70
|
+
assert.equal(users[0].last_name, 'updated again');
|
|
71
|
+
assert.equal(toString.call(users[0].createdAt), '[object Date]');
|
|
72
|
+
assert.equal(toString.call(users[0].updatedAt), '[object Date]');
|
|
73
|
+
done();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should work with just an ID passed in', function(done) {
|
|
78
|
+
Semantic.User.update(id, { first_name: 'foo' }).sort('first_name').exec(function(err, users) {
|
|
79
|
+
assert.ifError(err);
|
|
80
|
+
assert.equal(users[0].first_name, 'foo');
|
|
81
|
+
done();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should work with an empty object', function(done) {
|
|
86
|
+
Semantic.User.update({}, { type: 'update all' }, function(err, users) {
|
|
87
|
+
assert.ifError(err);
|
|
88
|
+
assert.strictEqual(users.length, 10);
|
|
89
|
+
assert.equal(users[0].type, 'update all');
|
|
90
|
+
done();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should work with null values', function(done) {
|
|
95
|
+
Semantic.User.update(id, { age: null }, function(err, users) {
|
|
96
|
+
assert.ifError(err);
|
|
97
|
+
assert.strictEqual(users[0].age, null);
|
|
98
|
+
done();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should update model attributes without supplying required fields', function(done) {
|
|
103
|
+
Semantic.Thing.update(thingId, { description: 'An updated thing' }, function(err, things) {
|
|
104
|
+
assert.ifError(err);
|
|
105
|
+
assert(Array.isArray(things));
|
|
106
|
+
assert.strictEqual(things.length, 1);
|
|
107
|
+
assert.equal(things[0].id, thingId);
|
|
108
|
+
assert.equal(things[0].description, 'An updated thing');
|
|
109
|
+
done();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('find updated records', function() {
|
|
115
|
+
|
|
116
|
+
/////////////////////////////////////////////////////
|
|
117
|
+
// TEST SETUP
|
|
118
|
+
////////////////////////////////////////////////////
|
|
119
|
+
|
|
120
|
+
before(function(done) {
|
|
121
|
+
|
|
122
|
+
// Insert 2 Users
|
|
123
|
+
var users = [];
|
|
124
|
+
|
|
125
|
+
for(var i=0; i<2; i++) {
|
|
126
|
+
users.push({first_name: 'update_find_user' + i, last_name: 'update', type: 'updateFind'});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
Semantic.User.createEach(users, function(err, users) {
|
|
130
|
+
if(err) return done(err);
|
|
131
|
+
|
|
132
|
+
// Update the 2 users
|
|
133
|
+
Semantic.User.update({ type: 'updateFind' }, { last_name: 'Updated Find' }, function(err) {
|
|
134
|
+
if(err) return done(err);
|
|
135
|
+
done();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
/////////////////////////////////////////////////////
|
|
142
|
+
// TEST METHODS
|
|
143
|
+
////////////////////////////////////////////////////
|
|
144
|
+
|
|
145
|
+
it('should allow the record to be found', function(done) {
|
|
146
|
+
Semantic.User.find({ type: 'updateFind' }, function(err, users) {
|
|
147
|
+
assert.ifError(err);
|
|
148
|
+
assert.strictEqual(users.length, 2);
|
|
149
|
+
assert.equal(users[0].last_name, 'Updated Find');
|
|
150
|
+
assert.equal(users[1].last_name, 'Updated Find');
|
|
151
|
+
done();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
});
|
|
157
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('SQL Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('.find()', 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: 'find_user' + i, type: 'find test', age: i*10 }); // include an integer field
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Sql.User.createEach(users, function(err, users) {
|
|
22
|
+
if(err) return done(err);
|
|
23
|
+
done();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/////////////////////////////////////////////////////
|
|
28
|
+
// TEST METHODS
|
|
29
|
+
////////////////////////////////////////////////////
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
it('should escape attribute names to prevent SQL injection attacks', function(done) {
|
|
33
|
+
Sql.User.find({ type: 'find_test', 'first_name`IS NULL OR 1=1 #': 'whatever' }, function(err, users) {
|
|
34
|
+
assert(err, 'Should have escaped field name and prevented data from being returned (caused an error)');
|
|
35
|
+
assert(!users || !users.length, 'Should have escaped field name and prevented data from being returned');
|
|
36
|
+
done();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should escape values when using startsWith modifier to prevent SQL injection attacks', function(done) {
|
|
41
|
+
var part = '\\\\\\" OR 1=1; -- %_';
|
|
42
|
+
Sql.User.find({ first_name: { startsWith: part }}, function(err, users) {
|
|
43
|
+
assert(!users || !users.length, 'Should have escaped first name and prevented data from being returned');
|
|
44
|
+
done();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should escape values when using endsWith modifier to prevent SQL injection attacks', function(done) {
|
|
49
|
+
var part = '\\\\\\" OR 1=1; -- %_';
|
|
50
|
+
Sql.User.find({ first_name: { endsWith: part }}, function(err, users) {
|
|
51
|
+
assert(!users || !users.length, 'Should have escaped first name and prevented data from being returned');
|
|
52
|
+
done();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should escape values when using contains modifier to prevent SQL injection attacks', function(done) {
|
|
57
|
+
var part = '\\\\\\" OR 1=1; -- %_';
|
|
58
|
+
Sql.User.find({ first_name: { contains: part }}, function(err, users) {
|
|
59
|
+
assert(!users || !users.length, 'Should have escaped first name and prevented data from being returned');
|
|
60
|
+
done();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should escape values when using like modifier to prevent SQL injection attacks', function(done) {
|
|
65
|
+
var part = '\\\\\\" OR 1=1; -- %_';
|
|
66
|
+
Sql.User.find({ first_name: { like: part }}, function(err, users) {
|
|
67
|
+
assert(!users || !users.length, 'Should have escaped first name and prevented data from being returned');
|
|
68
|
+
done();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var assert = require('assert'),
|
|
2
|
+
_ = require('lodash');
|
|
3
|
+
|
|
4
|
+
describe('SQL Interface', function() {
|
|
5
|
+
|
|
6
|
+
describe('.query()', function() {
|
|
7
|
+
|
|
8
|
+
/////////////////////////////////////////////////////
|
|
9
|
+
// TEST SETUP
|
|
10
|
+
////////////////////////////////////////////////////
|
|
11
|
+
|
|
12
|
+
before(function(done) {
|
|
13
|
+
|
|
14
|
+
// Insert 1 User
|
|
15
|
+
Sql.User.create({first_name: 'query_user', type: 'query test', age: 10 }, function(err, user) {
|
|
16
|
+
if(err) return done(err);
|
|
17
|
+
done();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/////////////////////////////////////////////////////
|
|
22
|
+
// TEST METHODS
|
|
23
|
+
////////////////////////////////////////////////////
|
|
24
|
+
|
|
25
|
+
it('should have method .query()', function(done) {
|
|
26
|
+
assert(Sql.User.query);
|
|
27
|
+
assert(_.isFunction(Sql.User.query));
|
|
28
|
+
done();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should return non undefined result', function(done) {
|
|
32
|
+
Sql.User.query('SELECT * FROM usertablesql', undefined, function(err, users) {
|
|
33
|
+
assert.ifError(err);
|
|
34
|
+
assert(users);
|
|
35
|
+
done();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
});
|
|
40
|
+
});
|