Skip to content

Commit

Permalink
updated typescript and enabled namespacedObjectsSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
yoav0gal committed Jan 10, 2024
1 parent 234c4cd commit 9674afc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fastify-hana",
"version": "0.2.7",
"version": "0.2.8",
"description": "Fastify Sap Hana connection plugin",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -54,7 +54,7 @@
"ts-node": "^10.9.1",
"ts-standard": "^12.0.1",
"tsd": "^0.16.0",
"typescript": "^4.5.4"
"typescript": "^5.3.3"
},
"tsd": {
"directory": "test"
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default fp<HanaOptions>(
async function executeInTransaction(
actions: (conn: hana.Connection) => Promise<void>
) {
const conn = await pool.getConnection();
const conn = pool.getConnection();
try {
conn.setAutoCommit(false);
await actions(conn);
Expand All @@ -64,7 +64,6 @@ export default fp<HanaOptions>(
fastify.decorate("executeInTransaction", executeInTransaction);

// Clear the pool on application close
//@ts-ignore
fastify.addHook("onClose", async (_instance) => {
await pool.clear();
});
Expand Down
19 changes: 19 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ async function executeQueryTest(t) {
await fastify.close();
}

/**
* This test would normally run a query against a real or mock HANA database to check that executeQuery is working as expected.
* This may involve setting up the database, inserting some test data, running the query, and then checking the results.
* Note that for this test, we'll use a mock
*/
async function executeQueryNoParamsTest(t) {
const fastify = Fastify();
fastify.register(fastifyHana, FASTIFY_HANA_OPTS);

await fastify.ready();

const result = await fastify.executeQuery("SELECT * FROM test");
t.same(result, MOCK_DATA);

await fastify.close();
}

/**
* This test would normally run a query against a real or mock HANA database to check that executeQuery is working as expected.
* This may involve setting up the database, inserting some test data, running the query, and then checking the results.
Expand Down Expand Up @@ -167,6 +184,8 @@ test("fastify-hana loads correctly", loadTest);

test("fastify.executeQuery works correctly", executeQueryTest);

test("fastify.executeQuery works without paramters", executeQueryNoParamsTest);

test("fastify.executeQuery throws on error", executeQueryFailTest);

test("fastify.executeInTransaction works correctly", executeInTransactionTest);
Expand Down
4 changes: 2 additions & 2 deletions test/mocksAndConsts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const MOCK_DATA = [{ id: 1, value: "test" }];
* @returns {Promise<any>} A promise resolving to the mocked query result.
* @throws {Error} If the number of parameters in the query does not match the provided parameters.
*/
async function mockExec(query: string, params: ExecuteQueryParameters) {
async function mockExec(query: string, params: ExecuteQueryParameters = []) {
if (!Array.isArray(params)) {
[query, params] = namedParameterBindingSupport(query, params);
}
Expand Down Expand Up @@ -56,7 +56,7 @@ function countSubstringOccurrences(str: string, substring: string) {

const hanaClientMock = {
createPool: () => ({
getConnection: async () => ({
getConnection: () => ({
exec: mockExec, // Mocking the exec function
disconnect: async () => {},
setAutoCommit: async () => {},
Expand Down

0 comments on commit 9674afc

Please sign in to comment.