Skip to content

Open-source status page, incident response and uptime monitoring

🧪 fix incidents tests (#610)

Thibault Le Ouay20c95ea981a4
diff --git a/apps/server/src/v1/incidents.test.ts b/apps/server/src/v1/incidents.test.ts
index 4ddf480e7..c14d10580 100644
--- a/apps/server/src/v1/incidents.test.ts
+++ b/apps/server/src/v1/incidents.test.ts
@@ -17,7 +17,7 @@ test("GET one Incident", async () => {
});
test("Update an incident ", async () => {
- const res = await api.request("/incident/1", {
+ const res = await api.request("/incident/2", {
method: "PUT",
headers: {
"x-openstatus-key": "1",
@@ -32,7 +32,7 @@ test("Update an incident ", async () => {
expect(await res.json()).toMatchObject({
acknowledgedAt: "2023-11-08T21:03:13.000Z",
monitorId: 1,
- id: 1,
+ id: 2,
startedAt: expect.any(String),
resolvedAt: null,
resolvedBy: null,
diff --git a/apps/server/src/v1/incidents.ts b/apps/server/src/v1/incidents.ts
index 67469ce60..656aefc11 100644
--- a/apps/server/src/v1/incidents.ts
+++ b/apps/server/src/v1/incidents.ts
@@ -46,7 +46,8 @@ const IncidentSchema = z.object({
.openapi({
description: "The date the incident was acknowledged",
})
- .optional(),
+ .optional()
+ .nullable(),
acknowledgedBy: z
.number()
@@ -211,7 +212,12 @@ incidentsApi.openapi(putRoute, async (c) => {
const _incident = await db
.select()
.from(incidentTable)
- .where(eq(incidentTable.id, Number(id)))
+ .where(
+ and(
+ eq(incidentTable.id, Number(id)),
+ eq(incidentTable.workspaceId, workspaceId),
+ ),
+ )
.get();
if (!_incident) return c.jsonT({ code: 404, message: "Not Found" });
@@ -225,6 +231,7 @@ incidentsApi.openapi(putRoute, async (c) => {
.set({
...input,
})
+ .where(eq(incidentTable.id, Number(id)))
.returning()
.get();
diff --git a/packages/db/src/seed.mts b/packages/db/src/seed.mts
index d5027f908..f24d8cf66 100644
--- a/packages/db/src/seed.mts
+++ b/packages/db/src/seed.mts
@@ -5,13 +5,13 @@ import { drizzle } from "drizzle-orm/libsql";
import { env } from "../env.mjs";
import {
+ incidentTable,
monitor,
monitorsToPages,
notification,
notificationsToMonitors,
page,
statusReport,
- incidentTable,
statusReportUpdate,
user,
usersToWorkspaces,
@@ -139,9 +139,19 @@ async function main() {
id: 1,
workspaceId: 1,
monitorId: 1,
+ createdAt: new Date(),
})
.run();
+ await db
+ .insert(incidentTable)
+ .values({
+ id: 2,
+ workspaceId: 1,
+ monitorId: 1,
+ createdAt: new Date(),
+ })
+ .run();
await db
.insert(statusReportUpdate)
.values({