From d4ee48df1e8a33b22b7b940dd24b5d9532196d87 Mon Sep 17 00:00:00 2001 From: Dieter Vyncke Date: Wed, 13 Dec 2023 09:44:33 +0100 Subject: [PATCH] Fix: tests --- __tests__/DatabaseLayer.test.ts | 6 +++--- src/query_builder/read.ts | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/__tests__/DatabaseLayer.test.ts b/__tests__/DatabaseLayer.test.ts index 8ded9df..c91da7b 100644 --- a/__tests__/DatabaseLayer.test.ts +++ b/__tests__/DatabaseLayer.test.ts @@ -172,10 +172,10 @@ describe('run statements', () => { it('with correct params returns first element found', () => { const fn = jest.fn(async () => ({ rows: [{ id: 1, teste1: 'Daniel', teste2: 3.5, teste3: '{"prop":123}' }] })) databaseLayer.executeSql = fn - const where = { teste2_eq: 3.5 } + const where = { teste2: { equals: 3.5 } } return databaseLayer.findBy(where).then(res => { expect(Qb.query).toBeCalledWith(tableName, { where, limit: 1 }) - expect(fn).toBeCalledWith(qbMockReturns, Object.values(where)) + expect(fn).toBeCalledWith(qbMockReturns, Object.values(where).map(option => Object.values(option)).flat()) expect(res).toEqual({ id: 1, teste1: 'Daniel', teste2: 3.5, teste3: '{"prop":123}' }) }) }) @@ -196,7 +196,7 @@ describe('run statements', () => { const where = { teste2_eq: 3.5 } return databaseLayer.findBy(where).then(res => { expect(Qb.query).toBeCalledWith(tableName, { where, limit: 1 }) - expect(fn).toBeCalledWith(qbMockReturns, Object.values(where)) + expect(fn).toBeCalledWith(qbMockReturns, Object.values(where).map(option => Object.values(option)).flat()) expect(res).toBeUndefined() }) }) diff --git a/src/query_builder/read.ts b/src/query_builder/read.ts index 6fee730..2554cf6 100644 --- a/src/query_builder/read.ts +++ b/src/query_builder/read.ts @@ -10,9 +10,7 @@ const defaultOptions: IQueryOptions<{ id: any }> = { // Creates the "SELECT" sql statement for find one record export function find(tableName: string) { - return `SELECT * - FROM ${tableName} - WHERE id = ? LIMIT 1;` + return `SELECT * FROM ${tableName} WHERE id = ? LIMIT 1;` } /* Creates the "SELECT" sql statement for query records