Skip to content

Commit a506f3f

Browse files
committed
Merge branches 'feat/PO-1477-batch-csv' and 'next' of github.com:Print-one/print-one-js into feat/PO-1477-batch-csv
2 parents a4bd3a6 + e85e14c commit a506f3f

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

docs/PrintOne.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,26 @@ const order = await client.createCsvOrder({
282282

283283
---
284284

285+
## `.getCsvOrder(id)`
286+
287+
Get a csv order by its ID.
288+
289+
**Parameters**
290+
291+
| Name | Type | Description |
292+
| ---- | -------- | ------------------------------- |
293+
| `id` | `string` | The ID of the csv order to get. |
294+
295+
**Returns: [`Promise<CsvOrder>`](./CsvOrder)**
296+
297+
**Example**
298+
299+
```js
300+
const csvOrder = await client.getCsvOrder("example-order-id");
301+
```
302+
303+
---
304+
285305
## `.createBatch(data)`
286306

287307
Create a new batch.

src/PrintOne.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,18 @@ export class PrintOne {
308308
return new CsvOrder(this.protected, csvInfo);
309309
}
310310

311+
/**
312+
* Get a csv order by its id.
313+
* @param { string } id The id of the csv order.
314+
* @param basePath The basePath to use for this request
315+
* @throws { PrintOneError } If the order could not be found.
316+
*/
317+
public async getCsvOrder(id: string, basePath = "orders"): Promise<CsvOrder> {
318+
const data = await this.client.GET<ICsvOrder>(`${basePath}/csv/${id}`);
319+
320+
return new CsvOrder(this.protected, data);
321+
}
322+
311323
/**
312324
* Get an order by its id.
313325
* @param { string } id The id of the order.

test/PrintOne.spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,61 @@ describe("createCsvOrder", function () {
801801
});
802802
});
803803

804+
describe("getCsvOrder", function () {
805+
let csvOrderId: string = null as unknown as string;
806+
const mapping: CreateCsvOrder["mapping"] = {
807+
recipient: {
808+
city: "{{City}}",
809+
name: "{{FirstName}} {{LastName}}",
810+
address: "{{Street}} {{HouseNr}}",
811+
country: "{{Country}}",
812+
postalCode: "{{ZIP}}",
813+
},
814+
};
815+
816+
beforeAll(async () => {
817+
const file = fs.readFileSync(path.join(__dirname, "assets/test.csv"));
818+
819+
const csvOrder = await client.createCsvOrder({
820+
mapping: mapping,
821+
template: template,
822+
finish: Finish.GLOSSY,
823+
file: file,
824+
});
825+
826+
csvOrderId = csvOrder.id;
827+
});
828+
829+
it("should get a csv order with all fields", async function () {
830+
// arrange
831+
832+
// act
833+
const csvOrder = await client.getCsvOrder(csvOrderId);
834+
835+
// assert
836+
expect(csvOrder).toBeDefined();
837+
expect(csvOrder.id).toEqual(expect.any(String));
838+
expect(csvOrder.status).toEqual(expect.any(String));
839+
expect(csvOrder.createdAt).toEqual(expect.any(Date));
840+
expect(csvOrder.updatedAt).toEqual(expect.any(Date));
841+
// if sendDate is undefined, it should be today
842+
expect(csvOrder.sendDate.getDay()).toEqual(new Date().getDay());
843+
expect(csvOrder.friendlyStatus).toEqual(expect.any(String));
844+
expect(csvOrder.sender).toEqual(undefined);
845+
expect(csvOrder.recipientMapping).toEqual(mapping.recipient);
846+
expect(csvOrder.templateId).toEqual(template.id);
847+
expect(csvOrder.mergeVariableMapping).toEqual(mapping.mergeVariables);
848+
expect(csvOrder.billingId).toEqual(undefined);
849+
expect(csvOrder.finish).toEqual(expect.any(String));
850+
expect(csvOrder.format).toEqual(expect.any(String));
851+
expect(csvOrder.isBillable).toEqual(expect.any(Boolean));
852+
expect(csvOrder.estimatedOrderCount).toEqual(expect.any(Number));
853+
expect(csvOrder.failedOrderCount).toEqual(expect.any(Number));
854+
expect(csvOrder.processedOrderCount).toEqual(expect.any(Number));
855+
expect(csvOrder.totalOrderCount).toEqual(expect.any(Number));
856+
});
857+
})
858+
804859
describe("getOrder", function () {
805860
let orderId: string = null as unknown as string;
806861

0 commit comments

Comments
 (0)