sipher/tests/discover.test.ts
Nixyan 8309770be5 feat: add server discovery tests and enhance public key validation
- Introduced a new test suite for server discovery functionality, ensuring proper registration and response handling.
- Enhanced public key validation logic to include detailed error messages for invalid keys.
- Updated package.json with a new test command for the discovery tests.
- Removed outdated Playwright CI workflow configuration.
2026-03-10 14:05:04 -03:00

39 lines
No EOL
1.3 KiB
TypeScript

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)
});