-
Notifications
You must be signed in to change notification settings - Fork 11
Make testInboxID
optional param
#70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0a2d134
refactor: rearrange error constants and update testing getter to vali…
narekhovhannisyan 6a534cd
test: add unit test for MailtrapClient to validate error handling whe…
narekhovhannisyan b72e941
refactor: extract test inbox ID validation into a separate method for…
narekhovhannisyan d7f7042
test: add unit test for MailtrapClient to ensure MailtrapError is thr…
narekhovhannisyan 1e10d77
test: add unit test for MailtrapClient to verify correct behavior whe…
narekhovhannisyan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ import TemplatesBaseAPI from "../../lib/api/Templates"; | |
|
||
const { ERRORS, CLIENT_SETTINGS } = CONFIG; | ||
const { TESTING_ENDPOINT, BULK_ENDPOINT, SENDING_ENDPOINT } = CLIENT_SETTINGS; | ||
const { TEST_INBOX_ID_MISSING, ACCOUNT_ID_MISSING, BULK_SANDBOX_INCOMPATIBLE } = | ||
const { ACCOUNT_ID_MISSING, BULK_SANDBOX_INCOMPATIBLE, TEST_INBOX_ID_MISSING } = | ||
ERRORS; | ||
|
||
describe("lib/mailtrap-client: ", () => { | ||
|
@@ -331,7 +331,49 @@ describe("lib/mailtrap-client: ", () => { | |
} | ||
}); | ||
|
||
it("throws MailtrapError(TEST_INBOX_ID_MISSING) when sending in sandbox mode without testInboxId", async () => { | ||
const client = new MailtrapClient({ | ||
token: "MY_API_TOKEN", | ||
sandbox: true, | ||
accountId: 123, | ||
}); | ||
|
||
await expect( | ||
client.send({ | ||
from: { email: "[email protected]", name: "Sender" }, | ||
to: [{ email: "[email protected]" }], | ||
subject: "Test", | ||
text: "Body", | ||
}) | ||
).rejects.toEqual(new MailtrapError(TEST_INBOX_ID_MISSING)); | ||
}); | ||
|
||
describe("batch sending:", () => { | ||
it("throws MailtrapError(TEST_INBOX_ID_MISSING) when batch sending in sandbox mode without testInboxId", async () => { | ||
const client = new MailtrapClient({ | ||
token: "MY_API_TOKEN", | ||
sandbox: true, | ||
accountId: 123, | ||
}); | ||
|
||
const batchData = { | ||
base: { | ||
from: { email: "[email protected]", name: "Sender" }, | ||
subject: "Test", | ||
text: "Body", | ||
}, | ||
requests: [ | ||
{ | ||
to: [{ email: "[email protected]" }], | ||
}, | ||
], | ||
}; | ||
|
||
await expect(client.batchSend(batchData)).rejects.toEqual( | ||
new MailtrapError(TEST_INBOX_ID_MISSING) | ||
); | ||
}); | ||
|
||
it("rejects with Mailtrap error when bulk and sandbox modes are used together", async () => { | ||
const batchClient = new MailtrapClient({ | ||
token: "MY_API_TOKEN", | ||
|
@@ -664,7 +706,7 @@ describe("lib/mailtrap-client: ", () => { | |
}); | ||
|
||
describe("get testing(): ", () => { | ||
it("rejects with Mailtrap error, when `testInboxId` is missing.", () => { | ||
it("rejects with Mailtrap error, when `accountId` is missing.", () => { | ||
const client = new MailtrapClient({ | ||
token: "MY_API_TOKEN", | ||
}); | ||
|
@@ -674,30 +716,25 @@ describe("lib/mailtrap-client: ", () => { | |
try { | ||
client.testing; | ||
} catch (error) { | ||
expect(error).toEqual(new MailtrapError(TEST_INBOX_ID_MISSING)); | ||
expect(error).toEqual(new MailtrapError(ACCOUNT_ID_MISSING)); | ||
} | ||
}); | ||
|
||
it("rejects with Mailtrap error, when `accountId` is missing.", () => { | ||
it("returns testing API object when accountId is provided, even without testInboxId", () => { | ||
const client = new MailtrapClient({ | ||
token: "MY_API_TOKEN", | ||
testInboxId: 5, | ||
accountId: 123, | ||
// testInboxId is intentionally omitted | ||
}); | ||
|
||
expect.assertions(1); | ||
|
||
try { | ||
client.testing; | ||
} catch (error) { | ||
expect(error).toEqual(new MailtrapError(ACCOUNT_ID_MISSING)); | ||
} | ||
const testingClient = client.testing; | ||
expect(testingClient).toBeInstanceOf(TestingAPI); | ||
}); | ||
|
||
it("returns testing API object, console warn is called twice.", () => { | ||
const client = new MailtrapClient({ | ||
token: "MY_API_TOKEN", | ||
sandbox: true, | ||
testInboxId: 10, | ||
accountId: 10, | ||
}); | ||
expect.assertions(1); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also be nice to have a test that the absence of
testInboxId
doesn't raise an error whenclient.testing
is called.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And remove
testInboxId
from all client setup cases where it's not needed anymore (like here).