Skip to content

Commit

Permalink
lib: in mailtrap client introduce testing getter.
Browse files Browse the repository at this point in the history
  • Loading branch information
narekhovhannisyan committed Nov 2, 2023
1 parent 69fffc4 commit befde10
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/lib/mailtrap-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import CONFIG from "../config";

import { Mail, SendResponse, MailtrapClientConfig } from "../types/mailtrap";

const { CLIENT_SETTINGS } = CONFIG;
const { CLIENT_SETTINGS, ERRORS } = CONFIG;
const { SENDING_ENDPOINT, MAX_REDIRECTS, USER_AGENT, TIMEOUT } =
CLIENT_SETTINGS;
const { TEST_INBOX_ID_MISSING, ACCOUNT_ID_MISSING } = ERRORS;

/**
* Mailtrap client class. Initializes instance with available methods.
Expand All @@ -25,7 +26,7 @@ export default class MailtrapClient {

private accountId?: number;

public testing: TestingAPI;
private testingAPI: TestingAPI;

/**
* Initalizes axios instance with Mailtrap params.
Expand All @@ -45,7 +46,28 @@ export default class MailtrapClient {
this.testInboxId = testInboxId;
this.accountId = accountId;

this.testing = new TestingAPI(this.axios, this.testInboxId, this.accountId);
this.testingAPI = new TestingAPI(
this.axios,
this.testInboxId,
this.accountId
);
}

/**
* Getter for testing API. Warns if some of the required keys are missing.
*/
get testing() {
if (!this.testInboxId) {
// eslint-disable-next-line no-console
console.warn(TEST_INBOX_ID_MISSING);
}

if (!this.accountId) {
// eslint-disable-next-line no-console
console.warn(ACCOUNT_ID_MISSING);
}

return this.testingAPI;
}

/**
Expand Down

0 comments on commit befde10

Please sign in to comment.