Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

secretRequest.test.ts

39 lines1.5 KB

1import { SecretRequestError } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 secretRequestDisplay,
6 secretRequestFailureMessage,
7 secretRequestPrivacyNote,
8} from "./secretRequest.ts";
9​
10describe("secretRequestDisplay", () => {
11 it("never offers the form for a request inherited from another thread", () => {
12 expect(secretRequestDisplay({ secretStatus: "pending" }, "inherited")).toEqual({
13 kind: "pending-elsewhere",
14 label: "Waiting for an answer in the original thread",
15 });
16 expect(secretRequestDisplay({ secretStatus: "saved" }, "inherited")).toMatchObject({
17 outcome: "saved",
18 });
19 });
20});
21​
22describe("secretRequestPrivacyNote", () => {
23 it("does not promise to hide a value that the agent's commands can read", () => {
24 expect(secretRequestPrivacyNote({})).toBe("Stored securely, never shown to the agent");
25 expect(secretRequestPrivacyNote({ delivery: "file" })).not.toContain("never shown");
26 });
27});
28​
29describe("secretRequestFailureMessage", () => {
30 it("passes through server errors but hides anything that could echo the payload", () => {
31 expect(
32 secretRequestFailureMessage(new SecretRequestError({ reason: "already_answered" })),
33 ).toBe("This secret request was already answered.");
34 expect(secretRequestFailureMessage(new Error('Expected string, got "whsec_1"'))).toBe(
35 "Could not answer the request. Try again.",
36 );
37 expect(secretRequestFailureMessage(undefined)).toBe("Could not answer the request. Try again.");
38 });
39});