diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks/reserve.test.ts')
-rw-r--r-- | packages/merchant-backoffice-ui/src/hooks/reserve.test.ts | 109 |
1 files changed, 63 insertions, 46 deletions
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" }); - }); }); |