Skip to content

Commit

Permalink
Merge pull request #21 from Print-one/next
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulRill00 authored Jun 5, 2024
2 parents 8c22d6c + 06066f6 commit 4ec0a4d
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 12 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# [1.3.0-next.1](https://github.com/Print-one/print-one-js/compare/v1.2.1...v1.3.0-next.1) (2024-05-22)


### Bug Fixes

* batch status filter ([2b0e209](https://github.com/Print-one/print-one-js/commit/2b0e20917d66ad21af372c5ed19f8f80da20ae71))
* batch status filter ([2db77de](https://github.com/Print-one/print-one-js/commit/2db77de99b2e53f85e459790e82828b91edd58db))
* import in CsvOrder.ts ([#19](https://github.com/Print-one/print-one-js/issues/19)) ([40986aa](https://github.com/Print-one/print-one-js/commit/40986aac4deb5ff5d9b87358f30c4a9138998a5e))


### Features

* :sparkles: added endpoint to get a CsvOrder by it's ID ([74b0313](https://github.com/Print-one/print-one-js/commit/74b0313fefc98ddb45184c3b27a9615ea39fe7e7))
* :sparkles: added remaining getBatches filters ([4c2996b](https://github.com/Print-one/print-one-js/commit/4c2996b4ad3cf29bab6daf32830ae419c9641e81))
* :sparkles: allow for getting CSV order by id ([0560944](https://github.com/Print-one/print-one-js/commit/0560944128abdeea5cf0ff5ec79391201e0598a3))
* :sparkles: allow for uploading CSVs to a Batch ([a4bd3a6](https://github.com/Print-one/print-one-js/commit/a4bd3a68ecc6f7d360ab751be88b22324249b6f6))
* :sparkles: support batch order's API urls ([c2ca919](https://github.com/Print-one/print-one-js/commit/c2ca919f5d91f0618f2699d180e6bc8830d560b7))
* ✨ added CsvOrder model + endpoints ([#7](https://github.com/Print-one/print-one-js/issues/7)) ([9e04141](https://github.com/Print-one/print-one-js/commit/9e041416bdc09a3f34d6f2da72bde6788770e39b))
* added format to DTO ([64ec3ad](https://github.com/Print-one/print-one-js/commit/64ec3adc8b51dd697d0c1244e663353b087a17c1))
* batch endpoints added ([#8](https://github.com/Print-one/print-one-js/issues/8)) ([0099217](https://github.com/Print-one/print-one-js/commit/009921704b0c7b75206341ef20b1f540c31e366c))
* implement PR feedback ([8420046](https://github.com/Print-one/print-one-js/commit/8420046c3655a0a9480f192f3879fcf9524c06f4))

## [1.2.1](https://github.com/Print-one/print-one-js/compare/v1.2.0...v1.2.1) (2024-04-15)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@print-one/print-one-js",
"version": "1.2.1",
"version": "1.3.0-next.1",
"description": "The official javascript client for Print.one",
"license": "MIT",
"author": "Print.one",
Expand All @@ -18,8 +18,8 @@
"build": "bsm",
"clean": "bsm",
"format": "bsm",
"lint": "bsm",
"postinstall": "bsm",
"lint": "bsm",
"prepublishOnly": "bsm build",
"semantic-release": "semantic-release",
"setup": "bsm build",
Expand Down
1 change: 1 addition & 0 deletions package.scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
_default: "bsm ~.*",
eslint: "eslint .",
prettier: "prettier -c .",
typescript: "tsc --noEmit",
},
postinstall: ["ts-patch install"],
test: {
Expand Down
1 change: 1 addition & 0 deletions src/PrintOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ export class PrintOne {
templateId: templateId,
finish: data.finish,
ready: ready ? ready : null,
sender: data.sender,
});

return new Batch(this.protected, response);
Expand Down
6 changes: 5 additions & 1 deletion src/models/Batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type CreateBatch = {
template: string | Template;
finish: Finish;
ready?: Date | boolean;
sender: Address;
};

export type CreateBatchOrder = {
Expand Down Expand Up @@ -187,7 +188,10 @@ export class Batch {
* @throws { PrintOneError } If the order could not be found.
*/
public async getCsvOrder(id: string): Promise<CsvOrder> {
return this._protected.printOne.getCsvOrder(id, `batches/${this.id}`);
return this._protected.printOne.getCsvOrder(
id,
`batches/${this.id}/orders`,
);
}

/**
Expand Down
13 changes: 12 additions & 1 deletion test/Batch.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Address,
Batch,
CreateBatchCsvOrder,
CsvOrder,
Expand All @@ -17,6 +18,14 @@ import { sleep } from "../src/utils";
let batch: Batch = null as unknown as Batch;
let template: Template = null as unknown as Template;

const address: Address = {
name: "Jane Doe",
address: "123 Main Street",
postalCode: "1234 AB",
city: "Somecity",
country: "NL",
};

beforeAll(async function () {
template = await client.createTemplate({
name: `Test Order ${new Date().toISOString().replaceAll(":", "-")}`,
Expand All @@ -31,6 +40,7 @@ beforeEach(async function () {
template: template,
name: `Test Batch ${new Date().toISOString().replaceAll(":", "-")}`,
finish: Finish.GLOSSY,
sender: address,
});
});

Expand Down Expand Up @@ -347,6 +357,7 @@ describe("getOrder", function () {
template: template,
name: `Test Batch ${new Date().toISOString().replaceAll(":", "-")}`,
finish: Finish.GLOSSY,
sender: address,
});
const order = await batch2.createOrder({
recipient: {
Expand Down Expand Up @@ -424,7 +435,7 @@ describe("BatchOrder", function () {

// assert
expect(order.status).toEqual("order_cancelled");
});
}, 30000);

it("should be able to refresh Order", async function () {

Check failure on line 440 in test/Batch.spec.ts

View workflow job for this annotation

GitHub Actions / Release

BatchOrder › should be able to refresh Order

thrown: "Exceeded timeout of 30000 ms for a test. Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout." at test/Batch.spec.ts:440:3 at Object.<anonymous> (test/Batch.spec.ts:420:1)
// arrange
Expand Down
6 changes: 4 additions & 2 deletions test/CsvOrder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ describe("getTemplate", function () {
describe("refresh", function () {
it("should refresh the csv order", async function () {
// precondition
expect(order.status).toEqual(CsvStatus.order_created);
if (order.status !== CsvStatus.order_created) {
return;
}

// arrange

Expand All @@ -88,7 +90,7 @@ describe("getOrders", function () {
// arrange

// act
while (await order.getOrders({}).then((x) => x.data.length < 1)) {
while (await order.getOrders().then((x) => x.data.length < 1)) {
await order.refresh();
await sleep(1000);
}
Expand Down
38 changes: 34 additions & 4 deletions test/PrintOne.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ beforeAll(async function () {

afterAll(async function () {
if (template) {
await template.delete();
await template.delete().catch(() => {});
}
});

Expand Down Expand Up @@ -1279,6 +1279,7 @@ describe("getOrders", function () {
name: "Test batch",
finish: Finish.GLOSSY,
template: template,
sender: exampleAddress,
});
const batchOrder = await batch.createOrder({
recipient: exampleAddress,
Expand Down Expand Up @@ -1383,6 +1384,7 @@ describe("createBatch", function () {
name: "Test batch",
finish: Finish.GLOSSY,
template: template,
sender: exampleAddress,
});

// assert
Expand All @@ -1398,6 +1400,7 @@ describe("createBatch", function () {
name: "Test batch",
finish: Finish.GLOSSY,
template: template,
sender: exampleAddress,
});

// assert
Expand Down Expand Up @@ -1435,6 +1438,7 @@ describe("createBatch", function () {
finish: Finish.GLOSSY,
template: template,
ready: sendDate,
sender: exampleAddress,
});

// assert
Expand All @@ -1444,21 +1448,22 @@ describe("createBatch", function () {

it("should create an batch that is ready", async function () {
// arrange
const sendDate = new Date();
sendDate.setDate(sendDate.getDate() + 10);

// act
const batch = await client.createBatch({
name: "Test batch",
finish: Finish.GLOSSY,
template: template,
ready: true,
sender: exampleAddress,
});

// assert
expect(batch).toBeDefined();
expect(batch.status).toEqual(BatchStatus.batch_user_ready);
expect(batch.sendDate).toBeBefore(new Date());
const withMargin = new Date();
withMargin.setMinutes(withMargin.getMinutes() + 1);
expect(batch.sendDate).toBeBefore(withMargin);
});

it("should create an batch with a billing id", async function () {
Expand All @@ -1471,6 +1476,7 @@ describe("createBatch", function () {
finish: Finish.GLOSSY,
template: template,
billingId: billingId,
sender: exampleAddress,
});

// assert
Expand All @@ -1487,6 +1493,7 @@ describe("createBatch", function () {
name: "Test batch",
finish: Finish.GLOSSY,
template: templateId,
sender: exampleAddress,
});

// assert
Expand All @@ -1504,6 +1511,7 @@ describe("getBatch", function () {
name: "Test batch",
template: template,
finish: Finish.GLOSSY,
sender: exampleAddress,
});
batchId = batch.id;
});
Expand Down Expand Up @@ -1900,6 +1908,28 @@ describe("getBatches", function () {
);
});

it("should use the status filter (single)", async function () {
// arrange

// act
const batches = await client.getBatches({
limit: 1,
filter: {
status: BatchStatus.batch_sent,
},
});
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]));
});

it("should use the status filter (single)", async function () {
// arrange

Expand Down

0 comments on commit 4ec0a4d

Please sign in to comment.