From 827932bfff047ff5aeb0c6ce48a37ea10edc35be Mon Sep 17 00:00:00 2001 From: Kewyn Akshlley Date: Thu, 18 Sep 2025 14:51:17 -0300 Subject: [PATCH 1/3] feat: batch validation --- .../com/resend/core/net/RequestOptions.java | 47 +++++++++++++- .../com/resend/core/net/impl/HttpClient.java | 7 +++ .../java/com/resend/services/batch/Batch.java | 36 ++++++++--- .../model/AbstractBatchEmailsResponse.java | 47 ++++++++++++++ .../services/batch/model/BatchError.java | 50 +++++++++++++++ .../model/CreateBatchEmailsResponse.java | 28 +++------ .../model/PermissiveBatchEmailsResponse.java | 61 +++++++++++++++++++ .../resend/services/emails/EmailsTest.java | 17 +++++- .../com/resend/services/util/EmailsUtil.java | 18 +++++- 9 files changed, 279 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/resend/services/batch/model/AbstractBatchEmailsResponse.java create mode 100644 src/main/java/com/resend/services/batch/model/BatchError.java create mode 100644 src/main/java/com/resend/services/batch/model/PermissiveBatchEmailsResponse.java diff --git a/src/main/java/com/resend/core/net/RequestOptions.java b/src/main/java/com/resend/core/net/RequestOptions.java index f3b65d3..a7086df 100644 --- a/src/main/java/com/resend/core/net/RequestOptions.java +++ b/src/main/java/com/resend/core/net/RequestOptions.java @@ -1,12 +1,15 @@ package com.resend.core.net; -import com.resend.services.domains.model.CreateDomainOptions; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; /** * Represents a request to create a request options. */ public class RequestOptions { private final String idempotencyKey; + private final Map additionalHeaders; /** * Constructs a RequestOptions object using the provided builder. @@ -15,6 +18,7 @@ public class RequestOptions { */ public RequestOptions(Builder builder) { this.idempotencyKey = builder.idempotencyKey; + this.additionalHeaders = Collections.unmodifiableMap(new HashMap<>(builder.additionalHeaders)); } /** @@ -26,6 +30,15 @@ public String getIdempotencyKey() { return idempotencyKey; } + /** + * Get the additional headers map. + * + * @return An unmodifiable map of additional headers. + */ + public Map getAdditionalHeaders() { + return additionalHeaders; + } + /** * Create a new builder instance for constructing RequestOptions objects. * @@ -40,6 +53,14 @@ public static Builder builder() { */ public static class Builder { private String idempotencyKey; + private final Map additionalHeaders; + + /** + * Constructs a new Builder with empty additional headers map. + */ + public Builder() { + this.additionalHeaders = new HashMap<>(); + } /** * Set the idempotencyKey. @@ -52,6 +73,28 @@ public Builder setIdempotencyKey(String idempotencyKey) { return this; } + /** + * Add a custom header to the additional headers map. + * + * @param name The header name. + * @param value The header value. + * @return The builder instance. + */ + public Builder add(String name, String value) { + this.additionalHeaders.put(name, value); + return this; + } + + /** + * Add multiple custom headers to the additional headers map. + * + * @param headers A map of headers to add. + * @return The builder instance. + */ + public Builder addAll(Map headers) { + this.additionalHeaders.putAll(headers); + return this; + } /** * Build a new RequestOptions object. @@ -62,4 +105,4 @@ public RequestOptions build() { return new RequestOptions(this); } } -} +} \ No newline at end of file diff --git a/src/main/java/com/resend/core/net/impl/HttpClient.java b/src/main/java/com/resend/core/net/impl/HttpClient.java index b007e3d..ef01a4a 100644 --- a/src/main/java/com/resend/core/net/impl/HttpClient.java +++ b/src/main/java/com/resend/core/net/impl/HttpClient.java @@ -154,6 +154,13 @@ public AbstractHttpResponse perform( requestBuilder.addHeader("Idempotency-Key", requestOptions.getIdempotencyKey()); } + if (requestOptions.getAdditionalHeaders() != null + && !requestOptions.getAdditionalHeaders().isEmpty()) { + for (Map.Entry entry : requestOptions.getAdditionalHeaders().entrySet()) { + requestBuilder.addHeader(entry.getKey(), entry.getValue()); + } + } + Request request = requestBuilder.build(); try { diff --git a/src/main/java/com/resend/services/batch/Batch.java b/src/main/java/com/resend/services/batch/Batch.java index 25e65d9..ab89930 100644 --- a/src/main/java/com/resend/services/batch/Batch.java +++ b/src/main/java/com/resend/services/batch/Batch.java @@ -6,7 +6,9 @@ import com.resend.core.net.RequestOptions; import com.resend.core.service.BaseService; +import com.resend.services.batch.model.AbstractBatchEmailsResponse; import com.resend.services.batch.model.CreateBatchEmailsResponse; +import com.resend.services.batch.model.PermissiveBatchEmailsResponse; import com.resend.services.emails.model.CreateEmailOptions; import okhttp3.MediaType; @@ -43,9 +45,7 @@ public CreateBatchEmailsResponse send(List emails) throws Re String responseBody = response.getBody(); - CreateBatchEmailsResponse createBatchEmailsResponse = resendMapper.readValue(responseBody, CreateBatchEmailsResponse.class); - - return createBatchEmailsResponse; + return resendMapper.readValue(responseBody, CreateBatchEmailsResponse.class); } /** @@ -67,19 +67,41 @@ public CreateBatchEmailsResponse send(List emails, RequestOp String responseBody = response.getBody(); - CreateBatchEmailsResponse createBatchEmailsResponse = resendMapper.readValue(responseBody, CreateBatchEmailsResponse.class); + return resendMapper.readValue(responseBody, CreateBatchEmailsResponse.class); + } + + /** + * Sends up to 100 batch emails with permissive mode. + * + * @param emails batch emails to send. + * @return The emails ids. + * @throws ResendException If an error occurs while sending batch emails. + */ + public PermissiveBatchEmailsResponse sendWithPermissive(List emails) throws ResendException { + RequestOptions requestOptions = RequestOptions.builder() + .add("x-batch-validation", "permissive") + .build(); + + String payload = super.resendMapper.writeValue(emails); + AbstractHttpResponse response = super.httpClient.perform("/emails/batch", super.apiKey, HttpMethod.POST, payload, MediaType.get("application/json"), requestOptions); + + if (!response.isSuccessful()) { + throw new RuntimeException("Failed to send batch emails with permissive mode: " + response.getCode() + " " + response.getBody()); + } + + String responseBody = response.getBody(); - return createBatchEmailsResponse; + return resendMapper.readValue(responseBody, PermissiveBatchEmailsResponse.class); } /** * Creates and sends a batch of email messages based on the provided list of email requests. * * @param emails A list of {@link CreateEmailOptions} objects representing the email messages to be sent. - * @return A {@link CreateBatchEmailsResponse} containing information about the created batch of emails. + * @return A {@link AbstractBatchEmailsResponse} containing information about the created batch of emails. * @throws ResendException if an error occurs during the creation and sending of the emails. */ - public CreateBatchEmailsResponse create(List emails) throws ResendException { + public AbstractBatchEmailsResponse create(List emails) throws ResendException { return this.send(emails); } diff --git a/src/main/java/com/resend/services/batch/model/AbstractBatchEmailsResponse.java b/src/main/java/com/resend/services/batch/model/AbstractBatchEmailsResponse.java new file mode 100644 index 0000000..19c45a2 --- /dev/null +++ b/src/main/java/com/resend/services/batch/model/AbstractBatchEmailsResponse.java @@ -0,0 +1,47 @@ +package com.resend.services.batch.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +import java.util.List; + +/** + * Base class for batch email responses. + * The actual implementation depends on the validation mode used. + */ +@JsonSubTypes({ + @JsonSubTypes.Type(CreateBatchEmailsResponse.class), + @JsonSubTypes.Type(PermissiveBatchEmailsResponse.class) +}) +public abstract class AbstractBatchEmailsResponse { + /** + * The list of e-mail ids created. + */ + @JsonProperty("data") + protected List data; + + /** + * Default constructor. + */ + public AbstractBatchEmailsResponse() { + } + + /** + * Constructor with data. + * + * @param data A list of successfully created batch emails. + */ + public AbstractBatchEmailsResponse(final List data) { + this.data = data; + } + + /** + * Get the list of successfully created batch emails. + * + * @return A list of batch emails. + */ + public List getData() { + return data; + } + +} \ No newline at end of file diff --git a/src/main/java/com/resend/services/batch/model/BatchError.java b/src/main/java/com/resend/services/batch/model/BatchError.java new file mode 100644 index 0000000..5b88d6e --- /dev/null +++ b/src/main/java/com/resend/services/batch/model/BatchError.java @@ -0,0 +1,50 @@ +package com.resend.services.batch.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents a validation error for a batch email in permissive mode. + */ +public class BatchError { + + @JsonProperty("index") + private Integer index; + + @JsonProperty("message") + private String message; + + /** + * Default constructor. + */ + public BatchError() { + } + + /** + * Constructor with index and message. + * + * @param index The index of the email in the batch request that failed validation. + * @param message The error message identifying the validation error. + */ + public BatchError(final Integer index, final String message) { + this.index = index; + this.message = message; + } + + /** + * Get the index of the email in the batch request that failed validation. + * + * @return The index of the failed email. + */ + public Integer getIndex() { + return index; + } + + /** + * Get the error message identifying the validation error. + * + * @return The error message. + */ + public String getMessage() { + return message; + } +} \ No newline at end of file diff --git a/src/main/java/com/resend/services/batch/model/CreateBatchEmailsResponse.java b/src/main/java/com/resend/services/batch/model/CreateBatchEmailsResponse.java index 7b61743..1989f84 100644 --- a/src/main/java/com/resend/services/batch/model/CreateBatchEmailsResponse.java +++ b/src/main/java/com/resend/services/batch/model/CreateBatchEmailsResponse.java @@ -1,39 +1,27 @@ package com.resend.services.batch.model; -import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.List; /** - * Represents the response for creating batch emails. + * Response for batch emails sent in strict mode. + * In strict mode, either all emails are sent successfully or the entire batch fails. */ -public class CreateBatchEmailsResponse { - - @JsonProperty("data") - private List data; +public class CreateBatchEmailsResponse extends AbstractBatchEmailsResponse { /** * Default constructor. */ public CreateBatchEmailsResponse() { + super(); } /** - * Constructor with a list of batch emails. + * Constructor with data. * - * @param data A list of batch emails. + * @param data A list of successfully created batch emails. */ public CreateBatchEmailsResponse(final List data) { - this.data = data; - } - - /** - * Get the list of batch emails. - * - * @return A list of batch emails. - */ - public List getData() { - return data; + super(data); } -} +} \ No newline at end of file diff --git a/src/main/java/com/resend/services/batch/model/PermissiveBatchEmailsResponse.java b/src/main/java/com/resend/services/batch/model/PermissiveBatchEmailsResponse.java new file mode 100644 index 0000000..e252500 --- /dev/null +++ b/src/main/java/com/resend/services/batch/model/PermissiveBatchEmailsResponse.java @@ -0,0 +1,61 @@ +package com.resend.services.batch.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +/** + * Response for batch emails sent in permissive mode. + * In permissive mode, partial success is allowed and validation errors are returned. + */ +public class PermissiveBatchEmailsResponse extends AbstractBatchEmailsResponse { + + @JsonProperty("errors") + private List errors; + + /** + * Default constructor. + */ + public PermissiveBatchEmailsResponse() { + super(); + } + + /** + * Constructor with data and errors. + * + * @param data A list of successfully created batch emails. + * @param errors A list of validation errors. + */ + public PermissiveBatchEmailsResponse(final List data, final List errors) { + super(data); + this.errors = errors; + } + + /** + * Get the list of validation errors. + * + * @return A list of batch email errors, never null (but may be empty). + */ + public List getErrors() { + return errors; + } + + /** + * Check if the response has any validation errors. + * + * @return true if there are validation errors, false otherwise. + */ + public boolean hasErrors() { + return errors != null && !errors.isEmpty(); + } + + /** + * Get the total number of failed emails. + * + * @return The count of emails that failed validation. + */ + public int getErrorCount() { + return errors != null ? errors.size() : 0; + } + +} \ No newline at end of file diff --git a/src/test/java/com/resend/services/emails/EmailsTest.java b/src/test/java/com/resend/services/emails/EmailsTest.java index 28a8afc..9e6fddf 100644 --- a/src/test/java/com/resend/services/emails/EmailsTest.java +++ b/src/test/java/com/resend/services/emails/EmailsTest.java @@ -2,7 +2,9 @@ import com.resend.core.exception.ResendException; import com.resend.core.net.RequestOptions; import com.resend.services.batch.Batch; +import com.resend.services.batch.model.AbstractBatchEmailsResponse; import com.resend.services.batch.model.CreateBatchEmailsResponse; +import com.resend.services.batch.model.PermissiveBatchEmailsResponse; import com.resend.services.emails.model.*; import com.resend.services.util.EmailsUtil; import org.junit.jupiter.api.BeforeEach; @@ -85,6 +87,19 @@ public void testCreateBatchEmails_Success() throws ResendException { assertEquals(expectedRes.getData().size(), sendBatchEmailsResponse.getData().size()); } + @Test + public void testCreatePermissiveBatchEmails_Success() throws ResendException { + List batchEmailsRequest = EmailsUtil.createBatchEmailOptions(); + PermissiveBatchEmailsResponse expectedRes = EmailsUtil.createPermissiveBatchEmailsResponse(); + + when(batch.sendWithPermissive(batchEmailsRequest)).thenReturn(expectedRes); + + PermissiveBatchEmailsResponse sendBatchEmailsResponse = batch.sendWithPermissive(batchEmailsRequest); + + assertNotNull(sendBatchEmailsResponse); + assertEquals(expectedRes.getData().size(), sendBatchEmailsResponse.getData().size()); + } + @Test public void testCreateBatchEmailsWithIdempotencyKey_Success() throws ResendException { List batchEmailsRequest = EmailsUtil.createBatchEmailOptions(); @@ -93,7 +108,7 @@ public void testCreateBatchEmailsWithIdempotencyKey_Success() throws ResendExcep when(batch.send(batchEmailsRequest, requestOptions)).thenReturn(expectedRes); - CreateBatchEmailsResponse sendBatchEmailsResponse = batch.send(batchEmailsRequest, requestOptions); + AbstractBatchEmailsResponse sendBatchEmailsResponse = batch.send(batchEmailsRequest, requestOptions); assertNotNull(sendBatchEmailsResponse); assertEquals(expectedRes.getData().size(), sendBatchEmailsResponse.getData().size()); diff --git a/src/test/java/com/resend/services/util/EmailsUtil.java b/src/test/java/com/resend/services/util/EmailsUtil.java index ccda985..4eaa69e 100644 --- a/src/test/java/com/resend/services/util/EmailsUtil.java +++ b/src/test/java/com/resend/services/util/EmailsUtil.java @@ -2,14 +2,14 @@ import com.resend.core.net.RequestOptions; import com.resend.services.batch.model.BatchEmail; +import com.resend.services.batch.model.BatchError; import com.resend.services.batch.model.CreateBatchEmailsResponse; +import com.resend.services.batch.model.PermissiveBatchEmailsResponse; import com.resend.services.emails.model.*; import com.resend.core.net.AbstractHttpResponse; import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Map; public class EmailsUtil { @@ -71,6 +71,20 @@ public static CreateBatchEmailsResponse createBatchEmailsResponse() { return new CreateBatchEmailsResponse(Arrays.asList(new BatchEmail("123"), new BatchEmail("321"))); } + public static PermissiveBatchEmailsResponse createPermissiveBatchEmailsResponse() { + List successes = Arrays.asList( + new BatchEmail("123"), + new BatchEmail("321") + ); + + List errors = Arrays.asList( + new BatchError(456, "Invalid recipient address"), + new BatchError(789, "Domain not reachable") + ); + + return new PermissiveBatchEmailsResponse(successes, errors); + } + public static Email createTestEmail() { return new Email( "email_object", From d918611f2175597ff61138380aa0f7e6b788bbf5 Mon Sep 17 00:00:00 2001 From: Kewyn Akshlley Date: Thu, 18 Sep 2025 14:54:26 -0300 Subject: [PATCH 2/3] fix: correct return type --- src/main/java/com/resend/services/batch/Batch.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/resend/services/batch/Batch.java b/src/main/java/com/resend/services/batch/Batch.java index ab89930..ad7a806 100644 --- a/src/main/java/com/resend/services/batch/Batch.java +++ b/src/main/java/com/resend/services/batch/Batch.java @@ -98,10 +98,10 @@ public PermissiveBatchEmailsResponse sendWithPermissive(List * Creates and sends a batch of email messages based on the provided list of email requests. * * @param emails A list of {@link CreateEmailOptions} objects representing the email messages to be sent. - * @return A {@link AbstractBatchEmailsResponse} containing information about the created batch of emails. + * @return A {@link CreateBatchEmailsResponse} containing information about the created batch of emails. * @throws ResendException if an error occurs during the creation and sending of the emails. */ - public AbstractBatchEmailsResponse create(List emails) throws ResendException { + public CreateBatchEmailsResponse create(List emails) throws ResendException { return this.send(emails); } From 65954304626f668374237bf74c0ddf50722fda97 Mon Sep 17 00:00:00 2001 From: Kewyn Akshlley Date: Mon, 22 Sep 2025 12:55:48 -0300 Subject: [PATCH 3/3] fix: Remove redundant call for permissive mode --- .../java/com/resend/services/batch/Batch.java | 26 -------- .../model/AbstractBatchEmailsResponse.java | 4 +- .../model/CreateBatchEmailsResponse.java | 42 +++++++++++-- .../model/PermissiveBatchEmailsResponse.java | 61 ------------------- .../resend/services/emails/EmailsTest.java | 10 +-- .../com/resend/services/util/EmailsUtil.java | 8 +-- 6 files changed, 50 insertions(+), 101 deletions(-) delete mode 100644 src/main/java/com/resend/services/batch/model/PermissiveBatchEmailsResponse.java diff --git a/src/main/java/com/resend/services/batch/Batch.java b/src/main/java/com/resend/services/batch/Batch.java index ad7a806..2426af1 100644 --- a/src/main/java/com/resend/services/batch/Batch.java +++ b/src/main/java/com/resend/services/batch/Batch.java @@ -6,9 +6,7 @@ import com.resend.core.net.RequestOptions; import com.resend.core.service.BaseService; -import com.resend.services.batch.model.AbstractBatchEmailsResponse; import com.resend.services.batch.model.CreateBatchEmailsResponse; -import com.resend.services.batch.model.PermissiveBatchEmailsResponse; import com.resend.services.emails.model.CreateEmailOptions; import okhttp3.MediaType; @@ -70,30 +68,6 @@ public CreateBatchEmailsResponse send(List emails, RequestOp return resendMapper.readValue(responseBody, CreateBatchEmailsResponse.class); } - /** - * Sends up to 100 batch emails with permissive mode. - * - * @param emails batch emails to send. - * @return The emails ids. - * @throws ResendException If an error occurs while sending batch emails. - */ - public PermissiveBatchEmailsResponse sendWithPermissive(List emails) throws ResendException { - RequestOptions requestOptions = RequestOptions.builder() - .add("x-batch-validation", "permissive") - .build(); - - String payload = super.resendMapper.writeValue(emails); - AbstractHttpResponse response = super.httpClient.perform("/emails/batch", super.apiKey, HttpMethod.POST, payload, MediaType.get("application/json"), requestOptions); - - if (!response.isSuccessful()) { - throw new RuntimeException("Failed to send batch emails with permissive mode: " + response.getCode() + " " + response.getBody()); - } - - String responseBody = response.getBody(); - - return resendMapper.readValue(responseBody, PermissiveBatchEmailsResponse.class); - } - /** * Creates and sends a batch of email messages based on the provided list of email requests. * diff --git a/src/main/java/com/resend/services/batch/model/AbstractBatchEmailsResponse.java b/src/main/java/com/resend/services/batch/model/AbstractBatchEmailsResponse.java index 19c45a2..45f59ab 100644 --- a/src/main/java/com/resend/services/batch/model/AbstractBatchEmailsResponse.java +++ b/src/main/java/com/resend/services/batch/model/AbstractBatchEmailsResponse.java @@ -10,10 +10,10 @@ * The actual implementation depends on the validation mode used. */ @JsonSubTypes({ - @JsonSubTypes.Type(CreateBatchEmailsResponse.class), - @JsonSubTypes.Type(PermissiveBatchEmailsResponse.class) + @JsonSubTypes.Type(CreateBatchEmailsResponse.class) }) public abstract class AbstractBatchEmailsResponse { + /** * The list of e-mail ids created. */ diff --git a/src/main/java/com/resend/services/batch/model/CreateBatchEmailsResponse.java b/src/main/java/com/resend/services/batch/model/CreateBatchEmailsResponse.java index 1989f84..9f47bf3 100644 --- a/src/main/java/com/resend/services/batch/model/CreateBatchEmailsResponse.java +++ b/src/main/java/com/resend/services/batch/model/CreateBatchEmailsResponse.java @@ -1,13 +1,18 @@ package com.resend.services.batch.model; +import com.fasterxml.jackson.annotation.JsonProperty; + import java.util.List; /** - * Response for batch emails sent in strict mode. - * In strict mode, either all emails are sent successfully or the entire batch fails. + * Response for batch emails sent in permissive mode. + * In permissive mode, partial success is allowed and validation errors are returned. */ public class CreateBatchEmailsResponse extends AbstractBatchEmailsResponse { + @JsonProperty("errors") + private List errors; + /** * Default constructor. */ @@ -16,12 +21,41 @@ public CreateBatchEmailsResponse() { } /** - * Constructor with data. + * Constructor with data and errors. * * @param data A list of successfully created batch emails. + * @param errors A list of validation errors. */ - public CreateBatchEmailsResponse(final List data) { + public CreateBatchEmailsResponse(final List data, final List errors) { super(data); + this.errors = errors; + } + + /** + * Get the list of validation errors. + * + * @return A list of batch email errors, never null (but may be empty). + */ + public List getErrors() { + return errors; + } + + /** + * Check if the response has any validation errors. + * + * @return true if there are validation errors, false otherwise. + */ + public boolean hasErrors() { + return errors != null && !errors.isEmpty(); + } + + /** + * Get the total number of failed emails. + * + * @return The count of emails that failed validation. + */ + public int getErrorCount() { + return errors != null ? errors.size() : 0; } } \ No newline at end of file diff --git a/src/main/java/com/resend/services/batch/model/PermissiveBatchEmailsResponse.java b/src/main/java/com/resend/services/batch/model/PermissiveBatchEmailsResponse.java deleted file mode 100644 index e252500..0000000 --- a/src/main/java/com/resend/services/batch/model/PermissiveBatchEmailsResponse.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.resend.services.batch.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.util.List; - -/** - * Response for batch emails sent in permissive mode. - * In permissive mode, partial success is allowed and validation errors are returned. - */ -public class PermissiveBatchEmailsResponse extends AbstractBatchEmailsResponse { - - @JsonProperty("errors") - private List errors; - - /** - * Default constructor. - */ - public PermissiveBatchEmailsResponse() { - super(); - } - - /** - * Constructor with data and errors. - * - * @param data A list of successfully created batch emails. - * @param errors A list of validation errors. - */ - public PermissiveBatchEmailsResponse(final List data, final List errors) { - super(data); - this.errors = errors; - } - - /** - * Get the list of validation errors. - * - * @return A list of batch email errors, never null (but may be empty). - */ - public List getErrors() { - return errors; - } - - /** - * Check if the response has any validation errors. - * - * @return true if there are validation errors, false otherwise. - */ - public boolean hasErrors() { - return errors != null && !errors.isEmpty(); - } - - /** - * Get the total number of failed emails. - * - * @return The count of emails that failed validation. - */ - public int getErrorCount() { - return errors != null ? errors.size() : 0; - } - -} \ No newline at end of file diff --git a/src/test/java/com/resend/services/emails/EmailsTest.java b/src/test/java/com/resend/services/emails/EmailsTest.java index 9e6fddf..35a4b61 100644 --- a/src/test/java/com/resend/services/emails/EmailsTest.java +++ b/src/test/java/com/resend/services/emails/EmailsTest.java @@ -4,7 +4,6 @@ import com.resend.services.batch.Batch; import com.resend.services.batch.model.AbstractBatchEmailsResponse; import com.resend.services.batch.model.CreateBatchEmailsResponse; -import com.resend.services.batch.model.PermissiveBatchEmailsResponse; import com.resend.services.emails.model.*; import com.resend.services.util.EmailsUtil; import org.junit.jupiter.api.BeforeEach; @@ -89,12 +88,15 @@ public void testCreateBatchEmails_Success() throws ResendException { @Test public void testCreatePermissiveBatchEmails_Success() throws ResendException { + RequestOptions options = RequestOptions.builder() + .add("x-batch-validation", "permissive").build(); + List batchEmailsRequest = EmailsUtil.createBatchEmailOptions(); - PermissiveBatchEmailsResponse expectedRes = EmailsUtil.createPermissiveBatchEmailsResponse(); + CreateBatchEmailsResponse expectedRes = EmailsUtil.createPermissiveBatchEmailsResponse(); - when(batch.sendWithPermissive(batchEmailsRequest)).thenReturn(expectedRes); + when(batch.send(batchEmailsRequest, options)).thenReturn(expectedRes); - PermissiveBatchEmailsResponse sendBatchEmailsResponse = batch.sendWithPermissive(batchEmailsRequest); + CreateBatchEmailsResponse sendBatchEmailsResponse = batch.send(batchEmailsRequest, options); assertNotNull(sendBatchEmailsResponse); assertEquals(expectedRes.getData().size(), sendBatchEmailsResponse.getData().size()); diff --git a/src/test/java/com/resend/services/util/EmailsUtil.java b/src/test/java/com/resend/services/util/EmailsUtil.java index 4eaa69e..282238a 100644 --- a/src/test/java/com/resend/services/util/EmailsUtil.java +++ b/src/test/java/com/resend/services/util/EmailsUtil.java @@ -4,10 +4,10 @@ import com.resend.services.batch.model.BatchEmail; import com.resend.services.batch.model.BatchError; import com.resend.services.batch.model.CreateBatchEmailsResponse; -import com.resend.services.batch.model.PermissiveBatchEmailsResponse; import com.resend.services.emails.model.*; import com.resend.core.net.AbstractHttpResponse; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -68,10 +68,10 @@ public static List createBatchEmailOptions() { } public static CreateBatchEmailsResponse createBatchEmailsResponse() { - return new CreateBatchEmailsResponse(Arrays.asList(new BatchEmail("123"), new BatchEmail("321"))); + return new CreateBatchEmailsResponse(Arrays.asList(new BatchEmail("123"), new BatchEmail("321")), new ArrayList<>()); } - public static PermissiveBatchEmailsResponse createPermissiveBatchEmailsResponse() { + public static CreateBatchEmailsResponse createPermissiveBatchEmailsResponse() { List successes = Arrays.asList( new BatchEmail("123"), new BatchEmail("321") @@ -82,7 +82,7 @@ public static PermissiveBatchEmailsResponse createPermissiveBatchEmailsResponse( new BatchError(789, "Domain not reachable") ); - return new PermissiveBatchEmailsResponse(successes, errors); + return new CreateBatchEmailsResponse(successes, errors); } public static Email createTestEmail() {