diff --git a/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/RemoteDepositsController.java b/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/RemoteDepositsController.java index bb9491cd..58244088 100644 --- a/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/RemoteDepositsController.java +++ b/mdx-web/src/main/java/com/mx/path/model/mdx/web/controller/RemoteDepositsController.java @@ -24,7 +24,12 @@ public RemoteDepositsController() { @RequestMapping(value = "/users/{user_id}/remote_deposits", method = RequestMethod.POST, consumes = MDX_MEDIA) public final ResponseEntity createRemoteDeposit(@RequestBody RemoteDeposit remoteDepositRequest) { AccessorResponse response = gateway().remoteDeposits().create(remoteDepositRequest); - return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK); + RemoteDeposit result = response.getResult(); + HttpStatus status = HttpStatus.OK; + if (result != null && result.getChallenges() != null && !result.getChallenges().isEmpty()) { + status = HttpStatus.ACCEPTED; + } + return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), status); } @RequestMapping(value = "/users/{userId}/remote_deposits/{id}", method = RequestMethod.GET) diff --git a/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/RemoteDepositsControllerTest.groovy b/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/RemoteDepositsControllerTest.groovy index d4e2348b..25991606 100644 --- a/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/RemoteDepositsControllerTest.groovy +++ b/mdx-web/src/test/groovy/com/mx/path/model/mdx/web/controller/RemoteDepositsControllerTest.groovy @@ -1,5 +1,7 @@ package com.mx.path.model.mdx.web.controller +import static org.mockito.ArgumentMatchers.any +import static org.mockito.Mockito.doReturn import static org.mockito.Mockito.spy import static org.mockito.Mockito.verify @@ -8,6 +10,7 @@ import com.mx.path.gateway.api.Gateway import com.mx.path.gateway.api.remote_deposit.RemoteDepositGateway import com.mx.path.model.mdx.model.MdxList import com.mx.path.model.mdx.model.account.Account +import com.mx.path.model.mdx.model.challenges.Challenge import com.mx.path.model.mdx.model.remote_deposit.Limits import com.mx.path.model.mdx.model.remote_deposit.RemoteDeposit @@ -64,6 +67,24 @@ class RemoteDepositsControllerTest extends Specification { response.getBody() == list } + def "createRemoteDeposit - 202"() { + given: + BaseController.setGateway(gateway) + + def mockResponse = new AccessorResponse().withResult(new RemoteDeposit().tap { + setChallenges(new MdxList().tap { add(new Challenge()) }) + }) + doReturn(mockResponse).when(remoteDepositGateway).create(any()) + + when: + def response = subject.createRemoteDeposit(new RemoteDeposit()) + + then: + response.body == mockResponse.result + response.body.wrapped + response.statusCode == HttpStatus.ACCEPTED + } + def "createRemoteDeposit interacts with gateway"() { given: BaseController.setGateway(gateway)