Openstatus www.openstatus.dev

🧪 fix incidents tests (#610)

authored by

Thibault Le Ouay and committed by
GitHub
20c95ea9 a0c5b48d

+22 -5
+2 -2
apps/server/src/v1/incidents.test.ts
··· 17 17 }); 18 18 19 19 test("Update an incident ", async () => { 20 - const res = await api.request("/incident/1", { 20 + const res = await api.request("/incident/2", { 21 21 method: "PUT", 22 22 headers: { 23 23 "x-openstatus-key": "1", ··· 32 32 expect(await res.json()).toMatchObject({ 33 33 acknowledgedAt: "2023-11-08T21:03:13.000Z", 34 34 monitorId: 1, 35 - id: 1, 35 + id: 2, 36 36 startedAt: expect.any(String), 37 37 resolvedAt: null, 38 38 resolvedBy: null,
+9 -2
apps/server/src/v1/incidents.ts
··· 46 46 .openapi({ 47 47 description: "The date the incident was acknowledged", 48 48 }) 49 - .optional(), 49 + .optional() 50 + .nullable(), 50 51 51 52 acknowledgedBy: z 52 53 .number() ··· 211 212 const _incident = await db 212 213 .select() 213 214 .from(incidentTable) 214 - .where(eq(incidentTable.id, Number(id))) 215 + .where( 216 + and( 217 + eq(incidentTable.id, Number(id)), 218 + eq(incidentTable.workspaceId, workspaceId), 219 + ), 220 + ) 215 221 .get(); 216 222 217 223 if (!_incident) return c.jsonT({ code: 404, message: "Not Found" }); ··· 225 231 .set({ 226 232 ...input, 227 233 }) 234 + .where(eq(incidentTable.id, Number(id))) 228 235 .returning() 229 236 .get(); 230 237
+11 -1
packages/db/src/seed.mts
··· 5 5 6 6 import { env } from "../env.mjs"; 7 7 import { 8 + incidentTable, 8 9 monitor, 9 10 monitorsToPages, 10 11 notification, 11 12 notificationsToMonitors, 12 13 page, 13 14 statusReport, 14 - incidentTable, 15 15 statusReportUpdate, 16 16 user, 17 17 usersToWorkspaces, ··· 139 139 id: 1, 140 140 workspaceId: 1, 141 141 monitorId: 1, 142 + createdAt: new Date(), 142 143 }) 143 144 .run(); 144 145 146 + await db 147 + .insert(incidentTable) 148 + .values({ 149 + id: 2, 150 + workspaceId: 1, 151 + monitorId: 1, 152 + createdAt: new Date(), 153 + }) 154 + .run(); 145 155 await db 146 156 .insert(statusReportUpdate) 147 157 .values({