taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit d768a1c75efc8c6fefc2b9fff644f63657d9e6c8
parent 023b8f576b22155bf6116f0fed19aa4c7c1397c9
Author: Florian Dold <florian@dold.me>
Date:   Mon,  1 Jul 2024 01:08:51 +0200

harness: improve merchant categories test

Diffstat:
Mpackages/taler-harness/src/integrationtests/test-merchant-categories.ts | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 63 insertions(+), 12 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-merchant-categories.ts b/packages/taler-harness/src/integrationtests/test-merchant-categories.ts @@ -84,19 +84,57 @@ export async function runMerchantCategoriesTest(t: GlobalTestState) { }, }); - const url = new URL("private/categories", merchant.makeInstanceBaseUrl()); - const res = await harnessHttpLib.fetch(url.href, { - method: "POST", - body: { - name: "Snacks", - name_i18n: {}, - }, - }); + let myNewCategoryId: number; - console.log(res.requestUrl); - console.log("status", res.status); - console.log(await res.json()); - t.assertTrue(res.status >= 200 && res.status < 300); + { + const url = new URL("private/categories", merchant.makeInstanceBaseUrl()); + const res = await harnessHttpLib.fetch(url.href, { + method: "POST", + body: { + name: "Snacks", + name_i18n: {}, + }, + }); + + console.log(res.requestUrl); + console.log("status", res.status); + const categoryJson = await res.json(); + console.log(categoryJson); + t.assertTrue(res.status >= 200 && res.status < 300); + myNewCategoryId = categoryJson.category_id; + } + + { + const url = new URL("private/products", merchant.makeInstanceBaseUrl()); + const res = await harnessHttpLib.fetch(url.href, { + method: "POST", + body: { + product_id: "foo", + description: "Bla Bla", + unit: "item", + price: "TESTKUDOS:6", + total_stock: -1, + }, + }); + t.assertTrue(res.status >= 200 && res.status < 300); + } + + { + const url = new URL("private/products", merchant.makeInstanceBaseUrl()); + const res = await harnessHttpLib.fetch(url.href, { + method: "POST", + body: { + product_id: "bar", + description: "Bla Bla", + unit: "item", + price: "TESTKUDOS:2", + total_stock: -1, + // FIXME: Don't hardcode + catgories: [myNewCategoryId], + }, + }); + t.assertTrue(res.status >= 200 && res.status < 300); + } { const posUrl = new URL("private/pos", merchant.makeInstanceBaseUrl()); @@ -105,6 +143,19 @@ export async function runMerchantCategoriesTest(t: GlobalTestState) { }); const posJson = await res.json(); console.log(j2s(posJson)); + t.assertTrue(res.status >= 200 && res.status < 300); + + t.assertDeepEqual(posJson.products.length, 2); + + const prodFoo = posJson.products.find((x: any) => x.product_id = "foo"); + t.assertTrue(!!prodFoo); + // Only default category + t.assertDeepEqual(prodFoo.categories, [0]); + + const prodBar = posJson.products.find((x: any) => x.product_id = "bar"); + t.assertTrue(!!prodBar); + // This should have the one we assigned to it. + t.assertDeepEqual(prodBar.categories, [myNewCategoryId]); } }