Martin Dimitrov 9950766b32
Some checks failed
Build and push image for doorman-homeassistant / docker (push) Successful in 39s
Build and push Doorman UI / API / docker (push) Failing after 18s
Build and push image for doorman-homeassistant / deploy-gitainer (push) Successful in 5s
add integ test step in github actions
2025-06-03 15:43:43 -07:00

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