From 67dbb6dc0cf3bc058ca90504ae02f0ead3a8d979 Mon Sep 17 00:00:00 2001 From: Tess Stoddard Date: Tue, 7 Apr 2026 14:06:59 -0600 Subject: [PATCH] feat!: add managed card alert endpoints --- .../account/AccountAlertBaseAccessor.java | 12 +- .../ManagedCardAlertBaseAccessor.java | 84 +++++++++++++ .../managed_card/ManagedCardBaseAccessor.java | 24 ++++ .../mx/path/model/mdx/model/Resources.java | 16 +-- .../AccountAlert.java => alerts/Alert.java} | 4 +- .../{account => }/alerts/AlertCriteria.java | 2 +- .../{account => }/alerts/DeliveryMethod.java | 2 +- .../controller/AccountAlertsController.java | 16 +-- .../ManagedCardAlertsController.java | 49 ++++++++ .../AccountAlertsControllerTest.groovy | 20 ++- .../ManagedCardAlertsControllerTest.groovy | 116 ++++++++++++++++++ 11 files changed, 308 insertions(+), 37 deletions(-) create mode 100644 mdx-models/src/main/java/com/mx/path/model/mdx/accessor/managed_card/ManagedCardAlertBaseAccessor.java rename mdx-models/src/main/java/com/mx/path/model/mdx/model/{account/alerts/AccountAlert.java => alerts/Alert.java} (79%) rename mdx-models/src/main/java/com/mx/path/model/mdx/model/{account => }/alerts/AlertCriteria.java (87%) rename mdx-models/src/main/java/com/mx/path/model/mdx/model/{account => }/alerts/DeliveryMethod.java (85%) create mode 100644 mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/ManagedCardAlertsController.java create mode 100644 mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/ManagedCardAlertsControllerTest.groovy diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/account/AccountAlertBaseAccessor.java b/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/account/AccountAlertBaseAccessor.java index 605c2853..90f1b73a 100644 --- a/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/account/AccountAlertBaseAccessor.java +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/account/AccountAlertBaseAccessor.java @@ -9,14 +9,14 @@ import com.mx.path.gateway.accessor.AccessorResponse; import com.mx.path.model.mdx.model.MdxList; import com.mx.path.model.mdx.model.account.Account; -import com.mx.path.model.mdx.model.account.alerts.AccountAlert; -import com.mx.path.model.mdx.model.account.alerts.DeliveryMethod; +import com.mx.path.model.mdx.model.alerts.Alert; +import com.mx.path.model.mdx.model.alerts.DeliveryMethod; /** * Accessor for account alert operations */ @GatewayClass -@API(description = "Access to account alerts", specificationUrl = "https://developer.mx.com/drafts/mdx/accounts/#accounts-alerts") +@API(description = "Access to account alerts", specificationUrl = "https://developer.mx.com/drafts/mdx/accounts/#alerts") public abstract class AccountAlertBaseAccessor extends Accessor { public AccountAlertBaseAccessor() { @@ -40,7 +40,7 @@ public AccountAlertBaseAccessor(AccessorConfiguration configuration) { */ @GatewayAPI @API(description = "Get account alert") - public AccessorResponse get(String accountId, String alertId) { + public AccessorResponse get(String accountId, String alertId) { throw new AccessorMethodNotImplementedException(); } @@ -52,7 +52,7 @@ public AccessorResponse get(String accountId, String alertId) { */ @GatewayAPI @API(description = "List account alerts") - public AccessorResponse> list(String accountId) { + public AccessorResponse> list(String accountId) { throw new AccessorMethodNotImplementedException(); } @@ -65,7 +65,7 @@ public AccessorResponse> list(String accountId) { */ @GatewayAPI @API(description = "Update an account alert") - public AccessorResponse update(String accountId, AccountAlert accountAlert) { + public AccessorResponse update(String accountId, Alert accountAlert) { throw new AccessorMethodNotImplementedException(); } diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/managed_card/ManagedCardAlertBaseAccessor.java b/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/managed_card/ManagedCardAlertBaseAccessor.java new file mode 100644 index 00000000..b044f573 --- /dev/null +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/managed_card/ManagedCardAlertBaseAccessor.java @@ -0,0 +1,84 @@ +package com.mx.path.model.mdx.accessor.managed_card; + +import com.mx.path.core.common.accessor.API; +import com.mx.path.core.common.accessor.AccessorMethodNotImplementedException; +import com.mx.path.core.common.gateway.GatewayAPI; +import com.mx.path.core.common.gateway.GatewayClass; +import com.mx.path.gateway.accessor.Accessor; +import com.mx.path.gateway.accessor.AccessorResponse; +import com.mx.path.model.mdx.model.MdxList; +import com.mx.path.model.mdx.model.alerts.Alert; +import com.mx.path.model.mdx.model.alerts.DeliveryMethod; +import com.mx.path.model.mdx.model.managed_cards.ManagedCard; + +/** + * Accessor for managed card alert operations + */ +@GatewayClass +@API(description = "Access to managed card alerts", specificationUrl = "https://developer.mx.com/drafts/mdx/managed_cards/#alerts") +public abstract class ManagedCardAlertBaseAccessor extends Accessor { + public ManagedCardAlertBaseAccessor() { + } + + /** + * Get a managed card alert + * + * @param cardId + * @param alertId + * @return + */ + @GatewayAPI + @API(description = "Get managed card alert") + public AccessorResponse get(String cardId, String alertId) { + throw new AccessorMethodNotImplementedException(); + } + + /** + * List managed card alerts + * + * @param cardId + * @return + */ + @GatewayAPI + @API(description = "List managed card alerts") + public AccessorResponse> list(String cardId) { + throw new AccessorMethodNotImplementedException(); + } + + /** + * Update a managed card alert + * + * @param cardId + * @param alert + * @return + */ + @GatewayAPI + @API(description = "Update a managed card alert") + public AccessorResponse update(String cardId, Alert alert) { + throw new AccessorMethodNotImplementedException(); + } + + /** + * List delivery methods + * + * @param cardId + * @param alertId + * @return + */ + @GatewayAPI + @API(description = "List delivery methods") + public AccessorResponse> deliveryMethods(String cardId, String alertId) { + throw new AccessorMethodNotImplementedException(); + } + + /** + * List managed cards eligible for alerts + * + * @return + */ + @GatewayAPI + @API(description = "List managed cards eligible for alerts") + public AccessorResponse> cards() { + throw new AccessorMethodNotImplementedException(); + } +} diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/managed_card/ManagedCardBaseAccessor.java b/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/managed_card/ManagedCardBaseAccessor.java index faec0d80..674f5a69 100644 --- a/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/managed_card/ManagedCardBaseAccessor.java +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/accessor/managed_card/ManagedCardBaseAccessor.java @@ -1,5 +1,8 @@ package com.mx.path.model.mdx.accessor.managed_card; +import lombok.AccessLevel; +import lombok.Getter; + import com.mx.path.core.common.accessor.API; import com.mx.path.core.common.accessor.AccessorMethodNotImplementedException; import com.mx.path.core.common.gateway.GatewayAPI; @@ -19,6 +22,9 @@ @GatewayClass @API(specificationUrl = "https://developer.mx.com/drafts/mdx/managed_cards/#mdx-managed-cards") public abstract class ManagedCardBaseAccessor extends Accessor { + @GatewayAPI + @Getter(AccessLevel.PROTECTED) + private ManagedCardAlertBaseAccessor alerts; public ManagedCardBaseAccessor() { } @@ -170,4 +176,22 @@ public AccessorResponse update(String id, ManagedCard card) { public AccessorResponse updateNotificationPreferences(String id, NotificationPreferences notificationPreferences) { throw new AccessorMethodNotImplementedException(); } + + /** + * Accessor for managed card alerts + * + * @return accessor + */ + @API + public ManagedCardAlertBaseAccessor alerts() { + return alerts; + } + + /** + * Sets managed card alert accessor + * @param alerts + */ + public void setAlerts(ManagedCardAlertBaseAccessor alerts) { + this.alerts = alerts; + } } diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/model/Resources.java b/mdx-models/src/main/java/com/mx/path/model/mdx/model/Resources.java index 84c24572..92651b1f 100644 --- a/mdx-models/src/main/java/com/mx/path/model/mdx/model/Resources.java +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/model/Resources.java @@ -18,11 +18,11 @@ import com.mx.path.model.mdx.model.account.StopPaymentReason; import com.mx.path.model.mdx.model.account.Transaction; import com.mx.path.model.mdx.model.account.TransactionsPage; -import com.mx.path.model.mdx.model.account.alerts.AccountAlert; -import com.mx.path.model.mdx.model.account.alerts.DeliveryMethod; import com.mx.path.model.mdx.model.ach_transfer.AchAccount; import com.mx.path.model.mdx.model.ach_transfer.AchScheduledTransfer; import com.mx.path.model.mdx.model.ach_transfer.AchTransfer; +import com.mx.path.model.mdx.model.alerts.Alert; +import com.mx.path.model.mdx.model.alerts.DeliveryMethod; import com.mx.path.model.mdx.model.authorization.Authorization; import com.mx.path.model.mdx.model.check.CheckImage; import com.mx.path.model.mdx.model.credit_report.CreditReport; @@ -285,8 +285,8 @@ public static void registerResources(GsonBuilder builder) { registerPaymentsModels(builder); // Register multistage transfer models registerMultistageTransferModels(builder); - // Register account alert models - registerAccountAlertModels(builder); + // Register alert models + registerAlertModels(builder); // Register product models registerProductModels(builder); // Register P2P transfer models @@ -446,10 +446,10 @@ private static void registerMultistageTransferModels(GsonBuilder builder) { }.getType(), new ModelWrappableSerializer("repayments")); } - private static void registerAccountAlertModels(GsonBuilder builder) { - // AccountAlert - builder.registerTypeAdapter(AccountAlert.class, new ModelWrappableSerializer("alert")); - builder.registerTypeAdapter(new TypeToken>() { + private static void registerAlertModels(GsonBuilder builder) { + // Alert + builder.registerTypeAdapter(Alert.class, new ModelWrappableSerializer("alert")); + builder.registerTypeAdapter(new TypeToken>() { }.getType(), new ModelWrappableSerializer("alerts")); // DeliveryMethod builder.registerTypeAdapter(new TypeToken>() { diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/model/account/alerts/AccountAlert.java b/mdx-models/src/main/java/com/mx/path/model/mdx/model/alerts/Alert.java similarity index 79% rename from mdx-models/src/main/java/com/mx/path/model/mdx/model/account/alerts/AccountAlert.java rename to mdx-models/src/main/java/com/mx/path/model/mdx/model/alerts/Alert.java index 3e27905e..f76a6db2 100644 --- a/mdx-models/src/main/java/com/mx/path/model/mdx/model/account/alerts/AccountAlert.java +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/model/alerts/Alert.java @@ -1,4 +1,4 @@ -package com.mx.path.model.mdx.model.account.alerts; +package com.mx.path.model.mdx.model.alerts; import java.util.List; @@ -10,7 +10,7 @@ @EqualsAndHashCode(callSuper = true) @Data -public class AccountAlert extends MdxBase { +public class Alert extends MdxBase { private List challenges; private List criteria; private List deliveryMethodIds; diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/model/account/alerts/AlertCriteria.java b/mdx-models/src/main/java/com/mx/path/model/mdx/model/alerts/AlertCriteria.java similarity index 87% rename from mdx-models/src/main/java/com/mx/path/model/mdx/model/account/alerts/AlertCriteria.java rename to mdx-models/src/main/java/com/mx/path/model/mdx/model/alerts/AlertCriteria.java index d9d9f2fd..23977fa1 100644 --- a/mdx-models/src/main/java/com/mx/path/model/mdx/model/account/alerts/AlertCriteria.java +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/model/alerts/AlertCriteria.java @@ -1,4 +1,4 @@ -package com.mx.path.model.mdx.model.account.alerts; +package com.mx.path.model.mdx.model.alerts; import lombok.Data; import lombok.EqualsAndHashCode; diff --git a/mdx-models/src/main/java/com/mx/path/model/mdx/model/account/alerts/DeliveryMethod.java b/mdx-models/src/main/java/com/mx/path/model/mdx/model/alerts/DeliveryMethod.java similarity index 85% rename from mdx-models/src/main/java/com/mx/path/model/mdx/model/account/alerts/DeliveryMethod.java rename to mdx-models/src/main/java/com/mx/path/model/mdx/model/alerts/DeliveryMethod.java index ab75f4c8..ce2ba5e8 100644 --- a/mdx-models/src/main/java/com/mx/path/model/mdx/model/account/alerts/DeliveryMethod.java +++ b/mdx-models/src/main/java/com/mx/path/model/mdx/model/alerts/DeliveryMethod.java @@ -1,4 +1,4 @@ -package com.mx.path.model.mdx.model.account.alerts; +package com.mx.path.model.mdx.model.alerts; import lombok.Data; import lombok.EqualsAndHashCode; diff --git a/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/AccountAlertsController.java b/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/AccountAlertsController.java index 3005eeed..0f23df3c 100644 --- a/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/AccountAlertsController.java +++ b/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/AccountAlertsController.java @@ -3,8 +3,8 @@ import com.mx.path.gateway.accessor.AccessorResponse; import com.mx.path.model.mdx.model.MdxList; import com.mx.path.model.mdx.model.account.Account; -import com.mx.path.model.mdx.model.account.alerts.AccountAlert; -import com.mx.path.model.mdx.model.account.alerts.DeliveryMethod; +import com.mx.path.model.mdx.model.alerts.Alert; +import com.mx.path.model.mdx.model.alerts.DeliveryMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -18,23 +18,23 @@ @RequestMapping(value = "{clientId}") public class AccountAlertsController extends BaseController { @RequestMapping(value = "/users/{userId}/accounts/{accountId}/alerts/{id}", method = RequestMethod.GET) - public final ResponseEntity getAlert(@PathVariable("accountId") String accountId, @PathVariable("id") String alertId) { + public final ResponseEntity getAlert(@PathVariable("accountId") String accountId, @PathVariable("id") String alertId) { ensureFeature("accounts"); - AccessorResponse response = gateway().accounts().accountAlerts().get(accountId, alertId); + AccessorResponse response = gateway().accounts().accountAlerts().get(accountId, alertId); return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK); } @RequestMapping(value = "/users/{userId}/accounts/{accountId}/alerts", method = RequestMethod.GET, produces = BaseController.MDX_MEDIA) - public final ResponseEntity> getAlertList(@PathVariable("accountId") String accountId) { + public final ResponseEntity> getAlertList(@PathVariable("accountId") String accountId) { ensureFeature("accounts"); - AccessorResponse> response = gateway().accounts().accountAlerts().list(accountId); + AccessorResponse> response = gateway().accounts().accountAlerts().list(accountId); return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK); } @RequestMapping(value = "/users/{userId}/accounts/{accountId}/alerts/{id}", method = RequestMethod.PUT, consumes = BaseController.MDX_MEDIA) - public final ResponseEntity updateAlert(@PathVariable("accountId") String accountId, @RequestBody AccountAlert accountAlert) { + public final ResponseEntity updateAlert(@PathVariable("accountId") String accountId, @RequestBody Alert accountAlert) { ensureFeature("accounts"); - AccessorResponse response = gateway().accounts().accountAlerts().update(accountId, accountAlert); + AccessorResponse response = gateway().accounts().accountAlerts().update(accountId, accountAlert); return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK); } diff --git a/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/ManagedCardAlertsController.java b/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/ManagedCardAlertsController.java new file mode 100644 index 00000000..dc70a877 --- /dev/null +++ b/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/ManagedCardAlertsController.java @@ -0,0 +1,49 @@ +package com.mx.path.model.mdx.web.controller; + +import com.mx.path.gateway.accessor.AccessorResponse; +import com.mx.path.model.mdx.model.MdxList; +import com.mx.path.model.mdx.model.alerts.Alert; +import com.mx.path.model.mdx.model.alerts.DeliveryMethod; +import com.mx.path.model.mdx.model.managed_cards.ManagedCard; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping(value = "{clientId}") +public class ManagedCardAlertsController extends BaseController { + @RequestMapping(value = "/users/{userId}/managed_cards/{cardId}/alerts/{id}", method = RequestMethod.GET) + public final ResponseEntity getAlert(@PathVariable("cardId") String cardId, @PathVariable("id") String alertId) { + AccessorResponse response = gateway().managedCards().alerts().get(cardId, alertId); + return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK); + } + + @RequestMapping(value = "/users/{userId}/managed_cards/{cardId}/alerts", method = RequestMethod.GET, produces = BaseController.MDX_MEDIA) + public final ResponseEntity> getAlertList(@PathVariable("cardId") String cardId) { + AccessorResponse> response = gateway().managedCards().alerts().list(cardId); + return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK); + } + + @RequestMapping(value = "/users/{userId}/managed_cards/{cardId}/alerts/{id}", method = RequestMethod.PUT, consumes = BaseController.MDX_MEDIA) + public final ResponseEntity updateAlert(@PathVariable("cardId") String cardId, @RequestBody Alert alert) { + AccessorResponse response = gateway().managedCards().alerts().update(cardId, alert); + return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK); + } + + @RequestMapping(value = "/users/{userId}/managed_cards/{cardId}/alerts/{id}/delivery_methods", method = RequestMethod.GET, produces = BaseController.MDX_MEDIA) + public final ResponseEntity> getDeliveryMethods(@PathVariable("cardId") String cardId, @PathVariable("id") String alertId) { + AccessorResponse> response = gateway().managedCards().alerts().deliveryMethods(cardId, alertId); + return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK); + } + + @RequestMapping(value = "/users/{userId}/managed_cards/alert", method = RequestMethod.GET, produces = BaseController.MDX_MEDIA) + public final ResponseEntity> getCards() { + AccessorResponse> response = gateway().managedCards().alerts().cards(); + return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK); + } +} diff --git a/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/AccountAlertsControllerTest.groovy b/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/AccountAlertsControllerTest.groovy index c873d9ae..9d99aa4a 100644 --- a/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/AccountAlertsControllerTest.groovy +++ b/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/AccountAlertsControllerTest.groovy @@ -10,10 +10,8 @@ import com.mx.path.gateway.api.account.AccountAlertGateway import com.mx.path.gateway.api.account.AccountGateway import com.mx.path.model.mdx.model.MdxList import com.mx.path.model.mdx.model.account.Account -import com.mx.path.model.mdx.model.account.alerts.AccountAlert -import com.mx.path.model.mdx.model.account.alerts.DeliveryMethod - -import org.springframework.http.HttpStatus +import com.mx.path.model.mdx.model.alerts.Alert +import com.mx.path.model.mdx.model.alerts.DeliveryMethod import spock.lang.Specification @@ -43,10 +41,10 @@ class AccountAlertsControllerTest extends Specification { given: def accountId = "account-id" def alertId = "alert-id" - def accountAlert = new AccountAlert() + def accountAlert = new Alert() when: - doReturn(new AccessorResponse().withResult(accountAlert)).when(accountAlertGateway).get(accountId, alertId) + doReturn(new AccessorResponse().withResult(accountAlert)).when(accountAlertGateway).get(accountId, alertId) def response = subject.getAlert(accountId, alertId) then: @@ -57,11 +55,11 @@ class AccountAlertsControllerTest extends Specification { def "getAlertList interacts with gateway"() { given: def accountId = "account-id" - def alerts = new MdxList() - alerts.add(new AccountAlert()) + def alerts = new MdxList() + alerts.add(new Alert()) when: - doReturn(new AccessorResponse>().withResult(alerts)).when(accountAlertGateway).list(accountId) + doReturn(new AccessorResponse>().withResult(alerts)).when(accountAlertGateway).list(accountId) def response = subject.getAlertList(accountId) then: @@ -72,10 +70,10 @@ class AccountAlertsControllerTest extends Specification { def "updateAlert interacts with gateway"() { given: def accountId = "account-id" - def accountAlert = new AccountAlert() + def accountAlert = new Alert() when: - doReturn(new AccessorResponse().withResult(accountAlert)).when(accountAlertGateway).update(accountId, accountAlert) + doReturn(new AccessorResponse().withResult(accountAlert)).when(accountAlertGateway).update(accountId, accountAlert) def response = subject.updateAlert(accountId, accountAlert) then: diff --git a/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/ManagedCardAlertsControllerTest.groovy b/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/ManagedCardAlertsControllerTest.groovy new file mode 100644 index 00000000..7f33551a --- /dev/null +++ b/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/ManagedCardAlertsControllerTest.groovy @@ -0,0 +1,116 @@ +package com.mx.path.model.mdx.web.controller + +import static org.mockito.Mockito.doReturn +import static org.mockito.Mockito.spy +import static org.mockito.Mockito.verify + +import com.mx.path.gateway.accessor.AccessorResponse +import com.mx.path.gateway.api.Gateway +import com.mx.path.gateway.api.managed_card.ManagedCardAlertGateway +import com.mx.path.gateway.api.managed_card.ManagedCardGateway +import com.mx.path.model.mdx.model.MdxList +import com.mx.path.model.mdx.model.alerts.Alert +import com.mx.path.model.mdx.model.alerts.DeliveryMethod +import com.mx.path.model.mdx.model.managed_cards.ManagedCard + +import spock.lang.Specification + +class ManagedCardAlertsControllerTest extends Specification { + ManagedCardAlertsController subject + Gateway gateway + ManagedCardAlertGateway alertGateway + + void setup() { + subject = new ManagedCardAlertsController() + alertGateway = spy(ManagedCardAlertGateway.builder().build()) + + gateway = Gateway.builder() + .managedCards(ManagedCardGateway.builder() + .alerts(alertGateway) + .build()) + .build() + + BaseController.setGateway(gateway) + } + + def cleanup() { + BaseController.clearGateway() + } + + def "getAlert interacts with gateway"() { + given: + def cardId = "card-id" + def alertId = "alert-id" + def alert = new Alert() + + when: + doReturn(new AccessorResponse().withResult(alert)).when(alertGateway).get(cardId, alertId) + def response = subject.getAlert(cardId, alertId) + + then: + verify(alertGateway).get(cardId, alertId) || true + response.body == alert + } + + def "getAlertList interacts with gateway"() { + given: + def cardId = "card-id" + def alerts = new MdxList().tap { + add(new Alert()) + } + + when: + doReturn(new AccessorResponse>().withResult(alerts)).when(alertGateway).list(cardId) + def response = subject.getAlertList(cardId) + + then: + verify(alertGateway).list(cardId) || true + response.body == alerts + } + + def "updateAlert interacts with gateway"() { + given: + def cardId = "card-id" + def alert = new Alert() + + when: + doReturn(new AccessorResponse().withResult(alert)).when(alertGateway).update(cardId, alert) + def response = subject.updateAlert(cardId, alert) + + then: + verify(alertGateway).update(cardId, alert) || true + response.body == alert + } + + def "getDeliveryMethods interacts with gateway"() { + given: + def cardId = "card-id" + def alertId = "alert-id" + def deliveryMethods = new MdxList().tap { + add(new DeliveryMethod()) + } + + when: + doReturn(new AccessorResponse>().withResult(deliveryMethods)).when(alertGateway).deliveryMethods(cardId, alertId) + def response = subject.getDeliveryMethods(cardId, alertId) + + then: + verify(alertGateway).deliveryMethods(cardId, alertId) || true + response.body == deliveryMethods + } + + def "getCards interacts with gateway"() { + given: + def cards = new MdxList().tap { + add(new ManagedCard()) + } + + when: + doReturn(new AccessorResponse>().withResult(cards)).when(alertGateway).cards() + def response = subject.getCards() + + then: + verify(alertGateway).cards() || true + response.body == cards + } +}