import { beforeEach, describe, expect, it, vi } from "vitest"; import { authedContext, getPluginClient } from "./setup"; vi.setConfig({ testTimeout: 120_000, hookTimeout: 60_000 }); const nodeInput = { hostname: "app.vault-test.dev", zone: "vault-test.dev", tenantAccountId: "acme.near", gateway: "vault-test.dev", tenancy: "dedicated" as const, hostingApp: "bos-acme-abc123", hostingUrl: "https://bos-acme-abc123.fly.dev", }; async function clearNode(hostname: string) { const client = await getPluginClient(authedContext("operator-1")); await client.nodes.remove({ hostname }).catch(() => undefined); } describe("node bindings", () => { beforeEach(async () => { await clearNode(nodeInput.hostname); }); it("refuses unauthenticated binding creation", async () => { const client = await getPluginClient(); await expect(client.nodes.create(nodeInput)).rejects.toThrow(/Authentication required/); }); it("creates a binding and serves it on the tenants route as a bare array", async () => { const client = await getPluginClient(authedContext("operator-1")); const created = await client.nodes.create(nodeInput); expect(created).toMatchObject({ hostname: nodeInput.hostname, accountId: nodeInput.tenantAccountId, tenancy: "dedicated", hostingApp: nodeInput.hostingApp, status: "active", }); expect(created.verificationToken).toBeNull(); const bindings = await client.tenants.bindings(); const row = bindings.find((binding) => binding.hostname === nodeInput.hostname); expect(row).toMatchObject({ tenancy: "dedicated", accountId: nodeInput.tenantAccountId, hostingUrl: nodeInput.hostingUrl, status: "active", }); }); it("refuses a duplicate hostname binding", async () => { const client = await getPluginClient(authedContext("operator-1")); await client.nodes.create(nodeInput); await expect(client.nodes.create(nodeInput)).rejects.toThrow(/already exists/); }); it("removes a binding", async () => { const client = await getPluginClient(authedContext("operator-1")); await client.nodes.create(nodeInput); const removed = await client.nodes.remove({ hostname: nodeInput.hostname }); expect(removed.removed).toBe(true); const bindings = await client.tenants.bindings(); expect(bindings.find((binding) => binding.hostname === nodeInput.hostname)).toBeUndefined(); }); });