@@ -6,20 +6,22 @@ const EventEmitter = require('events');
66
77class TestEmitter extends EventEmitter {
88
9- constructor ( ) {
9+ constructor ( done ) {
1010 super ( ) ;
1111 this . data = [ ] ;
1212 this . end = 0 ;
1313 this . error = [ ] ;
1414
1515 this . on ( 'data' , ( value ) => this . data . push ( value ) ) ;
1616 this . on ( 'error' , ( value ) => this . error . push ( value ) ) ;
17- this . on ( 'end' , ( ) => this . end ++ ) ;
17+ this . on ( 'end' , ( ) => {
18+ this . end ++ ;
19+ done ( ) ;
20+ } ) ;
1821 }
1922
2023}
2124
22-
2325describe ( 'Integration test' , ( ) => {
2426
2527
@@ -29,8 +31,6 @@ describe('Integration test', () => {
2931
3032 describe ( 'for INSERT' , ( ) => {
3133
32- let emitter ;
33-
3434 const cfg = {
3535 uri : process . env . MSSQL_URL ,
3636 query : 'INSERT INTO Test2.dbo.Tweets (Lang, Retweeted, Favorited, "Text", id, CreatedAt, Username, ScreenName) '
@@ -59,10 +59,36 @@ describe('Integration test', () => {
5959 expect ( result ) . deep . equal ( msg ) ;
6060 expect ( emitter . data . length ) . to . equal ( 0 ) ;
6161 // promises, no need to emit end
62- expect ( emitter . end . length ) . to . equal ( 0 ) ;
62+ expect ( emitter . end ) . to . equal ( 0 ) ;
63+ // No error
6364 expect ( emitter . error . length ) . to . equal ( 0 ) ;
6465 } ) ;
6566 } ) ;
66- } )
67+ } ) ;
68+
69+ describe ( 'for SELECT' , ( ) => {
70+
71+ const cfg = {
72+ uri : process . env . MSSQL_URL ,
73+ query : 'select * from Tweets ORDER BY id OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;'
74+ } ;
75+
76+ before ( ( ) => {
77+ return select . init ( cfg ) ;
78+ } ) ;
79+
80+ it ( 'should insert data' , ( done ) => {
81+ const emitter = new TestEmitter ( ( ) => {
82+ expect ( emitter . error . length ) . to . equal ( 0 ) ;
83+ expect ( emitter . data . length ) . to . equal ( 10 ) ;
84+ expect ( emitter . end ) . to . equal ( 1 ) ;
85+ done ( ) ;
86+ } ) ;
87+ const msg = {
88+ body : { }
89+ } ;
90+ select . process . call ( emitter , msg , cfg ) . catch ( err => done ( err ) ) ;
91+ } ) ;
92+ } ) ;
6793
6894} ) ;
0 commit comments