From 8b2156ed08e1a4c38c383d2d4344fbbdb004072b Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 25 Apr 2024 16:41:02 +0100 Subject: [PATCH] Add more AUTO tests. --- .../src/api/routes/tests/search.spec.ts | 82 ++++++++++++++++--- .../server/src/sdk/app/tables/internal/sqs.ts | 2 +- 2 files changed, 71 insertions(+), 13 deletions(-) diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index cc3bde3a07..0e52879022 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -19,15 +19,16 @@ import _ from "lodash" jest.unmock("mssql") describe.each([ - // ["internal", undefined], - // ["internal-sqs", undefined], - [DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)], + // ["lucene", undefined], + ["sqs", undefined], + // [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 isInternal = name === "internal" + const isSqs = name === "sqs" + const isLucene = name === "lucene" + const isInternal = isSqs || isLucene const config = setup.getConfig() let envCleanup: (() => void) | undefined @@ -60,7 +61,7 @@ describe.each([ } async function createRows(rows: Record[]) { - await Promise.all(rows.map(r => config.api.row.save(table._id!, r))) + await config.api.row.bulkImport(table._id!, { rows }) } class SearchAssertion { @@ -340,14 +341,14 @@ describe.each([ }).toFindNothing()) // We never implemented half-open ranges in Lucene. - !isInternal && + !isLucene && it("can search using just a low value", () => expectQuery({ range: { age: { low: 5 } }, }).toContainExactly([{ age: 10 }])) // We never implemented half-open ranges in Lucene. - !isInternal && + !isLucene && it("can search using just a high value", () => expectQuery({ range: { age: { high: 5 } }, @@ -458,14 +459,14 @@ describe.each([ }).toFindNothing()) // We never implemented half-open ranges in Lucene. - !isInternal && + !isLucene && it("can search using just a low value", () => expectQuery({ range: { dob: { low: JAN_5TH } }, }).toContainExactly([{ dob: JAN_10TH }])) // We never implemented half-open ranges in Lucene. - !isInternal && + !isLucene && it("can search using just a high value", () => expectQuery({ range: { dob: { high: JAN_5TH } }, @@ -643,7 +644,7 @@ describe.each([ // Range searches against bigints don't seem to work at all in Lucene, and I // couldn't figure out why. Given that we're replacing Lucene with SQS, // we've decided not to spend time on it. - !isInternal && + !isLucene && describe("range", () => { it("successfully finds a row", () => expectQuery({ @@ -678,7 +679,7 @@ describe.each([ }) isInternal && - describe.only("auto", () => { + describe("auto", () => { beforeAll(async () => { await createTable({ auto: { @@ -698,5 +699,62 @@ describe.each([ it("fails to find nonexistent row", () => expectQuery({ equal: { auto: 0 } }).toFindNothing()) }) + + describe("not equal", () => { + it("successfully finds a row", () => + expectQuery({ notEqual: { auto: 1 } }).toContainExactly([ + { auto: 2 }, + { auto: 3 }, + ])) + + it("fails to find nonexistent row", () => + expectQuery({ notEqual: { auto: 0 } }).toContainExactly([ + { auto: 1 }, + { auto: 2 }, + { auto: 3 }, + ])) + }) + + describe("oneOf", () => { + it("successfully finds a row", () => + expectQuery({ oneOf: { auto: [1] } }).toContainExactly([{ auto: 1 }])) + + it("fails to find nonexistent row", () => + expectQuery({ oneOf: { auto: [0] } }).toFindNothing()) + }) + + describe("range", () => { + it("successfully finds a row", () => + expectQuery({ + range: { auto: { low: 1, high: 1 } }, + }).toContainExactly([{ auto: 1 }])) + + it("successfully finds multiple rows", () => + expectQuery({ + range: { auto: { low: 1, high: 2 } }, + }).toContainExactly([{ auto: 1 }, { auto: 2 }])) + + it("successfully finds a row with a high bound", () => + expectQuery({ + range: { auto: { low: 2, high: 2 } }, + }).toContainExactly([{ auto: 2 }])) + + it("successfully finds no rows", () => + expectQuery({ + range: { auto: { low: 0, high: 0 } }, + }).toFindNothing()) + + isSqs && + it("can search using just a low value", () => + expectQuery({ + range: { auto: { low: 2 } }, + }).toContainExactly([{ auto: 2 }, { auto: 3 }])) + + isSqs && + it("can search using just a high value", () => + expectQuery({ + range: { auto: { high: 2 } }, + }).toContainExactly([{ auto: 1 }, { auto: 2 }])) + }) }) }) diff --git a/packages/server/src/sdk/app/tables/internal/sqs.ts b/packages/server/src/sdk/app/tables/internal/sqs.ts index 0726c94962..65d44b9af4 100644 --- a/packages/server/src/sdk/app/tables/internal/sqs.ts +++ b/packages/server/src/sdk/app/tables/internal/sqs.ts @@ -33,7 +33,7 @@ const FieldTypeMap: Record = { [FieldType.LONGFORM]: SQLiteType.TEXT, [FieldType.NUMBER]: SQLiteType.REAL, [FieldType.STRING]: SQLiteType.TEXT, - [FieldType.AUTO]: SQLiteType.TEXT, + [FieldType.AUTO]: SQLiteType.REAL, [FieldType.OPTIONS]: SQLiteType.TEXT, [FieldType.JSON]: SQLiteType.BLOB, [FieldType.INTERNAL]: SQLiteType.BLOB,