Skip to content
Open
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 @@ -192,6 +192,15 @@ public void validateForTaxGroupCreate(final String json) {
final JsonObject topLevelJsonElement = element.getAsJsonObject();
if (topLevelJsonElement.get(TaxApiConstants.taxComponentsParamName).isJsonArray()) {
final JsonArray array = topLevelJsonElement.get(TaxApiConstants.taxComponentsParamName).getAsJsonArray();
if (array.isEmpty()) {
dataValidationErrors.add(
ApiParameterError.parameterError(
"validation.msg.at.least.one.tax.component.required",
"Please add at least one Tax Component before submitting the Tax Group.",
TaxApiConstants.taxComponentsParamName
)
);
}
baseDataValidator.reset().parameter(TaxApiConstants.taxComponentsParamName).value(array.size()).integerGreaterThanZero();
for (int i = 1; i <= array.size(); i++) {
final JsonObject taxComponent = array.get(i - 1).getAsJsonObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,18 @@ void retrieveTaxComponentWithNonExistentId_shouldReturn404() {
"Response should contain the error code for tax component not found");
}

@Test
void createTaxGroupWithoutTaxComponent_shouldReturnValidationError() {
final PostTaxesGroupRequest taxGroupRequest = new PostTaxesGroupRequest().name(Utils.randomStringGenerator("TAX_GRP_", 4))
.taxComponents(new HashSet<>()).dateFormat("dd MMMM yyyy").locale("en");

CallFailedRuntimeException exception = taxGroupHelper.createTaxGroupExpectingError(taxGroupRequest);

assertEquals(400, exception.getStatus());
assertTrue(exception.getMessage().contains("validation.msg.at.least.one.tax.component.required"),
"Response should contain the error code requiring at least one tax component");
assertTrue(exception.getMessage().contains("Please add at least one Tax Component before submitting the Tax Group."),
"Response should contain the user friendly validation message");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ public List<GetTaxesGroupResponse> retrieveAllTaxGroups() {
public CallFailedRuntimeException retrieveTaxGroupExpectingError(Long taxGroupId) {
return fail(() -> fineractClient.taxGroup().retrieveOneTaxGroup(taxGroupId));
}

public CallFailedRuntimeException createTaxGroupExpectingError(PostTaxesGroupRequest request) {
return fail(() -> fineractClient.taxGroup().createTaxGroup(request));
}
}
Loading