51 lines
2.2 KiB
TypeScript
51 lines
2.2 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
import { ensureOwner, signIn } from "./helpers";
|
|
|
|
const BASE_URL = process.env.E2E_BASE_URL ?? "http://localhost:3000";
|
|
|
|
test("heartbeat monitor: URL ping, /fail, header ping", async ({ page, request }) => {
|
|
const owner = await ensureOwner(request);
|
|
await signIn(page, owner.email, owner.password);
|
|
|
|
const create = await page.request.post(`${BASE_URL}/api/monitors`, {
|
|
data: {
|
|
name: `e2e heartbeat ${Date.now()}`,
|
|
type: "heartbeat",
|
|
target: { period_sec: 3600, grace_sec: 300 },
|
|
enabled: true,
|
|
},
|
|
});
|
|
expect(create.status()).toBe(201);
|
|
const monitor = await create.json();
|
|
expect(monitor.heartbeat_token).toBeTruthy();
|
|
|
|
const ping = await request.get(`${BASE_URL}/public/hb/${monitor.heartbeat_token}`);
|
|
expect(ping.status()).toBe(200);
|
|
expect(await ping.text()).toBe("OK");
|
|
|
|
let got = await (await page.request.get(`${BASE_URL}/api/monitors/${monitor.monitor_id}`)).json();
|
|
expect(got.state.status).toBe("up");
|
|
|
|
const fail = await request.post(`${BASE_URL}/public/hb/${monitor.heartbeat_token}/fail`, { data: "disk full" });
|
|
expect(fail.status()).toBe(200);
|
|
|
|
got = await (await page.request.get(`${BASE_URL}/api/monitors/${monitor.monitor_id}`)).json();
|
|
expect(got.state.status).toBe("down");
|
|
expect(got.state.message).toContain("disk full");
|
|
|
|
const incidents = await (await page.request.get(`${BASE_URL}/api/monitors/${monitor.monitor_id}/incidents`)).json();
|
|
expect(incidents.length).toBeGreaterThan(0);
|
|
|
|
await new Promise((r) => setTimeout(r, 1100));
|
|
const headerPing = await request.post(`${BASE_URL}/public/hb`, { headers: { "X-Vantage-Token": monitor.heartbeat_token } });
|
|
expect(headerPing.status()).toBe(200);
|
|
got = await (await page.request.get(`${BASE_URL}/api/monitors/${monitor.monitor_id}`)).json();
|
|
expect(got.state.status).toBe("up");
|
|
|
|
expect((await request.get(`${BASE_URL}/public/hb/not-a-real-token`)).status()).toBe(404);
|
|
expect((await request.post(`${BASE_URL}/public/hb`)).status()).toBe(404);
|
|
|
|
await page.goto(`${BASE_URL}/monitors/${monitor.monitor_id}`);
|
|
await expect(page.getByText(/last ping/i)).toBeVisible();
|
|
});
|