Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ added endpoint to get a CsvOrder by it's ID #12

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/PrintOne.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>`](./CsvOrder)**

**Example**

```js
const csvOrder = await client.getCsvOrder("example-order-id");
```

---

## `.createBatch(data)`

Create a new batch.
Expand Down
12 changes: 12 additions & 0 deletions src/PrintOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CsvOrder> {
const data = await this.client.GET<ICsvOrder>(`${basePath}/csv/${id}`);

return new CsvOrder(this.protected, data);
}

/**
* Get an order by its id.
* @param { string } id The id of the order.
Expand Down
55 changes: 55 additions & 0 deletions test/PrintOne.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading