| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { fromDesktopApp, launchedFromDesktopApp } from "./desktop.ts"; |
| 5 | |
| 6 | const request = (cookie?: string) => new Request("https://g1t.sh/", { headers: cookie ? { cookie } : {} }); |
| 7 | |
| 8 | test("the desktop app is known by its cookie", () => { |
| 9 | assert.equal(fromDesktopApp(request("g1t_ws=acme; g1t_app=desktop")), true); |
| 10 | assert.equal(fromDesktopApp(request("g1t_app=web")), false); |
| 11 | assert.equal(fromDesktopApp(request()), false); |
| 12 | }); |
| 13 | |
| 14 | test("the launcher opens the site with ?app=desktop", () => { |
| 15 | assert.equal(launchedFromDesktopApp(new URL("https://g1t.sh/?app=desktop")), true); |
| 16 | assert.equal(launchedFromDesktopApp(new URL("https://g1t.sh/?app=other")), false); |
| 17 | assert.equal(launchedFromDesktopApp(new URL("https://g1t.sh/")), false); |
| 18 | }); |