41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { describe, test, expect, beforeAll } from "bun:test";
|
|
|
|
const baseUrl = "http://localhost:8080";
|
|
const doorName = "test";
|
|
const buzzerNumber = "6133163433";
|
|
|
|
const waitForService = async (url: string, timeout = 30000) => {
|
|
const start = Date.now();
|
|
|
|
while (Date.now() - start < timeout) {
|
|
try {
|
|
await fetch(url);
|
|
return true;
|
|
} catch (err) {
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
}
|
|
}
|
|
throw new Error(`Service at ${url} did not start within ${timeout}ms`);
|
|
};
|
|
|
|
beforeAll(async () => {
|
|
await waitForService(baseUrl);
|
|
});
|
|
|
|
describe("info route works", () => {
|
|
test("info works from UI", async () => {
|
|
const resp = await fetch(baseUrl + `/api/door/info?door=${doorName}`).then(res => res.json()) as any;
|
|
|
|
expect(resp.id as string).toBe(doorName);
|
|
expect(resp.buzzer).toBe(buzzerNumber);
|
|
});
|
|
|
|
test("info works from client", async () => {
|
|
const resp = await fetch(baseUrl + `/api/door/info?buzzer=${buzzerNumber}`).then(res => res.json()) as any;
|
|
|
|
// TODO: why is this different?
|
|
expect(resp.door as string).toBe(doorName);
|
|
expect(resp.buzzer).toBe(buzzerNumber);
|
|
});
|
|
});
|