From 72f6bc8930c4197a7bbc6904ac9bb1c973007de5 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 15 Mar 2022 11:52:54 +0000 Subject: [PATCH] Add test cases for SQL range filtering changes --- .../server/src/integrations/tests/sql.spec.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/packages/server/src/integrations/tests/sql.spec.js b/packages/server/src/integrations/tests/sql.spec.js index 6ef82f0113..c2e65c56b7 100644 --- a/packages/server/src/integrations/tests/sql.spec.js +++ b/packages/server/src/integrations/tests/sql.spec.js @@ -187,4 +187,55 @@ describe("SQL query builder", () => { sql: `select * from (select * from \`${TABLE_NAME}\` limit ?) as \`${TABLE_NAME}\`` }) }) + + it("should use greater than when only low range specified", () => { + const date = new Date() + const query = sql._query(generateReadJson({ + filters: { + range: { + property: { + low: date, + } + } + } + })) + expect(query).toEqual({ + bindings: [date, limit], + sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."property" > $1 limit $2) as "${TABLE_NAME}"` + }) + }) + + it("should use less than when only high range specified", () => { + const date = new Date() + const query = sql._query(generateReadJson({ + filters: { + range: { + property: { + high: date, + } + } + } + })) + expect(query).toEqual({ + bindings: [date, limit], + sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."property" < $1 limit $2) as "${TABLE_NAME}"` + }) + }) + + it("should use greater than when only low range specified", () => { + const date = new Date() + const query = sql._query(generateReadJson({ + filters: { + range: { + property: { + low: date, + } + } + } + })) + expect(query).toEqual({ + bindings: [date, limit], + sql: `select * from (select * from "${TABLE_NAME}" where "${TABLE_NAME}"."property" > $1 limit $2) as "${TABLE_NAME}"` + }) + }) })