Skip to content

Commit

Permalink
fix: return 202 when challenge provided when fetching/updating paymen…
Browse files Browse the repository at this point in the history
…t settings
  • Loading branch information
cmena-mx authored and ndasari2 committed Oct 21, 2023
1 parent 8d7a5a4 commit 6cced96
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,22 @@ public final ResponseEntity<Enrollment> setPaymentEnrollment(@RequestBody Enroll
@RequestMapping(value = "/payments/settings", method = RequestMethod.GET, consumes = BaseController.MDX_MEDIA)
public final ResponseEntity<Settings> getPaymentSettings() {
AccessorResponse<Settings> response = gateway().payments().settings();
Settings result = response.getResult();
// Return 202 returning challenge questions
if (result != null && result.getChallenges() != null && result.getChallenges().size() > 0) {
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.ACCEPTED);
}
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
}

@RequestMapping(value = "/payments/settings", method = RequestMethod.PUT, consumes = BaseController.MDX_MEDIA)
public final ResponseEntity<Settings> setPaymentSettings(@RequestBody Settings settingsRequest) {
AccessorResponse<Settings> response = gateway().payments().updateSettings(settingsRequest);
Settings result = response.getResult();
// Return 202 returning challenge questions
if (result != null && result.getChallenges() != null && result.getChallenges().size() > 0) {
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.ACCEPTED);
}
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import com.mx.path.gateway.api.Gateway
import com.mx.path.gateway.api.payment.PaymentGateway
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.payment.Payment
import com.mx.path.model.mdx.model.payment.Settings

import org.mockito.Mockito
import org.springframework.http.HttpStatus
Expand Down Expand Up @@ -124,4 +126,76 @@ class PaymentsControllerTest extends Specification {
response.getBody() == accounts
verify(paymentGateway).accounts() || true
}

def "getPaymentSettings interacts with gateway - 202"() {
given:
BaseController.setGateway(gateway)

def settings = new Settings().tap {
setChallenges(new ArrayList<Challenge>().tap {
add(new Challenge())
})
}

when:
Mockito.doReturn(new AccessorResponse<Settings>().withResult(settings)).when(paymentGateway).settings()
def response = subject.getPaymentSettings()

then:
HttpStatus.ACCEPTED == response.getStatusCode()
response.getBody() == settings
verify(paymentGateway).settings() || true
}

def "getPaymentSettings interacts with gateway - 200"() {
given:
BaseController.setGateway(gateway)

def settings = new Settings()

when:
Mockito.doReturn(new AccessorResponse<Settings>().withResult(settings)).when(paymentGateway).settings()
def response = subject.getPaymentSettings()

then:
HttpStatus.OK == response.getStatusCode()
response.getBody() == settings
verify(paymentGateway).settings() || true
}

def "setPaymentSettings interacts with gateway - 202"() {
given:
BaseController.setGateway(gateway)

def settings = new Settings().tap {
setChallenges(new ArrayList<Challenge>().tap {
add(new Challenge())
})
}

when:
Mockito.doReturn(new AccessorResponse<Settings>().withResult(settings)).when(paymentGateway).updateSettings(settings)
def response = subject.setPaymentSettings(settings)

then:
HttpStatus.ACCEPTED == response.getStatusCode()
response.getBody() == settings
verify(paymentGateway).updateSettings(settings) || true
}

def "setPaymentSettings interacts with gateway - 200"() {
given:
BaseController.setGateway(gateway)

def settings = new Settings()

when:
Mockito.doReturn(new AccessorResponse<Settings>().withResult(settings)).when(paymentGateway).updateSettings(settings)
def response = subject.setPaymentSettings(settings)

then:
HttpStatus.OK == response.getStatusCode()
response.getBody() == settings
verify(paymentGateway).updateSettings(settings) || true
}
}

0 comments on commit 6cced96

Please sign in to comment.