Open History to see the last commit
1import type { AuthConnectDevice } from "@t3tools/contracts";
2import * as DateTime from "effect/DateTime";
3import { describe, expect, it } from "vite-plus/test";
4
5import { unseenConnectDevices } from "./connectDeviceNotices.ts";
6
7const device = (proofKeyThumbprint: string, approvedAt: number): AuthConnectDevice => ({
8 proofKeyThumbprint,
9 verificationCode: "ABCD-EFGH",
10 approvedAt: DateTime.makeUnsafe(approvedAt),
11});
12
13describe("unseenConnectDevices", () => {
14 it("starts a new client at the newest key, then reports keys that arrive later", () => {
15 const own = device("own", 1_000);
16 const first = unseenConnectDevices([own], undefined);
17 expect(first).toEqual({ unseen: [], newest: 1_000 });
18
19 const stranger = device("stranger", 2_000);
20 expect(unseenConnectDevices([own, stranger], first.newest)).toEqual({
21 unseen: [stranger],
22 newest: 2_000,
23 });
24 });
25
26 it("reports the first key on a host that had none when this client looked", () => {
27 const empty = unseenConnectDevices([], undefined);
28 const stranger = device("stranger", 2_000);
29 expect(unseenConnectDevices([stranger], empty.newest).unseen).toEqual([stranger]);
30 });
31});