@@ -12,11 +12,9 @@ import AthenaQuery from "../index";
12
12
const athenaMock = mockClient ( AthenaClient ) ;
13
13
14
14
const athena = new Athena ( { } ) ;
15
- let athenaQuery : AthenaQuery ;
16
15
17
16
beforeEach ( ( ) => {
18
17
athenaMock . reset ( ) ;
19
- athenaQuery = new AthenaQuery ( athena ) ;
20
18
} ) ;
21
19
22
20
test ( "parse to json following ColumnInfo" , async ( ) => {
@@ -73,6 +71,7 @@ test("parse to json following ColumnInfo", async () => {
73
71
} ,
74
72
} ) ;
75
73
74
+ const athenaQuery = new AthenaQuery ( athena ) ;
76
75
const resultGen = athenaQuery . query ( "" ) ;
77
76
78
77
const res1 = await resultGen . next ( ) ;
@@ -111,6 +110,7 @@ test("wait query completed", async () => {
111
110
} ,
112
111
} ) ;
113
112
113
+ const athenaQuery = new AthenaQuery ( athena ) ;
114
114
const resultGen = athenaQuery . query ( "" ) ;
115
115
116
116
const res1 = await resultGen . next ( ) ;
@@ -148,6 +148,7 @@ test("get items with generator", async () => {
148
148
} ,
149
149
} ) ;
150
150
151
+ const athenaQuery = new AthenaQuery ( athena ) ;
151
152
const queryResultGen = athenaQuery . query ( "" ) ;
152
153
153
154
const res1 = await queryResultGen . next ( ) ;
@@ -210,6 +211,7 @@ test("get all item with generator", async () => {
210
211
211
212
const allItems = [ ] ;
212
213
214
+ const athenaQuery = new AthenaQuery ( athena ) ;
213
215
for await ( const item of athenaQuery . query ( "" ) ) {
214
216
allItems . push ( item ) ;
215
217
}
@@ -223,6 +225,64 @@ test("get all item with generator", async () => {
223
225
] ) ;
224
226
} ) ;
225
227
228
+ test ( "pass args to sdk" , async ( ) => {
229
+ athenaMock
230
+ . on ( StartQueryExecutionCommand )
231
+ . resolves ( { QueryExecutionId : "test-QueryExecutionId" } )
232
+ . on ( GetQueryExecutionCommand )
233
+ . resolves ( { QueryExecution : { Status : { State : "SUCCEEDED" } } } )
234
+ . on ( GetQueryResultsCommand )
235
+ . resolves ( {
236
+ ResultSet : {
237
+ ResultSetMetadata : {
238
+ ColumnInfo : [ { Name : "name" , Type : "varchar" } ] ,
239
+ } ,
240
+ Rows : [
241
+ // header row
242
+ { Data : [ { VarCharValue : "name" } ] } ,
243
+ { Data : [ { VarCharValue : "test-name-1" } ] } ,
244
+ ] ,
245
+ } ,
246
+ } ) ;
247
+
248
+ const athenaQuery = new AthenaQuery ( athena , {
249
+ db : "test-db" ,
250
+ workgroup : "test-workgroup" ,
251
+ catalog : "test-catalog" ,
252
+ } ) ;
253
+ const resultGen = athenaQuery . query ( "SELECT test FROM test;" , {
254
+ executionParameters : [ "'test'" , "123" ] ,
255
+ maxResults : 100 ,
256
+ } ) ;
257
+
258
+ await resultGen . next ( ) ;
259
+
260
+ expect (
261
+ athenaMock . commandCalls ( StartQueryExecutionCommand ) [ 0 ] . args [ 0 ] . input
262
+ ) . toEqual ( {
263
+ QueryString : "SELECT test FROM test;" ,
264
+ ExecutionParameters : [ "'test'" , "123" ] ,
265
+ WorkGroup : "test-workgroup" ,
266
+ QueryExecutionContext : {
267
+ Catalog : "test-catalog" ,
268
+ Database : "test-db" ,
269
+ } ,
270
+ } ) ;
271
+
272
+ expect (
273
+ athenaMock . commandCalls ( GetQueryExecutionCommand ) [ 0 ] . args [ 0 ] . input
274
+ ) . toEqual ( {
275
+ QueryExecutionId : "test-QueryExecutionId" ,
276
+ } ) ;
277
+
278
+ expect (
279
+ athenaMock . commandCalls ( GetQueryResultsCommand ) [ 0 ] . args [ 0 ] . input
280
+ ) . toEqual ( {
281
+ QueryExecutionId : "test-QueryExecutionId" ,
282
+ MaxResults : 100 ,
283
+ } ) ;
284
+ } ) ;
285
+
226
286
test ( "throw exception when query is respond as failed" , async ( ) => {
227
287
athenaMock
228
288
. on ( StartQueryExecutionCommand )
@@ -234,6 +294,7 @@ test("throw exception when query is respond as failed", async () => {
234
294
} ,
235
295
} ) ;
236
296
297
+ const athenaQuery = new AthenaQuery ( athena ) ;
237
298
const resultGen = athenaQuery . query ( "" ) ;
238
299
239
300
await expect ( resultGen . next ( ) ) . rejects . toThrow ( "for-test" ) ;
@@ -244,6 +305,7 @@ test("throw exception when query is respond as failed", async () => {
244
305
. on ( StartQueryExecutionCommand )
245
306
. resolves ( { QueryExecutionId : undefined } ) ;
246
307
308
+ const athenaQuery = new AthenaQuery ( athena ) ;
247
309
const resultGen = athenaQuery . query ( "" ) ;
248
310
249
311
await expect ( resultGen . next ( ) ) . rejects . toThrow (
0 commit comments