From 3f21a7e3081971dcdeacba4820c0f2904658f493 Mon Sep 17 00:00:00 2001 From: EresDev Date: Sun, 3 Nov 2024 11:10:36 -0500 Subject: [PATCH] test: post payment card order on production --- tests/fixtures/http-mocks.ts | 11 +++--- .../{order.json => order-card-13959.json} | 0 .../fixtures/post-order/order-card-18597.json | 36 +++++++++++++++++++ tests/unit/post-order.test.ts | 30 ++++++++++++---- 4 files changed, 66 insertions(+), 11 deletions(-) rename tests/fixtures/post-order/{order.json => order-card-13959.json} (100%) create mode 100644 tests/fixtures/post-order/order-card-18597.json diff --git a/tests/fixtures/http-mocks.ts b/tests/fixtures/http-mocks.ts index acb28ac5..67fc55b9 100644 --- a/tests/fixtures/http-mocks.ts +++ b/tests/fixtures/http-mocks.ts @@ -10,7 +10,8 @@ import transaction from "./get-order/transaction.json"; import noTransaction from "./get-order/no-transaction.json"; import transaction0x33f4 from "./get-redeem-code/transaction-0x33f4.json"; import card from "./get-redeem-code/card.json"; -import order from "./post-order/order.json"; +import orderCard13959 from "./post-order/order-card-13959.json"; +import orderCard18597 from "./post-order/order-card-18597.json"; import { RELOADLY_AUTH_URL, RELOADLY_PRODUCTION_API_URL, RELOADLY_SANDBOX_API_URL } from "../../functions/utils/helpers"; /** @@ -42,10 +43,10 @@ export const httpMocks = [ const productName = url.searchParams.get("productName"); if (productName == "mastercard") { - return HttpResponse.json([bestMastercardProd], { status: 200 }); + return HttpResponse.json(bestMastercardProd, { status: 200 }); } if (productName == "visa") { - return HttpResponse.json([bestVisaProd], { status: 200 }); + return HttpResponse.json(bestVisaProd, { status: 200 }); } return HttpResponse.json([], { status: 200 }); }), @@ -72,10 +73,10 @@ export const httpMocks = [ }), http.post(`${RELOADLY_PRODUCTION_API_URL}/orders`, () => { - return HttpResponse.json(order, { status: 200 }); + return HttpResponse.json(orderCard18597, { status: 200 }); }), http.post(`${RELOADLY_SANDBOX_API_URL}/orders`, () => { - return HttpResponse.json(order, { status: 200 }); + return HttpResponse.json(orderCard13959, { status: 200 }); }), http.get(`${RELOADLY_PRODUCTION_API_URL}/products/13959`, () => { diff --git a/tests/fixtures/post-order/order.json b/tests/fixtures/post-order/order-card-13959.json similarity index 100% rename from tests/fixtures/post-order/order.json rename to tests/fixtures/post-order/order-card-13959.json diff --git a/tests/fixtures/post-order/order-card-18597.json b/tests/fixtures/post-order/order-card-18597.json new file mode 100644 index 00000000..1bf4457a --- /dev/null +++ b/tests/fixtures/post-order/order-card-18597.json @@ -0,0 +1,36 @@ +{ + "transactionId": 39018, + "amount": 50, + "discount": 0, + "currencyCode": "USD", + "fee": 6, + "smsFee": 0, + "totalFee": 6, + "preOrdered": false, + "recipientEmail": null, + "recipientPhone": null, + "customIdentifier": "0xd670e1f4f47a0104217f30a8804f7e13803da1dbfd9270dcb6d8d3a5ba72a52e", + "status": "SUCCESSFUL", + "transactionCreatedTime": "2024-11-03 03:25:42", + "product": { + "productId": 18597, + "productName": "Virtual MasterCard International USD US", + "countryCode": "US", + "quantity": 1, + "unitPrice": 44, + "totalPrice": 44, + "currencyCode": "USD", + "brand": { + "brandId": 378, + "brandName": "Mastercard" + } + }, + "balanceInfo": { + "oldBalance": 212439823.44865, + "newBalance": 212439773.44865, + "cost": 50, + "currencyCode": "USD", + "currencyName": "US Dollar", + "updatedAt": "2024-11-02 13:46:17" + } +} diff --git a/tests/unit/post-order.test.ts b/tests/unit/post-order.test.ts index 0302c068..5d2cdddf 100644 --- a/tests/unit/post-order.test.ts +++ b/tests/unit/post-order.test.ts @@ -4,7 +4,8 @@ import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest import { onRequest as pagesFunction } from "../../functions/post-order"; import { httpMocks } from "../fixtures/http-mocks"; import minedTx from "../fixtures/post-order/mined-tx.json"; -import order from "../fixtures/post-order/order.json"; +import orderCard13959 from "../fixtures/post-order/order-card-13959.json"; +import orderCard18597 from "../fixtures/post-order/order-card-18597.json"; import receipt from "../fixtures/post-order/receipt.json"; import { getEventContext as createEventContext, TESTS_BASE_URL } from "./helpers"; @@ -31,7 +32,26 @@ describe("Post order for a payment card", () => { server.close(); }); - it.only("should post order on sandbox", async () => { + it("should post order on production", async () => { + const request = new Request(`${TESTS_BASE_URL}/post-order`, { + method: "POST", + body: JSON.stringify({ + type: "permit", + chainId: 31337, + txHash: "0xac3485ce523faa13970412a89ef42d10939b44abd33cbcff1ed84cb566a3a3d5", + productId: 18597, + country: "US", + }), + }) as Request>; + + const eventCtx = createEventContext(request, execContext); + const response = await pagesFunction(eventCtx); + await waitOnExecutionContext(execContext); + expect(response.status).toBe(200); + expect(await response.json()).toEqual(orderCard18597); + }); + + it("should post order on sandbox", async () => { const request = new Request(`${TESTS_BASE_URL}/post-order`, { method: "POST", body: JSON.stringify({ @@ -47,18 +67,16 @@ describe("Post order for a payment card", () => { const response = await pagesFunction(eventCtx); await waitOnExecutionContext(execContext); expect(response.status).toBe(200); - expect(await response.json()).toEqual(order); + expect(await response.json()).toEqual(orderCard13959); }); }); async function initMocks() { - vi.mock("../../shared/helpers"); const helpers = await import("../../shared/helpers"); - helpers.getFastestRpcUrl = vi.fn().mockImplementation(() => { + vi.spyOn(helpers, "getFastestRpcUrl").mockImplementation(async () => { return "http://127.0.0.1:8545"; }); - vi.mock("@ethersproject/providers"); const providers = await import("@ethersproject/providers"); providers.JsonRpcProvider.prototype.getTransactionReceipt = vi.fn().mockImplementation(async () => { return receipt;