Skip to content

Commit

Permalink
🐛 add missing 'failed' value to jobs (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianMindee authored Jan 16, 2025
1 parent a2bcb3f commit 85fe1f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/parsing/common/asyncPredictResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
33 changes: 22 additions & 11 deletions tests/inputs/localResponse.spec.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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" });
Expand All @@ -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<InvoiceV4>).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" });
Expand Down

0 comments on commit 85fe1f8

Please sign in to comment.