Skip to content

Commit d001266

Browse files
committed
Now can handle \t
1 parent dc28ef1 commit d001266

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

lib/actions/insert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function init(cfg) {
4848
default:
4949
console.log('WARNING: Can figure out the type key=%s type=%s', name, type);
5050
}
51-
// Now let's remove all :string :boolean :date etc to the name only
51+
// Now let's remove all :string :boolean :date etc to the name only
5252
sql = sql.replace(tuple, placeholder);
5353
}
5454
console.log('Resulting SQL=%s', sql);

spec-integration/select.spec.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'use strict';
2+
const expect = require('chai').expect;
3+
const insert = require('../lib/actions/insert');
4+
const select = require('../lib/actions/select');
5+
const EventEmitter = require('events');
6+
7+
class TestEmitter extends EventEmitter {
8+
9+
constructor() {
10+
super();
11+
this.data = [];
12+
this.end = 0;
13+
this.error = [];
14+
15+
this.on('data', (value) => this.data.push(value));
16+
this.on('error', (value) => this.error.push(value));
17+
this.on('end', () => this.end++);
18+
}
19+
20+
}
21+
22+
23+
describe('Integration test', () => {
24+
25+
26+
before(() => {
27+
if (!process.env.MSSQL_URL) throw new Error("Please set MSSQL_URL env variable to proceed");
28+
});
29+
30+
describe('for INSERT', () => {
31+
32+
let emitter;
33+
34+
const cfg = {
35+
uri : process.env.MSSQL_URL,
36+
query: 'INSERT INTO Test2.dbo.Tweets (Lang, Retweeted, Favorited, "Text", id, CreatedAt, Username, ScreenName) '
37+
+ 'VALUES (@lang:string, @retweeted:boolean, @favorited:boolean, @text:string, @id:bigint, @created_at:date, @username:string, @screenname:string)'
38+
};
39+
40+
before(() => {
41+
return insert.init(cfg);
42+
});
43+
44+
it('should insert data', () => {
45+
const emitter = new TestEmitter();
46+
const msg = {
47+
body: {
48+
lang: 'en',
49+
retweeted: false,
50+
favorited: false,
51+
text: 'Hello integration testing',
52+
id: 12345678910,
53+
created_at: new Date().toISOString(),
54+
username: 'Renat Zubairov',
55+
screenname: 'zubairov'
56+
}
57+
};
58+
return insert.process.call(emitter, msg).then((result) => {
59+
expect(result).deep.equal(msg);
60+
expect(emitter.data.length).to.equal(0);
61+
// promises, no need to emit end
62+
expect(emitter.end.length).to.equal(0);
63+
expect(emitter.error.length).to.equal(0);
64+
});
65+
});
66+
})
67+
68+
});

0 commit comments

Comments
 (0)