diff options
author | Sebastian <sebasjm@gmail.com> | 2023-01-03 10:01:04 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-01-03 10:01:04 -0300 |
commit | 9ad1f2712a92d58804e090a7c3dd4cc0a41ee1d9 (patch) | |
tree | 51ea688742936faece5c5055bc2b66dbf501782d | |
parent | a2668c22f0d18386fc988f27299172145d9fa15d (diff) |
pretty
10 files changed, 654 insertions, 466 deletions
diff --git a/packages/merchant-backoffice-ui/src/context/backend.test.ts b/packages/merchant-backoffice-ui/src/context/backend.test.ts index c7fb19293..77395ca0c 100644 --- a/packages/merchant-backoffice-ui/src/context/backend.test.ts +++ b/packages/merchant-backoffice-ui/src/context/backend.test.ts @@ -29,14 +29,17 @@ import { } from "../hooks/instance.js"; import { expect } from "chai"; import { ApiMockEnvironment } from "../hooks/testing.js"; -import { API_CREATE_INSTANCE, API_UPDATE_CURRENT_INSTANCE_AUTH, API_UPDATE_INSTANCE_AUTH_BY_ID } from "../hooks/urls.js"; +import { + API_CREATE_INSTANCE, + API_UPDATE_CURRENT_INSTANCE_AUTH, + API_UPDATE_INSTANCE_AUTH_BY_ID, +} from "../hooks/urls.js"; interface TestingContextProps { children?: ComponentChildren; } describe("backend context api ", () => { - it("should use new token after updating the instance token in the settings as user", async () => { const env = new ApiMockEnvironment(); @@ -61,10 +64,12 @@ describe("backend context api ", () => { } as MerchantBackend.Instances.QueryInstancesResponse, }); - management.setNewToken("another_token") + management.setNewToken("another_token"); }, ({ instance, management, admin }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); env.addRequestExpectation(API_CREATE_INSTANCE, { auth: "another_token", @@ -76,9 +81,10 @@ describe("backend context api ", () => { admin.createInstance({ id: "new_instance_id", } as MerchantBackend.Instances.InstanceConfigurationMessage); - }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); @@ -110,7 +116,9 @@ describe("backend context api ", () => { instance.setNewToken("another_token"); }, ({ instance, management, admin }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); env.addRequestExpectation(API_CREATE_INSTANCE, { auth: "another_token", @@ -123,7 +131,9 @@ describe("backend context api ", () => { id: "new_instance_id", } as MerchantBackend.Instances.InstanceConfigurationMessage); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); diff --git a/packages/merchant-backoffice-ui/src/hooks/instance.test.ts b/packages/merchant-backoffice-ui/src/hooks/instance.test.ts index c7aa63e20..76c2c47ae 100644 --- a/packages/merchant-backoffice-ui/src/hooks/instance.test.ts +++ b/packages/merchant-backoffice-ui/src/hooks/instance.test.ts @@ -22,7 +22,13 @@ import { tests } from "@gnu-taler/web-util/lib/index.browser"; import { expect } from "chai"; import { MerchantBackend } from "../declaration.js"; -import { useAdminAPI, useBackendInstances, useInstanceAPI, useInstanceDetails, useManagementAPI } from "./instance.js"; +import { + useAdminAPI, + useBackendInstances, + useInstanceAPI, + useInstanceDetails, + useManagementAPI, +} from "./instance.js"; import { ApiMockEnvironment } from "./testing.js"; import { API_CREATE_INSTANCE, @@ -30,17 +36,17 @@ import { API_GET_CURRENT_INSTANCE, API_LIST_INSTANCES, API_UPDATE_CURRENT_INSTANCE, - API_UPDATE_CURRENT_INSTANCE_AUTH, API_UPDATE_INSTANCE_BY_ID + API_UPDATE_CURRENT_INSTANCE_AUTH, + API_UPDATE_INSTANCE_BY_ID, } from "./urls.js"; describe("instance api interaction with details", () => { - it("should evict cache when updating an instance", async () => { const env = new ApiMockEnvironment(); env.addRequestExpectation(API_GET_CURRENT_INSTANCE, { response: { - name: 'instance_name' + name: "instance_name", } as MerchantBackend.Instances.QueryInstancesResponse, }); @@ -56,42 +62,47 @@ describe("instance api interaction with details", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - name: 'instance_name' + name: "instance_name", }); env.addRequestExpectation(API_UPDATE_CURRENT_INSTANCE, { request: { - name: 'other_name' + name: "other_name", } as MerchantBackend.Instances.InstanceReconfigurationMessage, }); env.addRequestExpectation(API_GET_CURRENT_INSTANCE, { response: { - name: 'other_name' + name: "other_name", } as MerchantBackend.Instances.QueryInstancesResponse, }); api.updateInstance({ - name: 'other_name' + name: "other_name", } as MerchantBackend.Instances.InstanceReconfigurationMessage); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - name: 'other_name' + name: "other_name", }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); it("should evict cache when setting the instance's token", async () => { @@ -99,11 +110,11 @@ describe("instance api interaction with details", () => { env.addRequestExpectation(API_GET_CURRENT_INSTANCE, { response: { - name: 'instance_name', + name: "instance_name", auth: { - method: 'token', - token: 'not-secret', - } + method: "token", + token: "not-secret", + }, } as MerchantBackend.Instances.QueryInstancesResponse, }); @@ -119,51 +130,56 @@ describe("instance api interaction with details", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - name: 'instance_name', + name: "instance_name", auth: { - method: 'token', - token: 'not-secret', - } + method: "token", + token: "not-secret", + }, }); env.addRequestExpectation(API_UPDATE_CURRENT_INSTANCE_AUTH, { request: { - method: 'token', - token: 'secret' + method: "token", + token: "secret", } as MerchantBackend.Instances.InstanceAuthConfigurationMessage, }); env.addRequestExpectation(API_GET_CURRENT_INSTANCE, { response: { - name: 'instance_name', + name: "instance_name", auth: { - method: 'token', - token: 'secret', - } + method: "token", + token: "secret", + }, } as MerchantBackend.Instances.QueryInstancesResponse, }); - api.setNewToken('secret') + api.setNewToken("secret"); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - name: 'instance_name', + name: "instance_name", auth: { - method: 'token', - token: 'secret', - } + method: "token", + token: "secret", + }, }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); it("should evict cache when clearing the instance's token", async () => { @@ -171,11 +187,11 @@ describe("instance api interaction with details", () => { env.addRequestExpectation(API_GET_CURRENT_INSTANCE, { response: { - name: 'instance_name', + name: "instance_name", auth: { - method: 'token', - token: 'not-secret', - } + method: "token", + token: "not-secret", + }, } as MerchantBackend.Instances.QueryInstancesResponse, }); @@ -191,46 +207,52 @@ describe("instance api interaction with details", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - name: 'instance_name', + name: "instance_name", auth: { - method: 'token', - token: 'not-secret', - } + method: "token", + token: "not-secret", + }, }); env.addRequestExpectation(API_UPDATE_CURRENT_INSTANCE_AUTH, { request: { - method: 'external', + method: "external", } as MerchantBackend.Instances.InstanceAuthConfigurationMessage, }); env.addRequestExpectation(API_GET_CURRENT_INSTANCE, { response: { - name: 'instance_name', + name: "instance_name", auth: { - method: 'external', - } + method: "external", + }, } as MerchantBackend.Instances.QueryInstancesResponse, }); api.clearToken(); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - name: 'instance_name', + name: "instance_name", auth: { - method: 'external', - } + method: "external", + }, }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); // const { result, waitForNextUpdate } = renderHook( @@ -266,14 +288,12 @@ describe("instance api interaction with details", () => { // } // }); - // act(async () => { // await result.current?.api.clearToken(); // }); // expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - // expect(result.current.query.loading).false; // await waitForNextUpdate({ timeout: 1 }); @@ -293,15 +313,16 @@ describe("instance api interaction with details", () => { }); describe("instance admin api interaction with listing", () => { - it("should evict cache when creating a new instance", async () => { const env = new ApiMockEnvironment(); env.addRequestExpectation(API_LIST_INSTANCES, { response: { - instances: [{ - name: 'instance_name' - } as MerchantBackend.Instances.Instance] + instances: [ + { + name: "instance_name", + } as MerchantBackend.Instances.Instance, + ], }, }); @@ -317,53 +338,65 @@ describe("instance admin api interaction with listing", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - instances: [{ - name: 'instance_name' - }] + instances: [ + { + name: "instance_name", + }, + ], }); env.addRequestExpectation(API_CREATE_INSTANCE, { request: { - name: 'other_name' + name: "other_name", } as MerchantBackend.Instances.InstanceConfigurationMessage, }); env.addRequestExpectation(API_LIST_INSTANCES, { response: { - instances: [{ - name: 'instance_name' - } as MerchantBackend.Instances.Instance, - { - name: 'other_name' - } as MerchantBackend.Instances.Instance] + instances: [ + { + name: "instance_name", + } as MerchantBackend.Instances.Instance, + { + name: "other_name", + } as MerchantBackend.Instances.Instance, + ], }, }); api.createInstance({ - name: 'other_name' + name: "other_name", } as MerchantBackend.Instances.InstanceConfigurationMessage); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - instances: [{ - name: 'instance_name' - }, { - name: 'other_name' - }] + instances: [ + { + name: "instance_name", + }, + { + name: "other_name", + }, + ], }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); it("should evict cache when deleting an instance", async () => { @@ -371,14 +404,16 @@ describe("instance admin api interaction with listing", () => { env.addRequestExpectation(API_LIST_INSTANCES, { response: { - instances: [{ - id: 'default', - name: 'instance_name' - } as MerchantBackend.Instances.Instance, - { - id: 'the_id', - name: 'second_instance' - } as MerchantBackend.Instances.Instance] + instances: [ + { + id: "default", + name: "instance_name", + } as MerchantBackend.Instances.Instance, + { + id: "the_id", + name: "second_instance", + } as MerchantBackend.Instances.Instance, + ], }, }); @@ -394,45 +429,58 @@ describe("instance admin api interaction with listing", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - instances: [{ - id: 'default', - name: 'instance_name' - }, { - id: 'the_id', - name: 'second_instance' - }] + instances: [ + { + id: "default", + name: "instance_name", + }, + { + id: "the_id", + name: "second_instance", + }, + ], }); - env.addRequestExpectation(API_DELETE_INSTANCE('the_id'), {}); + env.addRequestExpectation(API_DELETE_INSTANCE("the_id"), {}); env.addRequestExpectation(API_LIST_INSTANCES, { response: { - instances: [{ - id: 'default', - name: 'instance_name' - } as MerchantBackend.Instances.Instance] + instances: [ + { + id: "default", + name: "instance_name", + } as MerchantBackend.Instances.Instance, + ], }, }); - api.deleteInstance('the_id'); + api.deleteInstance("the_id"); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - instances: [{ - id: 'default', - name: 'instance_name' - }] + instances: [ + { + id: "default", + name: "instance_name", + }, + ], }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); @@ -510,14 +558,16 @@ describe("instance admin api interaction with listing", () => { env.addRequestExpectation(API_LIST_INSTANCES, { response: { - instances: [{ - id: 'default', - name: 'instance_name' - } as MerchantBackend.Instances.Instance, - { - id: 'the_id', - name: 'second_instance' - } as MerchantBackend.Instances.Instance] + instances: [ + { + id: "default", + name: "instance_name", + } as MerchantBackend.Instances.Instance, + { + id: "the_id", + name: "second_instance", + } as MerchantBackend.Instances.Instance, + ], }, }); @@ -533,72 +583,85 @@ describe("instance admin api interaction with listing", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - instances: [{ - id: 'default', - name: 'instance_name' - }, { - id: 'the_id', - name: 'second_instance' - }] + instances: [ + { + id: "default", + name: "instance_name", + }, + { + id: "the_id", + name: "second_instance", + }, + ], }); - env.addRequestExpectation(API_DELETE_INSTANCE('the_id'), { + env.addRequestExpectation(API_DELETE_INSTANCE("the_id"), { qparam: { - purge: 'YES' - } + purge: "YES", + }, }); env.addRequestExpectation(API_LIST_INSTANCES, { response: { - instances: [{ - id: 'default', - name: 'instance_name' - } as MerchantBackend.Instances.Instance] + instances: [ + { + id: "default", + name: "instance_name", + } as MerchantBackend.Instances.Instance, + ], }, }); - api.purgeInstance('the_id') + api.purgeInstance("the_id"); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - instances: [{ - id: 'default', - name: 'instance_name' - }] + instances: [ + { + id: "default", + name: "instance_name", + }, + ], }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); }); describe("instance management api interaction with listing", () => { - it("should evict cache when updating an instance", async () => { const env = new ApiMockEnvironment(); env.addRequestExpectation(API_LIST_INSTANCES, { response: { - instances: [{ - id: 'managed', - name: 'instance_name' - } as MerchantBackend.Instances.Instance] + instances: [ + { + id: "managed", + name: "instance_name", + } as MerchantBackend.Instances.Instance, + ], }, }); const hookBehavior = await tests.hookBehaveLikeThis( () => { - const api = useManagementAPI('managed'); + const api = useManagementAPI("managed"); const query = useBackendInstances(); return { query, api }; }, @@ -608,53 +671,61 @@ describe("instance management api interaction with listing", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - instances: [{ - id: 'managed', - name: 'instance_name' - }] + instances: [ + { + id: "managed", + name: "instance_name", + }, + ], }); - env.addRequestExpectation(API_UPDATE_INSTANCE_BY_ID('managed'), { + env.addRequestExpectation(API_UPDATE_INSTANCE_BY_ID("managed"), { request: { - name: 'other_name' + name: "other_name", } as MerchantBackend.Instances.InstanceReconfigurationMessage, }); env.addRequestExpectation(API_LIST_INSTANCES, { response: { instances: [ { - id: 'managed', - name: 'other_name' - } as MerchantBackend.Instances.Instance] + id: "managed", + name: "other_name", + } as MerchantBackend.Instances.Instance, + ], }, }); api.updateInstance({ - name: 'other_name' + name: "other_name", } as MerchantBackend.Instances.InstanceConfigurationMessage); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - instances: [{ - id: 'managed', - name: 'other_name' - }] + instances: [ + { + id: "managed", + name: "other_name", + }, + ], }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); - }); - diff --git a/packages/merchant-backoffice-ui/src/hooks/order.test.ts b/packages/merchant-backoffice-ui/src/hooks/order.test.ts index be4d1d804..2f4615729 100644 --- a/packages/merchant-backoffice-ui/src/hooks/order.test.ts +++ b/packages/merchant-backoffice-ui/src/hooks/order.test.ts @@ -29,11 +29,11 @@ import { API_DELETE_ORDER, API_FORGET_ORDER_BY_ID, API_GET_ORDER_BY_ID, - API_LIST_ORDERS, API_REFUND_ORDER_BY_ID + API_LIST_ORDERS, + API_REFUND_ORDER_BY_ID, } from "./urls.js"; describe("order api interaction with listing", () => { - it("should evict cache when creating an order", async () => { const env = new ApiMockEnvironment(); @@ -51,7 +51,6 @@ describe("order api interaction with listing", () => { }, }); - const newDate = (d: Date) => { //console.log("new date", d); }; @@ -68,9 +67,11 @@ describe("order api interaction with listing", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ orders: [{ order_id: "1" }, { order_id: "2" }], @@ -102,19 +103,22 @@ describe("order api interaction with listing", () => { } as any); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ orders: [{ order_id: "1" }, { order_id: "2" }, { order_id: "3" }], }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); it("should evict cache when doing a refund", async () => { @@ -123,16 +127,21 @@ describe("order api interaction with listing", () => { env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: 0, paid: "yes" }, response: { - orders: [{ order_id: "1", amount: 'EUR:12', refundable: true } as MerchantBackend.Orders.OrderHistoryEntry], + orders: [ + { + order_id: "1", + amount: "EUR:12", + refundable: true, + } as MerchantBackend.Orders.OrderHistoryEntry, + ], }, }); env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: -20, paid: "yes" }, - response: { orders: [], }, + response: { orders: [] }, }); - const newDate = (d: Date) => { //console.log("new date", d); }; @@ -149,61 +158,72 @@ describe("order api interaction with listing", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - orders: [{ - order_id: "1", - amount: 'EUR:12', - refundable: true, - }], + orders: [ + { + order_id: "1", + amount: "EUR:12", + refundable: true, + }, + ], }); - env.addRequestExpectation(API_REFUND_ORDER_BY_ID('1'), { + env.addRequestExpectation(API_REFUND_ORDER_BY_ID("1"), { request: { - reason: 'double pay', - refund: 'EUR:1' + reason: "double pay", + refund: "EUR:1", }, }); env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: 0, paid: "yes" }, response: { - orders: [{ order_id: "1", amount: 'EUR:12', refundable: false } as any], + orders: [ + { order_id: "1", amount: "EUR:12", refundable: false } as any, + ], }, }); env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: -20, paid: "yes" }, - response: { orders: [], }, + response: { orders: [] }, }); - api.refundOrder('1', { - reason: 'double pay', - refund: 'EUR:1' + api.refundOrder("1", { + reason: "double pay", + refund: "EUR:1", }); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - orders: [{ - order_id: "1", - amount: 'EUR:12', - refundable: false, - }], + orders: [ + { + order_id: "1", + amount: "EUR:12", + refundable: false, + }, + ], }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); it("should evict cache when deleting an order", async () => { @@ -223,7 +243,6 @@ describe("order api interaction with listing", () => { }, }); - const newDate = (d: Date) => { //console.log("new date", d); }; @@ -240,15 +259,17 @@ describe("order api interaction with listing", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ orders: [{ order_id: "1" }, { order_id: "2" }], }); - env.addRequestExpectation(API_DELETE_ORDER('1'), {}); + env.addRequestExpectation(API_DELETE_ORDER("1"), {}); env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: 0, paid: "yes" }, @@ -264,35 +285,36 @@ describe("order api interaction with listing", () => { }, }); - api.deleteOrder('1'); + api.deleteOrder("1"); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ orders: [{ order_id: "2" }], }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); - }); describe("order api interaction with details", () => { - it("should evict cache when doing a refund", async () => { const env = new ApiMockEnvironment(); - env.addRequestExpectation(API_GET_ORDER_BY_ID('1'), { + env.addRequestExpectation(API_GET_ORDER_BY_ID("1"), { // qparam: { delta: 0, paid: "yes" }, response: { - summary: 'description', - refund_amount: 'EUR:0', + summary: "description", + refund_amount: "EUR:0", } as unknown as MerchantBackend.Orders.CheckPaymentPaidResponse, }); @@ -302,7 +324,7 @@ describe("order api interaction with details", () => { const hookBehavior = await tests.hookBehaveLikeThis( () => { - const query = useOrderDetails('1') + const query = useOrderDetails("1"); const api = useOrderAPI(); return { query, api }; }, @@ -312,58 +334,63 @@ describe("order api interaction with details", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - summary: 'description', - refund_amount: 'EUR:0', + summary: "description", + refund_amount: "EUR:0", }); - env.addRequestExpectation(API_REFUND_ORDER_BY_ID('1'), { + env.addRequestExpectation(API_REFUND_ORDER_BY_ID("1"), { request: { - reason: 'double pay', - refund: 'EUR:1' + reason: "double pay", + refund: "EUR:1", }, }); - env.addRequestExpectation(API_GET_ORDER_BY_ID('1'), { + env.addRequestExpectation(API_GET_ORDER_BY_ID("1"), { response: { - summary: 'description', - refund_amount: 'EUR:1', + summary: "description", + refund_amount: "EUR:1", } as unknown as MerchantBackend.Orders.CheckPaymentPaidResponse, }); - api.refundOrder('1', { - reason: 'double pay', - refund: 'EUR:1' - }) + api.refundOrder("1", { + reason: "double pay", + refund: "EUR:1", + }); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - summary: 'description', - refund_amount: 'EUR:1', + summary: "description", + refund_amount: "EUR:1", }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - - }) + }); it("should evict cache when doing a forget", async () => { const env = new ApiMockEnvironment(); - env.addRequestExpectation(API_GET_ORDER_BY_ID('1'), { + env.addRequestExpectation(API_GET_ORDER_BY_ID("1"), { // qparam: { delta: 0, paid: "yes" }, response: { - summary: 'description', - refund_amount: 'EUR:0', + summary: "description", + refund_amount: "EUR:0", } as unknown as MerchantBackend.Orders.CheckPaymentPaidResponse, }); @@ -373,7 +400,7 @@ describe("order api interaction with details", () => { const hookBehavior = await tests.hookBehaveLikeThis( () => { - const query = useOrderDetails('1') + const query = useOrderDetails("1"); const api = useOrderAPI(); return { query, api }; }, @@ -383,48 +410,52 @@ describe("order api interaction with details", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - summary: 'description', - refund_amount: 'EUR:0', + summary: "description", + refund_amount: "EUR:0", }); - env.addRequestExpectation(API_FORGET_ORDER_BY_ID('1'), { + env.addRequestExpectation(API_FORGET_ORDER_BY_ID("1"), { request: { - fields: ['$.summary'] + fields: ["$.summary"], }, }); - env.addRequestExpectation(API_GET_ORDER_BY_ID('1'), { + env.addRequestExpectation(API_GET_ORDER_BY_ID("1"), { response: { summary: undefined, } as unknown as MerchantBackend.Orders.CheckPaymentPaidResponse, }); - api.forgetOrder('1', { - fields: ['$.summary'] - }) + api.forgetOrder("1", { + fields: ["$.summary"], + }); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ summary: undefined, }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - - }) -}) + }); +}); describe("order listing pagination", () => { - it("should not load more if has reach the end", async () => { const env = new ApiMockEnvironment(); env.addRequestExpectation(API_LIST_ORDERS, { @@ -441,7 +472,6 @@ describe("order listing pagination", () => { }, }); - const newDate = (d: Date) => { //console.log("new date", d); }; @@ -449,7 +479,7 @@ describe("order listing pagination", () => { const hookBehavior = await tests.hookBehaveLikeThis( () => { const date = new Date(12); - const query = useInstanceOrders({ wired: "yes", date }, newDate) + const query = useInstanceOrders({ wired: "yes", date }, newDate); const api = useOrderAPI(); return { query, api }; }, @@ -459,33 +489,40 @@ describe("order listing pagination", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ orders: [{ order_id: "1" }, { order_id: "2" }], }); - expect(query.isReachingEnd).true - expect(query.isReachingStart).true + expect(query.isReachingEnd).true; + expect(query.isReachingStart).true; // should not trigger new state update or query - query.loadMore() + query.loadMore(); query.loadMorePrev(); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); it("should load more if result brings more that PAGE_SIZE", async () => { const env = new ApiMockEnvironment(); - const ordersFrom0to20 = Array.from({ length: 20 }).map((e, i) => ({ order_id: String(i) })) - const ordersFrom20to40 = Array.from({ length: 20 }).map((e, i) => ({ order_id: String(i + 20) })) - const ordersFrom20to0 = [...ordersFrom0to20].reverse() + const ordersFrom0to20 = Array.from({ length: 20 }).map((e, i) => ({ + order_id: String(i), + })); + const ordersFrom20to40 = Array.from({ length: 20 }).map((e, i) => ({ + order_id: String(i + 20), + })); + const ordersFrom20to0 = [...ordersFrom0to20].reverse(); env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: 20, wired: "yes", date_ms: 12 }, @@ -508,7 +545,7 @@ describe("order listing pagination", () => { const hookBehavior = await tests.hookBehaveLikeThis( () => { const date = new Date(12); - const query = useInstanceOrders({ wired: "yes", date }, newDate) + const query = useInstanceOrders({ wired: "yes", date }, newDate); const api = useOrderAPI(); return { query, api }; }, @@ -518,62 +555,77 @@ describe("order listing pagination", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ orders: [...ordersFrom20to0, ...ordersFrom20to40], }); - expect(query.isReachingEnd).false - expect(query.isReachingStart).false + expect(query.isReachingEnd).false; + expect(query.isReachingStart).false; env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: -40, wired: "yes", date_ms: 13 }, response: { - orders: [...ordersFrom20to40, { order_id: '41' }], + orders: [...ordersFrom20to40, { order_id: "41" }], }, }); - query.loadMore() + query.loadMore(); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).true; }, ({ query, api }) => { expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - orders: [...ordersFrom20to0, ...ordersFrom20to40, { order_id: '41' }], + orders: [ + ...ordersFrom20to0, + ...ordersFrom20to40, + { order_id: "41" }, + ], }); env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: 40, wired: "yes", date_ms: 12 }, response: { - orders: [...ordersFrom0to20, { order_id: '-1' }], + orders: [...ordersFrom0to20, { order_id: "-1" }], }, }); - query.loadMorePrev() + query.loadMorePrev(); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).true; }, ({ query, api }) => { expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - orders: [{ order_id: '-1' }, ...ordersFrom20to0, ...ordersFrom20to40, { order_id: '41' }], + orders: [ + { order_id: "-1" }, + ...ordersFrom20to0, + ...ordersFrom20to40, + { order_id: "41" }, + ], }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); }); - - }); diff --git a/packages/merchant-backoffice-ui/src/hooks/order.ts b/packages/merchant-backoffice-ui/src/hooks/order.ts index 0bea6b963..5be480160 100644 --- a/packages/merchant-backoffice-ui/src/hooks/order.ts +++ b/packages/merchant-backoffice-ui/src/hooks/order.ts @@ -257,9 +257,9 @@ export function useInstanceOrders( !beforeData || !afterData ? [] : (beforeData || lastBefore).data.orders - .slice() - .reverse() - .concat((afterData || lastAfter).data.orders); + .slice() + .reverse() + .concat((afterData || lastAfter).data.orders); if (loadingAfter || loadingBefore) return { loading: true, data: { orders } }; if (beforeData && afterData) { return { ok: true, data: { orders }, ...pagination }; diff --git a/packages/merchant-backoffice-ui/src/hooks/product.test.ts b/packages/merchant-backoffice-ui/src/hooks/product.test.ts index a182b28f4..c2271eb64 100644 --- a/packages/merchant-backoffice-ui/src/hooks/product.test.ts +++ b/packages/merchant-backoffice-ui/src/hooks/product.test.ts @@ -22,13 +22,18 @@ import { tests } from "@gnu-taler/web-util/lib/index.browser"; import { expect } from "chai"; import { MerchantBackend } from "../declaration.js"; -import { useInstanceProducts, useProductAPI, useProductDetails } from "./product.js"; +import { + useInstanceProducts, + useProductAPI, + useProductDetails, +} from "./product.js"; import { ApiMockEnvironment } from "./testing.js"; import { API_CREATE_PRODUCT, - API_DELETE_PRODUCT, API_GET_PRODUCT_BY_ID, + API_DELETE_PRODUCT, + API_GET_PRODUCT_BY_ID, API_LIST_PRODUCTS, - API_UPDATE_PRODUCT_BY_ID + API_UPDATE_PRODUCT_BY_ID, } from "./urls.js"; describe("product api interaction with listing", () => { @@ -56,19 +61,21 @@ describe("product api interaction with listing", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).true; }, ({ query, api }) => { expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; - expect(query.data).deep.equals([ - { id: "1234", price: "ARS:12" }, - ]); + expect(query.data).deep.equals([{ id: "1234", price: "ARS:12" }]); env.addRequestExpectation(API_CREATE_PRODUCT, { - request: { price: "ARS:23" } as MerchantBackend.Products.ProductAddDetail, + request: { + price: "ARS:23", + } as MerchantBackend.Products.ProductAddDetail, }); env.addRequestExpectation(API_LIST_PRODUCTS, { @@ -77,28 +84,37 @@ describe("product api interaction with listing", () => { }, }); env.addRequestExpectation(API_GET_PRODUCT_BY_ID("1234"), { - response: { price: "ARS:12" } as MerchantBackend.Products.ProductDetail, + response: { + price: "ARS:12", + } as MerchantBackend.Products.ProductDetail, }); env.addRequestExpectation(API_GET_PRODUCT_BY_ID("1234"), { - response: { price: "ARS:12" } as MerchantBackend.Products.ProductDetail, + response: { + price: "ARS:12", + } as MerchantBackend.Products.ProductDetail, }); env.addRequestExpectation(API_GET_PRODUCT_BY_ID("2345"), { - response: { price: "ARS:23" } as MerchantBackend.Products.ProductDetail, + response: { + price: "ARS:23", + } as MerchantBackend.Products.ProductDetail, }); api.createProduct({ price: "ARS:23", - } as any) - + } as any); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals([ { @@ -111,11 +127,12 @@ describe("product api interaction with listing", () => { }, ]); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); it("should evict cache when updating a product", async () => { @@ -145,16 +162,18 @@ describe("product api interaction with listing", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; - expect(query.data).deep.equals([ - { id: "1234", price: "ARS:12" }, - ]); + expect(query.data).deep.equals([{ id: "1234", price: "ARS:12" }]); env.addRequestExpectation(API_UPDATE_PRODUCT_BY_ID("1234"), { - request: { price: "ARS:13" } as MerchantBackend.Products.ProductPatchDetail, + request: { + price: "ARS:13", + } as MerchantBackend.Products.ProductPatchDetail, }); env.addRequestExpectation(API_LIST_PRODUCTS, { @@ -163,18 +182,21 @@ describe("product api interaction with listing", () => { }, }); env.addRequestExpectation(API_GET_PRODUCT_BY_ID("1234"), { - response: { price: "ARS:13" } as MerchantBackend.Products.ProductDetail, + response: { + price: "ARS:13", + } as MerchantBackend.Products.ProductDetail, }); api.updateProduct("1234", { price: "ARS:13", - } as any) - + } as any); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals([ { @@ -183,11 +205,12 @@ describe("product api interaction with listing", () => { }, ]); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); it("should evict cache when deleting a product", async () => { @@ -217,12 +240,14 @@ describe("product api interaction with listing", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).true; }, ({ query, api }) => { expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals([ { id: "1234", price: "ARS:12" }, @@ -238,29 +263,34 @@ describe("product api interaction with listing", () => { }); env.addRequestExpectation(API_GET_PRODUCT_BY_ID("1234"), { - response: { price: "ARS:12" } as MerchantBackend.Products.ProductDetail, + response: { + price: "ARS:12", + } as MerchantBackend.Products.ProductDetail, }); api.deleteProduct("2345"); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).undefined; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; - expect(query.data).deep.equals([ - { id: "1234", price: "ARS:12" }, - ]); + expect(query.data).deep.equals([{ id: "1234", price: "ARS:12" }]); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); }); - }); describe("product api interaction with details", () => { @@ -285,16 +315,20 @@ describe("product api interaction with details", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ description: "this is a description", }); env.addRequestExpectation(API_UPDATE_PRODUCT_BY_ID("12"), { - request: { description: "other description" } as MerchantBackend.Products.ProductPatchDetail, + request: { + description: "other description", + } as MerchantBackend.Products.ProductPatchDetail, }); env.addRequestExpectation(API_GET_PRODUCT_BY_ID("12"), { @@ -306,21 +340,23 @@ describe("product api interaction with details", () => { api.updateProduct("12", { description: "other description", } as any); - }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ description: "other description", }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - - }) -})
\ No newline at end of file + }); +}); diff --git a/packages/merchant-backoffice-ui/src/hooks/reserve.test.ts b/packages/merchant-backoffice-ui/src/hooks/reserve.test.ts index da0e054e5..79c8c9229 100644 --- a/packages/merchant-backoffice-ui/src/hooks/reserve.test.ts +++ b/packages/merchant-backoffice-ui/src/hooks/reserve.test.ts @@ -25,7 +25,7 @@ import { useInstanceReserves, useReserveDetails, useReservesAPI, - useTipDetails + useTipDetails, } from "./reserves.js"; import { ApiMockEnvironment } from "./testing.js"; import { @@ -35,7 +35,7 @@ import { API_DELETE_RESERVE, API_GET_RESERVE_BY_ID, API_GET_TIP_BY_ID, - API_LIST_RESERVES + API_LIST_RESERVES, } from "./urls.js"; import { tests } from "@gnu-taler/web-util/lib/index.browser"; @@ -66,7 +66,7 @@ describe("reserve api interaction with listing", () => { }, ({ query, api }) => { expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ reserves: [{ reserve_pub: "11" }], @@ -101,10 +101,12 @@ describe("reserve api interaction with listing", () => { initial_balance: "ARS:3333", exchange_url: "http://url", wire_method: "iban", - }) + }); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; expect(query.ok).true; if (!query.ok) return; @@ -120,11 +122,12 @@ describe("reserve api interaction with listing", () => { ], }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); it("should evict cache when deleting a reserve", async () => { @@ -158,10 +161,12 @@ describe("reserve api interaction with listing", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }) + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ reserves: [ @@ -185,25 +190,25 @@ describe("reserve api interaction with listing", () => { }, }); - api.deleteReserve("11") + api.deleteReserve("11"); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }) + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ - reserves: [ - { reserve_pub: "22" }, - { reserve_pub: "33" }, - ], + reserves: [{ reserve_pub: "22" }, { reserve_pub: "33" }], }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); }); @@ -217,8 +222,8 @@ describe("reserve api interaction with details", () => { tips: [{ reason: "why?", tip_id: "id1", total_amount: "USD:10" }], } as MerchantBackend.Tips.ReserveDetail, qparam: { - tips: "yes" - } + tips: "yes", + }, }); const hookBehavior = await tests.hookBehaveLikeThis( @@ -233,9 +238,11 @@ describe("reserve api interaction with details", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ payto_uri: "payto://here", @@ -253,8 +260,8 @@ describe("reserve api interaction with details", () => { taler_tip_uri: "uri", tip_expiration: { t_s: 1 }, tip_status_url: "url", - } - },); + }, + }); env.addRequestExpectation(API_GET_RESERVE_BY_ID("11"), { response: { @@ -265,18 +272,20 @@ describe("reserve api interaction with details", () => { ], } as MerchantBackend.Tips.ReserveDetail, qparam: { - tips: "yes" - } + tips: "yes", + }, }); api.authorizeTipReserve("11", { amount: "USD:12", justification: "not", next_url: "http://taler.net", - }) + }); }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; expect(query.loading).false; @@ -291,11 +300,12 @@ describe("reserve api interaction with details", () => { ], }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); it("should evict cache when adding a tip for a random reserve", async () => { @@ -307,8 +317,8 @@ describe("reserve api interaction with details", () => { tips: [{ reason: "why?", tip_id: "id1", total_amount: "USD:10" }], } as MerchantBackend.Tips.ReserveDetail, qparam: { - tips: "yes" - } + tips: "yes", + }, }); const hookBehavior = await tests.hookBehaveLikeThis( @@ -323,9 +333,11 @@ describe("reserve api interaction with details", () => { expect(query.loading).true; }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ payto_uri: "payto://here", @@ -355,8 +367,8 @@ describe("reserve api interaction with details", () => { ], } as MerchantBackend.Tips.ReserveDetail, qparam: { - tips: "yes" - } + tips: "yes", + }, }); api.authorizeTip({ @@ -364,10 +376,11 @@ describe("reserve api interaction with details", () => { justification: "not", next_url: "http://taler.net", }); - }, ({ query, api }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).false; expect(query.ok).true; if (!query.ok) return; @@ -380,7 +393,9 @@ describe("reserve api interaction with details", () => { ], }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); @@ -388,7 +403,6 @@ describe("reserve api interaction with details", () => { }); describe("reserve api interaction with tip details", () => { - it("should list tips", async () => { const env = new ApiMockEnvironment(); @@ -398,8 +412,8 @@ describe("reserve api interaction with tip details", () => { reason: "not", } as MerchantBackend.Tips.TipDetails, qparam: { - pickups: "yes" - } + pickups: "yes", + }, }); const hookBehavior = await tests.hookBehaveLikeThis( @@ -410,22 +424,25 @@ describe("reserve api interaction with tip details", () => { {}, [ ({ query }) => { - expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); + expect(env.assertJustExpectedRequestWereMade()).deep.eq({ + result: "ok", + }); expect(query.loading).true; }, ({ query }) => { expect(query.loading).false; - expect(query.ok).true + expect(query.ok).true; if (!query.ok) return; expect(query.data).deep.equals({ total_picked_up: "USD:12", reason: "not", }); }, - ], env.buildTestingContext()); + ], + env.buildTestingContext(), + ); expect(hookBehavior).deep.eq({ result: "ok" }); expect(env.assertJustExpectedRequestWereMade()).deep.eq({ result: "ok" }); - }); }); diff --git a/packages/merchant-backoffice-ui/src/hooks/templates.ts b/packages/merchant-backoffice-ui/src/hooks/templates.ts index 55c3875b5..672eaf792 100644 --- a/packages/merchant-backoffice-ui/src/hooks/templates.ts +++ b/packages/merchant-backoffice-ui/src/hooks/templates.ts @@ -174,9 +174,10 @@ export function useInstanceTemplates( if (afterData.data.templates.length < MAX_RESULT_SIZE) { setPageAfter(pageAfter + 1); } else { - const from = `${afterData.data.templates[afterData.data.templates.length - 1] - .template_id - }`; + const from = `${ + afterData.data.templates[afterData.data.templates.length - 1] + .template_id + }`; if (from && updatePosition) updatePosition(from); } }, diff --git a/packages/merchant-backoffice-ui/src/hooks/transfer.ts b/packages/merchant-backoffice-ui/src/hooks/transfer.ts index c827772e4..b86247476 100644 --- a/packages/merchant-backoffice-ui/src/hooks/transfer.ts +++ b/packages/merchant-backoffice-ui/src/hooks/transfer.ts @@ -141,9 +141,10 @@ export function useInstanceTransfers( if (afterData.data.transfers.length < MAX_RESULT_SIZE) { setPageAfter(pageAfter + 1); } else { - const from = `${afterData.data.transfers[afterData.data.transfers.length - 1] + const from = `${ + afterData.data.transfers[afterData.data.transfers.length - 1] .transfer_serial_id - }`; + }`; if (from && updatePosition) updatePosition(from); } }, @@ -152,9 +153,10 @@ export function useInstanceTransfers( if (beforeData.data.transfers.length < MAX_RESULT_SIZE) { setPageBefore(pageBefore + 1); } else if (beforeData) { - const from = `${beforeData.data.transfers[beforeData.data.transfers.length - 1] + const from = `${ + beforeData.data.transfers[beforeData.data.transfers.length - 1] .transfer_serial_id - }`; + }`; if (from && updatePosition) updatePosition(from); } }, @@ -164,9 +166,9 @@ export function useInstanceTransfers( !beforeData || !afterData ? [] : (beforeData || lastBefore).data.transfers - .slice() - .reverse() - .concat((afterData || lastAfter).data.transfers); + .slice() + .reverse() + .concat((afterData || lastAfter).data.transfers); if (loadingAfter || loadingBefore) return { loading: true, data: { transfers } }; if (beforeData && afterData) { diff --git a/packages/merchant-backoffice-ui/src/utils/regex.test.ts b/packages/merchant-backoffice-ui/src/utils/regex.test.ts index 41f0156f5..341a19fb1 100644 --- a/packages/merchant-backoffice-ui/src/utils/regex.test.ts +++ b/packages/merchant-backoffice-ui/src/utils/regex.test.ts @@ -15,74 +15,73 @@ */ /** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ + * + * @author Sebastian Javier Marchano (sebasjm) + */ import { expect } from "chai"; import { AMOUNT_REGEX, PAYTO_REGEX } from "../../src/utils/constants.js"; -describe('payto uri format', () => { +describe("payto uri format", () => { const valids = [ - 'payto://iban/DE75512108001245126199?amount=EUR:200.0&message=hello', - 'payto://ach/122000661/1234', - 'payto://upi/alice@example.com?receiver-name=Alice&amount=INR:200', - 'payto://void/?amount=EUR:10.5', - 'payto://ilp/g.acme.bob' - ] + "payto://iban/DE75512108001245126199?amount=EUR:200.0&message=hello", + "payto://ach/122000661/1234", + "payto://upi/alice@example.com?receiver-name=Alice&amount=INR:200", + "payto://void/?amount=EUR:10.5", + "payto://ilp/g.acme.bob", + ]; - it('should be valid', () => { - valids.forEach(v => expect(v).match(PAYTO_REGEX)) + it("should be valid", () => { + valids.forEach((v) => expect(v).match(PAYTO_REGEX)); }); const invalids = [ // has two question marks - 'payto://iban/DE75?512108001245126199?amount=EUR:200.0&message=hello', + "payto://iban/DE75?512108001245126199?amount=EUR:200.0&message=hello", // has a space - 'payto://ach /122000661/1234', + "payto://ach /122000661/1234", // has a space - 'payto://upi/alice@ example.com?receiver-name=Alice&amount=INR:200', + "payto://upi/alice@ example.com?receiver-name=Alice&amount=INR:200", // invalid field name (mount instead of amount) - 'payto://void/?mount=EUR:10.5', + "payto://void/?mount=EUR:10.5", // payto:// is incomplete - 'payto: //ilp/g.acme.bob' - ] + "payto: //ilp/g.acme.bob", + ]; - it('should not be valid', () => { - invalids.forEach(v => expect(v).not.match(PAYTO_REGEX)) + it("should not be valid", () => { + invalids.forEach((v) => expect(v).not.match(PAYTO_REGEX)); }); -}) +}); -describe('amount format', () => { +describe("amount format", () => { const valids = [ - 'ARS:10', - 'COL:10.2', - 'UY:1,000.2', - 'ARS:10.123,123', - 'ARS:1,000,000', - 'ARSCOL:10', - 'THISISTHEMOTHERCOIN:1,000,000.123,123', - ] + "ARS:10", + "COL:10.2", + "UY:1,000.2", + "ARS:10.123,123", + "ARS:1,000,000", + "ARSCOL:10", + "THISISTHEMOTHERCOIN:1,000,000.123,123", + ]; - it('should be valid', () => { - valids.forEach(v => expect(v).match(AMOUNT_REGEX)) + it("should be valid", () => { + valids.forEach((v) => expect(v).match(AMOUNT_REGEX)); }); const invalids = [ //no currency name - ':10', + ":10", //use . instead of , - 'ARS:1.000.000', + "ARS:1.000.000", //currency name with numbers - '1ARS:10', + "1ARS:10", //currency name with numbers - 'AR5:10', + "AR5:10", //missing value - 'USD:', - ] + "USD:", + ]; - it('should not be valid', () => { - invalids.forEach(v => expect(v).not.match(AMOUNT_REGEX)) + it("should not be valid", () => { + invalids.forEach((v) => expect(v).not.match(AMOUNT_REGEX)); }); - -})
\ No newline at end of file +}); diff --git a/packages/merchant-backoffice-ui/src/utils/request.ts b/packages/merchant-backoffice-ui/src/utils/request.ts index 32b31a557..821eca4a7 100644 --- a/packages/merchant-backoffice-ui/src/utils/request.ts +++ b/packages/merchant-backoffice-ui/src/utils/request.ts @@ -200,7 +200,7 @@ async function buildRequestOk<T>( hasToken: boolean, ): Promise<HttpResponseOk<T>> { const dataTxt = await response.text(); - const data = dataTxt ? JSON.parse(dataTxt) : undefined + const data = dataTxt ? JSON.parse(dataTxt) : undefined; return { ok: true, data, @@ -234,7 +234,7 @@ async function buildRequestFailed( try { const dataTxt = await response.text(); - const data = dataTxt ? JSON.parse(dataTxt) : undefined + const data = dataTxt ? JSON.parse(dataTxt) : undefined; if (status && status >= 400 && status < 500) { const error: HttpResponseClientError = { clientError: true, |