Skip to content

Commit

Permalink
Merge pull request #10 from Print-one/feat/PO-1446-get-batches-more-f…
Browse files Browse the repository at this point in the history
…ilters
  • Loading branch information
PaulRill00 authored Mar 25, 2024
2 parents c526300 + 9795b9d commit 45629a9
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 14 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion src/PrintOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { CreateCsvOrder, CsvOrder } from "./models/CsvOrder";
import { ICsvOrder } from "./models/_interfaces/ICsvOrder";
import { Batch, CreateBatch } from "./models/Batch";
import { IBatch } from "./models/_interfaces/IBatch";
import { BatchStatus } from "./enums/BatchStatus";

export type RequestHandler = new (
token: string,
Expand Down Expand Up @@ -445,7 +446,9 @@ export class PrintOne {
sendDate?: DateFilter | boolean;
finish?: InFilter;
templates?: InFilter<string | Template>;
//TODO format, status, isBillable
format?: InFilter;
status?: InFilter<BatchStatus>;
isBillable?: boolean;
};
} = {},
): Promise<PaginatedResponse<Batch>> {
Expand All @@ -456,8 +459,17 @@ export class PrintOne {
...dateFilterToQuery("createdAt", options.filter?.createdAt),
...dateFilterToQuery("updatedAt", options.filter?.updatedAt),
...inFilterToQuery("finish", options.filter?.finish),
...inFilterToQuery("format", options.filter?.format),
...inFilterToQuery("status", options.filter?.status),
};

if (typeof options.filter?.isBillable === "boolean") {
params = {
...params,
"filter.isBillable": `$eq:${options.filter.isBillable}`,
};
}

if (options.filter?.templates) {
if (!Array.isArray(options.filter.templates)) {
options.filter.templates = [options.filter.templates];
Expand Down
5 changes: 5 additions & 0 deletions src/models/Batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PaginatedResponse } from "./PaginatedResponse";
import { Order } from "./Order";
import { Address } from "./Address";
import { IOrder } from "./_interfaces/IOrder";
import { Format } from "../enums/Format";
import { CreateBatchCsvOrder, CsvOrder } from "./CsvOrder";
import { ICsvOrder } from "./_interfaces/ICsvOrder";

Expand Down Expand Up @@ -53,6 +54,10 @@ export class Batch {
return this._data.finish as Finish;
}

public get format(): Format {
return this._data.format as Format;
}

public get isBillable(): boolean {
return this._data.isBillable;
}
Expand Down
1 change: 1 addition & 0 deletions src/models/_interfaces/IBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type IBatch = {
name: string;
billingId: string;
finish: string;
format: string;
isBillable: boolean;
templateId: string;
estimatedPrice: number;
Expand Down
4 changes: 2 additions & 2 deletions test/Batch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe("createCsvOrder", function () {
expect(csvOrder.sender).toEqual(undefined);
expect(csvOrder.recipientMapping).toEqual(mapping.recipient);
expect(csvOrder.templateId).toEqual(template.id);
expect(csvOrder.mergeVariableMapping).toEqual(mapping.mergeVariables);
expect(csvOrder.mergeVariableMapping).toStrictEqual({});
expect(csvOrder.billingId).toEqual(
expect.toBeOneOf([undefined, expect.any(String)]),
);
Expand Down Expand Up @@ -181,7 +181,7 @@ describe("getCsvOrder", function () {
expect(csvOrder.sender).toEqual(undefined);
expect(csvOrder.recipientMapping).toEqual(mapping.recipient);
expect(csvOrder.templateId).toEqual(template.id);
expect(csvOrder.mergeVariableMapping).toEqual(mapping.mergeVariables);
expect(csvOrder.mergeVariableMapping).toStrictEqual({});
expect(csvOrder.billingId).toBeOneOf([undefined, expect.any(String)]);
expect(csvOrder.finish).toEqual(expect.any(String));
expect(csvOrder.format).toEqual(expect.any(String));
Expand Down
26 changes: 24 additions & 2 deletions test/PrintOne.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ describe("createCsvOrder", function () {
expect(csvOrder.sender).toEqual(undefined);
expect(csvOrder.recipientMapping).toEqual(mapping.recipient);
expect(csvOrder.templateId).toEqual(template.id);
expect(csvOrder.mergeVariableMapping).toEqual(mapping.mergeVariables);
expect(csvOrder.mergeVariableMapping).toStrictEqual({});
expect(csvOrder.billingId).toBeOneOf([undefined, expect.any(String)]);
expect(csvOrder.finish).toEqual(expect.any(String));
expect(csvOrder.format).toEqual(expect.any(String));
Expand Down Expand Up @@ -844,7 +844,7 @@ describe("getCsvOrder", function () {
expect(csvOrder.sender).toEqual(undefined);
expect(csvOrder.recipientMapping).toEqual(mapping.recipient);
expect(csvOrder.templateId).toEqual(template.id);
expect(csvOrder.mergeVariableMapping).toEqual(mapping.mergeVariables);
expect(csvOrder.mergeVariableMapping).toStrictEqual({});
expect(csvOrder.billingId).toBeOneOf([undefined, expect.any(String)]);
expect(csvOrder.finish).toEqual(expect.any(String));
expect(csvOrder.format).toEqual(expect.any(String));
Expand Down Expand Up @@ -1617,6 +1617,28 @@ describe("getBatches", function () {
expect(batch.billingId).toEqual("test");
});

it("should apply the isBillable filter", async function () {
// arrange

// act
const batches = await client.getBatches({
limit: 1,
filter: {
isBillable: true,
},
});
const batch = batches.data[0];

if (batch === undefined) {
console.warn("No orders found, skipping test");
return;
}

// assert
expect(batch).toBeDefined();
expect(batch.isBillable).toEqual(true);
});

it("should apply the name filter", async function () {
// arrange
const batchName = (await client.getBatches()).data[1]?.name ?? "test";
Expand Down

0 comments on commit 45629a9

Please sign in to comment.