diff --git a/docs/PrintOne.md b/docs/PrintOne.md index 714d0c1..18f2721 100644 --- a/docs/PrintOne.md +++ b/docs/PrintOne.md @@ -282,6 +282,26 @@ const order = await client.createCsvOrder({ --- +## `.getCsvOrder(id)` + +Get a csv order by its ID. + +**Parameters** + +| Name | Type | Description | +| ---- | -------- | ------------------------------- | +| `id` | `string` | The ID of the csv order to get. | + +**Returns: [`Promise`](./CsvOrder)** + +**Example** + +```js +const csvOrder = await client.getCsvOrder("example-order-id"); +``` + +--- + ## `.createBatch(data)` Create a new batch. diff --git a/src/PrintOne.ts b/src/PrintOne.ts index 90ab7cf..1fe6845 100644 --- a/src/PrintOne.ts +++ b/src/PrintOne.ts @@ -308,6 +308,18 @@ export class PrintOne { return new CsvOrder(this.protected, csvInfo); } + /** + * Get a csv order by its id. + * @param { string } id The id of the csv order. + * @param basePath The basePath to use for this request + * @throws { PrintOneError } If the order could not be found. + */ + public async getCsvOrder(id: string, basePath = "orders"): Promise { + const data = await this.client.GET(`${basePath}/csv/${id}`); + + return new CsvOrder(this.protected, data); + } + /** * Get an order by its id. * @param { string } id The id of the order. diff --git a/test/PrintOne.spec.ts b/test/PrintOne.spec.ts index a631fd1..a3895c8 100644 --- a/test/PrintOne.spec.ts +++ b/test/PrintOne.spec.ts @@ -801,6 +801,61 @@ describe("createCsvOrder", function () { }); }); +describe("getCsvOrder", function () { + let csvOrderId: string = null as unknown as string; + const mapping: CreateCsvOrder["mapping"] = { + recipient: { + city: "{{City}}", + name: "{{FirstName}} {{LastName}}", + address: "{{Street}} {{HouseNr}}", + country: "{{Country}}", + postalCode: "{{ZIP}}", + }, + }; + + beforeAll(async () => { + const file = fs.readFileSync(path.join(__dirname, "assets/test.csv")); + + const csvOrder = await client.createCsvOrder({ + mapping: mapping, + template: template, + finish: Finish.GLOSSY, + file: file, + }); + + csvOrderId = csvOrder.id; + }); + + it("should get a csv order with all fields", async function () { + // arrange + + // act + const csvOrder = await client.getCsvOrder(csvOrderId); + + // assert + expect(csvOrder).toBeDefined(); + expect(csvOrder.id).toEqual(expect.any(String)); + expect(csvOrder.status).toEqual(expect.any(String)); + expect(csvOrder.createdAt).toEqual(expect.any(Date)); + expect(csvOrder.updatedAt).toEqual(expect.any(Date)); + // if sendDate is undefined, it should be today + expect(csvOrder.sendDate.getDay()).toEqual(new Date().getDay()); + expect(csvOrder.friendlyStatus).toEqual(expect.any(String)); + 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.billingId).toEqual(undefined); + expect(csvOrder.finish).toEqual(expect.any(String)); + expect(csvOrder.format).toEqual(expect.any(String)); + expect(csvOrder.isBillable).toEqual(expect.any(Boolean)); + expect(csvOrder.estimatedOrderCount).toEqual(expect.any(Number)); + expect(csvOrder.failedOrderCount).toEqual(expect.any(Number)); + expect(csvOrder.processedOrderCount).toEqual(expect.any(Number)); + expect(csvOrder.totalOrderCount).toEqual(expect.any(Number)); + }); +}) + describe("getOrder", function () { let orderId: string = null as unknown as string;