diff options
author | Florian Dold <florian@dold.me> | 2024-07-01 01:08:51 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-07-01 01:08:51 +0200 |
commit | d768a1c75efc8c6fefc2b9fff644f63657d9e6c8 (patch) | |
tree | 5d9839e2cd0a36fa17d4e51ef770325160b034ea /packages/taler-harness/src | |
parent | 023b8f576b22155bf6116f0fed19aa4c7c1397c9 (diff) | |
download | wallet-core-d768a1c75efc8c6fefc2b9fff644f63657d9e6c8.tar.xz |
harness: improve merchant categories test
Diffstat (limited to 'packages/taler-harness/src')
-rw-r--r-- | packages/taler-harness/src/integrationtests/test-merchant-categories.ts | 75 |
1 files 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 index 7bf96a723..5a7b690f7 100644 --- 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]); } } |