diff options
| author | Fuwn <[email protected]> | 2026-03-03 09:10:14 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-03 09:10:18 -0800 |
| commit | b3ac58a43e5c604a460e7cfcd6100a6d644f15c6 (patch) | |
| tree | ac7cdcf7f68d623eeb56d05b9f63cbfb5722ca41 /src/lib/Effect/json.test.ts | |
| parent | refactor(effect): add request body schema decoders to api routes (diff) | |
| download | due.moe-b3ac58a43e5c604a460e7cfcd6100a6d644f15c6.tar.xz due.moe-b3ac58a43e5c604a460e7cfcd6100a6d644f15c6.zip | |
refactor(effect): harden settings and media cache json parsing
Diffstat (limited to 'src/lib/Effect/json.test.ts')
| -rw-r--r-- | src/lib/Effect/json.test.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib/Effect/json.test.ts b/src/lib/Effect/json.test.ts new file mode 100644 index 00000000..b315fe61 --- /dev/null +++ b/src/lib/Effect/json.test.ts @@ -0,0 +1,24 @@ +import { describe, expect, it } from "vitest"; +import { + parseJsonStringOrDefault, + parseJsonStringOrThrow, +} from "$lib/Effect/json"; + +describe("effect json parsing", () => { + it("parses valid json strings", () => { + expect(parseJsonStringOrThrow(`{"ok":true,"value":3}`)).toEqual({ + ok: true, + value: 3, + }); + }); + + it("throws for invalid json strings", () => { + expect(() => parseJsonStringOrThrow("{nope}")).toThrowError(); + }); + + it("returns fallback for invalid json", () => { + expect(parseJsonStringOrDefault("{nope}", { ok: false })).toEqual({ + ok: false, + }); + }); +}); |