From a1164ac581961c9c6e7810953087f0576d57a510 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 10 Apr 2024 17:50:18 +0100 Subject: [PATCH 1/4] Working towards getting date tests working for SQS. --- .../src/api/routes/tests/search.spec.ts | 131 ++++++++---------- .../server/src/sdk/app/rows/search/sqs.ts | 2 +- packages/types/src/sdk/datasources.ts | 1 + 3 files changed, 63 insertions(+), 71 deletions(-) diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index f5d107d0de..5215595c8f 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -13,12 +13,12 @@ import { jest.unmock("mssql") describe.each([ - ["internal", undefined], + // ["internal", undefined], ["internal-sqs", undefined], - [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], - [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], - [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], - [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], + // [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], + // [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], + // [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], + // [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], ])("/api/:sourceId/search (%s)", (name, dsProvider) => { const isSqs = name === "internal-sqs" const config = setup.getConfig() @@ -83,9 +83,6 @@ describe.each([ { query: { equal: { name: "foo" } }, expected: [rows[0]] }, { query: { notEqual: { name: "foo" } }, expected: [rows[1]] }, { query: { oneOf: { name: ["foo"] } }, expected: [rows[0]] }, - // { query: { contains: { name: "f" } }, expected: [0] }, - // { query: { notContains: { name: ["f"] } }, expected: [1] }, - // { query: { containsAny: { name: ["f"] } }, expected: [0] }, ] it.each(stringSearchTests)( @@ -171,7 +168,7 @@ describe.each([ ) }) - describe("dates", () => { + describe.only("dates", () => { beforeEach(async () => { table = await config.api.table.save( tableForDatasource(datasource, { @@ -186,8 +183,8 @@ describe.each([ }) const rows = [ - { dob: new Date("2020-01-01") }, - { dob: new Date("2020-01-10") }, + { dob: new Date("2020-01-01").toISOString() }, + { dob: new Date("2020-01-10").toISOString() }, ] interface DateSearchTest { @@ -196,70 +193,66 @@ describe.each([ } const dateSearchTests: DateSearchTest[] = [ - { query: {}, expected: rows }, + //{ query: {}, expected: rows }, + //{ + // query: { onEmptyFilter: EmptyFilterOption.RETURN_ALL }, + // expected: rows, + //}, + //{ + // query: { onEmptyFilter: EmptyFilterOption.RETURN_NONE }, + // expected: [], + //}, { - query: { onEmptyFilter: EmptyFilterOption.RETURN_ALL }, - expected: rows, - }, - { - query: { onEmptyFilter: EmptyFilterOption.RETURN_NONE }, - expected: [], - }, - { - query: { equal: { dob: new Date("2020-01-01") } }, + query: { equal: { dob: new Date("2020-01-01").toISOString() } }, expected: [rows[0]], }, - { query: { equal: { dob: new Date("2020-01-02") } }, expected: [] }, - { - query: { notEqual: { dob: new Date("2020-01-01") } }, - expected: [rows[1]], - }, - { - query: { oneOf: { dob: [new Date("2020-01-01")] } }, - expected: [rows[0]], - }, - { - query: { - range: { - dob: { - low: new Date("2020-01-01").toISOString(), - high: new Date("2020-01-05").toISOString(), - }, - }, - }, - expected: [rows[0]], - }, - { - query: { - range: { - dob: { - low: new Date("2020-01-01").toISOString(), - high: new Date("2020-01-10").toISOString(), - }, - }, - }, - expected: rows, - }, - { - query: { - range: { - dob: { - low: new Date("2020-01-05").toISOString(), - high: new Date("2020-01-10").toISOString(), - }, - }, - }, - expected: [rows[1]], - }, + // { query: { equal: { dob: new Date("2020-01-02") } }, expected: [] }, + // { + // query: { notEqual: { dob: new Date("2020-01-01") } }, + // expected: [rows[1]], + // }, + // { + // query: { oneOf: { dob: [new Date("2020-01-01")] } }, + // expected: [rows[0]], + // }, + // { + // query: { + // range: { + // dob: { + // low: new Date("2020-01-01").toISOString(), + // high: new Date("2020-01-05").toISOString(), + // }, + // }, + // }, + // expected: [rows[0]], + // }, + // { + // query: { + // range: { + // dob: { + // low: new Date("2020-01-01").toISOString(), + // high: new Date("2020-01-10").toISOString(), + // }, + // }, + // }, + // expected: rows, + // }, + // { + // query: { + // range: { + // dob: { + // low: new Date("2020-01-05").toISOString(), + // high: new Date("2020-01-10").toISOString(), + // }, + // }, + // }, + // expected: [rows[1]], + // }, ] it.each(dateSearchTests)( `should be able to run query: $query`, async ({ query, expected }) => { - // TODO(samwho): most of these work for SQS, but not all. Fix 'em. - if (isSqs) { - return - } const savedRows = await Promise.all( rows.map(r => config.api.row.save(table._id!, r)) ) @@ -270,9 +263,7 @@ describe.each([ expect(foundRows).toEqual( expect.arrayContaining( expected.map(r => - expect.objectContaining( - savedRows.find(sr => sr.dob === r.dob.toISOString())! - ) + expect.objectContaining(savedRows.find(sr => sr.dob === r.dob)!) ) ) ) diff --git a/packages/server/src/sdk/app/rows/search/sqs.ts b/packages/server/src/sdk/app/rows/search/sqs.ts index 89dae7628f..565286ec1e 100644 --- a/packages/server/src/sdk/app/rows/search/sqs.ts +++ b/packages/server/src/sdk/app/rows/search/sqs.ts @@ -156,7 +156,7 @@ export async function search( try { const query = builder._query(request, { disableReturning: true, - disableBindings: true, + disableBindings: false, }) if (Array.isArray(query)) { diff --git a/packages/types/src/sdk/datasources.ts b/packages/types/src/sdk/datasources.ts index e1a012d81e..fff6b75dcc 100644 --- a/packages/types/src/sdk/datasources.ts +++ b/packages/types/src/sdk/datasources.ts @@ -74,6 +74,7 @@ export enum FilterType { EMPTY = "empty", NOT_EMPTY = "notEmpty", ONE_OF = "oneOf", + CONTAINS = "contains", } export enum DatasourceFeature { From ed8f0960e04165cf25ee96e378b3ca147dd79996 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 10 Apr 2024 17:54:45 +0100 Subject: [PATCH 2/4] All search tests for dates working across all datasources. --- .../src/api/routes/tests/search.spec.ts | 117 +++++++++--------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index 5215595c8f..96c3855f00 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -13,12 +13,12 @@ import { jest.unmock("mssql") describe.each([ - // ["internal", undefined], + ["internal", undefined], ["internal-sqs", undefined], - // [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], - // [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], - // [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], - // [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], + [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], + [DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)], + [DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)], + [DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)], ])("/api/:sourceId/search (%s)", (name, dsProvider) => { const isSqs = name === "internal-sqs" const config = setup.getConfig() @@ -168,7 +168,7 @@ describe.each([ ) }) - describe.only("dates", () => { + describe("dates", () => { beforeEach(async () => { table = await config.api.table.save( tableForDatasource(datasource, { @@ -193,61 +193,64 @@ describe.each([ } const dateSearchTests: DateSearchTest[] = [ - //{ query: {}, expected: rows }, - //{ - // query: { onEmptyFilter: EmptyFilterOption.RETURN_ALL }, - // expected: rows, - //}, - //{ - // query: { onEmptyFilter: EmptyFilterOption.RETURN_NONE }, - // expected: [], - //}, + { query: {}, expected: rows }, + { + query: { onEmptyFilter: EmptyFilterOption.RETURN_ALL }, + expected: rows, + }, + { + query: { onEmptyFilter: EmptyFilterOption.RETURN_NONE }, + expected: [], + }, { query: { equal: { dob: new Date("2020-01-01").toISOString() } }, expected: [rows[0]], }, - // { query: { equal: { dob: new Date("2020-01-02") } }, expected: [] }, - // { - // query: { notEqual: { dob: new Date("2020-01-01") } }, - // expected: [rows[1]], - // }, - // { - // query: { oneOf: { dob: [new Date("2020-01-01")] } }, - // expected: [rows[0]], - // }, - // { - // query: { - // range: { - // dob: { - // low: new Date("2020-01-01").toISOString(), - // high: new Date("2020-01-05").toISOString(), - // }, - // }, - // }, - // expected: [rows[0]], - // }, - // { - // query: { - // range: { - // dob: { - // low: new Date("2020-01-01").toISOString(), - // high: new Date("2020-01-10").toISOString(), - // }, - // }, - // }, - // expected: rows, - // }, - // { - // query: { - // range: { - // dob: { - // low: new Date("2020-01-05").toISOString(), - // high: new Date("2020-01-10").toISOString(), - // }, - // }, - // }, - // expected: [rows[1]], - // }, + { + query: { equal: { dob: new Date("2020-01-02").toISOString() } }, + expected: [], + }, + { + query: { notEqual: { dob: new Date("2020-01-01").toISOString() } }, + expected: [rows[1]], + }, + { + query: { oneOf: { dob: [new Date("2020-01-01").toISOString()] } }, + expected: [rows[0]], + }, + { + query: { + range: { + dob: { + low: new Date("2020-01-01").toISOString(), + high: new Date("2020-01-05").toISOString(), + }, + }, + }, + expected: [rows[0]], + }, + { + query: { + range: { + dob: { + low: new Date("2020-01-01").toISOString(), + high: new Date("2020-01-10").toISOString(), + }, + }, + }, + expected: rows, + }, + { + query: { + range: { + dob: { + low: new Date("2020-01-05").toISOString(), + high: new Date("2020-01-10").toISOString(), + }, + }, + }, + expected: [rows[1]], + }, ] it.each(dateSearchTests)( From 432b11a7f640570a03a8e0dc3878939714381a45 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 10 Apr 2024 17:56:57 +0100 Subject: [PATCH 3/4] Revert unneeded change to types. --- packages/types/src/sdk/datasources.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/types/src/sdk/datasources.ts b/packages/types/src/sdk/datasources.ts index fff6b75dcc..e1a012d81e 100644 --- a/packages/types/src/sdk/datasources.ts +++ b/packages/types/src/sdk/datasources.ts @@ -74,7 +74,6 @@ export enum FilterType { EMPTY = "empty", NOT_EMPTY = "notEmpty", ONE_OF = "oneOf", - CONTAINS = "contains", } export enum DatasourceFeature { From e6c3fd2951d41ba304f67aba062b74568c5c3250 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Wed, 10 Apr 2024 18:01:25 +0100 Subject: [PATCH 4/4] Make pro submodule match master. --- packages/pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pro b/packages/pro index f8e8f87bd5..ef186d0024 160000 --- a/packages/pro +++ b/packages/pro @@ -1 +1 @@ -Subproject commit f8e8f87bd52081e1303a5ae92c432ea5b38f3bb4 +Subproject commit ef186d00241f96037f9fd34d7a3826041977ab3a