// @ts-nocheck import fedFunctions, { handleRoutingNumberLookupResponse, unsuccessfulResult } from "./index"; const fed = fedFunctions(fakeFetch); function fakeFetch(url: string, opts: any) { return Promise.resolve({ achParticipants: ["resp"], }); } describe("Response handler", () => { test("it should return unsuccessful if there are no results, regardless of exact match", () => { const fakeApiResponse = { achParticipants: [] }; expect(handleRoutingNumberLookupResponse(fakeApiResponse, false)).toEqual(unsuccessfulResult); expect(handleRoutingNumberLookupResponse(fakeApiResponse, true)).toEqual(unsuccessfulResult); }); test("it should return unsuccessful if exact match flag is set and there are multiple responses", () => { const fakeApiResponse = { achParticipants: [1, 2] }; expect(handleRoutingNumberLookupResponse(fakeApiResponse, true)).toEqual(unsuccessfulResult); }); test("it should succeed if single participant", () => { const fakeApiResponse = { achParticipants: [1] }; expect(handleRoutingNumberLookupResponse(fakeApiResponse, true)).toEqual({ success: true, result: 1, }); }) test("it should succeed if multiple participants and not exact", () => { const fakeApiResponse = { achParticipants: [1, 2] }; expect(handleRoutingNumberLookupResponse(fakeApiResponse, false)).toEqual({ success: true, result: [1, 2], }); }); }); describe("Lookup by routing number", () => { it("should fail if routing number is not 9 digits", async () => { const resp = await fed.lookupByRoutingNumber("676876", true).catch(err => err); expect(resp.error).toEqual("Routing number must be 9 digits"); }); it("should succeed", async () => { const resp = await fed.lookupByRoutingNumber("887676976", true); expect(resp.success).toEqual(true); }); });