//@ts-nocheck import { testFetch } from "../../utils"; import cardFunctions from "./index"; import Chance from "chance"; import { MISSING_ACCOUNT_ID_ERROR_MESSAGE, MISSING_CARD_ID_ERROR_MESSAGE } from "../../constants"; const cards = cardFunctions(testFetch); const chance = new Chance(); describe("cards", () => { let accountID, cardID, badData; beforeEach(() => { accountID = chance.guid(); cardID = chance.guid(); badData = chance.string(); }); describe("list", () => { it("should return an error if there is no accountID", async () => { const resp = await cards.list({ badData }).catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ID_ERROR_MESSAGE); }); it("should succeed if there is an accountID", async () => { const resp = await cards.list({ accountID }); expect(resp.url).toEqual(`/accounts/${accountID}/cards`); }); }); describe("get", () => { it("should return an error if there is no accountID", async () => { const resp = await cards.get({ cardID }).catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ID_ERROR_MESSAGE); }); it("should error if no cardID", async () => { const resp = await cards.get({ accountID }).catch((err) => err); expect(resp.error).toEqual(MISSING_CARD_ID_ERROR_MESSAGE); }); it("should succeed if there is an accountID and cardID", async () => { const resp = await cards.get({ accountID, cardID }); expect(resp.url).toEqual(`/accounts/${accountID}/cards/${cardID}`); expect(resp.opts.method).toEqual("GET"); }); }); describe("disable", () => { it("should return an error if there is no accountID", async () => { const resp = await cards.disable({ cardID }).catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ID_ERROR_MESSAGE); }); it("should error if no cardID", async () => { const resp = await cards.disable({ accountID }).catch((err) => err); expect(resp.error).toEqual(MISSING_CARD_ID_ERROR_MESSAGE); }); it("should succeed if there is an accountID and cardID", async () => { const resp = await cards.disable({ accountID, cardID }); expect(resp.url).toEqual(`/accounts/${accountID}/cards/${cardID}`); expect(resp.opts.method).toEqual("DELETE"); }); }); });