@@ -6,20 +6,22 @@ const EventEmitter = require('events');
6
6
7
7
class TestEmitter extends EventEmitter {
8
8
9
- constructor ( ) {
9
+ constructor ( done ) {
10
10
super ( ) ;
11
11
this . data = [ ] ;
12
12
this . end = 0 ;
13
13
this . error = [ ] ;
14
14
15
15
this . on ( 'data' , ( value ) => this . data . push ( value ) ) ;
16
16
this . on ( 'error' , ( value ) => this . error . push ( value ) ) ;
17
- this . on ( 'end' , ( ) => this . end ++ ) ;
17
+ this . on ( 'end' , ( ) => {
18
+ this . end ++ ;
19
+ done ( ) ;
20
+ } ) ;
18
21
}
19
22
20
23
}
21
24
22
-
23
25
describe ( 'Integration test' , ( ) => {
24
26
25
27
@@ -29,8 +31,6 @@ describe('Integration test', () => {
29
31
30
32
describe ( 'for INSERT' , ( ) => {
31
33
32
- let emitter ;
33
-
34
34
const cfg = {
35
35
uri : process . env . MSSQL_URL ,
36
36
query : 'INSERT INTO Test2.dbo.Tweets (Lang, Retweeted, Favorited, "Text", id, CreatedAt, Username, ScreenName) '
@@ -59,10 +59,36 @@ describe('Integration test', () => {
59
59
expect ( result ) . deep . equal ( msg ) ;
60
60
expect ( emitter . data . length ) . to . equal ( 0 ) ;
61
61
// promises, no need to emit end
62
- expect ( emitter . end . length ) . to . equal ( 0 ) ;
62
+ expect ( emitter . end ) . to . equal ( 0 ) ;
63
+ // No error
63
64
expect ( emitter . error . length ) . to . equal ( 0 ) ;
64
65
} ) ;
65
66
} ) ;
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
+ } ) ;
67
93
68
94
} ) ;
0 commit comments