From ab9ce29b56f5f8d8bfa16570e56cfe13810cad6a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 9 Nov 2023 10:00:24 -0300 Subject: update test for "limit=0" optimization --- .../merchant-backoffice-ui/src/hooks/order.test.ts | 82 +++++----------------- .../src/hooks/transfer.test.ts | 29 +------- packages/merchant-backoffice-ui/src/hooks/urls.ts | 12 ++++ 3 files changed, 34 insertions(+), 89 deletions(-) (limited to 'packages') diff --git a/packages/merchant-backoffice-ui/src/hooks/order.test.ts b/packages/merchant-backoffice-ui/src/hooks/order.test.ts index aa67743df..c243309a8 100644 --- a/packages/merchant-backoffice-ui/src/hooks/order.test.ts +++ b/packages/merchant-backoffice-ui/src/hooks/order.test.ts @@ -37,17 +37,10 @@ describe("order api interaction with listing", () => { it("should evict cache when creating an order", async () => { const env = new ApiMockEnvironment(); - env.addRequestExpectation(API_LIST_ORDERS, { - qparam: { delta: 0, paid: "yes" }, - response: { - orders: [{ order_id: "1" } as MerchantBackend.Orders.OrderHistoryEntry], - }, - }); - env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: -20, paid: "yes" }, response: { - orders: [{ order_id: "2" } as MerchantBackend.Orders.OrderHistoryEntry], + orders: [{ order_id: "1" }, { order_id: "2" } as MerchantBackend.Orders.OrderHistoryEntry], }, }); @@ -84,17 +77,10 @@ describe("order api interaction with listing", () => { response: { order_id: "3" }, }); - env.addRequestExpectation(API_LIST_ORDERS, { - qparam: { delta: 0, paid: "yes" }, - response: { - orders: [{ order_id: "1" } as any], - }, - }); - env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: -20, paid: "yes" }, response: { - orders: [{ order_id: "2" } as any, { order_id: "3" } as any], + orders: [{ order_id: "1" }, { order_id: "2" } as any, { order_id: "3" } as any], }, }); @@ -124,22 +110,13 @@ describe("order api interaction with listing", () => { it("should evict cache when doing a refund", async () => { const env = new ApiMockEnvironment(); - env.addRequestExpectation(API_LIST_ORDERS, { - qparam: { delta: 0, paid: "yes" }, - response: { - 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: [{ + order_id: "1", + amount: "EUR:12", + refundable: true, + } as MerchantBackend.Orders.OrderHistoryEntry] }, }); const newDate = (d: Date) => { @@ -181,18 +158,11 @@ 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: false } as any, - ], - }, - }); - env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: -20, paid: "yes" }, - response: { orders: [] }, + response: { orders: [ + { order_id: "1", amount: "EUR:12", refundable: false } as any, + ] }, }); api.refundOrder("1", { @@ -229,17 +199,10 @@ describe("order api interaction with listing", () => { it("should evict cache when deleting an order", async () => { const env = new ApiMockEnvironment(); - env.addRequestExpectation(API_LIST_ORDERS, { - qparam: { delta: 0, paid: "yes" }, - response: { - orders: [{ order_id: "1" } as MerchantBackend.Orders.OrderHistoryEntry], - }, - }); - env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: -20, paid: "yes" }, response: { - orders: [{ order_id: "2" } as MerchantBackend.Orders.OrderHistoryEntry], + orders: [{ order_id: "1" }, { order_id: "2" } as MerchantBackend.Orders.OrderHistoryEntry], }, }); @@ -271,13 +234,6 @@ describe("order api interaction with listing", () => { env.addRequestExpectation(API_DELETE_ORDER("1"), {}); - env.addRequestExpectation(API_LIST_ORDERS, { - qparam: { delta: 0, paid: "yes" }, - response: { - orders: [], - }, - }); - env.addRequestExpectation(API_LIST_ORDERS, { qparam: { delta: -20, paid: "yes" }, response: { @@ -459,14 +415,14 @@ describe("order listing pagination", () => { it("should not load more if has reach the end", async () => { const env = new ApiMockEnvironment(); env.addRequestExpectation(API_LIST_ORDERS, { - qparam: { delta: 20, wired: "yes", date_ms: 12 }, + qparam: { delta: 20, wired: "yes", date_s: 12 }, response: { orders: [{ order_id: "1" } as any], }, }); env.addRequestExpectation(API_LIST_ORDERS, { - qparam: { delta: -20, wired: "yes", date_ms: 13 }, + qparam: { delta: -20, wired: "yes", date_s: 13 }, response: { orders: [{ order_id: "2" } as any], }, @@ -478,7 +434,7 @@ describe("order listing pagination", () => { const hookBehavior = await tests.hookBehaveLikeThis( () => { - const date = new Date(12); + const date = new Date(12000); const query = useInstanceOrders({ wired: "yes", date }, newDate); const api = useOrderAPI(); return { query, api }; @@ -525,14 +481,14 @@ describe("order listing pagination", () => { const ordersFrom20to0 = [...ordersFrom0to20].reverse(); env.addRequestExpectation(API_LIST_ORDERS, { - qparam: { delta: 20, wired: "yes", date_ms: 12 }, + qparam: { delta: 20, wired: "yes", date_s: 12 }, response: { orders: ordersFrom0to20, }, }); env.addRequestExpectation(API_LIST_ORDERS, { - qparam: { delta: -20, wired: "yes", date_ms: 13 }, + qparam: { delta: -20, wired: "yes", date_s: 13 }, response: { orders: ordersFrom20to40, }, @@ -544,7 +500,7 @@ describe("order listing pagination", () => { const hookBehavior = await tests.hookBehaveLikeThis( () => { - const date = new Date(12); + const date = new Date(12000); const query = useInstanceOrders({ wired: "yes", date }, newDate); const api = useOrderAPI(); return { query, api }; @@ -568,7 +524,7 @@ describe("order listing pagination", () => { expect(query.isReachingStart).false; env.addRequestExpectation(API_LIST_ORDERS, { - qparam: { delta: -40, wired: "yes", date_ms: 13 }, + qparam: { delta: -40, wired: "yes", date_s: 13 }, response: { orders: [...ordersFrom20to40, { order_id: "41" }], }, @@ -595,7 +551,7 @@ describe("order listing pagination", () => { }); env.addRequestExpectation(API_LIST_ORDERS, { - qparam: { delta: 40, wired: "yes", date_ms: 12 }, + qparam: { delta: 40, wired: "yes", date_s: 12 }, response: { orders: [...ordersFrom0to20, { order_id: "-1" }], }, diff --git a/packages/merchant-backoffice-ui/src/hooks/transfer.test.ts b/packages/merchant-backoffice-ui/src/hooks/transfer.test.ts index 10cb4226b..a7187af27 100644 --- a/packages/merchant-backoffice-ui/src/hooks/transfer.test.ts +++ b/packages/merchant-backoffice-ui/src/hooks/transfer.test.ts @@ -30,19 +30,10 @@ describe("transfer api interaction with listing", () => { it("should evict cache when informing a transfer", async () => { const env = new ApiMockEnvironment(); - env.addRequestExpectation(API_LIST_TRANSFERS, { - qparam: { limit: 0 }, - response: { - transfers: [{ wtid: "2" } as MerchantBackend.Transfers.TransferDetails], - }, - }); - // FIXME: is this query really needed? if the hook is rendered without - // position argument then then backend is returning the newest and no need - // to this second query env.addRequestExpectation(API_LIST_TRANSFERS, { qparam: { limit: -20 }, response: { - transfers: [], + transfers: [{ wtid: "2" } as MerchantBackend.Transfers.TransferDetails], }, }); @@ -83,17 +74,10 @@ describe("transfer api interaction with listing", () => { response: { total: "" } as any, }); - env.addRequestExpectation(API_LIST_TRANSFERS, { - qparam: { limit: 0 }, - response: { - transfers: [{ wtid: "2" } as any, { wtid: "3" } as any], - }, - }); - env.addRequestExpectation(API_LIST_TRANSFERS, { qparam: { limit: -20 }, response: { - transfers: [], + transfers: [{ wtid: "3" } as any, { wtid: "2" } as any], }, }); @@ -129,17 +113,10 @@ describe("transfer listing pagination", () => { it("should not load more if has reach the end", async () => { const env = new ApiMockEnvironment(); - env.addRequestExpectation(API_LIST_TRANSFERS, { - qparam: { limit: 0, payto_uri: "payto://" }, - response: { - transfers: [{ wtid: "2" } as any], - }, - }); - env.addRequestExpectation(API_LIST_TRANSFERS, { qparam: { limit: -20, payto_uri: "payto://" }, response: { - transfers: [{ wtid: "1" } as any], + transfers: [{ wtid: "2" }, { wtid: "1" } as any], }, }); diff --git a/packages/merchant-backoffice-ui/src/hooks/urls.ts b/packages/merchant-backoffice-ui/src/hooks/urls.ts index 00c5e95af..b6485259f 100644 --- a/packages/merchant-backoffice-ui/src/hooks/urls.ts +++ b/packages/merchant-backoffice-ui/src/hooks/urls.ts @@ -249,6 +249,18 @@ export const API_DELETE_INSTANCE = (id: string): Query => ({ url: `http://backend/management/instances/${id}`, }); +//////////////////// +// AUTH +//////////////////// + +export const API_NEW_LOGIN: Query< + MerchantBackend.Instances.LoginTokenRequest, + unknown +> = ({ + method: "POST", + url: `http://backend/private/token`, +}); + //////////////////// // INSTANCE //////////////////// -- cgit v1.2.3