From 2607e83420e9fdfa5f324a314f74864b4f7aafc9 Mon Sep 17 00:00:00 2001 From: Marty Byrde <45905689+Marty-Byrde@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:04:19 +0100 Subject: [PATCH 1/7] ref: added ZodEffects to schemaDefaults switch The reason for this change is that when a schema property uses the .transform utility method the type of this property includes ZodEffects. Without handling it in the schemaDefault method it will throw an error. --- schemas/utils/schemaDefaults.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/schemas/utils/schemaDefaults.ts b/schemas/utils/schemaDefaults.ts index 93a676b..1513f26 100644 --- a/schemas/utils/schemaDefaults.ts +++ b/schemas/utils/schemaDefaults.ts @@ -79,6 +79,9 @@ export default function schemaDefaults Date: Mon, 24 Feb 2025 12:50:24 +0100 Subject: [PATCH 2/7] ref: updated github-pages action versions Changed the version of the checkout, upload-pages-artifact and deploy-pages to version 4 --- .github/workflows/publish-documentation.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-documentation.yml b/.github/workflows/publish-documentation.yml index 80a1ed5..adf549b 100644 --- a/.github/workflows/publish-documentation.yml +++ b/.github/workflows/publish-documentation.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Node 21 uses: actions/setup-node@v4 @@ -35,10 +35,10 @@ jobs: - name: Upload Documentation to GitHub Pages id: "upload-documentation" - uses: "actions/upload-pages-artifact@v2" + uses: "actions/upload-pages-artifact@v4" with: path: "docs/" - name: Deploy Documentation to GitHub Pages id: "deployment" - uses: "actions/deploy-pages@v2" \ No newline at end of file + uses: "actions/deploy-pages@v4" From 85dea3550608bd6b15cb393daf935fdbe54874a8 Mon Sep 17 00:00:00 2001 From: Marty Byrde <45905689+Marty-Byrde@users.noreply.github.com> Date: Mon, 24 Feb 2025 12:55:18 +0100 Subject: [PATCH 3/7] ref: downgraded action version in publish-docs wf --- .github/workflows/publish-documentation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-documentation.yml b/.github/workflows/publish-documentation.yml index adf549b..2e102af 100644 --- a/.github/workflows/publish-documentation.yml +++ b/.github/workflows/publish-documentation.yml @@ -35,7 +35,7 @@ jobs: - name: Upload Documentation to GitHub Pages id: "upload-documentation" - uses: "actions/upload-pages-artifact@v4" + uses: "actions/upload-pages-artifact@v3" with: path: "docs/" From cf91099e3760e0d89bc7f69d9c6a086e09961b8b Mon Sep 17 00:00:00 2001 From: Marty Byrde <45905689+Marty-Byrde@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:05:12 +0100 Subject: [PATCH 4/7] fix: transformed article_category_id to handle null values The reason for this change is that the value of this property can be of type number or null. Given the current definition of number or undefined, when the value is null it is transformed to undefined. --- schemas/article/RawArticle.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/schemas/article/RawArticle.ts b/schemas/article/RawArticle.ts index 6c956e5..b2f5dd9 100644 --- a/schemas/article/RawArticle.ts +++ b/schemas/article/RawArticle.ts @@ -8,7 +8,11 @@ import { getRandomNumberAsString } from '@/functions/utils/randomDefaultValues' */ export const RawArticleSchema = z.object({ article_id: z.string().default(getRandomNumberAsString()).optional(), - article_category_id: z.number().optional(), + article_category_id: z + .number() + .nullable() + .transform((val) => (val === null ? undefined : val)) + .optional(), article_name: z.string().default('Article-XY'), article_code: z.string().default(getRandomNumberAsString()).optional(), article_eanCode: z.string().default(getRandomNumberAsString()).optional(), From db22f66e9c2d5a3d88d62a805ba0e601bf23b396 Mon Sep 17 00:00:00 2001 From: Marty Byrde <45905689+Marty-Byrde@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:08:43 +0100 Subject: [PATCH 5/7] test: added test-case to check validity of customers schema --- tests/api/Get.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/api/Get.test.ts b/tests/api/Get.test.ts index c6ab996..2210c3b 100644 --- a/tests/api/Get.test.ts +++ b/tests/api/Get.test.ts @@ -3,6 +3,7 @@ import GET from '@/api/GET' import { setAuthorization } from '@/config/authorization' import { RawInvoices, safeParseRawInvoices } from '@/schemas/invoice/RawInvoices' import { RawArticles, safeParseRawArticles } from '@/schemas/article/RawArticles' +import { RawCustomers, safeParseRawCustomers } from '@/schemas/customer/RawCustomers' beforeEach(() => { setAuthorization(process.env.AUTH_TOKEN!) @@ -15,7 +16,7 @@ describe('Testing #GET function: ', () => { expect(safeParseRawInvoices(response).success).toBe(true) }) - test('articles endpoint should return RawInvoices object', async () => { + test('articles endpoint should return RawArticles object', async () => { const response = await GET('articles') expect(safeParseRawArticles(response).success).toBe(true) @@ -25,4 +26,9 @@ describe('Testing #GET function: ', () => { const articles = await GET('articles') expect(articles.articles.length).toBeGreaterThan(0) }) + + test('validity of customer schema against response of /users endpoint', async () => { + const customers = await GET('users') + expect(safeParseRawCustomers(customers).success).toBe(true) + }) }) From 8788b533a2978dda3330736573214eabca1c1e59 Mon Sep 17 00:00:00 2001 From: Marty Byrde <45905689+Marty-Byrde@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:10:53 +0100 Subject: [PATCH 6/7] test: updated test-case by adding filters --- tests/api/Get.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/api/Get.test.ts b/tests/api/Get.test.ts index 2210c3b..d999516 100644 --- a/tests/api/Get.test.ts +++ b/tests/api/Get.test.ts @@ -17,9 +17,10 @@ describe('Testing #GET function: ', () => { }) test('articles endpoint should return RawArticles object', async () => { - const response = await GET('articles') + const response = await GET('articles', [`limit=${5}`]) expect(safeParseRawArticles(response).success).toBe(true) + expect(response.articles.length).toBeGreaterThanOrEqual(5) }) test('calling without filter params should yield results anyway', async () => { From 97488f0c80117c842f1fe5abe13b12ea0c434fa4 Mon Sep 17 00:00:00 2001 From: Marty Byrde <45905689+Marty-Byrde@users.noreply.github.com> Date: Wed, 26 Feb 2025 17:47:23 +0100 Subject: [PATCH 7/7] test: updated test-case assertions The reason for this change is that fetching invoices may return an empty array, hence the toBeGreaterThan assertions were updated to include equal and greaterThan. --- tests/invoices/getInvoices.test.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/invoices/getInvoices.test.ts b/tests/invoices/getInvoices.test.ts index ab734b6..cc9d21a 100644 --- a/tests/invoices/getInvoices.test.ts +++ b/tests/invoices/getInvoices.test.ts @@ -13,25 +13,20 @@ test('getInvoices - limit of 10, Expect 10 invoices', async () => { expect(invoices.length).toBeLessThanOrEqual(10) }) -test('getInvoices - limit of 0, Expect 0 invoices', async () => { - const invoices = await getInvoices(0) - expect(invoices).toHaveLength(0) -}) - test( - 'getInvoices - limit of 1000, Expect at least 0 invoices', + 'getInvoices - limit of 1000 expect at least 0 invoices', async () => { const invoices = await getInvoices(1000) expect(Array.isArray(invoices)).toBe(true) - expect(invoices.length).toBeGreaterThan(0) + expect(invoices.length).toBeGreaterThanOrEqual(0) }, 10 * 1000, ) -test('getInvoices - limit of -1, Expect at least 0 invoices', async () => { - const invoices = await getInvoices(-1) +test('getInvoices - default limit expect array of invoices', async () => { + const invoices = await getInvoices() expect(Array.isArray(invoices)).toBe(true) - expect(invoices.length).toBeGreaterThan(0) + expect(invoices.length).toBeGreaterThanOrEqual(0) }) test('getInvoices - No Authentication set; Expect Authentication Failure', async () => {