| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { connectLink, parseDiscovery } from "./discovery.ts"; |
| 5 | |
| 6 | test("a discovery document is read for its origins", () => { |
| 7 | assert.deepEqual( |
| 8 | parseDiscovery({ |
| 9 | name: "g1t", |
| 10 | site: "https://g1t.example.com/", |
| 11 | api: "http://10.0.0.5:8789/x", |
| 12 | mcp: "https://g1t.example.com/mcp/", |
| 13 | hosted: false, |
| 14 | phone: { chat: true, push: false }, |
| 15 | }), |
| 16 | { |
| 17 | name: "g1t", |
| 18 | site: "https://g1t.example.com", |
| 19 | api: "http://10.0.0.5:8789", |
| 20 | mcp: "https://g1t.example.com/mcp", |
| 21 | hosted: false, |
| 22 | phone: { chat: true, push: false }, |
| 23 | }, |
| 24 | ); |
| 25 | }); |
| 26 | |
| 27 | test("anything else is not one", () => { |
| 28 | assert.equal(parseDiscovery(null), null); |
| 29 | assert.equal(parseDiscovery({ site: "https://a.example", api: "https://b.example" }), null, "no name"); |
| 30 | assert.equal(parseDiscovery({ name: "g1t", site: "javascript:alert(1)", api: "https://b.example" }), null); |
| 31 | assert.equal(parseDiscovery({ name: "g1t", site: "https://a.example" }), null, "no API"); |
| 32 | }); |
| 33 | |
| 34 | test("a connect link carries the site", () => { |
| 35 | assert.equal(connectLink("https://g1t.example.com"), "g1t://connect?server=https%3A%2F%2Fg1t.example.com"); |
| 36 | }); |