Skip to content

Commit

Permalink
test: return err on ordering wrong card
Browse files Browse the repository at this point in the history
  • Loading branch information
EresDev committed Nov 3, 2024
1 parent 3f21a7e commit 4ebf5d2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/fixtures/http-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import bestCardSandbox from "./get-best-card/best-card-sandbox.json";
import bestMastercardProd from "./get-best-card/best-master-card-prod.json";
import bestVisaProd from "./get-best-card/best-visa-card-prod.json";
import card18597 from "./get-best-card/card-18597.json";
import card18732 from "./post-order/card-18732.json";
import card18598 from "./get-best-card/card-18598.json";
import noCardMt from "./get-best-card/no-card-mt.json";
import transaction from "./get-order/transaction.json";
Expand Down Expand Up @@ -83,6 +84,10 @@ export const httpMocks = [
return HttpResponse.json(bestCardSandbox, { status: 200 });
}),

http.get(`${RELOADLY_PRODUCTION_API_URL}/products/18732`, () => {
return HttpResponse.json(card18732, { status: 200 });
}),

http.get(`${RELOADLY_SANDBOX_API_URL}/products/13959`, () => {
return HttpResponse.json(bestCardSandbox, { status: 200 });
}),
Expand Down
38 changes: 38 additions & 0 deletions tests/fixtures/post-order/card-18732.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"productId": 18732,
"productName": "Mastercard Prepaid USD Debit (Virtual only) US",
"global": false,
"supportsPreOrder": false,
"senderFee": 1.0,
"senderFeePercentage": 1.0,
"discountPercentage": 0.0,
"denominationType": "RANGE",
"recipientCurrencyCode": "USD",
"minRecipientDenomination": 5.0,
"maxRecipientDenomination": 1000.0,
"senderCurrencyCode": "USD",
"minSenderDenomination": 5.0,
"maxSenderDenomination": 1000.0,
"fixedRecipientDenominations": [],
"fixedSenderDenominations": null,
"fixedRecipientToSenderDenominationsMap": null,
"metadata": null,
"logoUrls": ["https://cdn.reloadly.com/giftcards/1e703d6a-b8a5-4b88-8f11-62cb3e4a5c0d.png"],
"brand": {
"brandId": 378,
"brandName": "Mastercard"
},
"category": {
"id": 1,
"name": "Payment Cards"
},
"country": {
"isoName": "US",
"name": "United States",
"flagUrl": "https://s3.amazonaws.com/rld-flags/us.svg"
},
"redeemInstruction": {
"concise": "Your Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD",
"verbose": "Redeem Instruction:\nYour Virtual Promotional Prepaid Mastercard can be used online, for phone/mail orders, or in stores that accept mobile wallet where Debit Mastercard is accepted. This card must be used within 6 months from the time you receive your link. Visit MyPrepaidCenter.com for card usage details.\n2% currency conversion fee will apply if the merchant settles in a currency other than USD\n\nTerms and condition:\nVirtual card is issued by Pathward®, N.A., Member FDIC, pursuant to license by Mastercard International Incorporated. Mastercard and the circles design are registered trademarks of Mastercard International Incorporated. No cash access or recurring payments. Can be used where Debit Mastercard is accepted online, for phone/mail orders, or in stores that accept mobile wallet. Valid for up to 6 months; unused funds will forfeit after the valid thru date. Terms and conditions apply. See Cardholder Agreement for details <a href=\"https://www.myprepaidcenter.com/page/mastercard-promo-virtual\" target=\"_blank\" rel=\"noopener\">https://www.myprepaidcenter.com/page/mastercard-promo-virtual\n\nMastercard is widely accepted globally*, with the exception of certain countries where credit cards are blocked due to economic sanctions or other regulatory restrictions. Specifically, this includes:\nChina, The Democratic People's Republic of Korea (North Korea), The Islamic Republic of Iran, The Syrian Arab Republic, Ukraine, The Bahamas, Barbados, Benin, Burundi, Burkina Faso, Cambodia, The Cayman Islands, Chad, The Central African Republic, Congo, Comoros, Dominican Republic, Cuba, Guinea, Eritrea, Guinea-Bissau, Haiti, Iraq, Lebanon, Laos, Lesotho, Myanmar, Madagascar, Nicaragua, Panama, Somalia, Sudan, South Sudan, Uganda, Venezuela , Yemen, Zimbabwe, Liberia\n\nHow to use:\nGo to =\"http://www.MyPrepaidCenter.com/redeem\">MyPrepaidCenter.com/redeem and enter code\nComplete the online registration page and accept the cardholder agreement and e-sign agreement, then you will be able to view your 16-digit card number, expiration date, security information, where your card can be used, available balance, transaction history, etc.\nPlastic card available upon request. Requesting a plastic card will reduce the card’s value by $3.00 for manufacturing and fulfillment cost, and can take 7-14 business days. \nRecipient can request a plastic card once they have completed the card registration and activation at <a href=\"http://www.MyPrepaidCenter.com\">MyPrepaidCenter.com"
}
}
19 changes: 19 additions & 0 deletions tests/unit/post-order.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ describe("Post order for a payment card", () => {
expect(await response.json()).toEqual(orderCard18597);
});

it("should return err for ordering card that is not best suited", async () => {
const request = new Request(`${TESTS_BASE_URL}/post-order`, {
method: "POST",
body: JSON.stringify({
type: "permit",
chainId: 31337,
txHash: "0xac3485ce523faa13970412a89ef42d10939b44abd33cbcff1ed84cb566a3a3d5",
productId: 18732,
country: "US",
}),
}) as Request<unknown, IncomingRequestCfProperties<unknown>>;

const eventCtx = createEventContext(request, execContext);
const response = await pagesFunction(eventCtx);
await waitOnExecutionContext(execContext);
expect(response.status).toBe(500);
expect(await response.json()).toEqual({ message: "There was an error while processing your request." });
});

it("should post order on sandbox", async () => {
const request = new Request(`${TESTS_BASE_URL}/post-order`, {
method: "POST",
Expand Down

0 comments on commit 4ebf5d2

Please sign in to comment.