-
Notifications
You must be signed in to change notification settings - Fork 11
Batch Sending Api #63
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
base: main
Are you sure you want to change the base?
Conversation
…, bulk, and sandbox emails in batch
WalkthroughThe changes introduce batch email sending functionality to the codebase. This includes a new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MailtrapClient
participant MailtrapAPI
User->>MailtrapClient: batchSend(BatchSendRequest)
MailtrapClient->>MailtrapAPI: POST /api/batch (payload with base + requests)
MailtrapAPI-->>MailtrapClient: BatchSendResponse (message_ids)
MailtrapClient-->>User: Promise resolves with BatchSendResponse
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 3
🧹 Nitpick comments (10)
README.md (1)
69-74
: The new Batch Sending API section looks good, but fix the list indentation.The addition of the Batch Sending API section with links to examples aligns perfectly with the PR objectives. However, there's a minor formatting issue with the list items.
Fix the markdown list indentation by removing the leading space before each dash:
### Batch Sending API - - [Send a batch of emails](examples/batch/send-batch.ts) - - [Send a batch of transactional emails](examples/batch/transactional-batch.ts) - - [Send a batch of bulk emails](examples/batch/bulk-batch.ts) - - [Send a batch of sandbox emails](examples/batch/sandbox-batch.ts) + - [Send a batch of emails](examples/batch/send-batch.ts) + - [Send a batch of transactional emails](examples/batch/transactional-batch.ts) + - [Send a batch of bulk emails](examples/batch/bulk-batch.ts) + - [Send a batch of sandbox emails](examples/batch/sandbox-batch.ts)🧰 Tools
🪛 LanguageTool
[grammar] ~72-~72: Possible verb agreement error. Did you mean “sends”? (Some collective nouns can be treated as both singular and plural, so ‘Send’ is not always incorrect.)
Context: ...ails](examples/batch/send-batch.ts) - [Send a batch of transactional emails](exampl...(COLLECTIVE_NOUN_VERB_AGREEMENT_VBP)
🪛 markdownlint-cli2 (0.17.2)
71-71: Unordered list indentation
Expected: 0; Actual: 1(MD007, ul-indent)
72-72: Unordered list indentation
Expected: 0; Actual: 1(MD007, ul-indent)
73-73: Unordered list indentation
Expected: 0; Actual: 1(MD007, ul-indent)
74-74: Unordered list indentation
Expected: 0; Actual: 1(MD007, ul-indent)
examples/testing/send-mail.ts (1)
6-7
: Redundant documentation links - consider consolidating.There are two @see links pointing to the same article, with the second one just adding a fragment identifier to the URL.
Consider consolidating these links or making the purpose of the second link more explicit:
* @see https://help.mailtrap.io/article/69-sending-domain-setup -* @see https://help.mailtrap.io/article/69-sending-domain-setup#Demo-Domain--oYOU5" +* @see https://help.mailtrap.io/article/69-sending-domain-setup#Demo-Domain--oYOU5 "Demo Domain Setup Details"Alternatively, remove the first link if the second one with the fragment identifier is more specific and useful.
examples/batch/template.ts (1)
1-39
: Well-structured example for template-based batch sending.This example clearly demonstrates how to use the new batch sending functionality with templates. The code is well-organized with proper comments explaining prerequisites and an intuitive structure separating base properties from individual request properties.
Consider enhancing the example by adding a comment showing what the expected response structure would look like, to help users better understand the API:
}) - .then(console.log) + .then((response) => { + // Example response structure: + // { + // success: true, + // message_ids: ["msg_1234abcd", "msg_5678efgh"] + // } + console.log(response); + }) .catch(console.error);examples/batch/bulk.ts (1)
20-21
: Subject line doesn't match example typeThe subject line contains "Sandbox Email" but this is a bulk email example. This could be confusing to users.
- subject: "Sandbox Email", + subject: "Bulk Email",src/lib/MailtrapClient.ts (2)
147-149
: Consider simplifying the conditional URL constructionThe variable name
ifSandbox
is not very descriptive, and the conditional logic could be simplified for better readability.- const ifSandbox = - this.sandbox && this.testInboxId ? `/${this.testInboxId}` : ""; - const url = `${host}/api/batch${ifSandbox}`; + const testInboxPath = this.sandbox && this.testInboxId ? `/${this.testInboxId}` : ""; + const url = `${host}/api/batch${testInboxPath}`;
152-157
: Consider handling optional fields more elegantlyThe current implementation includes all fields in the mapped requests, even if they're undefined. You might want to only include fields that are actually present in the request.
- const preparedRequests = request.requests.map((req) => ({ - to: req.to, - cc: req.cc, - bcc: req.bcc, - custom_variables: req.custom_variables, - })); + const preparedRequests = request.requests.map((req) => { + const mappedRequest: Record<string, any> = { to: req.to }; + + if (req.cc) mappedRequest.cc = req.cc; + if (req.bcc) mappedRequest.bcc = req.bcc; + if (req.custom_variables) mappedRequest.custom_variables = req.custom_variables; + + return mappedRequest; + });src/types/mailtrap.ts (2)
72-77
: Consider reusing the existingSendResponse
type.The new
BatchSendResponse
type has the same structure as the existingSendResponse
type. To avoid duplication and ensure consistency, consider reusingSendResponse
instead of creating a new type.-export type BatchSendResponse = { - success: true; - message_ids: string[]; -}; +export type BatchSendResponse = SendResponse;
87-101
: Consider using union types to better represent content vs template emails.The
base
object combines properties for both content-based emails (text
,html
) and template-based emails (template_uuid
). Consider modeling this similar to the existing pattern whereexport type BatchSendRequest = { - base: { - from: Address; - subject?: string; - text?: string | Buffer; - html?: string | Buffer; - template_uuid?: string; - category?: string; - attachments?: Attachment[]; - headers?: MailtrapHeaders; - custom_variables?: CustomVariables; - reply_to?: Address; - }; + base: { + from: Address; + category?: string; + attachments?: Attachment[]; + headers?: MailtrapHeaders; + custom_variables?: CustomVariables; + reply_to?: Address; + } & ( + { + subject: string; + text?: string | Buffer; + html?: string | Buffer; + } | { + template_uuid: string; + } + ); requests: BatchSendRequestItem[]; };src/__tests__/lib/mailtrap-client.test.ts (2)
521-538
: Enhance test coverage with template variables.The test data for template-based batch sending doesn't exercise the
template_variables
property withinBatchSendRequestItem
. Add a test with different template variables for each recipient to ensure this functionality works correctly.requests: [ { to: [ { email: "[email protected]", name: "recipient1", }, ], + template_variables: { + user_name: "John Doe", + product_name: "Product A" + } }, { to: [ { email: "[email protected]", name: "recipient2", }, ], + template_variables: { + user_name: "Jane Smith", + product_name: "Product B" + } }, ],
386-691
: Consider refactoring tests to reduce duplication.The batch sending tests contain significant duplication in test data and assertion patterns. Consider extracting common setup and test data into helper functions or variables to improve maintainability.
For example, you could create a helper function for batch test setup:
function setupBatchTest(clientConfig, endpoint) { const client = new MailtrapClient(clientConfig); const expectedResponseData = { success: true, message_ids: ["0c7fd939-02cf-11ed-88c2-0a58a9feac02"], }; mock.onPost(endpoint).reply(200, expectedResponseData); const batchData = { base: { from: { email: "[email protected]", name: "Mailtrap", }, subject: "Batch Subject", text: "Batch Text", }, requests: [ { to: [ { email: "[email protected]", name: "recipient1", }, ], }, { to: [ { email: "[email protected]", name: "recipient2", }, ], }, ], }; return { client, expectedResponseData, batchData }; }Then use it in your tests:
it("successfully sends a batch of emails in bulk mode", async () => { const { client, expectedResponseData, batchData } = setupBatchTest( { token: "MY_API_TOKEN", bulk: true }, `${BULK_ENDPOINT}/api/batch` ); const result = await client.batchSend(batchData); expect(mock.history.post[0].url).toEqual(`${BULK_ENDPOINT}/api/batch`); expect(mock.history.post[0].data).toEqual( JSON.stringify({ base: batchData.base, requests: batchData.requests.map((req) => ({ to: req.to, })), }) ); expect(result).toEqual(expectedResponseData); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (10)
README.md
(1 hunks)examples/batch/bulk.ts
(1 hunks)examples/batch/sandbox.ts
(1 hunks)examples/batch/template.ts
(1 hunks)examples/batch/transactional.ts
(1 hunks)examples/testing/send-mail.ts
(1 hunks)src/__tests__/lib/mailtrap-client.test.ts
(1 hunks)src/lib/MailtrapClient.ts
(2 hunks)src/lib/mail-buffer-encoder.ts
(1 hunks)src/types/mailtrap.ts
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/lib/MailtrapClient.ts (2)
src/types/mailtrap.ts (2)
BatchSendRequest
(87-101)BatchSendResponse
(74-77)src/lib/mail-buffer-encoder.ts (1)
encodeMailBuffers
(8-33)
src/lib/mail-buffer-encoder.ts (1)
src/types/mailtrap.ts (1)
src/__tests__/lib/mailtrap-client.test.ts (1)
src/lib/MailtrapError.ts (1)
MailtrapError
(1-1)
🪛 LanguageTool
README.md
[grammar] ~72-~72: Possible verb agreement error. Did you mean “sends”? (Some collective nouns can be treated as both singular and plural, so ‘Send’ is not always incorrect.)
Context: ...ails](examples/batch/send-batch.ts) - [Send a batch of transactional emails](exampl...
(COLLECTIVE_NOUN_VERB_AGREEMENT_VBP)
🪛 markdownlint-cli2 (0.17.2)
README.md
71-71: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
72-72: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
73-73: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
74-74: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
🔇 Additional comments (10)
src/lib/mail-buffer-encoder.ts (1)
8-8
: Good improvement to function signature flexibility.Changing the function signature to accept
Partial<Mail>
instead of justThis change aligns well with the batch sending functionality being added in this PR and follows good TypeScript practices.
examples/batch/bulk.ts (1)
1-40
: Overall, the example looks goodThis example clearly demonstrates how to use the batch sending API in bulk mode. The code structure is clean and includes proper error handling with promise chaining.
examples/batch/transactional.ts (1)
1-38
: Example looks goodThis transactional batch sending example is well-structured and demonstrates the API usage clearly. It includes proper documentation, placeholder values, and error handling.
examples/batch/sandbox.ts (1)
1-43
: Example looks goodThe sandbox mode batch sending example is well-implemented with all the necessary configuration options. The code is clean and follows the same pattern as the other examples, ensuring consistency across the codebase.
src/lib/MailtrapClient.ts (2)
14-20
: Imports look goodThe updated import statement correctly includes the new batch-related types that are used in the implementation.
139-163
: Implementation is solidThe
batchSend
method implementation looks good. It:
- Properly determines the host based on the client configuration
- Correctly constructs the API URL with conditional test inbox ID for sandbox mode
- Uses the existing
encodeMailBuffers
function to process the base mail- Maps request items to include only the necessary fields
- Makes a POST request to the batch API endpoint with properly structured data
The implementation follows the same patterns as the existing code, which ensures consistency.
src/types/mailtrap.ts (1)
79-85
: LGTM: Clear and well-structured recipient details type.The
BatchSendRequestItem
type is well-defined with appropriate optional fields for customizing individual recipients in a batch.src/__tests__/lib/mailtrap-client.test.ts (3)
555-607
: LGTM: Comprehensive test for transactional batch sending.This test thoroughly verifies the functionality of transactional batch sending, covering the proper endpoint construction, request payload formatting, and response handling.
609-652
: LGTM: Proper API error handling test.This test effectively validates that API errors are properly caught and converted to
MailtrapError
instances with the correct error message.
654-690
: LGTM: Proper HTTP transport error handling test.This test ensures that HTTP transport errors are correctly handled and converted to
MailtrapError
instances with appropriate error messages.
…ne/template structures
… in batch sending
@coderabbitai check |
Tip For best results, initiate chat on the files or code changes. @narekhovhannisyan I've checked the PR implementation and everything looks good! The batch sending API is well-implemented with:
The approach of having a base email template with individual recipient customizations is a solid design pattern for batch operations. The implementation aligns well with the existing codebase structure while extending functionality in a useful way. |
}; | ||
|
||
try { | ||
await batchClient.batchSend(batchData); |
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.
Should we raise incompatibility error much earlier, during initialization of MailtrapClient
?
const expectedResponseData = { | ||
success: true, | ||
message_ids: ["0c7fd939-02cf-11ed-88c2-0a58a9feac02"], | ||
}; |
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.
This is not a correct schema of the Batch API response, please check https://api-docs.mailtrap.io/docs/mailtrap-api-docs/f96000c8de409-batch-send-email-including-templates
const expectedResponseData = { | ||
success: true, | ||
message_ids: ["0c7fd939-02cf-11ed-88c2-0a58a9feac02"], | ||
}; |
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.
The actual response schema: https://api-docs.mailtrap.io/docs/mailtrap-api-docs/48b526aa487b1-batch-send-email-including-templates
const responseData = { | ||
success: false, | ||
errors: ["from is required", "subject is required"], | ||
}; |
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.
This too doesn't match the way error response is returned from the Batch API
} | ||
|
||
export interface BatchSendRequest { | ||
base: InlineBatchSendBase | TemplateBatchSendBase; |
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.
base
is not required, so I guess it should be base?
?
to: BaseAddress[]; | ||
cc?: BaseAddress[]; | ||
bcc?: BaseAddress[]; | ||
custom_variables?: Record<string, string>; |
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.
There's much more supported attributes on this level too, e.g. reply_to
, text
, html
, category
..., even template_uuid
.
From API docs:
base
- General properties of all emails in the batch. Each of them can be overridden in requests for individual emails.
requests
- The list of emails. Each of them requires recipients (one of to, cc, or bcc). Each email inherits properties from base but can override them.
template_uuid: string; // Required for template usage | ||
template_variables?: Record<string, string>; | ||
custom_variables?: Record<string, string>; | ||
category?: string; |
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.
I think category
is actually not allowed when using a template (since category is set on template already)
Co-authored-by: Marcin Klocek <[email protected]>
Co-authored-by: Marcin Klocek <[email protected]>
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.
Actionable comments posted: 1
♻️ Duplicate comments (2)
src/__tests__/lib/mailtrap-client.test.ts (2)
376-379
:⚠️ Potential issueUse correct API response schema
The API response schema used in the test doesn't match the actual Batch API response schema as mentioned in a previous review comment.
const expectedResponseData = { success: true, - message_ids: ["0c7fd939-02cf-11ed-88c2-0a58a9feac02"], + // Update with the actual response schema from https://api-docs.mailtrap.io/docs/mailtrap-api-docs/f96000c8de409-batch-send-email-including-templates + message_id: "0c7fd939-02cf-11ed-88c2-0a58a9feac02" };
432-435
:⚠️ Potential issueUse correct API response schema for sandbox mode
The API response schema used in the test doesn't match the actual Batch API response schema as mentioned in a previous review comment.
const expectedResponseData = { success: true, - message_ids: ["0c7fd939-02cf-11ed-88c2-0a58a9feac02"], + // Update with the actual response schema from https://api-docs.mailtrap.io/docs/mailtrap-api-docs/48b526aa487b1-batch-send-email-including-templates + message_id: "0c7fd939-02cf-11ed-88c2-0a58a9feac02" };
🧹 Nitpick comments (2)
README.md (1)
71-74
: Fix list indentation in markdownThe markdownlint static analysis tool has flagged an indentation issue with the unordered list items.
- - [Send a batch of transactional emails](examples/batch/transactional.ts) - - [Send a batch of bulk emails](examples/batch/bulk.ts) - - [Send a batch of sandbox emails](examples/batch/sandbox.ts) - - [Send a batch of emails from template](examples/batch/template.ts) + - [Send a batch of transactional emails](examples/batch/transactional.ts) + - [Send a batch of bulk emails](examples/batch/bulk.ts) + - [Send a batch of sandbox emails](examples/batch/sandbox.ts) + - [Send a batch of emails from template](examples/batch/template.ts)🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
71-71: Unordered list indentation
Expected: 0; Actual: 1(MD007, ul-indent)
72-72: Unordered list indentation
Expected: 0; Actual: 1(MD007, ul-indent)
73-73: Unordered list indentation
Expected: 0; Actual: 1(MD007, ul-indent)
74-74: Unordered list indentation
Expected: 0; Actual: 1(MD007, ul-indent)
src/__tests__/lib/mailtrap-client.test.ts (1)
361-361
: Consider raising incompatibility error earlierAs mentioned in a previous review comment, the incompatibility between bulk and sandbox modes could potentially be detected during client initialization rather than when calling the
batchSend
method.This approach would provide earlier feedback to developers about the configuration issue before they attempt to use the API.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (4)
README.md
(1 hunks)examples/batch/bulk.ts
(1 hunks)src/__tests__/lib/mailtrap-client.test.ts
(1 hunks)src/types/mailtrap.ts
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- examples/batch/bulk.ts
- src/types/mailtrap.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/__tests__/lib/mailtrap-client.test.ts (1)
src/lib/MailtrapError.ts (1)
MailtrapError
(1-1)
🪛 markdownlint-cli2 (0.17.2)
README.md
71-71: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
72-72: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
73-73: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
74-74: Unordered list indentation
Expected: 0; Actual: 1
(MD007, ul-indent)
🔇 Additional comments (9)
README.md (1)
69-75
:✅ Verification successful
Well structured documentation addition for Batch Sending API
The new section clearly documents the batch sending capabilities with appropriate links to example files, making it easier for users to understand and implement this functionality.
Let's verify the file paths and ensure they match the actual repository structure:
🏁 Script executed:
#!/bin/bash # Check if the example files exist at the specified paths echo "Verifying file paths for batch sending examples..." for file in examples/batch/{transactional,bulk,sandbox,template}.ts; do if [[ -f "$file" ]]; then echo "✅ File exists: $file" else echo "❌ File missing: $file" fi doneLength of output: 914
Approve documentation update for Batch Sending API
All example links correctly point to existing files in
examples/batch
:
- ✅ examples/batch/transactional.ts
- ✅ examples/batch/bulk.ts
- ✅ examples/batch/sandbox.ts
- ✅ examples/batch/template.ts
The added section is clear and makes it easy for users to find and run batch-sending examples.
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
71-71: Unordered list indentation
Expected: 0; Actual: 1(MD007, ul-indent)
72-72: Unordered list indentation
Expected: 0; Actual: 1(MD007, ul-indent)
73-73: Unordered list indentation
Expected: 0; Actual: 1(MD007, ul-indent)
74-74: Unordered list indentation
Expected: 0; Actual: 1(MD007, ul-indent)
src/__tests__/lib/mailtrap-client.test.ts (8)
331-674
: Comprehensive test coverage for new batch sending functionalityThe test suite is well-structured and covers all the key scenarios for the batch sending functionality. It tests various modes (bulk, sandbox, transactional), template usage, and error handling.
332-368
: Good validation of incompatible modesThis test correctly verifies that batch sending rejects with a MailtrapError when both bulk and sandbox modes are enabled simultaneously.
370-423
: Bulk mode batch sending tests are correctly implementedThe test properly validates the endpoint, request payload structure, and response handling for bulk mode batch sending.
425-479
: Sandbox mode batch sending tests are correctly implementedThe test properly validates the endpoint, request payload structure, and response handling for sandbox mode batch sending.
481-536
: Template batch sending tests are correctly implementedThe test appropriately validates the batch sending functionality with templates, including the template_uuid and template_variables in the base payload.
538-590
: Transactional batch sending tests are correctly implementedThe test properly validates the endpoint, request payload structure, and response handling for transactional batch sending.
592-635
: API error handling tests are comprehensiveThe test properly verifies error handling when the API returns error messages.
637-673
: HTTP transport error handling tests are comprehensiveThe test correctly verifies that HTTP transport errors are properly handled and wrapped in a MailtrapError with an appropriate message.
const responseData = { | ||
success: false, | ||
errors: ["from is required", "subject is required"], | ||
}; |
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.
💡 Verification agent
🧩 Analysis chain
Update API error response schema
The error response schema used in the test may not match the actual Batch API error response format as mentioned in a previous review comment.
🏁 Script executed:
#!/bin/bash
# Search for error response handling in the implementation
echo "Searching for error response handling in MailtrapClient.ts..."
rg -A 10 "batchSend.*catch" src/lib/MailtrapClient.ts
Length of output: 188
I couldn’t locate the error‐handling in the initially referenced file path—let’s first discover where the MailtrapClient
lives and how it handles batch errors:
Please run this so we can confirm the real API error schema and update the test accordingly.
🏁 Script executed:
#!/bin/bash
# 1) Find the implementation file for MailtrapClient
CLIENT_FILE=$(rg -l "class MailtrapClient" -n .) || exit 1
echo "MailtrapClient implementation: $CLIENT_FILE"
# 2) Look for any batch/send methods
echo "— Searching for batch/send methods —"
rg -n "batch" "$CLIENT_FILE" || echo "No 'batch' matches"
rg -n "send" "$CLIENT_FILE" || echo "No 'send' matches"
# 3) Inspect catch blocks / error‐response parsing
echo "— Searching for error handling —"
rg -A5 "catch" "$CLIENT_FILE" || echo "No catch blocks found"
rg -A5 "errors" "$CLIENT_FILE" || echo "No 'errors' property references"
Length of output: 1022
Let’s locate and inspect the handleSendingError
helper to see the real error payload shape:
🏁 Script executed:
#!/bin/bash
# Find where handleSendingError is defined and its implementation
echo "Searching for handleSendingError definition and usage..."
rg -n "handleSendingError" -n src/lib
Length of output: 392
Let’s inspect the full handleSendingError
implementation to see how it parses error.response.data
:
🏁 Script executed:
#!/bin/bash
# Show the implementation of handleSendingError with context
rg -n -C 10 "export default function handleSendingError" src/lib/axios-logger.ts
Length of output: 751
Let’s view the full error‐parsing logic to confirm the exact shape returned by handleSendingError
:
🏁 Script executed:
#!/bin/bash
# Show expanded context for handleSendingError to capture how it builds the final error object
rg -n -C 50 "export default function handleSendingError" src/lib/axios-logger.ts
Length of output: 2101
Update API error response schema in test
The client’s handleSendingError
helper expects the server to return an errors
object (with name
and/or base
arrays) or an error
string—never a bare array. In your test src/__tests__/lib/mailtrap-client.test.ts
, update the stub and assertion:
- Replace this block…
const responseData = { success: false, errors: ["from is required", "subject is required"], };
- …with:
const responseData = { errors: { name: ["from is required", "subject is required"], }, };
- And adjust your thrown‐error assertion to expect the message:
"from is required, subject is required"
🤖 Prompt for AI Agents
In src/__tests__/lib/mailtrap-client.test.ts around lines 598 to 601, the test's
stubbed API error response uses an incorrect schema with an errors array. Update
the responseData object to have an errors property containing a name array with
the error messages, matching the actual API error format handled by
handleSendingError. Also, modify the test assertion to expect the combined error
message string "from is required, subject is required" instead of an array.
Motivation
Integrate Batch Sending API into current node.js SDK to support sending multiple emails in a single request, improving efficiency and reducing API calls.
Changes
batchSend
method toMailtrapClient
classHow to test
npm test
Summary by CodeRabbit
New Features
Documentation
Examples
Tests