From b07db7b0980bc260d3b053b61783de6247a25e77 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 25 Apr 2024 16:51:42 +0100 Subject: [PATCH] Make sure we're treating AUTO as numbers. --- .../src/api/routes/tests/search.spec.ts | 63 +++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/packages/server/src/api/routes/tests/search.spec.ts b/packages/server/src/api/routes/tests/search.spec.ts index 0e52879022..c20e4e36c8 100644 --- a/packages/server/src/api/routes/tests/search.spec.ts +++ b/packages/server/src/api/routes/tests/search.spec.ts @@ -61,7 +61,10 @@ describe.each([ } async function createRows(rows: Record[]) { - await config.api.row.bulkImport(table._id!, { rows }) + // await config.api.row.bulkImport(table._id!, { rows }) + for (const row of rows) { + await config.api.row.save(table._id!, row) + } } class SearchAssertion { @@ -689,7 +692,7 @@ describe.each([ subtype: AutoFieldSubType.AUTO_ID, }, }) - await createRows([{}, {}, {}]) + await createRows(new Array(10).fill({})) }) describe("equal", () => { @@ -705,6 +708,13 @@ describe.each([ expectQuery({ notEqual: { auto: 1 } }).toContainExactly([ { auto: 2 }, { auto: 3 }, + { auto: 4 }, + { auto: 5 }, + { auto: 6 }, + { auto: 7 }, + { auto: 8 }, + { auto: 9 }, + { auto: 10 }, ])) it("fails to find nonexistent row", () => @@ -712,6 +722,13 @@ describe.each([ { auto: 1 }, { auto: 2 }, { auto: 3 }, + { auto: 4 }, + { auto: 5 }, + { auto: 6 }, + { auto: 7 }, + { auto: 8 }, + { auto: 9 }, + { auto: 10 }, ])) }) @@ -747,8 +764,8 @@ describe.each([ isSqs && it("can search using just a low value", () => expectQuery({ - range: { auto: { low: 2 } }, - }).toContainExactly([{ auto: 2 }, { auto: 3 }])) + range: { auto: { low: 9 } }, + }).toContainExactly([{ auto: 9 }, { auto: 10 }])) isSqs && it("can search using just a high value", () => @@ -756,5 +773,43 @@ describe.each([ range: { auto: { high: 2 } }, }).toContainExactly([{ auto: 1 }, { auto: 2 }])) }) + + describe("sort", () => { + it("sorts ascending", () => + expectSearch({ + query: {}, + sort: "auto", + sortOrder: SortOrder.ASCENDING, + }).toMatchExactly([ + { auto: 1 }, + { auto: 2 }, + { auto: 3 }, + { auto: 4 }, + { auto: 5 }, + { auto: 6 }, + { auto: 7 }, + { auto: 8 }, + { auto: 9 }, + { auto: 10 }, + ])) + + it("sorts descending", () => + expectSearch({ + query: {}, + sort: "auto", + sortOrder: SortOrder.DESCENDING, + }).toMatchExactly([ + { auto: 10 }, + { auto: 9 }, + { auto: 8 }, + { auto: 7 }, + { auto: 6 }, + { auto: 5 }, + { auto: 4 }, + { auto: 3 }, + { auto: 2 }, + { auto: 1 }, + ])) + }) }) })