diff options
author | Florian Dold <florian@dold.me> | 2023-08-29 09:02:16 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-08-29 09:03:19 +0200 |
commit | b13bd85215ad64e7a2764ac7e7fee5945ffa1c07 (patch) | |
tree | 70643c7e76baeb9f61857add603dc381b6f03766 /packages/taler-harness/src/integrationtests/test-merchant-instances.ts | |
parent | 8941f29cb457f86235b73f125e77a88cb762f353 (diff) | |
download | wallet-core-b13bd85215ad64e7a2764ac7e7fee5945ffa1c07.tar.xz |
taler-harness: remove axios usage, renovate some tests
Diffstat (limited to 'packages/taler-harness/src/integrationtests/test-merchant-instances.ts')
-rw-r--r-- | packages/taler-harness/src/integrationtests/test-merchant-instances.ts | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-merchant-instances.ts b/packages/taler-harness/src/integrationtests/test-merchant-instances.ts index 78626ea3d..f7d89c543 100644 --- a/packages/taler-harness/src/integrationtests/test-merchant-instances.ts +++ b/packages/taler-harness/src/integrationtests/test-merchant-instances.ts @@ -18,8 +18,6 @@ * Imports. */ import { URL } from "@gnu-taler/taler-util"; -import axiosImp from "axios"; -const axios = axiosImp.default; import { ExchangeService, GlobalTestState, @@ -27,7 +25,9 @@ import { MerchantService, setupDb, getPayto, + harnessHttpLib, } from "../harness/harness.js"; +import { createPlatformHttpLib } from "@gnu-taler/taler-util/http"; /** * Do basic checks on instance management and authentication. @@ -61,15 +61,19 @@ export async function runMerchantInstancesTest(t: GlobalTestState) { const baseUrl = merchant.makeInstanceBaseUrl(); { - const r = await axios.get(new URL("config", baseUrl).href); - console.log(r.data); - t.assertDeepEqual(r.data.currency, "TESTKUDOS"); + 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 axios.get(new URL("management/instances", baseUrl).href); - t.assertDeepEqual(r.data.instances, []); + 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! @@ -104,11 +108,14 @@ export async function runMerchantInstancesTest(t: GlobalTestState) { // Check that a "malformed" bearer Authorization header gets ignored { const url = merchant.makeInstanceBaseUrl(); - const resp = await axios.get(new URL("management/instances", url).href, { - headers: { - Authorization: "foo bar-baz", + const resp = await harnessHttpLib.fetch( + new URL("management/instances", url).href, + { + headers: { + Authorization: "foo bar-baz", + }, }, - }); + ); t.assertDeepEqual(resp.status, 200); } @@ -130,9 +137,7 @@ export async function runMerchantInstancesTest(t: GlobalTestState) { }); console.log(exc); - - t.assertAxiosError(exc); - t.assertTrue(exc.response?.status === 401); + t.assertTrue(exc.errorDetail.httpStatusCode === 401); merchantClient = new MerchantApiClient(merchant.makeInstanceBaseUrl(), { method: "token", @@ -145,12 +150,15 @@ export async function runMerchantInstancesTest(t: GlobalTestState) { // Now, try some variations. { const url = merchant.makeInstanceBaseUrl(); - const resp = await axios.get(new URL("management/instances", url).href, { - headers: { - // Note the spaces - Authorization: "Bearer secret-token:foobar", + const resp = await harnessHttpLib.fetch( + new URL("management/instances", url).href, + { + headers: { + // Note the spaces + Authorization: "Bearer secret-token:foobar", + }, }, - }); + ); t.assertDeepEqual(resp.status, 200); } @@ -176,7 +184,7 @@ export async function runMerchantInstancesTest(t: GlobalTestState) { await unauthMerchantClient.deleteInstance("myinst"); }); console.log(exc); - t.assertAxiosError(exc); + t.assertTrue(exc.errorDetail.httpStatusCode === 401); t.assertDeepEqual(exc.response?.status, 401); } } |