Skip to content

Open-source status page, incident response and uptime monitoring

1.1 KB
Raw Blame
import { expect, test } from "vitest";

import { app } from "@/index";

import { MonitorSchema } from "./schema";

test("update the monitor", async () => {
  const res = await app.request("/v1/monitor/1", {
    method: "PUT",
    headers: {
      "x-openstatus-key": "1",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      name: "New Name",
    }),
  });
  const data = await res.json();
  const monitor = MonitorSchema.parse(data);
  expect(res.status).toBe(200);
  expect(monitor.name).toBe("New Name");
});

test("invalid monitor id should return 404", async () => {
  const res = await app.request("/v1/monitor/404", {
    method: "PUT",
    headers: {
      "x-openstatus-key": "1",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({/* */}),
  });

  expect(res.status).toBe(404);
});

test("no auth key should return 401", async () => {
  const res = await app.request("/v1/monitor/2", {
    method: "PUT",
    headers: {
      "content-type": "application/json",
    },
    body: JSON.stringify({/* */}),
  });

  expect(res.status).toBe(401);
});