Skip to content

Commit a743d6f

Browse files
authored
[GOV-314A] Adding voucher status api (#273)
1 parent 09b2e95 commit a743d6f

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

src/main/java/org/mifos/integrationtest/config/VoucherManagementConfig.java

+3
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ public class VoucherManagementConfig {
1717
public String voucherValidityEndpoint;
1818
@Value("${voucher-management.endpoints.fetch}")
1919
public String fetchVoucherEndpoint;
20+
21+
@Value("${voucher-management.endpoints.voucher-status}")
22+
public String voucherStatus;
2023
}

src/main/resources/application.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ voucher-management:
141141
voucher-validity: /voucher/validity
142142
fetch: /vouchers
143143
actuator: "/actuator/health"
144+
voucher-status: "/voucher/{{serialNumber}}?fields=status"
144145

145146

146147
mock-payment-schema:

src/test/java/org/mifos/integrationtest/cucumber/stepdef/VoucherManagementStepDef.java

+18
Original file line numberDiff line numberDiff line change
@@ -673,4 +673,22 @@ public String addUnsupportedParamsInRequestBody(String requestBody) {
673673

674674
return requestBody;
675675
}
676+
677+
@And("I can call the voucher status API with expected status of {int} until I get the status as {string}")
678+
public void iCanCallTheVoucherStatusAPIWithExpectedStatusOfUntilIGetTheStatusAs(int expectedStatus, String status) {
679+
await().atMost(awaitMost, SECONDS).pollDelay(pollDelay, SECONDS).pollInterval(pollInterval, SECONDS).untilAsserted(() -> {
680+
com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
681+
String endpoint = voucherManagementConfig.voucherStatus;
682+
RequestSpecification requestSpec = Utils.getDefaultSpec();
683+
// requestSpec.queryParam("fields", "status");
684+
endpoint = String.format(endpoint.replace("{{serialNumber}}", "%s"), scenarioScopeState.serialNumber);
685+
scenarioScopeState.response = RestAssured.given(requestSpec).header("Content-Type", "application/json")
686+
.header("X-Registering-Institution-ID", scenarioScopeState.registeringInstitutionId)
687+
.baseUri(voucherManagementConfig.voucherManagementContactPoint).expect()
688+
.spec(new ResponseSpecBuilder().expectStatusCode(expectedStatus).build()).when().get(endpoint).andReturn().asString();
689+
690+
logger.info("Status Response: {}", scenarioScopeState.response);
691+
assertThat(scenarioScopeState.response.contains(status)).isTrue();
692+
});
693+
}
676694
}

src/test/java/resources/voucherManagementTest.feature

+39
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,42 @@ Feature: Voucher Management Api Test
102102
And I can register the stub with "/createVoucher" endpoint for "PUT" request with status of 200
103103
And I can register the stub with "/activateVoucher" endpoint for "PUT" request with status of 200
104104
When I call the create, Activate voucher API and store it in "vouchertest/loadTest_demo.csv"
105+
106+
@gov
107+
Scenario: Voucher Status Check for inactive voucher, active voucher and redeemed voucher
108+
When I can inject MockServer
109+
Then I can start mock server
110+
And I can register the stub with "/createVoucher" endpoint for "PUT" request with status of 200
111+
Given I can create an VoucherRequestDTO for voucher creation
112+
When I call the create voucher API with expected status of 202 and stub "/createVoucher"
113+
# Then I will sleep for 10000 millisecond
114+
Then I should be able to extract response body from callback
115+
And I can call the voucher status API with expected status of 200 until I get the status as "01"
116+
Given I can create an VoucherRequestDTO for voucher activation
117+
And I can register the stub with "/activateVoucher" endpoint for "PUT" request with status of 200
118+
When I call the activate voucher API with expected status of 202 and stub "/activateVoucher"
119+
# Then I will sleep for 5000 millisecond
120+
Then I should be able to assert response body from callback on "/activateVoucher"
121+
And I can call the voucher status API with expected status of 200 until I get the status as "02"
122+
Given I can create an RedeemVoucherRequestDTO for voucher redemption
123+
When I call the redeem voucher API with expected status of 200
124+
Then I can assert that redemption was successful by asserting the status in response
125+
And I can call the voucher status API with expected status of 200 until I get the status as "05"
126+
127+
128+
129+
@createAndActivateVoucher @gov
130+
Scenario: Voucher Status Check for inactive voucher, active voucher, suspended and cancelled voucher
131+
Given I can create an VoucherRequestDTO for voucher suspension
132+
And I can register the stub with "/suspendVoucher" endpoint for "PUT" request with status of 200
133+
When I call the suspend voucher API with expected status of 202 and stub "/suspendVoucher"
134+
And I can call the voucher status API with expected status of 200 until I get the status as "06"
135+
And I can create an VoucherRequestDTO for voucher reactivation
136+
And I can register the stub with "/reactivateVoucher" endpoint for "PUT" request with status of 200
137+
When I call the activate voucher API with expected status of 202 and stub "/reactivateVoucher"
138+
And I can call the voucher status API with expected status of 200 until I get the status as "02"
139+
Given I can create an VoucherRequestDTO for voucher cancellation
140+
And I can register the stub with "/cancelVoucher" endpoint for "PUT" request with status of 200
141+
When I call the cancel voucher API with expected status of 202 and stub "/cancelVoucher"
142+
And I can call the voucher status API with expected status of 200 until I get the status as "03"
143+

0 commit comments

Comments
 (0)