diff --git a/src/parsing/common/asyncPredictResponse.ts b/src/parsing/common/asyncPredictResponse.ts index f35c6f27..aee7b144 100644 --- a/src/parsing/common/asyncPredictResponse.ts +++ b/src/parsing/common/asyncPredictResponse.ts @@ -18,7 +18,7 @@ export class Job { /** ID of the job. */ id: string; /** Status of the job. */ - status?: "waiting" | "processing" | "completed"; + status?: "waiting" | "processing" | "completed" | "failed"; /** The time taken to process the job, in milliseconds. */ milliSecsTaken?: number; diff --git a/tests/inputs/localResponse.spec.ts b/tests/inputs/localResponse.spec.ts index 4aca811b..6dce7e2b 100644 --- a/tests/inputs/localResponse.spec.ts +++ b/tests/inputs/localResponse.spec.ts @@ -1,19 +1,20 @@ -import {LocalResponse,} from "../../src"; +import { LocalResponse } from "../../src"; import * as fs from "node:fs/promises"; -import {expect} from "chai"; -import {Client, PredictResponse, AsyncPredictResponse} from "../../src"; -import {InternationalIdV2, InvoiceV4} from "../../src/product"; +import { expect } from "chai"; +import { Client, PredictResponse, AsyncPredictResponse } from "../../src"; +import { InternationalIdV2, InvoiceV4 } from "../../src/product"; const signature: string = "5ed1673e34421217a5dbfcad905ee62261a3dd66c442f3edd19302072bbf70d0"; const dummySecretKey: string = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH"; const filePath: string = "tests/data/async/get_completed_empty.json"; const invoicePath: string = "tests/data/products/invoices/response_v4/complete.json"; +const failedPath: string = "tests/data/async/get_failed_job_error.json"; const internationalIdPath: string = "tests/data/products/international_id/response_v2/complete.json"; describe("A valid local response", () => { it("should load a string properly.", async () => { - const fileObj = await fs.readFile(filePath, { encoding: "utf-8" }) + const fileObj = await fs.readFile(filePath, { encoding: "utf-8" }); const localResponse = new LocalResponse(fileObj); await localResponse.init(); expect(localResponse.asDict()).to.not.be.null; @@ -22,7 +23,7 @@ describe("A valid local response", () => { expect(localResponse.isValidHmacSignature(dummySecretKey, signature)).to.be.true; }); - it('should load a file properly.', async () => { + it("should load a file properly.", async () => { const localResponse = new LocalResponse(filePath); await localResponse.init(); expect(localResponse.asDict()).to.not.be.null; @@ -31,7 +32,7 @@ describe("A valid local response", () => { expect(localResponse.isValidHmacSignature(dummySecretKey, signature)).to.be.true; }); - it('should load a file properly.', async () => { + it("should load a file properly.", async () => { const fileStr = (await fs.readFile(filePath, { encoding: "utf-8" })).replace(/\r/g, "").replace(/\n/g, ""); const fileBuffer = Buffer.from(fileStr, "utf-8"); const localResponse = new LocalResponse(fileBuffer); @@ -42,8 +43,8 @@ describe("A valid local response", () => { expect(localResponse.isValidHmacSignature(dummySecretKey, signature)).to.be.true; }); - it('should load into a sync prediction.', async () => { - const fileObj = await fs.readFile(invoicePath, { encoding: "utf-8" }) + it("should load into a sync prediction.", async () => { + const fileObj = await fs.readFile(invoicePath, { encoding: "utf-8" }); const localResponse = new LocalResponse(fileObj); await localResponse.init(); const dummyClient = new Client({ apiKey: "dummy-key" }); @@ -53,8 +54,18 @@ describe("A valid local response", () => { expect(JSON.stringify(prediction.getRawHttp())).to.eq(JSON.stringify(JSON.parse(fileObj))); }); - it('should load into an async prediction.', async () => { - const fileObj = await fs.readFile(internationalIdPath, { encoding: "utf-8" }) + it("should load a failed prediction.", async () => { + const fileObj = await fs.readFile(failedPath, { encoding: "utf-8" }); + const localResponse = new LocalResponse(fileObj); + await localResponse.init(); + const dummyClient = new Client({ apiKey: "dummy-key" }); + const prediction = await dummyClient.loadPrediction(InvoiceV4, localResponse); + expect(prediction).to.be.an.instanceof(AsyncPredictResponse); + expect((prediction as AsyncPredictResponse).job.status).to.be.eq("failed"); + }); + + it("should load into an async prediction.", async () => { + const fileObj = await fs.readFile(internationalIdPath, { encoding: "utf-8" }); const localResponse = new LocalResponse(fileObj); await localResponse.init(); const dummyClient = new Client({ apiKey: "dummy-key" });