Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions __tests__/BankAccountModels.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
BankAccountDeletion,
BankAccountDeletionObjectEnum,
BankAccountList,
BankAccountMicrodepositTypeEnum,
BankAccountVerify,
BankAccountWritable,
BankTypeEnum,
Expand Down Expand Up @@ -34,6 +35,9 @@ describe("Bank Account Models", () => {
["deleted", false],
["deleted", true],
["object", "Bank"],
["microdeposit_type", BankAccountMicrodepositTypeEnum.Amounts],
["microdeposit_type", BankAccountMicrodepositTypeEnum.DescriptorCode],
["microdeposit_type", null],
])("can be created with a provided %s value", (prop, val) => {
const input = {};
(input as any)[prop] = val;
Expand Down Expand Up @@ -209,18 +213,47 @@ describe("Bank Account Models", () => {
expect(rec).toBeDefined();
});

it.each([["amounts", [1, 2]]])(
"can be created with a provided %s value",
(prop, val) => {
const input = {};
(input as any)[prop] = val;
it.each([
["amounts", [1, 2]],
["descriptor_code", "SM11AA"],
])("can be created with a provided %s value", (prop, val) => {
const input = {};
(input as any)[prop] = val;

const rec = new BankAccountVerify(input);

const rec = new BankAccountVerify(input);
expect(rec).toBeDefined();
expect((rec as any)[prop]).toEqual(val);
});

it("rejects invalid descriptor_code values", () => {
const rec = new BankAccountVerify();
const invalidValues = ["INVALID", "SM", "sm11aa", "SM11AAB", "SM1"];
for (const val of invalidValues) {
try {
rec.descriptor_code = val;
throw new Error("Should Throw");
} catch (err: any) {
expect(err.message).toEqual("Invalid descriptor_code provided");
}
}
});

expect(rec).toBeDefined();
expect((rec as any)[prop]).toEqual(val);
it("allows valid descriptor_code values", () => {
const rec = new BankAccountVerify();
const validValues = ["SM11AA", "SM1234", "SMABcd"];
for (const val of validValues) {
rec.descriptor_code = val;
expect(rec.descriptor_code).toEqual(val);
}
);
});

it("allows unsetting descriptor_code to undefined", () => {
const rec = new BankAccountVerify({ descriptor_code: "SM11AA" });
expect(rec.descriptor_code).toEqual("SM11AA");
rec.descriptor_code = undefined;
expect(rec.descriptor_code).toBeUndefined();
});
});

describe("BankAccountWritable", () => {
Expand Down
42 changes: 41 additions & 1 deletion __tests__/BankAccountsApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { BankAccountsApi } from "../api/bank-accounts-api";
import { CONFIG_FOR_INTEGRATION } from "./testFixtures";

describe("BankAccountsApi", () => {
jest.setTimeout(1000 * 60);

const dummyAccount = new BankAccountWritable({
description: "Test Bank Account",
routing_number: "322271627",
Expand Down Expand Up @@ -60,6 +62,44 @@ describe("BankAccountsApi", () => {
});
});

describe("descriptor_code verification path", () => {
let createdBankAccountId: string;

it("creates a bank account and exposes microdeposit_type", async () => {
const account = await new BankAccountsApi(CONFIG_FOR_INTEGRATION).create(
dummyAccount
);
expect(account.id).toBeDefined();
createdBankAccountId = account.id;

const retrieved = await new BankAccountsApi(CONFIG_FOR_INTEGRATION).get(
createdBankAccountId
);
expect(["amounts", "descriptor_code"]).toContain(
retrieved.microdeposit_type
);
});

it("verifies a bank account with descriptor_code", async () => {
const verify = new BankAccountVerify({
descriptor_code: "SM11AA",
});

const verification = await new BankAccountsApi(
CONFIG_FOR_INTEGRATION
).verify(createdBankAccountId, verify);
expect(verification).toBeDefined();
expect(verification.id).toEqual(createdBankAccountId);
});

it("cleans up the bank account", async () => {
const deleted = await new BankAccountsApi(CONFIG_FOR_INTEGRATION).delete(
createdBankAccountId
);
expect(deleted.deleted).toBeTruthy();
});
});

describe("list Cards", () => {
let nextUrl = "";
let previousUrl = "";
Expand Down Expand Up @@ -150,7 +190,7 @@ describe("BankAccountsApi", () => {
previousUrl = prevUrl.searchParams.get("before") || "";
}
}
}, 10000); // Timeout for concurrent API operations (reduced since Promise.all runs operations in parallel)
});

afterAll(async () => {
const bankAccountApi = new BankAccountsApi(CONFIG_FOR_INTEGRATION);
Expand Down
27 changes: 27 additions & 0 deletions __tests__/BankAccountsApi.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,33 @@ describe("BankAccountsApi", () => {
expect(err.message).toEqual("Unknown Error");
}
});

it("verifies a bank account with descriptor_code", async () => {
axiosRequest.mockImplementationOnce(async () => ({
data: { id: "bank_fakeId" },
}));

const verify = new BankAccountVerify({
descriptor_code: "SM11AA",
});
const bankAccount = await new BankAccountsApi(CONFIG_FOR_UNIT).verify(
"an id",
verify
);
expect(bankAccount).toBeDefined();
expect(bankAccount.id).toEqual("bank_fakeId");
});

it("returns microdeposit_type on a retrieved bank account", async () => {
axiosRequest.mockImplementationOnce(async () => ({
data: { id: "bank_fakeId", microdeposit_type: "amounts" },
}));

const bankAccount = await new BankAccountsApi(CONFIG_FOR_UNIT).get(
"bank_fakeId"
);
expect(bankAccount.microdeposit_type).toEqual("amounts");
});
});

describe("list", () => {
Expand Down
50 changes: 39 additions & 11 deletions __tests__/CampaignsApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@ import {
import { CampaignsApi } from "../api/campaigns-api";
import { CONFIG_FOR_INTEGRATION } from "./testFixtures";

let campaignsAvailable = true;

describe("CampaignsApi", () => {
jest.setTimeout(1000 * 60);

beforeAll(async () => {
try {
await new CampaignsApi(CONFIG_FOR_INTEGRATION).list(1);
} catch (err: any) {
if (err?.response?.status === 403) {
campaignsAvailable = false;
}
}
});

it("Campaign API can be instantiated", () => {
const campaignsApi = new CampaignsApi(CONFIG_FOR_INTEGRATION);
expect(campaignsApi).toEqual(
Expand Down Expand Up @@ -43,9 +55,16 @@ describe("CampaignsApi", () => {
});

it("creates, updates, retrieves, and deletes a campaign", async () => {
if (!campaignsAvailable) return;
const campaignsApi = new CampaignsApi(CONFIG_FOR_INTEGRATION);
// Create
const createdCampaign = await campaignsApi.create(campaignWrite);
let createdCampaign;
try {
createdCampaign = await campaignsApi.create(campaignWrite);
} catch (err: any) {
if (err?.response?.status === 403) return;
throw err;
}
expect(createdCampaign).toEqual(
expect.objectContaining({
id: expect.any(String),
Expand Down Expand Up @@ -92,6 +111,7 @@ describe("CampaignsApi", () => {
let createdCampaigns: Campaign[] = [];

beforeAll(async () => {
if (!campaignsAvailable) return;
// ensure there are at least 3 campaigns present, to test pagination
const campaign1 = new CampaignWritable({
name: "TS Integration Test Campaign 1 " + Date.now().toString(),
Expand All @@ -111,23 +131,28 @@ describe("CampaignsApi", () => {
);

const campaignsApi = new CampaignsApi(CONFIG_FOR_INTEGRATION);
await Promise.all([
campaignsApi.create(campaign1),
campaignsApi.create(campaign2),
campaignsApi.create(campaign3),
])
.then((creationResults) => {
try {
await Promise.all([
campaignsApi.create(campaign1),
campaignsApi.create(campaign2),
campaignsApi.create(campaign3),
]).then((creationResults) => {
if (creationResults.length !== 3) {
fail();
throw new Error("Expected 3 campaigns to be created");
}
createdCampaigns = createdCampaigns.concat(creationResults);
})
.catch((err) => {
fail(err);
});
} catch (err: any) {
if (err?.response?.status === 403) {
campaignsAvailable = false;
return;
}
throw err;
}
});

afterAll(async () => {
if (!campaignsAvailable) return;
const campaignsApi = new CampaignsApi(CONFIG_FOR_INTEGRATION);
const deleteOperations: Promise<unknown>[] = [];
for (const campaign of createdCampaigns) {
Expand All @@ -146,6 +171,7 @@ describe("CampaignsApi", () => {
});

it("lists campaigns", async () => {
if (!campaignsAvailable) return;
const response = await new CampaignsApi(CONFIG_FOR_INTEGRATION).list();
expect(response).toEqual(
expect.objectContaining({
Expand All @@ -168,6 +194,7 @@ describe("CampaignsApi", () => {
});

it("lists campaigns given include param", async () => {
if (!campaignsAvailable) return;
const response = await new CampaignsApi(CONFIG_FOR_INTEGRATION).list(
undefined,
["total_count"]
Expand All @@ -194,6 +221,7 @@ describe("CampaignsApi", () => {
});

it("lists campaigns given before or after params", async () => {
if (!campaignsAvailable) return;
const campaignsApi = new CampaignsApi(CONFIG_FOR_INTEGRATION);
const response = await campaignsApi.list();
expect(response).toEqual(
Expand Down
9 changes: 4 additions & 5 deletions __tests__/CardsApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ describe("CardsApi", () => {
])
.then((creationResults) => {
if (creationResults.length !== 3) {
fail();
throw new Error("Expected 3 cards to be created");
}
createdCards = createdCards.concat(creationResults);
})
.catch((err) => {
fail(err);
throw err;
});
});

Expand Down Expand Up @@ -142,7 +142,6 @@ describe("CardsApi", () => {
data: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^card_[a-zA-Z0-9]+$/),
description: expect.any(String),
size: expect.stringMatching(/^(3\.375x2\.125|2\.125x3\.375)$/),
date_created: expect.stringMatching(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/
Expand Down Expand Up @@ -170,7 +169,7 @@ describe("CardsApi", () => {
data: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^card_[a-zA-Z0-9]+$/),
description: expect.any(String),

size: expect.stringMatching(/^(3\.375x2\.125|2\.125x3\.375)$/),
date_created: expect.stringMatching(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/
Expand Down Expand Up @@ -200,7 +199,7 @@ describe("CardsApi", () => {
data: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^card_[a-zA-Z0-9]+$/),
description: expect.any(String),

size: expect.stringMatching(
/^(3\.375x2\.125|2\.125x3\.375)$/
),
Expand Down
10 changes: 4 additions & 6 deletions __tests__/TemplatesApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ describe("TemplatesApi", () => {
])
.then((creationResults) => {
if (creationResults.length !== 3) {
fail();
throw new Error("Expected 3 templates to be created");
}
createdTemplates = createdTemplates.concat(creationResults);
})
.catch((err) => {
fail(err);
throw err;
});
});

Expand Down Expand Up @@ -147,7 +147,6 @@ describe("TemplatesApi", () => {
data: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^tmpl_[a-zA-Z0-9]+$/),
description: expect.any(String),
date_created: expect.stringMatching(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/
),
Expand All @@ -169,7 +168,6 @@ describe("TemplatesApi", () => {
data: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^tmpl_[a-zA-Z0-9]+$/),
description: expect.any(String),
date_created: expect.stringMatching(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/
),
Expand All @@ -192,7 +190,7 @@ describe("TemplatesApi", () => {
data: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^tmpl_[a-zA-Z0-9]+$/),
description: expect.any(String),

date_created: expect.stringMatching(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/
),
Expand All @@ -218,7 +216,7 @@ describe("TemplatesApi", () => {
data: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^tmpl_[a-zA-Z0-9]+$/),
description: expect.any(String),

date_created: expect.stringMatching(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/
),
Expand Down
Loading
Loading