aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Effect/json.test.ts
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-03-03 09:10:14 -0800
committerFuwn <[email protected]>2026-03-03 09:10:18 -0800
commitb3ac58a43e5c604a460e7cfcd6100a6d644f15c6 (patch)
treeac7cdcf7f68d623eeb56d05b9f63cbfb5722ca41 /src/lib/Effect/json.test.ts
parentrefactor(effect): add request body schema decoders to api routes (diff)
downloaddue.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.ts24
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,
+ });
+ });
+});