Skip to content

Commit

Permalink
feat: fixed api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kammerlo committed May 3, 2024
1 parent 9a3c51c commit e3e2028
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,13 @@ private List<Producer> getPublicRoots(List<PublicRoot> publicRoots) {

@Override
public void verifyNetworkRequest(final NetworkIdentifier networkIdentifier) {
if(!verifyBlockchain(networkIdentifier.getBlockchain())) {
throw ExceptionFactory.invalidBlockchainError();
}
if(!verifyNetwork(networkIdentifier.getNetwork())) {
throw ExceptionFactory.networkNotFoundError();
if (networkIdentifier != null) {
if (!verifyBlockchain(networkIdentifier.getBlockchain())) {
throw ExceptionFactory.invalidBlockchainError();
}
if (!verifyNetwork(networkIdentifier.getNetwork())) {
throw ExceptionFactory.networkNotFoundError();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.cardanofoundation.rosetta.api.account.controller;

import org.cardanofoundation.rosetta.api.network.service.NetworkService;
import org.cardanofoundation.rosetta.common.util.Constants;
import org.openapitools.client.model.NetworkIdentifier;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.test.web.servlet.MockMvc;
Expand Down Expand Up @@ -34,6 +37,10 @@ class AccountApiImplementationTest {

@Mock
AccountService accountService;

@Mock
NetworkService networkService;

@Spy
@InjectMocks
AccountApiImplementation accountController;
Expand All @@ -47,6 +54,8 @@ void setUp() {
void accountBalancePositiveTest() {
AccountBalanceRequest request = Mockito.mock(AccountBalanceRequest.class);
AccountBalanceResponse response = Mockito.mock(AccountBalanceResponse.class);
request.setNetworkIdentifier(NetworkIdentifier.builder().blockchain(Constants.CARDANO_BLOCKCHAIN).network(Constants.DEVKIT).build());

Mockito.when(accountService.getAccountBalance(request)).thenReturn(response);

ResponseEntity<AccountBalanceResponse> actual = accountController.accountBalance(request);
Expand All @@ -61,8 +70,9 @@ void accountBalancePositiveTest() {
void accountCoinsPositiveTest() {
AccountCoinsRequest request = Mockito.mock(AccountCoinsRequest.class);
AccountCoinsResponse response = Mockito.mock(AccountCoinsResponse.class);
Mockito.when(accountService.getAccountCoins(request)).thenReturn(response);
request.setNetworkIdentifier(NetworkIdentifier.builder().blockchain(Constants.CARDANO_BLOCKCHAIN).network(Constants.DEVKIT).build());

Mockito.when(accountService.getAccountCoins(request)).thenReturn(response);
ResponseEntity<AccountCoinsResponse> actual = accountController.accountCoins(request);

assertEquals(response, actual.getBody());
Expand Down

0 comments on commit e3e2028

Please sign in to comment.