diff --git a/src/PrintOne.ts b/src/PrintOne.ts index c757b5d..b0d8636 100644 --- a/src/PrintOne.ts +++ b/src/PrintOne.ts @@ -12,6 +12,7 @@ import { InFilter, inFilterToQuery, invertedFilterToQuery, + mapInFilter, PaginationOptions, sortToQuery, } from "./utils"; @@ -31,6 +32,7 @@ import { ICsvOrder } from "./models/_interfaces/ICsvOrder"; import { Batch, CreateBatch } from "./models/Batch"; import { IBatch } from "./models/_interfaces/IBatch"; import { BatchStatus } from "./enums/BatchStatus"; +import { stringify } from "ts-jest"; export type RequestHandler = new ( token: string, @@ -461,7 +463,10 @@ export class PrintOne { ...dateFilterToQuery("updatedAt", options.filter?.updatedAt), ...inFilterToQuery("finish", options.filter?.finish), ...inFilterToQuery("format", options.filter?.format), - ...inFilterToQuery("status", options.filter?.status), + ...inFilterToQuery( + "status", + mapInFilter(options.filter?.status, (v) => v.toUpperCase()), + ), }; if (typeof options.filter?.isBillable === "boolean") { diff --git a/src/utils.ts b/src/utils.ts index 509285c..aa241c7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -43,6 +43,21 @@ export function sortToQuery( return query; } +export function mapInFilter( + values: undefined | InFilter, + mapper: (value: T) => R, +): undefined | InFilter { + if (values === undefined) { + return undefined; + } + + if (typeof values === "string") { + return mapper(values); + } else { + return values.map(mapper); + } +} + export type InFilter = T | T[]; export function inFilterToQuery( diff --git a/test/PrintOne.spec.ts b/test/PrintOne.spec.ts index c3274cf..dcda7ef 100644 --- a/test/PrintOne.spec.ts +++ b/test/PrintOne.spec.ts @@ -1872,4 +1872,31 @@ describe("getBatches", function () { expect(batch).toBeDefined(); expect(batch.templateId).toEqual(template.id); }); + + it("should use the status filter", async function () { + // arrange + + // act + const batches = await client.getBatches({ + limit: 1, + filter: { + status: [BatchStatus.batch_created, BatchStatus.batch_user_ready], + }, + }); + const batch = batches.data[0]; + + if (batch === undefined) { + console.warn("No batches found, skipping test"); + return; + } + + // assert + expect(batch).toBeDefined(); + expect(batch.status).toEqual( + expect.toBeOneOf([ + BatchStatus.batch_created, + BatchStatus.batch_user_ready, + ]), + ); + }); });