Skip to content

Commit 5760fca

Browse files
committed
move from expect to chai library, use gulp for tasks
1 parent 7bff536 commit 5760fca

9 files changed

+332
-381
lines changed

gulpfile.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
var gulp = require('gulp');
4+
var mocha = require('gulp-mocha');
5+
6+
gulp.task('test', function() {
7+
return gulp.src(['tests/*.js'], {read: false})
8+
.pipe(
9+
mocha({
10+
reporter: 'spec',
11+
bail: true
12+
})
13+
);
14+
});

package.json

+28-23
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
{
2-
"name": "json-sql",
3-
"description": "node.js json to sql queries mapper",
4-
"version": "0.2.4",
5-
"author": "Artem Zhukov <[email protected]>",
6-
"repository": {
7-
"type": "git",
8-
"url": "[email protected]:2do2go/json-sql.git"
9-
},
10-
"keywords": [
11-
"json-sql", "json", "sql", "odm", "mapper", "db", "database"
12-
],
13-
"scripts": {
14-
"test": "mocha tests/*.js --reporter spec --bail"
15-
},
16-
"dependencies": {
17-
"underscore": "1.8.2"
18-
},
19-
"devDependencies": {
20-
"mocha": "1.15.1",
21-
"expect.js": "0.2.0"
22-
},
23-
"main": "./lib/index"
24-
}
2+
"name": "json-sql",
3+
"description": "node.js json to sql queries mapper",
4+
"version": "0.2.4",
5+
"author": "Artem Zhukov <[email protected]>",
6+
"repository": {
7+
"type": "git",
8+
"url": "[email protected]:2do2go/json-sql.git"
9+
},
10+
"keywords": [
11+
"json-sql",
12+
"json",
13+
"sql",
14+
"odm",
15+
"mapper",
16+
"db",
17+
"database"
18+
],
19+
"dependencies": {
20+
"underscore": "1.8.2"
21+
},
22+
"devDependencies": {
23+
"chai": "2.2.0",
24+
"gulp": "^3.8.11",
25+
"gulp-mocha": "^2.0.1",
26+
"mocha": "2.2.4"
27+
},
28+
"main": "./lib/index"
29+
}

tests/0_base.js

+48-76
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,38 @@
22

33
var jsonSql = require('../lib')();
44
var Builder = require('../lib').Builder;
5-
var expect = require('expect.js');
5+
var expect = require('chai').expect;
66

77
describe('Builder', function() {
88
it('should have fields', function() {
9-
expect(jsonSql).to.be.ok();
10-
expect(jsonSql).to.be.a(Builder);
9+
expect(jsonSql).to.be.ok;
10+
expect(jsonSql).to.be.an.instanceof(Builder);
1111

12-
expect(jsonSql.dialect).to.be.ok();
12+
expect(jsonSql.dialect).to.be.ok;
1313

14-
expect(jsonSql._query).to.be('');
15-
expect(jsonSql._values).to.eql({});
14+
expect(jsonSql._query).to.be.equal('');
15+
expect(jsonSql._values).to.be.eql({});
1616

17-
expect(jsonSql.dialect.blocks).to.be.ok();
18-
expect(jsonSql.dialect.templates).to.be.ok();
19-
expect(jsonSql.dialect.conditions).to.be.ok();
20-
expect(jsonSql.dialect.modifiers).to.be.ok();
21-
expect(jsonSql.dialect.logicalOperators).to.be.ok();
17+
expect(jsonSql.dialect.blocks).to.be.ok;
18+
expect(jsonSql.dialect.templates).to.be.ok;
19+
expect(jsonSql.dialect.conditions).to.be.ok;
20+
expect(jsonSql.dialect.modifiers).to.be.ok;
21+
expect(jsonSql.dialect.logicalOperators).to.be.ok;
2222
});
2323

2424
it('should throw error with wrong `type` property', function() {
2525
expect(function() {
2626
jsonSql.build({
2727
type: 'wrong'
2828
});
29-
}).to.throwError(function(e) {
30-
expect(e).to.be.a(Error);
31-
expect(e.message).to.be('Unknown template type "wrong"');
32-
});
29+
}).to.throw('Unknown template type "wrong"');
3330
});
3431

3532
it('should throw error without `table`, `query` and `select` properties', function() {
3633
expect(function() {
3734
jsonSql.build({});
38-
}).to.throwError(function(e) {
39-
expect(e).to.be.a(Error);
40-
expect(e.message).to.be('Neither `table`, `query`, `select`, `expression` properties ' +
41-
'are not set in `select` clause');
42-
});
35+
}).to.throw('Neither `table`, `query`, `select`, `expression` properties ' +
36+
'are not set in `select` clause');
4337
});
4438

4539
it('should throw error with both `table` and `select` properties', function() {
@@ -48,10 +42,7 @@ describe('Builder', function() {
4842
table: 'users',
4943
select: {table: 'payments'}
5044
});
51-
}).to.throwError(function(e) {
52-
expect(e).to.be.a(Error);
53-
expect(e.message).to.be('Wrong using `table`, `select` properties together in `select` clause');
54-
});
45+
}).to.throw('Wrong using `table`, `select` properties together in `select` clause');
5546
});
5647

5748
it('should throw error with both `table` and `query` properties', function() {
@@ -60,10 +51,7 @@ describe('Builder', function() {
6051
table: 'users',
6152
query: {table: 'payments'}
6253
});
63-
}).to.throwError(function(e) {
64-
expect(e).to.be.a(Error);
65-
expect(e.message).to.be('Wrong using `table`, `query` properties together in `select` clause');
66-
});
54+
}).to.throw('Wrong using `table`, `query` properties together in `select` clause');
6755
});
6856

6957
it('should throw error with both `query` and `select` properties', function() {
@@ -72,10 +60,7 @@ describe('Builder', function() {
7260
query: {table: 'payments'},
7361
select: {table: 'payments'}
7462
});
75-
}).to.throwError(function(e) {
76-
expect(e).to.be.a(Error);
77-
expect(e.message).to.be('Wrong using `query`, `select` properties together in `select` clause');
78-
});
63+
}).to.throw('Wrong using `query`, `select` properties together in `select` clause');
7964
});
8065

8166
it('should throw error without `name` property in `with` clause', function() {
@@ -88,10 +73,7 @@ describe('Builder', function() {
8873
}],
8974
table: 'users'
9075
});
91-
}).to.throwError(function(e) {
92-
expect(e).to.be.a(Error);
93-
expect(e.message).to.be('`name` property is not set in `with` clause');
94-
});
76+
}).to.throw('`name` property is not set in `with` clause');
9577
});
9678

9779
it('should throw error without `query` and `select` properties in `with` clause', function() {
@@ -102,11 +84,7 @@ describe('Builder', function() {
10284
}],
10385
table: 'users'
10486
});
105-
}).to.throwError(function(e) {
106-
expect(e).to.be.a(Error);
107-
expect(e.message).to.be('Neither `query`, `select`, `expression` properties ' +
108-
'are not set in `with` clause');
109-
});
87+
}).to.throw('Neither `query`, `select`, `expression` properties are not set in `with` clause');
11088
});
11189

11290
it('should throw error with both `query` and `select` properties in `with` clause', function() {
@@ -119,10 +97,7 @@ describe('Builder', function() {
11997
}],
12098
table: 'users'
12199
});
122-
}).to.throwError(function(e) {
123-
expect(e).to.be.a(Error);
124-
expect(e.message).to.be('Wrong using `query`, `select` properties together in `with` clause');
125-
});
100+
}).to.throw('Wrong using `query`, `select` properties together in `with` clause');
126101
});
127102

128103
it('should be ok with array in `with` clause', function() {
@@ -136,9 +111,9 @@ describe('Builder', function() {
136111
table: 'users'
137112
});
138113

139-
expect(result.query).to.be('with "payments" as (select * from "payments") select * from ' +
114+
expect(result.query).to.be.equal('with "payments" as (select * from "payments") select * from ' +
140115
'"users";');
141-
expect(result.values).to.eql({});
116+
expect(result.values).to.be.eql({});
142117
});
143118

144119
it('should be ok with object in `with` clause', function() {
@@ -153,25 +128,25 @@ describe('Builder', function() {
153128
table: 'users'
154129
});
155130

156-
expect(result.query).to.be('with "payments" as (select * from "payments") select * from ' +
131+
expect(result.query).to.be.equal('with "payments" as (select * from "payments") select * from ' +
157132
'"users";');
158-
expect(result.values).to.eql({});
133+
expect(result.values).to.be.eql({});
159134
});
160135

161136
it('should create array values with option `namedValues` = false', function() {
162137
jsonSql.configure({
163138
namedValues: false
164139
});
165140

166-
expect(jsonSql._values).to.eql([]);
141+
expect(jsonSql._values).to.be.eql([]);
167142

168143
var result = jsonSql.build({
169144
table: 'users',
170145
condition: {name: 'John'}
171146
});
172147

173-
expect(result.query).to.be('select * from "users" where "name" = $1;');
174-
expect(result.values).to.eql(['John']);
148+
expect(result.query).to.be.equal('select * from "users" where "name" = $1;');
149+
expect(result.values).to.be.eql(['John']);
175150
});
176151

177152
it('should use prefix `@` for values with option `valuesPrefix` = @', function() {
@@ -184,8 +159,8 @@ describe('Builder', function() {
184159
condition: {name: 'John'}
185160
});
186161

187-
expect(result.query).to.be('select * from "users" where "name" = @p1;');
188-
expect(result.values).to.eql({p1: 'John'});
162+
expect(result.query).to.be.equal('select * from "users" where "name" = @p1;');
163+
expect(result.values).to.be.eql({p1: 'John'});
189164
});
190165

191166
it('should return prefixed values with method `prefixValues`', function() {
@@ -194,9 +169,9 @@ describe('Builder', function() {
194169
condition: {name: 'John'}
195170
});
196171

197-
expect(result.query).to.be('select * from "users" where "name" = @p1;');
198-
expect(result.values).to.eql({p1: 'John'});
199-
expect(result.prefixValues()).to.eql({'@p1': 'John'});
172+
expect(result.query).to.be.equal('select * from "users" where "name" = @p1;');
173+
expect(result.values).to.be.eql({p1: 'John'});
174+
expect(result.prefixValues()).to.be.eql({'@p1': 'John'});
200175
});
201176

202177
it('should return array values with method `getValuesArray`', function() {
@@ -205,9 +180,9 @@ describe('Builder', function() {
205180
condition: {name: 'John'}
206181
});
207182

208-
expect(result.query).to.be('select * from "users" where "name" = @p1;');
209-
expect(result.values).to.eql({p1: 'John'});
210-
expect(result.getValuesArray()).to.eql(['John']);
183+
expect(result.query).to.be.equal('select * from "users" where "name" = @p1;');
184+
expect(result.values).to.be.eql({p1: 'John'});
185+
expect(result.getValuesArray()).to.be.eql(['John']);
211186
});
212187

213188
it('should return object values with method `getValuesObject`', function() {
@@ -216,35 +191,35 @@ describe('Builder', function() {
216191
namedValues: false
217192
});
218193

219-
expect(jsonSql._values).to.eql([]);
194+
expect(jsonSql._values).to.be.eql([]);
220195

221196
var result = jsonSql.build({
222197
table: 'users',
223198
condition: {name: 'John'}
224199
});
225200

226-
expect(result.query).to.be('select * from "users" where "name" = $1;');
227-
expect(result.values).to.eql(['John']);
228-
expect(result.prefixValues()).to.eql({'$1': 'John'});
229-
expect(result.getValuesObject()).to.eql({1: 'John'});
201+
expect(result.query).to.be.equal('select * from "users" where "name" = $1;');
202+
expect(result.values).to.be.eql(['John']);
203+
expect(result.prefixValues()).to.be.eql({'$1': 'John'});
204+
expect(result.getValuesObject()).to.be.eql({1: 'John'});
230205
});
231206

232207
it('should create query without values with option `separatedValues` = false', function() {
233208
jsonSql.configure({
234209
separatedValues: false
235210
});
236211

237-
expect(jsonSql._values).to.not.be.ok();
238-
expect(jsonSql._placeholderId).to.not.be.ok();
212+
expect(jsonSql._values).to.not.be.ok;
213+
expect(jsonSql._placeholderId).to.not.be.ok;
239214

240215
var result = jsonSql.build({
241216
type: 'insert',
242217
table: 'users',
243218
values: {name: 'John', surname: 'Doe'}
244219
});
245220

246-
expect(result.query).to.be('insert into "users" ("name", "surname") values (\'John\', \'Doe\');');
247-
expect(result.values).to.not.be.ok();
221+
expect(result.query).to.be.equal('insert into "users" ("name", "surname") values (\'John\', \'Doe\');');
222+
expect(result.values).to.not.be.ok;
248223
});
249224

250225
it('should create query without wrapping identifiers with option `wrappedIdentifiers` = false',
@@ -259,7 +234,7 @@ describe('Builder', function() {
259234
values: {name: 'John'}
260235
});
261236

262-
expect(result.query).to.be('insert into users (name) values ($p1);');
237+
expect(result.query).to.be.equal('insert into users (name) values ($p1);');
263238
}
264239
);
265240

@@ -276,10 +251,7 @@ describe('Builder', function() {
276251
'users.a.b': 1
277252
}
278253
});
279-
}).to.throwError(function(e) {
280-
expect(e).to.be.a(Error);
281-
expect(e.message).to.be('Can\'t wrap identifier with name name "users.a.b"');
282-
});
254+
}).to.throw('Can\'t wrap identifier with name name "users.a.b"');
283255
});
284256

285257
it('shouldn\'t wrap identifiers twice', function() {
@@ -296,7 +268,7 @@ describe('Builder', function() {
296268
}
297269
});
298270

299-
expect(result.query).to.be('insert into "users" ("name", "users"."age") values ($p1, 22);');
271+
expect(result.query).to.be.equal('insert into "users" ("name", "users"."age") values ($p1, 22);');
300272
});
301273

302274
it('should wrap identifiers with dots', function() {
@@ -313,6 +285,6 @@ describe('Builder', function() {
313285
}
314286
});
315287

316-
expect(result.query).to.be('insert into "users" ("name", "users"."age") values ($p1, 22);');
288+
expect(result.query).to.be.equal('insert into "users" ("name", "users"."age") values ($p1, 22);');
317289
});
318290
});

0 commit comments

Comments
 (0)