Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check for challenges in create account controller #104

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ public final ResponseEntity<?> deleteAccount(@PathVariable("id") String accountI
@RequestMapping(value = "/users/{userId}/accounts", method = RequestMethod.POST)
public final ResponseEntity<Account> createAccount(@RequestBody Account accountRequest) throws Exception {
AccessorResponse<Account> response = gateway().accounts().create(accountRequest);
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);

// Return 202 returning challenge questions
Account result = response.getResult();
HttpStatus status = HttpStatus.OK;
if (result.getChallenges() != null && !result.getChallenges().isEmpty()) {
status = HttpStatus.ACCEPTED;
}
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), status);
}

@RequestMapping(value = "/users/{userId}/accounts/{id}", method = RequestMethod.PUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.mx.path.model.mdx.model.account.Transaction
import com.mx.path.model.mdx.model.account.TransactionSearchRequest
import com.mx.path.model.mdx.model.account.TransactionsPage
import com.mx.path.model.mdx.model.account.options.TransactionListOptions
import com.mx.path.model.mdx.model.challenges.Challenge
import com.mx.path.testing.WithMockery

import org.mockito.Mockito
Expand Down Expand Up @@ -46,7 +47,7 @@ class AccountsControllerTest extends Specification implements WithMockery {

def "create when implemented"() {
given:
def account = new Account();
def account = new Account()
AccountsController.setGateway(gateway)
Mockito.doReturn(new AccessorResponse<Account>().withResult(account)).when(accountGateway).create(account)

Expand All @@ -59,6 +60,24 @@ class AccountsControllerTest extends Specification implements WithMockery {
HttpStatus.OK == response.statusCode
}

def "create with challenges"() {
given:
def challenges = new MdxList()
challenges.add(new Challenge())
def account = new Account()
account.setChallenges(challenges)
AccountsController.setGateway(gateway)
Mockito.doReturn(new AccessorResponse<Account>().withResult(account)).when(accountGateway).create(account)

when:
def response = subject.createAccount(account)

then:
verify(accountGateway).create(account) || true
response.body == account
HttpStatus.ACCEPTED == response.statusCode
}

def "delete when implemented"() {
given:
AccountsController.setGateway(gateway)
Expand Down
Loading