//@ts-nocheck import { testFetch } from "../../utils"; import representativesFunctions from "./index"; import Chance from "chance"; import { MISSING_ACCOUNT_ID_ERROR_MESSAGE, MISSING_REPRESENTATIVE_ID_ERROR, MISSING_REPRESENTATIVE_ERROR, MISSING_REPRESENTATIVE_NAME_ERROR, } from "../../constants"; import bankAccounts from "../bank-accounts"; const representatives = representativesFunctions(testFetch); const chance = new Chance(); describe("Account representatives", () => { let accountID, representativeID, representative; beforeEach(() => { accountID = chance.guid(); representativeID = chance.guid(); representative = { accountID, representativeID, name: { firstName: chance.name(), lastName: chance.last(), suffix: chance.string(), }, phone: { number: chance.phone(), countryCode: chance.string(), }, email: chance.email(), }; }); describe("get account representative", () => { it("should return an error if there is no accountID", async () => { const resp = await representatives.get({ representativeID }).catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ID_ERROR_MESSAGE); }); it("should return an error if there is no representativeID", async () => { const resp = await representatives.get({ accountID }).catch((err) => err); expect(resp.error).toEqual(MISSING_REPRESENTATIVE_ID_ERROR); }); it("should succeed if there is an accountID and a representativeID", async () => { const resp = await representatives.get({ accountID, representativeID }); expect(resp.url).toEqual(`/accounts/${accountID}/representatives/${representativeID}`); expect(resp.opts.method).toEqual("GET"); }); }); describe("list account representatives", () => { it("should return an error if there is no accountID", async () => { const resp = await representatives.list({ representativeID }).catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ID_ERROR_MESSAGE); }); it("should succeed if there is an accountID", async () => { const resp = await representatives.list({ accountID }); expect(resp.url).toEqual(`/accounts/${accountID}/representatives`); expect(resp.opts.method).toEqual("GET"); }); }); describe("create account representatives", () => { it("should return an error if there is no accountID", async () => { const resp = await representatives.create({ representativeID }).catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ID_ERROR_MESSAGE); }); it("should return an error if there is no representative", async () => { const resp = await representatives.create({ accountID }).catch((err) => err); expect(resp.error).toEqual(MISSING_REPRESENTATIVE_ERROR); }); it("should return an error if there is not a first or last name", async () => { const badRepresentative = { ...chance.string(), representativeID, name: { ...chance.string(), suffix: chance.string(), }, }; const resp = await representatives .create({ accountID, representative: badRepresentative }) .catch((err) => err); expect(resp.error).toEqual(MISSING_REPRESENTATIVE_NAME_ERROR); }); it("should succeed if there is an accountID, and a representative", async () => { const resp = await representatives.create({ accountID, representative }); expect(resp.url).toEqual(`/accounts/${accountID}/representatives`); expect(resp.opts.method).toEqual("POST"); expect(resp.opts.body).toEqual(representative); }); }); describe("update account representative", () => { it("should return an error if there is no accountID", async () => { const resp = await representatives.update({ representativeID }).catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ID_ERROR_MESSAGE); }); it("should return an error if there is no representative", async () => { const resp = await representatives.update({ accountID }).catch((err) => err); expect(resp.error).toEqual(MISSING_REPRESENTATIVE_ERROR); }); it("should return an error if there is no representativeID", async () => { const badRepresentative = { firstName: chance.string(), lastName: chance.string(), }; const resp = await representatives .update({ accountID, representative: badRepresentative }) .catch((err) => err); expect(resp.error).toEqual(MISSING_REPRESENTATIVE_ID_ERROR); }); it("should return an error if there is not a first or last name", async () => { const badRepresentative = { ...chance.string(), representativeID, name: { ...chance.string(), suffix: chance.string(), }, }; const resp = await representatives .update({ accountID, representative: badRepresentative }) .catch((err) => err); expect(resp.error).toEqual(MISSING_REPRESENTATIVE_NAME_ERROR); }); it("should succeed if there is an accountID, and a representative", async () => { const resp = await representatives.update({ accountID, representative }); expect(resp.url).toEqual( `/accounts/${accountID}/representatives/${representative.representativeID}` ); expect(resp.opts.method).toEqual("PUT"); expect(resp.opts.body).toEqual(representative); }); }); describe("delete account representative", () => { it("should return an error if there is no accountID", async () => { const resp = await representatives.delete({ representativeID }).catch((err) => err); expect(resp.error).toEqual(MISSING_ACCOUNT_ID_ERROR_MESSAGE); }); it("should return an error if there is no representativeID", async () => { const resp = await representatives.delete({ accountID }).catch((err) => err); expect(resp.error).toEqual(MISSING_REPRESENTATIVE_ID_ERROR); }); it("should succeed if there is an accountID, and a representativeID", async () => { const resp = await representatives.delete({ accountID, representativeID }); expect(resp.url).toEqual(`/accounts/${accountID}/representatives/${representativeID}`); expect(resp.opts.method).toEqual("DELETE"); }); }); });