diff --git a/src/main/java/com/resend/services/automations/model/ListAutomationRunsParams.java b/src/main/java/com/resend/services/automations/model/ListAutomationRunsParams.java index 87b85ea..daf4d76 100644 --- a/src/main/java/com/resend/services/automations/model/ListAutomationRunsParams.java +++ b/src/main/java/com/resend/services/automations/model/ListAutomationRunsParams.java @@ -1,6 +1,9 @@ package com.resend.services.automations.model; +import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -9,7 +12,7 @@ */ public class ListAutomationRunsParams { - private final RunStatus status; + private final List status; private final Integer limit; private final String after; private final String before; @@ -22,11 +25,11 @@ public ListAutomationRunsParams(Builder builder) { } /** - * Retrieves the status filter. + * Retrieves the status filters. * - * @return The run status filter. + * @return The list of run status filters. */ - public RunStatus getStatus() { + public List getStatus() { return status; } @@ -65,8 +68,11 @@ public String getBefore() { public String toQueryString() { Map queryParams = new LinkedHashMap<>(); - if (status != null) { - queryParams.put("status", status.getValue()); + if (status != null && !status.isEmpty()) { + String statusValue = status.stream() + .map(RunStatus::getValue) + .collect(Collectors.joining(",")); + queryParams.put("status", statusValue); } if (limit != null) { queryParams.put("limit", limit.toString()); @@ -97,13 +103,36 @@ public static Builder builder() { } public static class Builder { - private RunStatus status; + private List status; private Integer limit; private String after; private String before; - public Builder status(RunStatus status) { - this.status = status; + /** + * Adds status filters. + * + * @param status The run statuses to filter by. + * @return This builder instance. + */ + public Builder status(RunStatus... status) { + if (this.status == null) { + this.status = new ArrayList<>(); + } + this.status.addAll(Arrays.asList(status)); + return this; + } + + /** + * Adds status filters from a list. + * + * @param status The list of run statuses to filter by. + * @return This builder instance. + */ + public Builder status(List status) { + if (this.status == null) { + this.status = new ArrayList<>(); + } + this.status.addAll(status); return this; } diff --git a/src/test/java/com/resend/services/automations/AutomationsTest.java b/src/test/java/com/resend/services/automations/AutomationsTest.java index 6e5340c..62eaa57 100644 --- a/src/test/java/com/resend/services/automations/AutomationsTest.java +++ b/src/test/java/com/resend/services/automations/AutomationsTest.java @@ -155,6 +155,26 @@ public void testListAutomationRunsWithParams_Success() throws ResendException { verify(automations, times(1)).listRuns(automationId, params); } + @Test + public void testListAutomationRunsWithMultipleStatuses_Success() throws ResendException { + String automationId = "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"; + ListAutomationRunsParams params = ListAutomationRunsParams.builder() + .status(RunStatus.RUNNING, RunStatus.COMPLETED) + .limit(10) + .build(); + + ListAutomationRunsResponseSuccess expectedResponse = AutomationsUtil.listAutomationRunsResponse(); + + when(automations.listRuns(automationId, params)).thenReturn(expectedResponse); + + ListAutomationRunsResponseSuccess response = automations.listRuns(automationId, params); + + assertNotNull(response); + assertEquals(2, params.getStatus().size()); + assertEquals("?status=running,completed&limit=10", params.toQueryString()); + verify(automations, times(1)).listRuns(automationId, params); + } + @Test public void testGetAutomationRun_Success() throws ResendException { GetAutomationRunOptions options = GetAutomationRunOptions.builder()