import { expect, test } from "@playwright/test"; import createDebug from "debug"; import { clearServerRegistry, getServerByUrl, insertServerEcho, } from "./helpers/db"; const debug = createDebug("test:discover"); const url = "http://172.21.157.201:3001"; test.beforeEach(async () => { await clearServerRegistry() }) test.afterEach(async () => { await clearServerRegistry() }) test("discover server", async ({ request, page }) => { const response = await request.post(`http://192.168.3.26:3000/discover`, { data: { method: "REGISTER", url: new URL(url).toString(), publicKey: process.env.FEDERATION_PUBLIC_KEY!, } }) const status = response.status() const body = await response.json(); debug("response status: %o", status); debug("response body: %o", body); expect(status).toBe(200) expect(body).toMatchObject({ message: "Server registered successfully" }) expect(body.echo).toBeInstanceOf(Object) // We can't assert the exact object because the echo is generated by the server // Insert the server echo into our database await insertServerEcho("http://192.168.3.26:3000", body.echo.publicKey as string); // check on the database itself if the server was registered const server = await getServerByUrl("http://192.168.3.26:3000"); expect(server).toBeDefined() expect(server?.publicKey).toBe(body.echo.publicKey as string) });