@@ -62,6 +62,87 @@ describe('CSV Read component', async () => {
62
62
} ) ;
63
63
} ) ;
64
64
65
+ describe ( 'emitAll: emitBatch' , async ( ) => {
66
+ it ( 'should contain batchSize field' , async ( ) => {
67
+ cfg = {
68
+ emitAll : 'emitBatch' ,
69
+ } ;
70
+ const expectedMetadata = {
71
+ in : {
72
+ type : 'object' ,
73
+ properties : {
74
+ url : {
75
+ type : 'string' ,
76
+ required : true ,
77
+ title : 'URL' ,
78
+ } ,
79
+ header : {
80
+ type : 'boolean' ,
81
+ required : false ,
82
+ title : 'Contains headers' ,
83
+ } ,
84
+ delimiter : {
85
+ type : 'string' ,
86
+ required : false ,
87
+ title : 'Delimiter' ,
88
+ } ,
89
+ dynamicTyping : {
90
+ type : 'boolean' ,
91
+ required : false ,
92
+ title : 'Convert Data types' ,
93
+ } ,
94
+ batchSize : {
95
+ title : 'Batch Size' ,
96
+ type : 'number' ,
97
+ required : true ,
98
+ } ,
99
+ } ,
100
+ } ,
101
+ out : { } ,
102
+ } ;
103
+ const metadata = await readCSV . getMetaModel ( cfg ) ;
104
+ expect ( metadata ) . to . deep . equal ( expectedMetadata ) ;
105
+ } ) ;
106
+ } ) ;
107
+
108
+ describe ( 'emitAll: fetchAll' , async ( ) => {
109
+ it ( 'should not contain batchSize field' , async ( ) => {
110
+ cfg = {
111
+ emitAll : 'fetchAll' ,
112
+ } ;
113
+ const expectedMetadata = {
114
+ in : {
115
+ type : 'object' ,
116
+ properties : {
117
+ url : {
118
+ type : 'string' ,
119
+ required : true ,
120
+ title : 'URL' ,
121
+ } ,
122
+ header : {
123
+ type : 'boolean' ,
124
+ required : false ,
125
+ title : 'Contains headers' ,
126
+ } ,
127
+ delimiter : {
128
+ type : 'string' ,
129
+ required : false ,
130
+ title : 'Delimiter' ,
131
+ } ,
132
+ dynamicTyping : {
133
+ type : 'boolean' ,
134
+ required : false ,
135
+ title : 'Convert Data types' ,
136
+ } ,
137
+ } ,
138
+ } ,
139
+ out : { } ,
140
+ } ;
141
+ const metadata = await readCSV . getMetaModel ( cfg ) ;
142
+ expect ( metadata ) . to . deep . equal ( expectedMetadata ) ;
143
+ } ) ;
144
+ } ) ;
145
+
65
146
it ( 'One file' , async ( ) => {
66
147
msg . body = {
67
148
url : 'http://test.env.mock/formats.csv' ,
@@ -133,6 +214,42 @@ describe('CSV Read component', async () => {
133
214
. to . equal ( 2.71828 ) ; // Number
134
215
} ) ;
135
216
217
+ it ( 'emitBatch: true, batchSize is negative' , async ( ) => {
218
+ msg . body = {
219
+ url : 'http://test.env.mock/formats.csv' ,
220
+ header : true ,
221
+ dynamicTyping : true ,
222
+ batchSize : - 5 ,
223
+ } ;
224
+ cfg = {
225
+ emitAll : 'emitBatch' ,
226
+ } ;
227
+ context . emit = sinon . spy ( ) ;
228
+ try {
229
+ await readCSV . process . call ( context , msg , cfg ) ;
230
+ } catch ( err ) {
231
+ expect ( err . message ) . to . be . equal ( '\'batchSize\' must be a positive integer!' ) ;
232
+ }
233
+ } ) ;
234
+
235
+ it ( 'emitBatch: true, batchSize is string' , async ( ) => {
236
+ msg . body = {
237
+ url : 'http://test.env.mock/formats.csv' ,
238
+ header : true ,
239
+ dynamicTyping : true ,
240
+ batchSize : 'asd' ,
241
+ } ;
242
+ cfg = {
243
+ emitAll : 'emitBatch' ,
244
+ } ;
245
+ context . emit = sinon . spy ( ) ;
246
+ try {
247
+ await readCSV . process . call ( context , msg , cfg ) ;
248
+ } catch ( err ) {
249
+ expect ( err . message ) . to . be . equal ( '\'batchSize\' must be a positive integer!' ) ;
250
+ }
251
+ } ) ;
252
+
136
253
it ( 'emitAll: emitIndividually, header: false, dynamicTyping: false' , async ( ) => {
137
254
msg . body = {
138
255
url : 'http://test.env.mock/formats.csv' ,
0 commit comments