Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.0 kB ยท 63 lines
TypeScript
at incident-api
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import { db, eq } from "@openstatus/db";import { auditLog } from "@openstatus/db/src/schema";import { expect } from "@std/expect";import { afterAll, describe, test } from "@std/testing/bdd";
import { SEEDED_WORKSPACE_TEAM_ID } from "../../test/fixtures";import { withTestTransaction } from "../../test/helpers";
const SENTINEL_ENTITY_ID = `with-test-transaction-sanity-${Date.now()}`;
describe("withTestTransaction", () => { afterAll(async () => { // Defensive: if the rollback failed, the inserted row would leak. // Clean it up so a regression doesn't pollute future runs. await db .delete(auditLog) .where(eq(auditLog.entityId, SENTINEL_ENTITY_ID)) .catch(() => undefined); });
test("rolls back inserts so they never reach committed db", async () => { let visibleInsideTx = false;
await withTestTransaction(async (tx) => { await tx.insert(auditLog).values({ workspaceId: SEEDED_WORKSPACE_TEAM_ID, actorType: "system", actorId: "with-test-transaction-sanity", action: "monitor.create", entityType: "monitor", entityId: SENTINEL_ENTITY_ID, });
const inTxRows = await tx .select() .from(auditLog) .where(eq(auditLog.entityId, SENTINEL_ENTITY_ID)) .all(); visibleInsideTx = inTxRows.length === 1; });
expect(visibleInsideTx).toBe(true);
const committedRows = await db .select() .from(auditLog) .where(eq(auditLog.entityId, SENTINEL_ENTITY_ID)) .all(); expect(committedRows).toHaveLength(0); });
test("propagates non-sentinel errors thrown inside the callback", async () => { const promise = withTestTransaction(async () => { throw new Error("boom"); }); await expect(promise).rejects.toThrow("boom"); });
test("returns the callback's return value", async () => { const value = await withTestTransaction(async () => 42); expect(value).toBe(42); });});