|
| 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