-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for deserializing string dates
- Loading branch information
1 parent
b5f8ec1
commit cd74f85
Showing
5 changed files
with
30 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
import { UUID_SCHEMA } from "../../../src/shared/domain"; | ||
import { isEqual, parseJSON } from "date-fns"; | ||
import { DATE_OR_STRING_SCHEMA, UUID_SCHEMA } from "../../../src/shared/domain"; | ||
|
||
test("uuidSchema", async () => { | ||
test("UUID_SCHEMA", async () => { | ||
const uuid = "d3ZU8GmTG3"; | ||
expect(await UUID_SCHEMA.parseAsync(uuid)).toBe("d3ZU8GmTG3"); | ||
}); | ||
|
||
test("DATE_OR_STRING_SCHEMA", async () => { | ||
// In the past we've had some deserialize bugs pop up because JSON stores dates | ||
// as strings. This test is just to help prevent regressions. | ||
|
||
const date = new Date("2020-01-01T20:37:21.765Z") | ||
const parsed = await DATE_OR_STRING_SCHEMA.parseAsync(date); | ||
expect(isEqual(date, parsed)).toBe(true); | ||
|
||
const serializedDate = "2022-09-09T20:37:21.765Z"; | ||
const parsedSerializedDate = parseJSON(serializedDate); | ||
expect(isEqual(parsedSerializedDate, parsedSerializedDate)).toBe(true); | ||
} |