Skip to content

Commit 0a41ab9

Browse files
authored
chore: add test for options (#15)
1 parent 33a4cc5 commit 0a41ab9

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

test/index.test.ts

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ import AthenaQuery from "../index";
1212
const athenaMock = mockClient(AthenaClient);
1313

1414
const athena = new Athena({});
15-
let athenaQuery: AthenaQuery;
1615

1716
beforeEach(() => {
1817
athenaMock.reset();
19-
athenaQuery = new AthenaQuery(athena);
2018
});
2119

2220
test("parse to json following ColumnInfo", async () => {
@@ -73,6 +71,7 @@ test("parse to json following ColumnInfo", async () => {
7371
},
7472
});
7573

74+
const athenaQuery = new AthenaQuery(athena);
7675
const resultGen = athenaQuery.query("");
7776

7877
const res1 = await resultGen.next();
@@ -111,6 +110,7 @@ test("wait query completed", async () => {
111110
},
112111
});
113112

113+
const athenaQuery = new AthenaQuery(athena);
114114
const resultGen = athenaQuery.query("");
115115

116116
const res1 = await resultGen.next();
@@ -148,6 +148,7 @@ test("get items with generator", async () => {
148148
},
149149
});
150150

151+
const athenaQuery = new AthenaQuery(athena);
151152
const queryResultGen = athenaQuery.query("");
152153

153154
const res1 = await queryResultGen.next();
@@ -210,6 +211,7 @@ test("get all item with generator", async () => {
210211

211212
const allItems = [];
212213

214+
const athenaQuery = new AthenaQuery(athena);
213215
for await (const item of athenaQuery.query("")) {
214216
allItems.push(item);
215217
}
@@ -223,6 +225,64 @@ test("get all item with generator", async () => {
223225
]);
224226
});
225227

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+
226286
test("throw exception when query is respond as failed", async () => {
227287
athenaMock
228288
.on(StartQueryExecutionCommand)
@@ -234,6 +294,7 @@ test("throw exception when query is respond as failed", async () => {
234294
},
235295
});
236296

297+
const athenaQuery = new AthenaQuery(athena);
237298
const resultGen = athenaQuery.query("");
238299

239300
await expect(resultGen.next()).rejects.toThrow("for-test");
@@ -244,6 +305,7 @@ test("throw exception when query is respond as failed", async () => {
244305
.on(StartQueryExecutionCommand)
245306
.resolves({ QueryExecutionId: undefined });
246307

308+
const athenaQuery = new AthenaQuery(athena);
247309
const resultGen = athenaQuery.query("");
248310

249311
await expect(resultGen.next()).rejects.toThrow(

0 commit comments

Comments
 (0)