Skip to content

Commit 944925b

Browse files
committed
test(fmodata): add tests for Date value handling in temporal columns
This commit introduces a new test case to ensure that only Date values are accepted for temporal columns (e.g., dateField, timeField, timestampField) in the fmodata package. It verifies that non-temporal fields (e.g., textField) correctly reject Date values, enhancing type safety and validation in the filter tests.
1 parent c72543a commit 944925b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

packages/fmodata/tests/filters.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
or,
3333
startsWith,
3434
textField,
35+
timeField,
3536
timestampField,
3637
tolower,
3738
toupper,
@@ -628,4 +629,37 @@ describe("Filter Tests", () => {
628629
.getQueryString();
629630
expect(gtTimestampQuery).toContain("createdAt gt 2024-01-01T12:34:56.000Z");
630631
});
632+
633+
it("should only allow Date values with temporal columns", () => {
634+
const typedTable = fmTableOccurrence("typed_table", {
635+
id: textField().primaryKey(),
636+
notes: textField(),
637+
invoiceDate: dateField(),
638+
alarmTime: timeField(),
639+
createdAt: timestampField(),
640+
});
641+
const now = new Date("2024-01-01T12:34:56.000Z");
642+
643+
// Temporal fields should accept Date values
644+
gt(typedTable.invoiceDate, now);
645+
gte(typedTable.alarmTime, now);
646+
lt(typedTable.createdAt, now);
647+
lte(typedTable.invoiceDate, now);
648+
eq(typedTable.createdAt, now);
649+
ne(typedTable.alarmTime, now);
650+
651+
// Non-temporal fields must reject Date values
652+
// @ts-expect-error - Date values should not be allowed for text columns
653+
gt(typedTable.notes, now);
654+
// @ts-expect-error - Date values should not be allowed for text columns
655+
gte(typedTable.notes, now);
656+
// @ts-expect-error - Date values should not be allowed for text columns
657+
lt(typedTable.notes, now);
658+
// @ts-expect-error - Date values should not be allowed for text columns
659+
lte(typedTable.notes, now);
660+
// @ts-expect-error - Date values should not be allowed for text columns
661+
eq(typedTable.notes, now);
662+
// @ts-expect-error - Date values should not be allowed for text columns
663+
ne(typedTable.notes, now);
664+
});
631665
});

0 commit comments

Comments
 (0)