forked from js-data/js-data-rethinkdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmocha.start.js
126 lines (114 loc) · 3.25 KB
/
mocha.start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*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 mocha = require('mocha');
var coMocha = require('co-mocha');
coMocha(mocha);
var DSRethinkDBAdapter = require('./');
var JSData = require('js-data');
JSData.DSUtils.Promise = require('bluebird');
var adapter, store, DSUtils, DSErrors, User, Post, Comment;
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
};
var test = new mocha();
var testGlobals = [];
for (var key in globals) {
global[key] = globals[key];
testGlobals.push(globals[key]);
}
test.globals(testGlobals);
beforeEach(function () {
store = new JSData.DS({
log: false
});
adapter = new DSRethinkDBAdapter();
DSUtils = JSData.DSUtils;
DSErrors = JSData.DSErrors;
globals.User = global.User = User = store.defineResource({
name: 'user',
relations: {
hasMany: {
post: {
localField: 'posts',
foreignKey: 'userId'
},
comment: {
localField: 'comments',
foreignKey: 'userId'
}
}
}
});
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;
globals.DSErrors = DSErrors;
global.DSErrors = globals.DSErrors;
});
afterEach(function* () {
globals.adapter = null;
global.adapter = null;
yield adapter.destroyAll(Comment);
yield adapter.destroyAll(Post);
yield adapter.destroyAll(User);
});