diff --git a/schemas/article/RawArticle.ts b/schemas/article/RawArticle.ts index 6c956e5..99eae03 100644 --- a/schemas/article/RawArticle.ts +++ b/schemas/article/RawArticle.ts @@ -8,7 +8,10 @@ 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() + .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(), 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 { setAuthorization(process.env.AUTH_TOKEN!) @@ -15,14 +16,20 @@ describe('Testing #GET function: ', () => { expect(safeParseRawInvoices(response).success).toBe(true) }) - test('articles endpoint should return RawInvoices object', async () => { - const response = await GET('articles') + test('articles endpoint should return RawArticles object', async () => { + 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 () => { 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) + }) }) 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 () => {