| 
1 |  | -import { MediaState } from "@badger/prisma/client";  | 
 | 1 | +import { JobState, MediaState } from "@badger/prisma/client";  | 
2 | 2 | import { it, expect } from "vitest";  | 
3 | 3 | import { doOneJob } from "../index.js";  | 
4 | 4 | import { integrate } from "@badger/testing";  | 
@@ -28,7 +28,7 @@ async function uploadTestFileToTus() {  | 
28 | 28 |     throw new Error("Tus rejected creation");  | 
29 | 29 |   }  | 
30 | 30 | 
 
  | 
31 |  | -  const uploadReq = await got.stream.patch(createRes.headers.location!, {  | 
 | 31 | +  const uploadReq = got.stream.patch(createRes.headers.location!, {  | 
32 | 32 |     body: sourceFile,  | 
33 | 33 |     headers: {  | 
34 | 34 |       "Tus-Resumable": "1.0.0",  | 
@@ -104,4 +104,49 @@ integrate("ProcessMediaJob", () => {  | 
104 | 104 |     );  | 
105 | 105 |     expect(tusRes.statusCode).not.toBe(200);  | 
106 | 106 |   });  | 
 | 107 | + | 
 | 108 | +  it("handles failure", async () => {  | 
 | 109 | +    const testMediaPath = await uploadTestFileToTus();  | 
 | 110 | +    const media = await db.media.create({  | 
 | 111 | +      data: {  | 
 | 112 | +        name: "__FAIL__smpte_bars_15s.mp4",  | 
 | 113 | +        durationSeconds: 0,  | 
 | 114 | +        rawPath: "",  | 
 | 115 | +        continuityItems: {  | 
 | 116 | +          create: {  | 
 | 117 | +            name: "Test",  | 
 | 118 | +            durationSeconds: 0,  | 
 | 119 | +            order: 1,  | 
 | 120 | +            show: {  | 
 | 121 | +              create: {  | 
 | 122 | +                name: "Test",  | 
 | 123 | +                start: new Date(),  | 
 | 124 | +              },  | 
 | 125 | +            },  | 
 | 126 | +          },  | 
 | 127 | +        },  | 
 | 128 | +      },  | 
 | 129 | +    });  | 
 | 130 | +    const job = await db.baseJob.create({  | 
 | 131 | +      data: {  | 
 | 132 | +        jobType: "ProcessMediaJob",  | 
 | 133 | +        jobPayload: {  | 
 | 134 | +          mediaId: media.id,  | 
 | 135 | +          sourceType: "Tus",  | 
 | 136 | +          source: testMediaPath,  | 
 | 137 | +        },  | 
 | 138 | +      },  | 
 | 139 | +    });  | 
 | 140 | +    await doOneJob();  | 
 | 141 | +    await expect(  | 
 | 142 | +      db.baseJob.findFirst({ where: { id: job.id } }),  | 
 | 143 | +    ).resolves.toHaveProperty("state", JobState.Failed);  | 
 | 144 | +    // Check the file is not deleted from Tus  | 
 | 145 | +    const res = await got.head(process.env.TUS_ENDPOINT + "/" + testMediaPath, {  | 
 | 146 | +      headers: {  | 
 | 147 | +        "Tus-Resumable": "1.0.0",  | 
 | 148 | +      },  | 
 | 149 | +    });  | 
 | 150 | +    expect(res.statusCode).toBe(200);  | 
 | 151 | +  });  | 
107 | 152 | });  | 
0 commit comments