2
2
const expect = require ( 'chai' ) . expect ;
3
3
const insert = require ( '../lib/actions/insert' ) ;
4
4
const select = require ( '../lib/actions/select' ) ;
5
+ const { messages} = require ( 'elasticio-node' ) ;
5
6
const EventEmitter = require ( 'events' ) ;
6
7
7
8
class TestEmitter extends EventEmitter {
8
9
9
- constructor ( done ) {
10
- super ( ) ;
11
- this . data = [ ] ;
12
- this . end = 0 ;
13
- this . error = [ ] ;
10
+ constructor ( done ) {
11
+ super ( ) ;
12
+ this . data = [ ] ;
13
+ this . end = 0 ;
14
+ this . error = [ ] ;
14
15
15
- this . on ( 'data' , ( value ) => this . data . push ( value ) ) ;
16
- this . on ( 'error' , ( value ) => {
17
- this . error . push ( value )
18
- console . error ( value . stack || value ) ;
19
- } ) ;
20
- this . on ( 'end' , ( ) => {
21
- this . end ++ ;
22
- done ( ) ;
23
- } ) ;
24
- }
16
+ this . on ( 'data' , ( value ) => this . data . push ( value ) ) ;
17
+ this . on ( 'error' , ( value ) => {
18
+ this . error . push ( value )
19
+ console . error ( value . stack || value ) ;
20
+ } ) ;
21
+ this . on ( 'end' , ( ) => {
22
+ this . end ++ ;
23
+ done ( ) ;
24
+ } ) ;
25
+ }
25
26
26
27
}
27
28
28
29
describe ( 'Integration test' , ( ) => {
29
30
30
31
31
- before ( ( ) => {
32
- if ( ! process . env . MSSQL_URL ) throw new Error ( "Please set MSSQL_URL env variable to proceed" ) ;
33
- } ) ;
32
+ before ( ( ) => {
33
+ if ( ! process . env . MSSQL_URL ) throw new Error ( "Please set MSSQL_URL env variable to proceed" ) ;
34
+ } ) ;
34
35
35
- describe ( 'for INSERT' , ( ) => {
36
+ describe ( 'for INSERT' , ( ) => {
36
37
37
- const cfg = {
38
- uri : process . env . MSSQL_URL ,
39
- query : 'INSERT INTO Test2.dbo.Tweets (Lang, Retweeted, Favorited, "Text", id, CreatedAt, Username, ScreenName) '
40
- + 'VALUES (@lang, @retweeted:boolean, @favorited:boolean, @text:string, @id:bigint, @created_at:date, @username, @screenname:string)'
41
- } ;
38
+ const cfg = {
39
+ uri : process . env . MSSQL_URL ,
40
+ query : 'INSERT INTO Test2.dbo.Tweets (Lang, Retweeted, Favorited, "Text", id, CreatedAt, Username, ScreenName) '
41
+ + 'VALUES (@lang, @retweeted:boolean, @favorited:boolean, @text:string, @id:bigint, @created_at:date, @username, @screenname:string)'
42
+ } ;
42
43
43
- before ( ( ) => {
44
- return insert . init ( cfg ) ;
45
- } ) ;
44
+ before ( ( ) => {
45
+ return insert . init ( cfg ) ;
46
+ } ) ;
46
47
47
- it ( 'should insert data' , ( ) => {
48
- const emitter = new TestEmitter ( ) ;
49
- const msg = {
50
- body : {
51
- lang : 'en' ,
52
- retweeted : false ,
53
- favorited : false ,
54
- text : 'Hello integration testing' ,
55
- id : 12345678910 ,
56
- created_at : new Date ( ) . toISOString ( ) ,
57
- username : 'Renat Zubairov' ,
58
- screenname : 'zubairov'
59
- }
60
- } ;
61
- return insert . process . call ( emitter , msg ) . then ( ( result ) => {
62
- expect ( result ) . deep . equal ( msg ) ;
63
- expect ( emitter . data . length ) . to . equal ( 0 ) ;
64
- // promises, no need to emit end
65
- expect ( emitter . end ) . to . equal ( 0 ) ;
66
- // No error
67
- expect ( emitter . error . length ) . to . equal ( 0 ) ;
68
- } ) ;
48
+ it ( 'should insert data' , ( ) => {
49
+ const emitter = new TestEmitter ( ) ;
50
+ const msg = {
51
+ body : {
52
+ lang : 'en' ,
53
+ retweeted : false ,
54
+ favorited : false ,
55
+ text : 'Hello integration testing' ,
56
+ id : 12345678910 ,
57
+ created_at : new Date ( ) . toISOString ( ) ,
58
+ username : 'Renat Zubairov' ,
59
+ screenname : 'zubairov'
60
+ }
61
+ } ;
62
+ return insert . process . call ( emitter , msg ) . then ( ( result ) => {
63
+ expect ( result ) . deep . equal ( msg ) ;
64
+ expect ( emitter . data . length ) . to . equal ( 0 ) ;
65
+ // promises, no need to emit end
66
+ expect ( emitter . end ) . to . equal ( 0 ) ;
67
+ // No error
68
+ expect ( emitter . error . length ) . to . equal ( 0 ) ;
69
+ } ) ;
70
+ } ) ;
69
71
} ) ;
70
- } ) ;
71
72
72
- describe ( 'for SELECT' , ( ) => {
73
+ describe ( 'for SELECT' , ( ) => {
74
+
75
+ const cfg = {
76
+ uri : process . env . MSSQL_URL
77
+ } ;
73
78
74
- const cfg = {
75
- uri : process . env . MSSQL_URL ,
76
- query : 'select * from Tweets ORDER BY id OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;'
77
- } ;
79
+ before ( ( ) => {
80
+ return select . init ( cfg ) ;
81
+ } ) ;
78
82
79
- before ( ( ) => {
80
- return select . init ( cfg ) ;
83
+ it ( 'should select data' , ( done ) => {
84
+ const emitter = new TestEmitter ( ( ) => {
85
+ expect ( emitter . error . length ) . to . equal ( 0 ) ;
86
+ expect ( emitter . data . length ) . to . equal ( 10 ) ;
87
+ expect ( emitter . end ) . to . equal ( 1 ) ;
88
+ done ( ) ;
89
+ } ) ;
90
+ const msg = messages . newMessageWithBody ( {
91
+ query : 'select * from Tweets ORDER BY id OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;'
92
+ } ) ;
93
+ select . process . call ( emitter , msg , cfg ) . catch ( err => done ( err ) ) ;
94
+ } ) ;
81
95
} ) ;
82
96
83
- it ( 'should select data' , ( done ) => {
84
- const emitter = new TestEmitter ( ( ) => {
85
- expect ( emitter . error . length ) . to . equal ( 0 ) ;
86
- expect ( emitter . data . length ) . to . equal ( 10 ) ;
87
- expect ( emitter . end ) . to . equal ( 1 ) ;
88
- done ( ) ;
89
- } ) ;
90
- const msg = {
91
- body : {
92
- lang : 'en'
93
- }
94
- } ;
95
- select . process . call ( emitter , msg , cfg ) . catch ( err => done ( err ) ) ;
97
+ describe ( 'for legacy SELECT configuration' , ( ) => {
98
+
99
+ const cfg = {
100
+ uri : process . env . MSSQL_URL ,
101
+ query : 'select * from Tweets ORDER BY id OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;'
102
+ } ;
103
+
104
+ before ( ( ) => {
105
+ return select . init ( cfg ) ;
106
+ } ) ;
107
+
108
+ it ( 'should select data' , ( done ) => {
109
+ const emitter = new TestEmitter ( ( ) => {
110
+ expect ( emitter . error . length ) . to . equal ( 0 ) ;
111
+ expect ( emitter . data . length ) . to . equal ( 10 ) ;
112
+ expect ( emitter . end ) . to . equal ( 1 ) ;
113
+ done ( ) ;
114
+ } ) ;
115
+ const msg = messages . newMessageWithBody ( {
116
+ } ) ;
117
+ select . process . call ( emitter , msg , cfg ) . catch ( err => done ( err ) ) ;
118
+ } ) ;
96
119
} ) ;
97
- } ) ;
98
120
99
- describe ( 'for polling SELECT' , ( ) => {
121
+
122
+ describe ( 'for polling SELECT' , ( ) => {
100
123
101
124
const cfg = {
102
- uri : process . env . MSSQL_URL ,
103
- query : "select * from Leads where Created >= '%%EIO_LAST_POLL%%'"
125
+ uri : process . env . MSSQL_URL
104
126
} ;
105
127
106
128
before ( ( ) => {
@@ -114,7 +136,9 @@ describe('Integration test', () => {
114
136
done ( ) ;
115
137
} ) ;
116
138
const msg = {
117
- body : { }
139
+ body : {
140
+ query : "select * from Leads where Created >= '%%EIO_LAST_POLL%%'"
141
+ }
118
142
} ;
119
143
select . process . call ( emitter , msg , cfg , { } ) . catch ( err => done ( err ) ) ;
120
144
} ) ;
0 commit comments