aboutsummaryrefslogtreecommitdiff
path: root/tests/session-io.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/session-io.test.ts')
-rw-r--r--tests/session-io.test.ts51
1 files changed, 28 insertions, 23 deletions
diff --git a/tests/session-io.test.ts b/tests/session-io.test.ts
index 6de919b..88c1ee6 100644
--- a/tests/session-io.test.ts
+++ b/tests/session-io.test.ts
@@ -16,29 +16,7 @@ import {
type TabInput = Parameters<typeof tabToExport>[0];
-function validExport(): SessionExport {
- return {
- exportedAt: "2026-04-24T00:00:00.000Z",
- tabs: [
- {
- headers: "{}",
- operationName: "MyOp",
- query: "query MyOp { hello }",
- title: "MyOp",
- variables: "{}"
- }
- ],
- version: 1
- };
-}
-
-function isError(result: unknown): result is { error: string } {
- return typeof result === "object" &&
- result !== null &&
- "error" in result;
-}
-
-/*** TESTS -------------------------------------------- ***/
+/*** PROGRAM ------------------------------------------ ***/
test("validateSessionExport round-trips a valid payload unchanged", () => {
const data = validExport();
@@ -58,6 +36,7 @@ test("validateSessionExport rejects non-object input", () => {
test("validateSessionExport rejects wrong version", () => {
const zero = validateSessionExport({ ...validExport(), version: 0 });
const two = validateSessionExport({ ...validExport(), version: 2 });
+
const missing = validateSessionExport({
exportedAt: "2026-04-24T00:00:00.000Z",
tabs: []
@@ -142,6 +121,7 @@ test("validateSessionExport accepts null operationName", () => {
test("validateSessionExport rejects string field > 1 MB", () => {
const big = "x".repeat(1024 * 1024 + 1);
+
const result = validateSessionExport({
exportedAt: "2026-04-24T00:00:00.000Z",
tabs: [
@@ -167,6 +147,7 @@ test("validateSessionExport rejects > 50 tabs", () => {
title: "t",
variables: "{}"
}));
+
const result = validateSessionExport({
exportedAt: "2026-04-24T00:00:00.000Z",
tabs,
@@ -199,3 +180,27 @@ test("tabToExport strips id, result, operations, titleDirty", () => {
variables: "{}"
});
});
+
+/*** HELPER ------------------------------------------- ***/
+
+function isError(result: unknown): result is { error: string } {
+ return typeof result === "object" &&
+ result !== null &&
+ "error" in result;
+}
+
+function validExport(): SessionExport {
+ return {
+ exportedAt: "2026-04-24T00:00:00.000Z",
+ tabs: [
+ {
+ headers: "{}",
+ operationName: "MyOp",
+ query: "query MyOp { hello }",
+ title: "MyOp",
+ variables: "{}"
+ }
+ ],
+ version: 1
+ };
+}