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

secretRequest.test.ts

28 lines1.2 KB

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