Skip to content

Commit dc28ef1

Browse files
committed
Added first test (now with mocha). Mocha is the best testing framework in the world, really #great
1 parent ae61b6a commit dc28ef1

File tree

3 files changed

+92
-26
lines changed

3 files changed

+92
-26
lines changed

Gruntfile.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
"request-promise": "^4.1.1"
3333
},
3434
"scripts": {
35-
"pretest": "node_modules/.bin/eslint lib spec Gruntfile.js --ext .json --ext .js --fix",
36-
"test": "NODE_ENV=test grunt"
35+
"pretest": "node_modules/.bin/eslint lib spec --ext .json --ext .js --fix",
36+
"test": "NODE_ENV=test mocha spec/*"
3737
},
3838
"devDependencies": {
39+
"chai": "^3.5.0",
3940
"eslint": "^3.1.1",
4041
"eslint-config-xo-space": "^0.15.0",
4142
"eslint-plugin-json": "^1.2.0",
42-
"grunt": "^1.0.1",
43-
"grunt-jasmine-node": "^0.3.1"
43+
"mocha": "^3.2.0"
4444
},
4545
"eslintConfig": {
4646
"extends": "xo-space",

spec/metadata.spec.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
'use strict';
2+
const expect = require('chai').expect;
3+
const insert = require('../lib/actions/insert');
4+
5+
describe('Metadata test', () => {
6+
const cfg = {
7+
query: 'INSERT INTO Test2.dbo.Tweets (Lang, Retweeted, Favorited, "Text", id, CreatedAt, Username, ScreenName) '
8+
+ 'VALUES (@lang:string, @retweeted:boolean, @favorited:boolean, @text:string, @id:bigint, @created_at:date, @username:string, @screenname:string)'
9+
};
10+
11+
12+
it('should generate metadata', (done) => {
13+
insert.getMetaModel(cfg, (err, result) => {
14+
expect(err).to.be.null;
15+
expect(result).to.deep.equal({
16+
"in": {
17+
"properties": {
18+
"created_at": {
19+
"type": "string"
20+
},
21+
"favorited": {
22+
"type": "string"
23+
},
24+
"id": {
25+
"type": "number"
26+
},
27+
"lang": {
28+
"type": "string"
29+
},
30+
"retweeted": {
31+
"type": "string"
32+
},
33+
"screenname": {
34+
"type": "string"
35+
},
36+
"text": {
37+
"type": "string"
38+
},
39+
"username": {
40+
"type": "string"
41+
}
42+
},
43+
"type": "object"
44+
},
45+
"out": {}
46+
}
47+
);
48+
done();
49+
});
50+
});
51+
52+
it('should not fail on empty query', (done) => {
53+
insert.getMetaModel({}, (err, result) => {
54+
expect(err).to.be.null;
55+
expect(result).to.deep.equal({
56+
"in": {
57+
"properties": {},
58+
"type": "object"
59+
},
60+
"out": {}
61+
}
62+
);
63+
done();
64+
});
65+
});
66+
67+
it('should not handle duplicate fields', (done) => {
68+
insert.getMetaModel({
69+
query: '@foo:string @foo:string @bar:date'
70+
}, (err, result) => {
71+
expect(err).to.be.null;
72+
expect(result).to.deep.equal({
73+
"in": {
74+
"type": "object",
75+
"properties": {
76+
"foo": {type: 'string'},
77+
"bar": {type: 'string'}
78+
}
79+
},
80+
"out": {}
81+
}
82+
);
83+
done();
84+
});
85+
});
86+
87+
88+
});

0 commit comments

Comments
 (0)