Skip to content

Commit

Permalink
feat: returning 202 when challenges present for post rdc
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin-hurst committed Sep 24, 2024
1 parent 557893d commit da34f74
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ public RemoteDepositsController() {
@RequestMapping(value = "/users/{user_id}/remote_deposits", method = RequestMethod.POST, consumes = MDX_MEDIA)
public final ResponseEntity<RemoteDeposit> createRemoteDeposit(@RequestBody RemoteDeposit remoteDepositRequest) {
AccessorResponse<RemoteDeposit> 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down Expand Up @@ -64,6 +67,24 @@ class RemoteDepositsControllerTest extends Specification {
response.getBody() == list
}

def "createRemoteDeposit - 202"() {
given:
BaseController.setGateway(gateway)

def mockResponse = new AccessorResponse<RemoteDeposit>().withResult(new RemoteDeposit().tap {
setChallenges(new MdxList<Challenge>().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)
Expand Down

0 comments on commit da34f74

Please sign in to comment.