From fb47c45cc4cf83ada053d5b03e1c71652bce9dbe Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 26 Jun 2024 13:13:15 +0200 Subject: harness: simple test for merchant categories --- .../integrationtests/test-merchant-categories.ts | 102 +++++++++++++++++++++ .../src/integrationtests/testrunner.ts | 2 + 2 files changed, 104 insertions(+) create mode 100644 packages/taler-harness/src/integrationtests/test-merchant-categories.ts (limited to 'packages') diff --git a/packages/taler-harness/src/integrationtests/test-merchant-categories.ts b/packages/taler-harness/src/integrationtests/test-merchant-categories.ts new file mode 100644 index 000000000..a6ddc31e2 --- /dev/null +++ b/packages/taler-harness/src/integrationtests/test-merchant-categories.ts @@ -0,0 +1,102 @@ +/* + This file is part of GNU Taler + (C) 2021 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see + */ + +/** + * Imports. + */ +import { URL } from "@gnu-taler/taler-util"; +import { + ExchangeService, + GlobalTestState, + MerchantService, + generateRandomPayto, + harnessHttpLib, + setupDb, +} from "../harness/harness.js"; + +/** + * Do basic checks on instance management and authentication. + */ +export async function runMerchantCategoriesTest(t: GlobalTestState) { + // Set up test environment + + const db = await setupDb(t); + + const exchange = ExchangeService.create(t, { + name: "testexchange-1", + currency: "TESTKUDOS", + httpPort: 8081, + database: db.connStr, + }); + + const merchant = await MerchantService.create(t, { + name: "testmerchant-1", + currency: "TESTKUDOS", + httpPort: 8083, + database: db.connStr, + }); + + // We add the exchange to the config, but note that the exchange won't be started. + merchant.addExchange(exchange); + + await merchant.start(); + await merchant.pingUntilAvailable(); + + // Base URL for the default instance. + const baseUrl = merchant.makeInstanceBaseUrl(); + + { + const r = await harnessHttpLib.fetch(new URL("config", baseUrl).href); + const data = await r.json(); + console.log(data); + t.assertDeepEqual(data.currency, "TESTKUDOS"); + } + + // Instances should initially be empty + { + const r = await harnessHttpLib.fetch( + new URL("management/instances", baseUrl).href, + ); + const data = await r.json(); + t.assertDeepEqual(data.instances, []); + } + + // Add an instance, no auth! + await merchant.addInstanceWithWireAccount({ + id: "default", + name: "Default Instance", + paytoUris: [generateRandomPayto("merchant-default")], + auth: { + method: "external", + }, + }); + + 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); + console.log(await res.json()); + t.assertTrue(res.status >= 200 && res.status < 300); +} + +runMerchantCategoriesTest.suites = ["merchant"]; diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts index b329036eb..cd0bc9419 100644 --- a/packages/taler-harness/src/integrationtests/testrunner.ts +++ b/packages/taler-harness/src/integrationtests/testrunner.ts @@ -49,6 +49,7 @@ import { runFeeRegressionTest } from "./test-fee-regression.js"; import { runForcedSelectionTest } from "./test-forced-selection.js"; import { runKycTest } from "./test-kyc.js"; import { runLibeufinBankTest } from "./test-libeufin-bank.js"; +import { runMerchantCategoriesTest } from "./test-merchant-categories.js"; import { runMerchantExchangeConfusionTest } from "./test-merchant-exchange-confusion.js"; import { runMerchantInstancesDeleteTest } from "./test-merchant-instances-delete.js"; import { runMerchantInstancesUrlsTest } from "./test-merchant-instances-urls.js"; @@ -236,6 +237,7 @@ const allTests: TestMainFunction[] = [ runWithdrawalAmountTest, runWithdrawalFlexTest, runExchangeMasterPubChangeTest, + runMerchantCategoriesTest, ]; export interface TestRunSpec { -- cgit v1.2.3