Files
Termix/plugins/tunnels/tests/backend/c2s-source-host.test.ts
T

32 lines
994 B
TypeScript
Raw Normal View History

+17
2026-09-20 14:56:39 -05:00
import { describe, expect, it, vi } from "vitest";
2026-10-01 16:20:16 -05:00
import { resolveC2SSourceHostId } from "../../src/backend/c2s-relay.js";
+17
2026-09-20 14:56:39 -05:00
describe("resolveC2SSourceHostId", () => {
2026-10-01 16:20:16 -05:00
it("uses the row matching the stable sync id", async () => {
+17
2026-09-20 14:56:39 -05:00
const findBySyncId = vi.fn().mockResolvedValue(42);
await expect(
resolveC2SSourceHostId(
{ sourceHostId: 7, sourceHostSyncId: "host-sync-id" },
findBySyncId,
),
).resolves.toBe(42);
expect(findBySyncId).toHaveBeenCalledWith("host-sync-id");
});
2026-10-01 16:20:16 -05:00
it("keeps a local id when no sync id is available", async () => {
+17
2026-09-20 14:56:39 -05:00
await expect(
resolveC2SSourceHostId({ sourceHostId: 7 }, vi.fn()),
).resolves.toBe(7);
});
it("does not silently fall back to a mismatched id", async () => {
await expect(
resolveC2SSourceHostId(
{ sourceHostId: 7, sourceHostSyncId: "missing" },
vi.fn().mockResolvedValue(null),
),
).rejects.toThrow("not found on the remote server");
});
});