Skip to content

Commit

Permalink
chore: list gift cards test
Browse files Browse the repository at this point in the history
  • Loading branch information
pbkompasz committed Aug 27, 2024
1 parent 1538755 commit 7b35557
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions functions/list-gift-cards.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { waitOnExecutionContext, env } from "cloudflare:test";
import { describe, it, expect } from "vitest";
import Chance from "chance";
import { onRequest, getGiftCards } from "./list-gift-cards";
import { createContext, DEFAULT_BASE_URL } from "./vitest-helpers";
import { getAccessToken } from "./helpers";

describe("List Gift Cards", () => {
it("get supported gift cards for US", async () => {
const { ctx, eventCtx } = createContext(DEFAULT_BASE_URL, { country: "US" });

const response = await onRequest(eventCtx);
await waitOnExecutionContext(ctx);

expect(response.status).toBe(200);
});

it("get supported gift cards for any country", async () => {
const chance = new Chance();
const country = chance.country();
const { ctx, eventCtx } = createContext(DEFAULT_BASE_URL, { country });

const response = await onRequest(eventCtx);
await waitOnExecutionContext(ctx);

expect(response.status, `No cards found for ${country}`).toBe(200);
});
});

describe("Post order helpers", () => {
it("VISA gift cards from random country", async () => {
const accessToken = await getAccessToken(env);
const chance = new Chance();
const country = chance.country();
const productQuery = "visa";
const cards = await getGiftCards(productQuery, country, accessToken);
expect(cards.length, `No ${productQuery} cards for ${country} country`).toBeGreaterThan(0);
});

it("MasterCard gift cards from random country", async () => {
const accessToken = await getAccessToken(env);
const chance = new Chance();
const country = chance.country();
const productQuery = "mastercard";
const cards = await getGiftCards(productQuery, country, accessToken);
expect(cards.length, `No ${productQuery} cards for ${country} country`).toBeGreaterThan(0);
});

it("any gift cards from random country", async () => {
const accessToken = await getAccessToken(env);
const chance = new Chance();
const country = chance.country();
const productQuery = "";
const cards = await getGiftCards(productQuery, country, accessToken);
expect(cards.length, `No cards for ${country} country`).toBeGreaterThan(0);
});

it("visa gift cards from US", async () => {
const accessToken = await getAccessToken(env);
const country = "US";
const productQuery = "visa";
const cards = await getGiftCards(productQuery, country, accessToken);
console.log(cards);
expect(cards.length, `No cards for ${country} country`).toBeGreaterThan(0);
});
});

0 comments on commit 7b35557

Please sign in to comment.