Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/test-me-tasks.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Unit tests for me/tasks API helpers (patch + board state merge).
* Unit tests for me/tasks API helpers (board state merge).
* Path encoding lives in scripts/test-paths.mjs (encodeTaskPathParam).
* Run: node --experimental-strip-types scripts/test-me-tasks.mjs
*/
import {
Expand Down
29 changes: 29 additions & 0 deletions scripts/test-paths.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
flatClassPath,
flatTaskPath,
isValidTaskRouteRef,
encodeTaskPathParam,
normalizeMeTaskPointer,
} from "../src/common/paths.ts";

let failed = 0;
Expand Down Expand Up @@ -145,6 +147,33 @@ assert(!isValidTaskRouteRef("t@mvla.net/abc123"), "rejects email/classId (class,
assert(!isValidTaskRouteRef("a~b~c~d"), "rejects four-segment refs");
assert(!isValidTaskRouteRef("classId~"), "rejects trailing empty task id");

console.log("\n--- me/tasks path encoding (tilde, not %2F) ---\n");

assertEq(
normalizeMeTaskPointer("classA/taskB"),
{ path: "classA/taskB", tildeRef: "classA~taskB" },
"normalize slash"
);
assertEq(
normalizeMeTaskPointer("classA~taskB"),
{ path: "classA/taskB", tildeRef: "classA~taskB" },
"normalize tilde"
);
assertEq(
normalizeMeTaskPointer("teacher@school.edu/classA/taskB"),
{ path: "classA/taskB", tildeRef: "classA~taskB" },
"normalize legacy email path"
);
assert(
encodeTaskPathParam("classA/taskB") === encodeURIComponent("classA~taskB"),
"encode prefers tilde, not %2F"
);
assert(!encodeTaskPathParam("classA/taskB").includes("%2F"), "encoded path must not contain %2F");
assert(
encodeTaskPathParam("classA~taskB") === encodeURIComponent("classA~taskB"),
"encode tilde passthrough"
);

console.log("\n--- done ---\n");
if (failed) {
console.error(`${failed} assertion(s) failed`);
Expand Down
6 changes: 4 additions & 2 deletions src/common/meTaskState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* @module common/meTaskState
*/

import { flatTaskPath } from "./paths";

/** Per-task personal state returned by me/tasks and board payloads. */
export interface MeTaskState {
ref: string;
Expand All @@ -16,6 +14,10 @@ export interface MeTaskState {
workspace_id: string | null;
}

function flatTaskPath(classId: string, taskId: string): string {
return [classId, taskId].join("/");
}

/** Merge board task row fields into a MeTaskState map entry. */
export function meTaskStateFromBoardTask(
task: Record<string, unknown>,
Expand Down
Loading
Loading