1
1
/*global assert:true */
2
2
'use strict' ;
3
3
4
- var assert = require ( 'chai' ) . assert ;
5
- assert . equalObjects = function ( a , b , m ) {
6
- assert . deepEqual ( JSON . parse ( JSON . stringify ( a ) ) , JSON . parse ( JSON . stringify ( b ) ) , m || 'Objects should be equal!' ) ;
7
- } ;
4
+ var JSData = require ( 'js-data' ) ;
5
+ var TestRunner = require ( 'js-data-adapter-tests' ) ;
6
+
8
7
var mocha = require ( 'mocha' ) ;
9
8
var coMocha = require ( 'co-mocha' ) ;
9
+
10
10
coMocha ( mocha ) ;
11
- var JSData = require ( 'js-data' ) ;
12
11
JSData . DSUtils . Promise = require ( 'bluebird' ) ;
13
- var DSSqlAdapter = require ( './' ) ;
14
12
15
- var adapter , store , DSUtils , DSErrors , Profile , User , Post , Comment ;
13
+ var DSSqlAdapter = require ( './' ) ;
16
14
17
15
var globals = module . exports = {
18
- fail : function ( msg ) {
19
- assert . equal ( 'should not reach this!: ' + msg , 'failure' ) ;
20
- } ,
21
- TYPES_EXCEPT_STRING : [ 123 , 123.123 , null , undefined , { } , [ ] , true , false , function ( ) {
22
- } ] ,
23
- TYPES_EXCEPT_STRING_OR_ARRAY : [ 123 , 123.123 , null , undefined , { } , true , false , function ( ) {
24
- } ] ,
25
- TYPES_EXCEPT_STRING_OR_NUMBER : [ null , undefined , { } , [ ] , true , false , function ( ) {
26
- } ] ,
27
- TYPES_EXCEPT_STRING_OR_OBJECT : [ 123 , 123.123 , null , undefined , [ ] , true , false , function ( ) {
28
- } ] ,
29
- TYPES_EXCEPT_STRING_OR_NUMBER_OBJECT : [ null , undefined , [ ] , true , false , function ( ) {
30
- } ] ,
31
- TYPES_EXCEPT_STRING_OR_ARRAY_OR_NUMBER : [ null , undefined , { } , true , false , function ( ) {
32
- } ] ,
33
- TYPES_EXCEPT_NUMBER : [ 'string' , null , undefined , { } , [ ] , true , false , function ( ) {
34
- } ] ,
35
- TYPES_EXCEPT_OBJECT : [ 'string' , 123 , 123.123 , null , undefined , true , false , function ( ) {
36
- } ] ,
37
- TYPES_EXCEPT_BOOLEAN : [ 'string' , 123 , 123.123 , null , undefined , { } , [ ] , function ( ) {
38
- } ] ,
39
- TYPES_EXCEPT_FUNCTION : [ 'string' , 123 , 123.123 , null , undefined , { } , [ ] , true , false ] ,
40
- assert : assert ,
41
- adapter : undefined ,
16
+ TestRunner : TestRunner ,
17
+ assert : TestRunner . assert ,
42
18
co : require ( 'co' )
43
19
} ;
44
20
@@ -52,91 +28,27 @@ for (var key in globals) {
52
28
}
53
29
test . globals ( testGlobals ) ;
54
30
55
- beforeEach ( function ( ) {
56
- store = new JSData . DS ( {
57
- log : false
58
- } ) ;
59
- adapter = new DSSqlAdapter ( {
60
- client : 'mysql' ,
61
- connection : {
62
- host : process . env . DB_HOST || 'localhost' ,
63
- user : process . env . DB_USER || process . env . C9_USER || 'ubuntu' ,
64
- database : process . env . DB_NAME || ( process . env . C9_USER ? 'c9' : 'circle_test' )
65
- //user: 'root',
66
- //database: 'test'
67
- }
68
- } ) ;
69
- DSUtils = JSData . DSUtils ;
70
- DSErrors = JSData . DSErrors ;
71
- globals . Profile = global . Profile = Profile = store . defineResource ( {
72
- name : 'profile'
73
- } ) ;
74
- globals . User = global . User = User = store . defineResource ( {
75
- name : 'user' ,
76
- relations : {
77
- hasMany : {
78
- post : {
79
- localField : 'posts' ,
80
- foreignKey : 'post'
81
- }
82
- } ,
83
- hasOne : {
84
- profile : {
85
- localField : 'profile' ,
86
- localKey : 'profileId'
87
- }
88
- }
89
- }
90
- } ) ;
91
- globals . Post = global . Post = Post = store . defineResource ( {
92
- name : 'post' ,
93
- relations : {
94
- belongsTo : {
95
- user : {
96
- localField : 'user' ,
97
- localKey : 'userId'
98
- }
99
- } ,
100
- hasMany : {
101
- comment : {
102
- localField : 'comments' ,
103
- foreignKey : 'postId'
104
- }
105
- }
106
- }
107
- } ) ;
108
- globals . Comment = global . Comment = Comment = store . defineResource ( {
109
- name : 'comment' ,
110
- relations : {
111
- belongsTo : {
112
- post : {
113
- localField : 'post' ,
114
- localKey : 'postId'
115
- } ,
116
- user : {
117
- localField : 'user' ,
118
- localKey : 'userId'
119
- }
120
- }
121
- }
122
- } ) ;
123
-
124
- globals . adapter = adapter ;
125
- global . adapter = globals . adapter ;
126
-
127
- globals . DSUtils = DSUtils ;
128
- global . DSUtils = globals . DSUtils ;
31
+ var config = {
32
+ client : 'mysql' ,
33
+ connection : {
34
+ host : process . env . DB_HOST || 'localhost' ,
35
+ user : process . env . DB_USER || process . env . C9_USER || 'ubuntu' ,
36
+ database : process . env . DB_NAME || ( process . env . C9_USER ? 'c9' : 'circle_test' )
37
+ }
38
+ } ;
129
39
130
- globals . DSErrors = DSErrors ;
131
- global . DSErrors = globals . DSErrors ;
40
+ TestRunner . init ( {
41
+ DS : JSData . DS ,
42
+ Adapter : DSSqlAdapter ,
43
+ adapterConfig : config
132
44
} ) ;
133
45
134
- afterEach ( function * ( ) {
135
- globals . adapter = null ;
136
- global . adapter = null ;
137
-
138
- yield adapter . destroyAll ( Comment ) ;
139
- yield adapter . destroyAll ( Post ) ;
140
- yield adapter . destroyAll ( User ) ;
141
- yield adapter . destroyAll ( Profile ) ;
46
+ beforeEach ( function ( ) {
47
+ globals . DSUtils = global . DSUtils = this . $$DSUtils
48
+ globals . DSErrors = global . DSErrors = this . $$DSErrors
49
+ globals . adapter = global . adapter = this . $$adapter
50
+ globals . User = global . User = this . $$User
51
+ globals . Profile = global . Profile = this . $$Profile ;
52
+ globals . Post = global . Post = this . $$Post ;
53
+ globals . Comment = global . Comment = this . $$Comment ;
142
54
} ) ;
0 commit comments