/** @jest-environment jsdom */ // @ts-nocheck import { testFetch } from "../utils"; import accountsFuctions from "./index"; import Chance from "chance"; import { MISSING_ACCOUNT_OR_FOREIGN_ID_ERROR_MESSAGE, MISSING_ACCOUNT_ERROR_MESSAGE, MISSING_ACCOUNT_ID_ERROR_MESSAGE, } from "../constants"; const accounts = accountsFuctions(testFetch); const chance = new Chance(); describe("Get account", () => { let accountID; beforeEach(() => { accountID = chance.guid(); }); it("should fail if no accountID or foreignID passed", async () => { const resp = await accounts.get({ key: "value" }).catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_OR_FOREIGN_ID_ERROR_MESSAGE); }); it("should handle accountID", async () => { const resp = await accounts.get({ accountID }); expect(resp.url).toEqual(`/accounts/${accountID}`); }); it("should handle foreignID", async () => { const resp = await accounts.get({ foreignID: accountID }); expect(resp.url).toEqual(`/accounts?foreignID=${accountID}`); }); }); describe("Create account", () => { it("should error if no account", async () => { const resp = await accounts.create().catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ERROR_MESSAGE); }); it("should succeed", async () => { const resp = await accounts.create({ firstName: "Jane", lastName: "doe" }); expect(resp.url).toEqual("/accounts"); expect(resp.opts.method).toEqual("POST"); }); }); describe("Update account", () => { it("should error if no account", async () => { const resp = await accounts.update().catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ERROR_MESSAGE); }); it("should error if no accountID", async () => { const resp = await accounts.update({ firstName: "steve" }).catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ID_ERROR_MESSAGE); }); it("should succeed", async () => { const resp = await accounts.update({ accountID: "87g8yy", firstName: "Jane", lastName: "doe" }); expect(resp.url).toEqual("/accounts/87g8yy"); expect(resp.opts.method).toEqual("PUT"); }); }); describe("Patch account", () => { it("should error if no account", async () => { const resp = await accounts.patch().catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ERROR_MESSAGE); }); it("should error if no accountID", async () => { const resp = await accounts.patch({ firstName: "steve" }).catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ID_ERROR_MESSAGE); }); it("should succeed", async () => { const resp = await accounts.patch({ accountID: "87g8yy", firstName: "Jane", lastName: "doe" }); expect(resp.url).toEqual("/accounts/87g8yy"); expect(resp.opts.method).toEqual("PATCH"); }); }); describe("Get TOS Token", () => { it("should succeed", async () => { const resp = await accounts.getTermsOfServiceToken(); expect(resp.url).toEqual("/tos-token"); }); }); describe("Accept Terms of Service", () => { let accountID; beforeEach(() => { accountID = chance.guid(); }); it("should error if no accountID", async () => { const resp = await accounts.acceptTermsOfService({}).catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ID_ERROR_MESSAGE); }); it("should succeed", async () => { const resp = await accounts.acceptTermsOfService({ accountID }); expect(resp.url).toEqual(`/accounts/${accountID}`); expect(resp.opts.method).toEqual("PATCH"); }); });