Add sorting tests for dateonly fields.

This commit is contained in:
Sam Rose 2025-01-13 11:56:33 +00:00
parent 0ae1d09534
commit d06b22d4b8
No known key found for this signature in database
1 changed files with 192 additions and 126 deletions

View File

@ -1690,6 +1690,9 @@ if (descriptions.length) {
describe.each([true, false])( describe.each([true, false])(
"search with timestamp: %s", "search with timestamp: %s",
searchWithTimestamp => { searchWithTimestamp => {
describe.each(["/", "-"])(
"date separator: %s",
separator => {
const SAVE_SUFFIX = saveWithTimestamp const SAVE_SUFFIX = saveWithTimestamp
? "T00:00:00.000Z" ? "T00:00:00.000Z"
: "" : ""
@ -1705,7 +1708,10 @@ if (descriptions.length) {
beforeAll(async () => { beforeAll(async () => {
tableOrViewId = await createTableOrView({ tableOrViewId = await createTableOrView({
dateid: { name: "dateid", type: FieldType.STRING }, dateid: {
name: "dateid",
type: FieldType.STRING,
},
date: { date: {
name: "date", name: "date",
type: FieldType.DATETIME, type: FieldType.DATETIME,
@ -1751,7 +1757,9 @@ if (descriptions.length) {
describe("notEqual", () => { describe("notEqual", () => {
it("successfully finds a row", async () => { it("successfully finds a row", async () => {
await expectQuery({ await expectQuery({
notEqual: { date: `${JAN_1ST}${SEARCH_SUFFIX}` }, notEqual: {
date: `${JAN_1ST}${SEARCH_SUFFIX}`,
},
}).toContainExactly([ }).toContainExactly([
{ date: JAN_10TH }, { date: JAN_10TH },
{ dateid: NULL_DATE__ID }, { dateid: NULL_DATE__ID },
@ -1760,7 +1768,9 @@ if (descriptions.length) {
it("fails to find nonexistent row", async () => { it("fails to find nonexistent row", async () => {
await expectQuery({ await expectQuery({
notEqual: { date: `${JAN_30TH}${SEARCH_SUFFIX}` }, notEqual: {
date: `${JAN_30TH}${SEARCH_SUFFIX}`,
},
}).toContainExactly([ }).toContainExactly([
{ date: JAN_1ST }, { date: JAN_1ST },
{ date: JAN_10TH }, { date: JAN_10TH },
@ -1822,6 +1832,62 @@ if (descriptions.length) {
}).toFindNothing() }).toFindNothing()
}) })
}) })
describe.only("sort", () => {
it("sorts ascending", async () => {
await expectSearch({
query: {},
sort: "date",
sortOrder: SortOrder.ASCENDING,
}).toMatchExactly([
{ dateid: NULL_DATE__ID },
{ date: JAN_1ST },
{ date: JAN_10TH },
])
})
it("sorts descending", async () => {
await expectSearch({
query: {},
sort: "date",
sortOrder: SortOrder.DESCENDING,
}).toMatchExactly([
{ date: JAN_10TH },
{ date: JAN_1ST },
{ dateid: NULL_DATE__ID },
])
})
describe("sortType STRING", () => {
it("sorts ascending", async () => {
await expectSearch({
query: {},
sort: "date",
sortType: SortType.STRING,
sortOrder: SortOrder.ASCENDING,
}).toMatchExactly([
{ dateid: NULL_DATE__ID },
{ date: JAN_1ST },
{ date: JAN_10TH },
])
})
it("sorts descending", async () => {
await expectSearch({
query: {},
sort: "date",
sortType: SortType.STRING,
sortOrder: SortOrder.DESCENDING,
}).toMatchExactly([
{ date: JAN_10TH },
{ date: JAN_1ST },
{ dateid: NULL_DATE__ID },
])
})
})
})
}
)
} }
) )
} }