Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
test(web): cover transcription dedupe and error status guards
Richie McIlroy535bf01e8b93
diff --git a/apps/web/__tests__/integration/transcribe.test.ts b/apps/web/__tests__/integration/transcribe.test.tsindex d00d638cf..3e9732020 100644--- a/apps/web/__tests__/integration/transcribe.test.ts+++ b/apps/web/__tests__/integration/transcribe.test.ts@@ -9,7 +9,11 @@ vi.mock("@cap/env", () => ({const mockStart = vi.hoisted(() => vi.fn());const schemaMocks = vi.hoisted(() => ({- videos: { id: "id", settings: "settings" },+ videos: {+ id: "id",+ settings: "settings",+ transcriptionStatus: "transcriptionStatus",+ },organizations: { id: "id", settings: "settings" },s3Buckets: { id: "id" },videoUploads: { videoId: "videoId", phase: "phase" },@@ -25,6 +29,7 @@ vi.mock("@/workflows/transcribe", () => ({let mockQueryResult: unknown[] = [];let mockUploadQueryResult: unknown[] = [];+let mockUpdateResult: unknown = [{ affectedRows: 1 }];vi.mock("@cap/database", () => ({db: () => ({@@ -49,7 +54,7 @@ vi.mock("@cap/database", () => ({}),update: () => ({set: () => ({- where: vi.fn().mockResolvedValue([]),+ where: vi.fn().mockResolvedValue(mockUpdateResult),}),}),}),@@ -63,7 +68,9 @@ vi.mock("@cap/database/schema", () => ({}));vi.mock("drizzle-orm", () => ({+ and: vi.fn((...conditions) => ({ conditions })),eq: vi.fn((field, value) => ({ field, value })),+ isNull: vi.fn((field) => ({ field, operator: "isNull" })),}));import type { Video } from "@cap/web-domain";@@ -75,6 +82,7 @@ describe("transcribeVideo", () => {vi.clearAllMocks();mockQueryResult = [];mockUploadQueryResult = [];+ mockUpdateResult = [{ affectedRows: 1 }];});describe("input validation", () => {@@ -264,6 +272,30 @@ describe("transcribeVideo", () => {expect(result.message).toContain("in progress");expect(mockStart).not.toHaveBeenCalled();});++ it("returns early when transcription failed until manual retry resets it", async () => {+ mockQueryResult = [+ {+ video: {+ id: "video-123",+ transcriptionStatus: "ERROR",+ settings: null,+ },+ bucket: null,+ settings: null,+ orgSettings: null,+ },+ ];++ const result = await transcribeVideo(+ "video-123" as Video.VideoId,+ "user-456",+ );++ expect(result.success).toBe(true);+ expect(result.message).toContain("in progress");+ expect(mockStart).not.toHaveBeenCalled();+ });});describe("workflow triggering", () => {@@ -307,6 +339,19 @@ describe("transcribeVideo", () => {expect(mockStart).toHaveBeenCalledTimes(1);});+ it("does not trigger workflow when another request claimed transcription first", async () => {+ mockUpdateResult = [{ affectedRows: 0 }];++ const result = await transcribeVideo(+ "video-123" as Video.VideoId,+ "user-456",+ );++ expect(result.success).toBe(true);+ expect(result.message).toContain("in progress");+ expect(mockStart).not.toHaveBeenCalled();+ });+it("passes correct payload to workflow", async () => {await transcribeVideo("video-123" as Video.VideoId, "user-456", true);