Skip to content

Commit

Permalink
[PHEE-669] Tc for Account Status and Account Name APIs (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankita10r authored May 28, 2024
1 parent 79eee95 commit 5210ea9
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 32 deletions.
2 changes: 2 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ amsmifos:
ams:
base-url: https://ams-mifos.sandbox.fynarfin.io
balance-endpoint: /ams/accounts/{IdentifierType}/{IdentifierId}/balance
status-endpoint: /ams/accounts/{IdentifierType}/{IdentifierId}/status
name-endpoint: /ams/accounts/{IdentifierType}/{IdentifierId}/accountname

loan:
base-url: https://fynams.sandbox.fynarfin.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ public void iShouldPollTheTransferQueryEndpointWithTransactionIdUntilStatusIsPop
public void iCanCreateGSMATransactionDTOWithDifferentPayerAndPayee() {
GSMATransferHelper gsmaTransferHelper = new GSMATransferHelper();
Fee fee = gsmaTransferHelper.feeHelper("11", "USD", "string");
GsmaParty debit = gsmaTransferHelper.gsmaPartyHelper("msisdn", gsmaTransferStepDef.debitParty);
GsmaParty credit = gsmaTransferHelper.gsmaPartyHelper("msisdn", gsmaTransferStepDef.creditParty);
GsmaParty debit = gsmaTransferHelper.gsmaPartyHelper("msisdn", scenarioScopeState.debitParty);
GsmaParty credit = gsmaTransferHelper.gsmaPartyHelper("msisdn", scenarioScopeState.creditParty);
InternationalTransferInformation internationalTransferInformation = gsmaTransferHelper
.internationalTransferInformationHelper("string", "string", "directtoaccount", "USA", "USA", "USA", "USA");
IdDocument idDocument = gsmaTransferHelper.idDocumentHelper("passport", "string", "USA", "2022-09-28T12:51:19.260+00:00",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@

public class GSMATransferStepDef extends BaseStepDef {

String debitParty = "";
String creditParty = "";
int balance;
@Value("${ams.base-url}")
String amsBaseUrl;
@Value("${ams.balance-endpoint}")
String amsBalanceEndpoint;
@Value("${ams.status-endpoint}")
String amsStatusEndpoint;

@Value("${ams.name-endpoint}")
String amsNameEndpoint;
@Autowired
GsmaConfig gsmaConfig;

Expand Down Expand Up @@ -385,7 +386,7 @@ public void callCreateDebitInteropIdentifierEndpointMSISDN() throws JsonProcessi
// Setting account ID in path
PostSavingsAccountsResponse savingsAccountResponse = objectMapper.readValue(gsmaTransferDef.responseSavingsAccount,
PostSavingsAccountsResponse.class);
String payer_identifier = debitParty;
String payer_identifier = scenarioScopeState.debitParty;
String debitInteropEndpoint = gsmaConfig.interopIdentifierEndpoint;

debitInteropEndpoint = debitInteropEndpoint.replaceAll("\\{\\{identifierType\\}\\}", "MSISDN");
Expand All @@ -409,7 +410,7 @@ public void callCreateCreditInteropIdentifierEndpointMSISDN() throws JsonProcess
// Setting account ID in path
PostSavingsAccountsResponse savingsAccountResponse = objectMapper.readValue(gsmaTransferDef.responseSavingsAccount,
PostSavingsAccountsResponse.class);
String payer_identifier = creditParty;
String payer_identifier = scenarioScopeState.creditParty;
String creditInteropEndpoint = gsmaConfig.interopIdentifierEndpoint;
creditInteropEndpoint = creditInteropEndpoint.replaceAll("\\{\\{identifierType\\}\\}", "MSISDN");
creditInteropEndpoint = creditInteropEndpoint.replaceAll("\\{\\{identifier\\}\\}", payer_identifier);
Expand All @@ -428,7 +429,7 @@ public void iCallTheBalanceApiForPayerBalance() throws JsonProcessingException {
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
String finalEndpoint = amsBalanceEndpoint;
finalEndpoint = finalEndpoint.replace("{IdentifierType}", "MSISDN");
finalEndpoint = finalEndpoint.replace("{IdentifierId}", debitParty.isEmpty() ? scenarioScopeState.payerIdentifier : debitParty);
finalEndpoint = finalEndpoint.replace("{IdentifierId}", scenarioScopeState.debitParty.isEmpty() ? scenarioScopeState.payerIdentifier : scenarioScopeState.debitParty);
logger.info("Endpoint: " + finalEndpoint);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(amsBaseUrl).body("").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(finalEndpoint).andReturn().asString();
Expand All @@ -444,7 +445,7 @@ public void iCallTheBalanceApiForPayeeBalance() throws JsonProcessingException {
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
String finalEndpoint = amsBalanceEndpoint;
finalEndpoint = finalEndpoint.replace("{IdentifierType}", "MSISDN");
finalEndpoint = finalEndpoint.replace("{IdentifierId}", creditParty.isEmpty() ? scenarioScopeState.payeeIdentifier : creditParty);
finalEndpoint = finalEndpoint.replace("{IdentifierId}", scenarioScopeState.creditParty.isEmpty() ? scenarioScopeState.payeeIdentifier : scenarioScopeState.creditParty);
logger.info("Endpoint: " + finalEndpoint);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(amsBaseUrl).body("").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(finalEndpoint).andReturn().asString();
Expand All @@ -460,7 +461,7 @@ public void iCallTheBalanceApiForPayerBalanceAfterDebit() throws JsonProcessingE
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
String finalEndpoint = amsBalanceEndpoint;
finalEndpoint = finalEndpoint.replace("{IdentifierType}", "MSISDN");
finalEndpoint = finalEndpoint.replace("{IdentifierId}", debitParty.isEmpty() ? scenarioScopeState.payerIdentifier : debitParty);
finalEndpoint = finalEndpoint.replace("{IdentifierId}", scenarioScopeState.debitParty.isEmpty() ? scenarioScopeState.payerIdentifier : scenarioScopeState.debitParty);
logger.info("Endpoint: " + finalEndpoint);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(amsBaseUrl).body("").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(finalEndpoint).andReturn().asString();
Expand All @@ -479,7 +480,7 @@ public void iCallTheBalanceApiForPayeeBalanceAfterCredit() throws JsonProcessing
String finalEndpoint = amsBalanceEndpoint;
finalEndpoint = finalEndpoint.replace("{IdentifierType}", "MSISDN");
finalEndpoint = finalEndpoint.replace("{IdentifierId}",
creditParty.isEmpty() ? scenarioScopeState.payeeIdentifier : creditParty);
scenarioScopeState.creditParty.isEmpty() ? scenarioScopeState.payeeIdentifier : scenarioScopeState.creditParty);
logger.info("Endpoint: " + finalEndpoint);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(amsBaseUrl).body("").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(finalEndpoint).andReturn().asString();
Expand All @@ -494,11 +495,11 @@ public void iCallTheBalanceApiForPayeeBalanceAfterCredit() throws JsonProcessing
@When("I create a set of debit and credit party")
public void iCreateASetOfDebitAndCreditParty() {
Random random = new Random();
debitParty = String.valueOf(random.nextInt(900000000) + 1000000000);
creditParty = String.valueOf(random.nextInt(900000000) + 1000000000);
assertThat(debitParty).isNotEmpty();
assertThat(creditParty).isNotEmpty();
assertThat(debitParty).isNotEqualTo(creditParty);
scenarioScopeState.debitParty = String.valueOf(random.nextInt(900000000) + 1000000000);
scenarioScopeState.creditParty = String.valueOf(random.nextInt(900000000) + 1000000000);
assertThat(scenarioScopeState.debitParty).isNotEmpty();
assertThat(scenarioScopeState.creditParty).isNotEmpty();
assertThat(scenarioScopeState.debitParty).isNotEqualTo(scenarioScopeState.creditParty);

}

Expand Down Expand Up @@ -638,11 +639,11 @@ public void iCreateASetOfDebitAndCreditPartyFromFile(String filename) {
while (scanner.hasNextLine() && !line.isEmpty()) {
String line2 = scanner.nextLine();
String[] parts = line2.split(",");
debitParty = parts[4];
creditParty = parts[6];
assertThat(debitParty).isNotEmpty();
assertThat(creditParty).isNotEmpty();
assertThat(debitParty).isNotEqualTo(creditParty);
scenarioScopeState.debitParty = parts[4];
scenarioScopeState.creditParty = parts[6];
assertThat(scenarioScopeState.debitParty).isNotEmpty();
assertThat(scenarioScopeState.creditParty).isNotEmpty();
assertThat(scenarioScopeState.debitParty).isNotEqualTo(scenarioScopeState.creditParty);
}
scanner.close();
} catch (FileNotFoundException e) {
Expand Down Expand Up @@ -682,7 +683,7 @@ public void iCallTheBalanceApiForPayeeBalance(String id) throws JsonProcessingEx
}
scenarioScopeState.payeeIdentifierforBatch[Integer.parseInt(id)] = scenarioScopeState.payeeIdentifier;
finalEndpoint = finalEndpoint.replace("{IdentifierType}", "MSISDN");
finalEndpoint = finalEndpoint.replace("{IdentifierId}", creditParty.isEmpty() ? scenarioScopeState.payeeIdentifier : creditParty);
finalEndpoint = finalEndpoint.replace("{IdentifierId}", scenarioScopeState.payeeIdentifier);
logger.info("Endpoint: " + finalEndpoint);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(amsBaseUrl).body("").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(finalEndpoint).andReturn().asString();
Expand All @@ -703,7 +704,7 @@ public void iCallTheBalanceApiForPayeeBalanceForCombinedTestsCases(String id) th
}
scenarioScopeState.payeeIdentifierforBatch[Integer.parseInt(id)] = scenarioScopeState.payeeIdentifier;
finalEndpoint = finalEndpoint.replace("{IdentifierType}", "MSISDN");
finalEndpoint = finalEndpoint.replace("{IdentifierId}", creditParty.isEmpty() ? scenarioScopeState.payeeIdentifier : creditParty);
finalEndpoint = finalEndpoint.replace("{IdentifierId}", scenarioScopeState.creditParty.isEmpty() ? scenarioScopeState.payeeIdentifier : scenarioScopeState.creditParty);
logger.info("Endpoint: " + finalEndpoint);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(amsBaseUrl).body("").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(finalEndpoint).andReturn().asString();
Expand All @@ -720,8 +721,7 @@ public void iCallTheBalanceApiForPayeeBalanceAfterCredit(String id) throws JsonP
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
String finalEndpoint = amsBalanceEndpoint;
finalEndpoint = finalEndpoint.replace("{IdentifierType}", "MSISDN");
finalEndpoint = finalEndpoint.replace("{IdentifierId}",
creditParty.isEmpty() ? scenarioScopeState.payeeIdentifierforBatch[Integer.parseInt(id)] : creditParty);
finalEndpoint = finalEndpoint.replace("{IdentifierId}",scenarioScopeState.payeeIdentifierforBatch[Integer.parseInt(id)]);
logger.info("Endpoint: " + finalEndpoint);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(amsBaseUrl).body("").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(finalEndpoint).andReturn().asString();
Expand All @@ -741,7 +741,7 @@ public void iCallTheBalanceApiForPayerBalance(String id) throws JsonProcessingEx
}
scenarioScopeState.payerIdentifierforBatch[Integer.parseInt(id)] = scenarioScopeState.payerIdentifier;
finalEndpoint = finalEndpoint.replace("{IdentifierType}", "MSISDN");
finalEndpoint = finalEndpoint.replace("{IdentifierId}", debitParty.isEmpty() ? scenarioScopeState.payerIdentifier : debitParty);
finalEndpoint = finalEndpoint.replace("{IdentifierId}", scenarioScopeState.payerIdentifier);
logger.info("Endpoint: " + finalEndpoint);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(amsBaseUrl).body("").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(finalEndpoint).andReturn().asString();
Expand All @@ -762,7 +762,7 @@ public void iCallTheBalanceApiForPayerBalanceForCombinedTestCases(String id) thr
}
scenarioScopeState.payerIdentifierforBatch[Integer.parseInt(id)] = scenarioScopeState.payerIdentifier;
finalEndpoint = finalEndpoint.replace("{IdentifierType}", "MSISDN");
finalEndpoint = finalEndpoint.replace("{IdentifierId}", debitParty.isEmpty() ? scenarioScopeState.payerIdentifier : debitParty);
finalEndpoint = finalEndpoint.replace("{IdentifierId}", scenarioScopeState.debitParty.isEmpty() ? scenarioScopeState.payerIdentifier : scenarioScopeState.debitParty);
logger.info("Endpoint: " + finalEndpoint);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(amsBaseUrl).body("").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(finalEndpoint).andReturn().asString();
Expand All @@ -780,7 +780,7 @@ public void iCallTheBalanceApiForPayerBalanceAfterDebit(String id) throws JsonPr
String finalEndpoint = amsBalanceEndpoint;
finalEndpoint = finalEndpoint.replace("{IdentifierType}", "MSISDN");
finalEndpoint = finalEndpoint.replace("{IdentifierId}",
debitParty.isEmpty() ? scenarioScopeState.payerIdentifierforBatch[Integer.parseInt(id)] : debitParty);
scenarioScopeState.payerIdentifierforBatch[Integer.parseInt(id)]);
logger.info("Endpoint: " + finalEndpoint);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(amsBaseUrl).body("").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(finalEndpoint).andReturn().asString();
Expand All @@ -792,4 +792,47 @@ public void iCallTheBalanceApiForPayerBalanceAfterDebit(String id) throws JsonPr
assertThat(avlBal == originBal - debitAmt).isTrue();

}

@Then("I call the account status api")
public void iCallTheAccountStatus() throws JsonProcessingException {
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
String finalEndpoint = amsStatusEndpoint;
finalEndpoint = finalEndpoint.replace("{IdentifierType}", "MSISDN");
finalEndpoint = finalEndpoint.replace("{IdentifierId}", scenarioScopeState.debitParty);
logger.info("Endpoint: " + finalEndpoint);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(amsBaseUrl).body("").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(finalEndpoint).andReturn().asString();
logger.info("Status Response: " + scenarioScopeState.response);

}

@And("I can assert {string} status in response")
public void iCanAssertStatusInResponse(String status) {
assertThat(scenarioScopeState.response.contains(status)).isTrue();
}

@Then("I call the account name api")
public void iCallTheAccountName() throws JsonProcessingException {
RequestSpecification requestSpec = Utils.getDefaultSpec(scenarioScopeState.tenant);
String finalEndpoint = amsNameEndpoint;
finalEndpoint = finalEndpoint.replace("{IdentifierType}", "MSISDN");
finalEndpoint = finalEndpoint.replace("{IdentifierId}", scenarioScopeState.debitParty);
logger.info("Endpoint: " + finalEndpoint);
scenarioScopeState.response = RestAssured.given(requestSpec).baseUri(amsBaseUrl).body("").expect()
.spec(new ResponseSpecBuilder().expectStatusCode(200).build()).when().get(finalEndpoint).andReturn().asString();
logger.info("Status Response: " + scenarioScopeState.response);

}

@And("I can assert name in response")
public void iCanAssertNameInResponse() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(scenarioScopeState.response);

String firstName = jsonNode.get("name").get("firstName").asText();
String lastName = jsonNode.get("name").get("lastName").asText();
logger.info("Name is {} {}", firstName, lastName);
assertThat(firstName.isEmpty()).isFalse();
assertThat(lastName.isEmpty()).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public class ScenarioScopeState {

protected int initialBalForPayer;
protected int initialBalForPayee;

protected String debitParty;
protected String creditParty;
protected String[] payeeIdentifierforBatch;
protected String[] payerIdentifierforBatch;
protected int[] initialBalForPayeeForBatch;
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/resources/account.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Feature: Account Status and Account Name Check api

@amsIntegration
Scenario: Savings account Status Test
Given I have Fineract-Platform-TenantId as "payerfsp1"
When I create a set of debit and credit party
When I call the create payer client endpoint
Then I call the create savings product endpoint
When I call the create savings account endpoint
Then I call the debit interop identifier endpoint with MSISDN
Given I have tenant as "payerfsp"
Then I call the account status api
And I can assert "submitted" status in response
Then I approve the deposit with command "approve"
Given I have tenant as "payerfsp"
Then I call the account status api
And I can assert "approved" status in response
When I activate the account with command "activate"
Then I call the deposit account endpoint with command "deposit" for amount 11
Given I have tenant as "payerfsp"
Then I call the account status api
And I can assert "active" status in response

@amsIntegration
Scenario: Savings account Name Test
Given I have Fineract-Platform-TenantId as "payerfsp1"
When I create a set of debit and credit party
When I call the create payer client endpoint
Then I call the create savings product endpoint
When I call the create savings account endpoint
Then I call the debit interop identifier endpoint with MSISDN
Then I approve the deposit with command "approve"
When I activate the account with command "activate"
Then I call the deposit account endpoint with command "deposit" for amount 100
Given I have tenant as "payerfsp"
Then I call the account name api
Then I can assert name in response
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id,request_id,payment_mode,payer_identifier_type,payer_identifier,payee_identifier_type,payee_identifier,amount,currency,note
0,f41f4f3a-479f-44d3-b254-1f6574b11e09,gsma,msisdn,2224,msisdn,2032,10,USD,Test Payee Payment
1,caf6c982-7182-4d4d-9931-75da625cec66,gsma,msisdn,2225,msisdn,2033,5,USD,Test Payee Payment
2,7e79d1b1-d000-43f4-a13f-451dd4c51457,gsma,msisdn,2226,msisdn,2034,1,USD,Test Payee Payment
0,1fe8af66-9a34-4b92-bbd5-1a116b635bb5,gsma,msisdn,4004,msisdn,3815,10,USD,Test Payee Payment
1,dbbe52aa-20a0-4eb9-80a0-ad6df8068e40,gsma,msisdn,4005,msisdn,3816,5,USD,Test Payee Payment
2,021955bc-8a96-45d3-bec0-69e365d5369c,gsma,msisdn,4006,msisdn,3817,1,USD,Test Payee Payment

0 comments on commit 5210ea9

Please sign in to comment.