Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 37 additions & 1 deletion __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,7 +213,10 @@ describe("Bank Account Models", () => {
expect(rec).toBeDefined();
});

it.each([["amounts", [1, 2]]])(
it.each([
["amounts", [1, 2]],
["descriptor_code", "SM11AA"],
])(
"can be created with a provided %s value",
(prop, val) => {
const input = {};
Expand All @@ -221,6 +228,35 @@ describe("Bank Account Models", () => {
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");
}
}
});

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
38 changes: 38 additions & 0 deletions __tests__/BankAccountsApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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
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
21 changes: 20 additions & 1 deletion models/bank-account-verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,33 @@ export class BankAccountVerify {
if (typeof input?.amounts !== "undefined") {
this.amounts = input.amounts;
}
if (typeof input?.descriptor_code !== "undefined") {
this.descriptor_code = input.descriptor_code;
}
}

/**
* In live mode, an array containing the two micro deposits (in cents) placed in the bank account. In test mode, no micro deposits will be placed, so any two integers between `1` and `100` will work.
* @type {Array<number>}
* @memberof BankAccountVerify
*/
"amounts": Array<number>;
"amounts"?: Array<number>;

/**
* The 6-character code (beginning with SM) from the bank statement descriptor of the single $0.01 microdeposit sent via Stripe Financial Connections. Required when microdeposit_type is descriptor_code. Mutually exclusive with amounts.
* @type {string}
* @memberof BankAccountVerify
*/
private "_descriptor_code"?: string;
public get descriptor_code() {
return this._descriptor_code;
}
public set descriptor_code(newValue: string | undefined) {
if (newValue && !/^SM[a-zA-Z0-9]{4}$/.test(newValue)) {
throw new Error("Invalid descriptor_code provided");
}
this._descriptor_code = newValue;
}

public toJSON() {
let out = {};
Expand Down
18 changes: 18 additions & 0 deletions models/bank-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export class BankAccount {
if (typeof input?.object !== "undefined") {
this.object = input.object;
}
if (typeof input?.microdeposit_type !== "undefined") {
this.microdeposit_type = input.microdeposit_type;
}
}

/**
Expand Down Expand Up @@ -186,6 +189,13 @@ export class BankAccount {
*/
"object": BankAccountObjectEnum;

/**
* The type of microdeposit verification required. Present when verified is false; null once the account is verified. Use this to determine which field to submit to the verify endpoint: amounts or descriptor_code.
* @type {string}
* @memberof BankAccount
*/
"microdeposit_type"?: BankAccountMicrodepositTypeEnum | null;

public toJSON() {
let out = {};
for (const [key, value] of Object.entries(this)) {
Expand All @@ -212,6 +222,14 @@ export enum BankAccountAccountTypeEnum {
export enum BankAccountObjectEnum {
BankAccount = "bank_account",
}
/**
* @export
* @enum {string}
*/
export enum BankAccountMicrodepositTypeEnum {
Amounts = "amounts",
DescriptorCode = "descriptor_code",
}

/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"address validation",
"address autocomplete"
],
"version": "1.3.6",
"version": "1.4.0",
"homepage": "https://github.com/lob/lob-typescript-sdk",
"author": "Lob <support@lob.com> (https://lob.com/)",
"repository": {
Expand Down
Loading