Skip to content

Commit

Permalink
refactor(test): refactor authentication tests (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Oct 12, 2023
1 parent 8478f61 commit bfaebfd
Show file tree
Hide file tree
Showing 41 changed files with 122 additions and 131 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ The full API of this library can be found in [api.md](https://www.github.com/Mod
import ModernTreasury from 'modern-treasury';

const modernTreasury = new ModernTreasury({
apiKey: 'my api key', // defaults to process.env["MODERN_TREASURY_API_KEY"]
organizationId: 'my-organization-ID',
organizationId: 'my-organization-ID', // defaults to process.env["MODERN_TREASURY_ORGANIZATION_ID"]
apiKey: 'My API Key', // defaults to process.env["MODERN_TREASURY_API_KEY"]
});

async function main() {
Expand All @@ -46,8 +46,8 @@ This library includes TypeScript definitions for all request params and response
import ModernTreasury from 'modern-treasury';

const modernTreasury = new ModernTreasury({
apiKey: 'my api key', // defaults to process.env["MODERN_TREASURY_API_KEY"]
organizationId: 'my-organization-ID',
organizationId: 'my-organization-ID', // defaults to process.env["MODERN_TREASURY_ORGANIZATION_ID"]
apiKey: 'My API Key', // defaults to process.env["MODERN_TREASURY_API_KEY"]
});

async function main() {
Expand Down Expand Up @@ -166,7 +166,6 @@ You can use the `maxRetries` option to configure or disable this:
// Configure the default for all requests:
const modernTreasury = new ModernTreasury({
maxRetries: 0, // default is 2
organizationId: 'my-organization-ID',
});

// Or, configure per-request:
Expand All @@ -184,7 +183,6 @@ Requests time out after 1 minute by default. You can configure this with a `time
// Configure the default for all requests:
const modernTreasury = new ModernTreasury({
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
organizationId: 'my-organization-ID',
});

// Override per-request:
Expand Down Expand Up @@ -266,7 +264,6 @@ import HttpsProxyAgent from 'https-proxy-agent';
// Configure the default for all requests:
const modernTreasury = new ModernTreasury({
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
organizationId: 'my-organization-ID',
});

// Override per-request:
Expand Down
26 changes: 16 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ import * as TopLevelAPI from 'modern-treasury/resources/top-level';

export interface ClientOptions {
/**
* Defaults to process.env["MODERN_TREASURY_API_KEY"].
* Defaults to process.env['MODERN_TREASURY_API_KEY'].
*/
apiKey?: string;

/**
* Defaults to process.env['MODERN_TREASURY_ORGANIZATION_ID'].
*/
organizationId?: string;

/**
* Defaults to process.env['MODERN_TREASURY_WEBHOOK_KEY'].
*/
webhookKey?: string | null;

/**
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
*/
Expand Down Expand Up @@ -68,33 +78,29 @@ export interface ClientOptions {
* param to `undefined` in request options.
*/
defaultQuery?: Core.DefaultQuery;

organizationId?: string;

webhookKey?: string | null;
}

/** API Client for interfacing with the Modern Treasury API. */
export class ModernTreasury extends Core.APIClient {
apiKey: string;
organizationId: string;
webhookKey?: string | null;
webhookKey: string | null;

private _options: ClientOptions;

/**
* API Client for interfacing with the Modern Treasury API.
*
* @param {string} [opts.apiKey=process.env['MODERN_TREASURY_API_KEY']] - The API Key to send to the API.
* @param {string} [opts.apiKey==process.env['MODERN_TREASURY_API_KEY'] ?? undefined]
* @param {string} [opts.organizationId==process.env['MODERN_TREASURY_ORGANIZATION_ID'] ?? undefined]
* @param {string | null} [opts.webhookKey==process.env['MODERN_TREASURY_WEBHOOK_KEY'] ?? null]
* @param {string} [opts.baseURL] - Override the default base URL for the API.
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
* @param {string} [opts.organizationId]
* @param {string | null} [opts.webhookKey]
*/
constructor({
apiKey = Core.readEnv('MODERN_TREASURY_API_KEY'),
Expand All @@ -104,7 +110,7 @@ export class ModernTreasury extends Core.APIClient {
}: ClientOptions = {}) {
if (apiKey === undefined) {
throw new Errors.ModernTreasuryError(
"The MODERN_TREASURY_API_KEY environment variable is missing or empty; either provide it, or instantiate the ModernTreasury client with an apiKey option, like new ModernTreasury({ apiKey: 'my apiKey' }).",
"The MODERN_TREASURY_API_KEY environment variable is missing or empty; either provide it, or instantiate the ModernTreasury client with an apiKey option, like new ModernTreasury({ apiKey: 'My API Key' }).",
);
}
if (organizationId === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/account-collection-flows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource accountCollectionFlows', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/account-details.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource accountDetails', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/connections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource connections', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/counterparties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource counterparties', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury, { toFile } from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource documents', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource events', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/expected-payments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource expectedPayments', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/external-accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource externalAccounts', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/incoming-payment-details.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource incomingPaymentDetails', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/internal-accounts/balance-reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource balanceReports', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource internalAccounts', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/invoices/invoices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource invoices', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/invoices/line-items.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource lineItems', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/ledger-account-balance-monitors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource ledgerAccountBalanceMonitors', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/ledger-account-categories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource ledgerAccountCategories', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/ledger-account-payouts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource ledgerAccountPayouts', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/ledger-account-statements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource ledgerAccountStatements', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/ledger-accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource ledgerAccounts', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/ledger-entries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource ledgerEntries', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/ledger-event-handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource ledgerEventHandlers', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource ledgerTransactions', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/ledger-transactions/versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource versions', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/api-resources/ledgerable-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ModernTreasury from 'modern-treasury';
import { Response } from 'node-fetch';

const modernTreasury = new ModernTreasury({
apiKey: 'something1234',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
apiKey: 'My API Key',
organizationId: 'my-organization-ID',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource ledgerableEvents', () => {
Expand Down
Loading

0 comments on commit bfaebfd

Please sign in to comment.