Skip to content

Refactored core adapter tests into a re-usable, standalone repo. #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 27 additions & 115 deletions mocha.start.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,20 @@
/*global assert:true */
'use strict';

var assert = require('chai').assert;
assert.equalObjects = function (a, b, m) {
assert.deepEqual(JSON.parse(JSON.stringify(a)), JSON.parse(JSON.stringify(b)), m || 'Objects should be equal!');
};
var JSData = require('js-data');
var TestRunner = require('js-data-adapter-tests');

var mocha = require('mocha');
var coMocha = require('co-mocha');

coMocha(mocha);
var JSData = require('js-data');
JSData.DSUtils.Promise = require('bluebird');
var DSSqlAdapter = require('./');

var adapter, store, DSUtils, DSErrors, Profile, User, Post, Comment;
var DSSqlAdapter = require('./');

var globals = module.exports = {
fail: function (msg) {
assert.equal('should not reach this!: ' + msg, 'failure');
},
TYPES_EXCEPT_STRING: [123, 123.123, null, undefined, {}, [], true, false, function () {
}],
TYPES_EXCEPT_STRING_OR_ARRAY: [123, 123.123, null, undefined, {}, true, false, function () {
}],
TYPES_EXCEPT_STRING_OR_NUMBER: [null, undefined, {}, [], true, false, function () {
}],
TYPES_EXCEPT_STRING_OR_OBJECT: [123, 123.123, null, undefined, [], true, false, function () {
}],
TYPES_EXCEPT_STRING_OR_NUMBER_OBJECT: [null, undefined, [], true, false, function () {
}],
TYPES_EXCEPT_STRING_OR_ARRAY_OR_NUMBER: [null, undefined, {}, true, false, function () {
}],
TYPES_EXCEPT_NUMBER: ['string', null, undefined, {}, [], true, false, function () {
}],
TYPES_EXCEPT_OBJECT: ['string', 123, 123.123, null, undefined, true, false, function () {
}],
TYPES_EXCEPT_BOOLEAN: ['string', 123, 123.123, null, undefined, {}, [], function () {
}],
TYPES_EXCEPT_FUNCTION: ['string', 123, 123.123, null, undefined, {}, [], true, false],
assert: assert,
adapter: undefined,
TestRunner: TestRunner,
assert: TestRunner.assert,
co: require('co')
};

@@ -52,91 +28,27 @@ for (var key in globals) {
}
test.globals(testGlobals);

beforeEach(function () {
store = new JSData.DS({
log: false
});
adapter = new DSSqlAdapter({
client: 'mysql',
connection: {
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || process.env.C9_USER || 'ubuntu',
database: process.env.DB_NAME || (process.env.C9_USER ? 'c9' : 'circle_test')
//user: 'root',
//database: 'test'
}
});
DSUtils = JSData.DSUtils;
DSErrors = JSData.DSErrors;
globals.Profile = global.Profile = Profile = store.defineResource({
name: 'profile'
});
globals.User = global.User = User = store.defineResource({
name: 'user',
relations: {
hasMany: {
post: {
localField: 'posts',
foreignKey: 'post'
}
},
hasOne: {
profile: {
localField: 'profile',
localKey: 'profileId'
}
}
}
});
globals.Post = global.Post = Post = store.defineResource({
name: 'post',
relations: {
belongsTo: {
user: {
localField: 'user',
localKey: 'userId'
}
},
hasMany: {
comment: {
localField: 'comments',
foreignKey: 'postId'
}
}
}
});
globals.Comment = global.Comment = Comment = store.defineResource({
name: 'comment',
relations: {
belongsTo: {
post: {
localField: 'post',
localKey: 'postId'
},
user: {
localField: 'user',
localKey: 'userId'
}
}
}
});

globals.adapter = adapter;
global.adapter = globals.adapter;

globals.DSUtils = DSUtils;
global.DSUtils = globals.DSUtils;
var config = {
client: 'mysql',
connection: {
host: process.env.DB_HOST || 'localhost',
user: process.env.DB_USER || process.env.C9_USER || 'ubuntu',
database: process.env.DB_NAME || (process.env.C9_USER ? 'c9' : 'circle_test')
}
};

globals.DSErrors = DSErrors;
global.DSErrors = globals.DSErrors;
TestRunner.init({
DS: JSData.DS,
Adapter: DSSqlAdapter,
adapterConfig: config
});

afterEach(function* () {
globals.adapter = null;
global.adapter = null;

yield adapter.destroyAll(Comment);
yield adapter.destroyAll(Post);
yield adapter.destroyAll(User);
yield adapter.destroyAll(Profile);
beforeEach(function () {
globals.DSUtils = global.DSUtils = this.$$DSUtils
globals.DSErrors = global.DSErrors = this.$$DSErrors
globals.adapter = global.adapter = this.$$adapter
globals.User = global.User = this.$$User
globals.Profile = global.Profile = this.$$Profile;
globals.Post = global.Post = this.$$Post;
globals.Comment = global.Comment = this.$$Comment;
});
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -30,12 +30,13 @@
"babel-eslint": "4.1.3",
"babel-loader": "5.3.2",
"bluebird": "2.10.2",
"chai": "3.3.0",
"chai": "3.4.1",
"co": "4.6.0",
"co-mocha": "1.1.2",
"codacy-coverage": "1.1.3",
"coveralls": "2.11.4",
"istanbul": "0.4.0",
"js-data-adapter-tests": "~1.x",
"mocha": "2.3.3",
"standard": "5.3.1",
"webpack": "1.12.2"
@@ -55,7 +56,7 @@
"mout": "0.11.0"
},
"peerDependencies": {
"js-data": ">=2.0.0",
"js-data": "~2.x",
"knex": ">=0.7.4"
}
}
23 changes: 0 additions & 23 deletions test/create.spec.js

This file was deleted.

16 changes: 0 additions & 16 deletions test/destroy.spec.js

This file was deleted.

14 changes: 0 additions & 14 deletions test/destroyAll.spec.js

This file was deleted.

83 changes: 0 additions & 83 deletions test/find.spec.js

This file was deleted.

194 changes: 0 additions & 194 deletions test/findAll.spec.js

This file was deleted.

33 changes: 0 additions & 33 deletions test/update.spec.js

This file was deleted.

43 changes: 0 additions & 43 deletions test/updateAll.spec.js

This file was deleted.