diff --git a/CHANGELOG.md b/CHANGELOG.md index 2660746..7f9b21a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/package-lock.json b/package-lock.json index 3674be8..ebfd205 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@print-one/print-one-js", - "version": "1.2.1", + "version": "1.3.0-next.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@print-one/print-one-js", - "version": "1.2.1", + "version": "1.3.0-next.1", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 412c21f..772d44d 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/package.scripts.js b/package.scripts.js index a938552..319c991 100644 --- a/package.scripts.js +++ b/package.scripts.js @@ -14,6 +14,7 @@ module.exports = { _default: "bsm ~.*", eslint: "eslint .", prettier: "prettier -c .", + typescript: "tsc --noEmit", }, postinstall: ["ts-patch install"], test: { diff --git a/src/PrintOne.ts b/src/PrintOne.ts index 9902748..8880d38 100644 --- a/src/PrintOne.ts +++ b/src/PrintOne.ts @@ -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); diff --git a/src/models/Batch.ts b/src/models/Batch.ts index ae22d60..8d9c20b 100644 --- a/src/models/Batch.ts +++ b/src/models/Batch.ts @@ -17,6 +17,7 @@ export type CreateBatch = { template: string | Template; finish: Finish; ready?: Date | boolean; + sender: Address; }; export type CreateBatchOrder = { @@ -187,7 +188,10 @@ export class Batch { * @throws { PrintOneError } If the order could not be found. */ public async getCsvOrder(id: string): Promise { - return this._protected.printOne.getCsvOrder(id, `batches/${this.id}`); + return this._protected.printOne.getCsvOrder( + id, + `batches/${this.id}/orders`, + ); } /** diff --git a/test/Batch.spec.ts b/test/Batch.spec.ts index d67823d..e6557c9 100644 --- a/test/Batch.spec.ts +++ b/test/Batch.spec.ts @@ -1,4 +1,5 @@ import { + Address, Batch, CreateBatchCsvOrder, CsvOrder, @@ -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(":", "-")}`, @@ -31,6 +40,7 @@ beforeEach(async function () { template: template, name: `Test Batch ${new Date().toISOString().replaceAll(":", "-")}`, finish: Finish.GLOSSY, + sender: address, }); }); @@ -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: { @@ -424,7 +435,7 @@ describe("BatchOrder", function () { // assert expect(order.status).toEqual("order_cancelled"); - }); + }, 30000); it("should be able to refresh Order", async function () { // arrange diff --git a/test/CsvOrder.spec.ts b/test/CsvOrder.spec.ts index ea4c493..4413754 100644 --- a/test/CsvOrder.spec.ts +++ b/test/CsvOrder.spec.ts @@ -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 @@ -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); } diff --git a/test/PrintOne.spec.ts b/test/PrintOne.spec.ts index e4927b5..45a4420 100644 --- a/test/PrintOne.spec.ts +++ b/test/PrintOne.spec.ts @@ -46,7 +46,7 @@ beforeAll(async function () { afterAll(async function () { if (template) { - await template.delete(); + await template.delete().catch(() => {}); } }); @@ -1279,6 +1279,7 @@ describe("getOrders", function () { name: "Test batch", finish: Finish.GLOSSY, template: template, + sender: exampleAddress, }); const batchOrder = await batch.createOrder({ recipient: exampleAddress, @@ -1383,6 +1384,7 @@ describe("createBatch", function () { name: "Test batch", finish: Finish.GLOSSY, template: template, + sender: exampleAddress, }); // assert @@ -1398,6 +1400,7 @@ describe("createBatch", function () { name: "Test batch", finish: Finish.GLOSSY, template: template, + sender: exampleAddress, }); // assert @@ -1435,6 +1438,7 @@ describe("createBatch", function () { finish: Finish.GLOSSY, template: template, ready: sendDate, + sender: exampleAddress, }); // assert @@ -1444,8 +1448,6 @@ 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({ @@ -1453,12 +1455,15 @@ describe("createBatch", function () { 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 () { @@ -1471,6 +1476,7 @@ describe("createBatch", function () { finish: Finish.GLOSSY, template: template, billingId: billingId, + sender: exampleAddress, }); // assert @@ -1487,6 +1493,7 @@ describe("createBatch", function () { name: "Test batch", finish: Finish.GLOSSY, template: templateId, + sender: exampleAddress, }); // assert @@ -1504,6 +1511,7 @@ describe("getBatch", function () { name: "Test batch", template: template, finish: Finish.GLOSSY, + sender: exampleAddress, }); batchId = batch.id; }); @@ -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