aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/taler-harness/src/integrationtests/test-merchant-categories.ts75
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]);
}
}