gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] 04/05: update testing hook


From: gnunet
Subject: [taler-wallet-core] 04/05: update testing hook
Date: Thu, 19 Oct 2023 07:56:26 +0200

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository wallet-core.

commit a67518ab1a865fc79374a19bce6513b0caa2eab6
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Thu Oct 19 02:45:36 2023 -0300

    update testing hook
---
 .../merchant-backoffice-ui/src/hooks/testing.tsx   | 61 +++++++++++++++++++++-
 packages/web-util/src/context/api.ts               |  9 ++--
 packages/web-util/src/hooks/useNotifications.ts    |  2 +-
 3 files changed, 67 insertions(+), 5 deletions(-)

diff --git a/packages/merchant-backoffice-ui/src/hooks/testing.tsx 
b/packages/merchant-backoffice-ui/src/hooks/testing.tsx
index 847d512b0..386944854 100644
--- a/packages/merchant-backoffice-ui/src/hooks/testing.tsx
+++ b/packages/merchant-backoffice-ui/src/hooks/testing.tsx
@@ -21,11 +21,13 @@
 
 import { MockEnvironment } from "@gnu-taler/web-util/testing";
 import { ComponentChildren, FunctionalComponent, h, VNode } from "preact";
+import { HttpRequestLibrary, HttpRequestOptions, HttpResponse } from 
"@gnu-taler/taler-util/http";
 import { SWRConfig } from "swr";
 import { ApiContextProvider } from "@gnu-taler/web-util/browser";
 import { BackendContextProvider } from "../context/backend.js";
 import { InstanceContextProvider } from "../context/instance.js";
 import { HttpResponseOk, RequestOptions } from "@gnu-taler/web-util/browser";
+import { TalerBankIntegrationHttpClient, TalerCoreBankHttpClient } from 
"@gnu-taler/taler-util";
 
 export class ApiMockEnvironment extends MockEnvironment {
   constructor(debug = false) {
@@ -47,6 +49,7 @@ export class ApiMockEnvironment extends MockEnvironment {
     }: {
       children: ComponentChildren;
     }): VNode {
+
       async function request<T>(
         base: string,
         path: string,
@@ -89,6 +92,62 @@ export class ApiMockEnvironment extends MockEnvironment {
       }
       const SC: any = SWRConfig;
 
+      const mockHttpClient = new class implements HttpRequestLibrary {
+        async fetch(url: string, options?: HttpRequestOptions | undefined): 
Promise<HttpResponse> {
+          const _url = new URL(url);
+          const mocked = __SAVE_REQUEST_AND_GET_MOCKED_RESPONSE(
+            {
+              method: options?.method ?? "GET",
+              url: _url.href,
+            },
+            {
+              qparam: _url.searchParams,
+              auth: options as any,
+              request: options?.body as any,
+            },
+          );
+          const status = mocked.expectedQuery?.query.code ?? 200;
+          const requestPayload = mocked.expectedQuery?.params?.request;
+          const responsePayload = mocked.expectedQuery?.params?.response;
+
+          // FIXME: complete this implementation to mock any query
+          const resp: HttpResponse = {
+            requestUrl: _url.href,
+            status: status,
+            headers: {} as any,
+            requestMethod: options?.method ?? "GET",
+            json: async () => responsePayload,
+            text: async () => responsePayload as any as string,
+            bytes: async () => responsePayload as ArrayBuffer,
+          };
+          return resp
+        }
+        get(url: string, opt?: HttpRequestOptions): Promise<HttpResponse> {
+          return this.fetch(url, {
+            method: "GET",
+            ...opt,
+          });
+        }
+
+        postJson(
+          url: string,
+          body: any,
+          opt?: HttpRequestOptions,
+        ): Promise<HttpResponse> {
+          return this.fetch(url, {
+            method: "POST",
+            headers: { "Content-Type": "application/json" },
+            body: JSON.stringify(body),
+            ...opt,
+          });
+        }
+
+      }
+      const bankCore = new TalerCoreBankHttpClient("", mockHttpClient)
+      const bankIntegration = bankCore.getIntegrationAPI()
+      const bankRevenue = bankCore.getRevenueAPI("")
+      const bankWire = bankCore.getWireGatewayAPI("")
+
       return (
         <BackendContextProvider defaultUrl="http://backend";>
           <InstanceContextProvider
@@ -99,7 +158,7 @@ export class ApiMockEnvironment extends MockEnvironment {
               changeToken: () => null,
             }}
           >
-            <ApiContextProvider value={{ request }}>
+            <ApiContextProvider value={{ request, bankCore, bankIntegration, 
bankRevenue, bankWire }}>
               <SC
                 value={{
                   loadingTimeout: 0,
diff --git a/packages/web-util/src/context/api.ts 
b/packages/web-util/src/context/api.ts
index 81586bd35..23b7e77af 100644
--- a/packages/web-util/src/context/api.ts
+++ b/packages/web-util/src/context/api.ts
@@ -19,17 +19,20 @@
  * @author Sebastian Javier Marchano (sebasjm)
  */
 
+import { TalerBankIntegrationHttpClient, TalerCoreBankHttpClient, 
TalerRevenueHttpClient, TalerWireGatewayHttpClient } from 
"@gnu-taler/taler-util";
 import { ComponentChildren, createContext, h, VNode } from "preact";
 import { useContext } from "preact/hooks";
 import { defaultRequestHandler } from "../utils/request.js";
 
 interface Type {
   request: typeof defaultRequestHandler;
+  bankCore: TalerCoreBankHttpClient,
+  bankIntegration: TalerBankIntegrationHttpClient,
+  bankWire: TalerWireGatewayHttpClient,
+  bankRevenue: TalerRevenueHttpClient,
 }
 
-const Context = createContext<Type>({
-  request: defaultRequestHandler,
-});
+const Context = createContext<Type>(undefined as any);
 
 export const useApiContext = (): Type => useContext(Context);
 export const ApiContextProvider = ({
diff --git a/packages/web-util/src/hooks/useNotifications.ts 
b/packages/web-util/src/hooks/useNotifications.ts
index e9e8a240b..8f9e0e835 100644
--- a/packages/web-util/src/hooks/useNotifications.ts
+++ b/packages/web-util/src/hooks/useNotifications.ts
@@ -8,7 +8,7 @@ export interface ErrorNotification {
   type: "error";
   title: TranslatedString;
   description?: TranslatedString;
-  debug?: string;
+  debug?: any;
 }
 export interface InfoNotification {
   type: "info";

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]