Skip to content

chore: add test for options #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import AthenaQuery from "../index";
const athenaMock = mockClient(AthenaClient);

const athena = new Athena({});
let athenaQuery: AthenaQuery;

beforeEach(() => {
athenaMock.reset();
athenaQuery = new AthenaQuery(athena);
});

test("parse to json following ColumnInfo", async () => {
Expand Down Expand Up @@ -73,6 +71,7 @@ test("parse to json following ColumnInfo", async () => {
},
});

const athenaQuery = new AthenaQuery(athena);
const resultGen = athenaQuery.query("");

const res1 = await resultGen.next();
Expand Down Expand Up @@ -111,6 +110,7 @@ test("wait query completed", async () => {
},
});

const athenaQuery = new AthenaQuery(athena);
const resultGen = athenaQuery.query("");

const res1 = await resultGen.next();
Expand Down Expand Up @@ -148,6 +148,7 @@ test("get items with generator", async () => {
},
});

const athenaQuery = new AthenaQuery(athena);
const queryResultGen = athenaQuery.query("");

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

const allItems = [];

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

test("pass args to sdk", async () => {
athenaMock
.on(StartQueryExecutionCommand)
.resolves({ QueryExecutionId: "test-QueryExecutionId" })
.on(GetQueryExecutionCommand)
.resolves({ QueryExecution: { Status: { State: "SUCCEEDED" } } })
.on(GetQueryResultsCommand)
.resolves({
ResultSet: {
ResultSetMetadata: {
ColumnInfo: [{ Name: "name", Type: "varchar" }],
},
Rows: [
// header row
{ Data: [{ VarCharValue: "name" }] },
{ Data: [{ VarCharValue: "test-name-1" }] },
],
},
});

const athenaQuery = new AthenaQuery(athena, {
db: "test-db",
workgroup: "test-workgroup",
catalog: "test-catalog",
});
const resultGen = athenaQuery.query("SELECT test FROM test;", {
executionParameters: ["'test'", "123"],
maxResults: 100,
});

await resultGen.next();

expect(
athenaMock.commandCalls(StartQueryExecutionCommand)[0].args[0].input
).toEqual({
QueryString: "SELECT test FROM test;",
ExecutionParameters: ["'test'", "123"],
WorkGroup: "test-workgroup",
QueryExecutionContext: {
Catalog: "test-catalog",
Database: "test-db",
},
});

expect(
athenaMock.commandCalls(GetQueryExecutionCommand)[0].args[0].input
).toEqual({
QueryExecutionId: "test-QueryExecutionId",
});

expect(
athenaMock.commandCalls(GetQueryResultsCommand)[0].args[0].input
).toEqual({
QueryExecutionId: "test-QueryExecutionId",
MaxResults: 100,
});
});

test("throw exception when query is respond as failed", async () => {
athenaMock
.on(StartQueryExecutionCommand)
Expand All @@ -234,6 +294,7 @@ test("throw exception when query is respond as failed", async () => {
},
});

const athenaQuery = new AthenaQuery(athena);
const resultGen = athenaQuery.query("");

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

const athenaQuery = new AthenaQuery(athena);
const resultGen = athenaQuery.query("");

await expect(resultGen.next()).rejects.toThrow(
Expand Down