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

webhookAddress.test.ts

36 lines1.3 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { webhookAddress } from "./webhookAddress.ts";
4​
5const path = "/api/hooks/scheduled-task%3Ahook/token";
6const endpoint = (url: string | null) => ({ path, url, hasSecret: false });
7​
8describe("webhookAddress", () => {
9 it("uses the T3 Connect URL when the server has one", () => {
10 expect(webhookAddress(endpoint("https://relay.t3.codes/v1/hooks/k/t/x"), null)).toEqual({
11 address: "https://relay.t3.codes/v1/hooks/k/t/x",
12 copyable: true,
13 note: null,
14 });
15 });
16​
17 it("builds a direct URL on the environment's address without T3 Connect", () => {
18 const result = webhookAddress(endpoint(null), "https://mac.tail1234.ts.net/");
19 expect(result.address).toBe(`https://mac.tail1234.ts.net${path}`);
20 expect(result.copyable).toBe(true);
21 expect(result.note).toContain("Tailscale");
22 });
23​
24 it("says only this computer can call a loopback address", () => {
25 const result = webhookAddress(endpoint(null), "http://127.0.0.1:3773/");
26 expect(result.copyable).toBe(true);
27 expect(result.note).toContain("Only this computer");
28 });
29​
30 it("falls back to the path when the address is unknown", () => {
31 expect(webhookAddress(endpoint(null), null)).toMatchObject({
32 address: path,
33 copyable: false,
34 });
35 });
36});