| 12345678910111213141516171819202122232425262728293031 |
- import { readFileSync } from "node:fs";
- import { resolve } from "node:path";
- import { describe, expect, it } from "vitest";
- const sql = readFileSync(resolve(process.cwd(), "src/lib/ledger-backfill/trigger.sql"), "utf-8");
- describe("fn_upsert_usage_ledger trigger SQL", () => {
- it("contains warmup exclusion check", () => {
- expect(sql).toContain("blocked_by = 'warmup'");
- });
- it("contains ON CONFLICT UPSERT", () => {
- expect(sql).toContain("ON CONFLICT (request_id) DO UPDATE");
- });
- it("contains EXCEPTION error handling", () => {
- expect(sql).toContain("EXCEPTION WHEN OTHERS");
- });
- it("pre-validates provider_chain before extraction", () => {
- expect(sql).toContain("jsonb_typeof");
- });
- it("computes is_success from error_message", () => {
- expect(sql).toContain("error_message IS NULL");
- });
- it("creates trigger binding", () => {
- expect(sql).toContain("CREATE TRIGGER trg_upsert_usage_ledger");
- });
- });
|