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

AYS-602 | Blank Check Added to EmergencyEvacuationApp to Validate Source & Target City/District Difference #429

Merged
merged 6 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -115,9 +115,9 @@ private boolean isPhoneNumberMustNotBeSameOne() {
@SuppressWarnings("This method is unused by the application directly but Spring is using it in the background.")
private boolean isSourceCityAndDistrictDifferentFromTargetCityAndDistrict() {

if (this.sourceCity == null || this.sourceDistrict == null || this.targetCity == null || this.targetDistrict == null) {
if (StringUtils.isBlank(this.sourceCity) || StringUtils.isBlank(this.sourceDistrict) || StringUtils.isBlank(this.targetCity) || StringUtils.isBlank(this.targetDistrict)) {
return true;
}
}
agitrubard marked this conversation as resolved.
Show resolved Hide resolved

if (!this.sourceCity.equalsIgnoreCase(this.targetCity)){
agitrubard marked this conversation as resolved.
Show resolved Hide resolved
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,90 @@ void givenInvalidEmergencyEvacuationApplicationRequest_whenSourceCityAndDistrict
.create(Mockito.any(EmergencyEvacuationApplicationRequest.class));
}

@Test
void givenInvalidEmergencyEvacuationApplicationRequest_whenSourceCityAndTargetCityAreBlank_thenReturnValidationError() throws Exception {
// Given
EmergencyEvacuationApplicationRequest mockApplicationRequest = new EmergencyEvacuationRequestBuilder()
.withValidValues()
.withSourceCity("")
.withSourceDistrict("Maltepe")
.withTargetCity("")
.withTargetDistrict("Maltepe")
.build();

// Then
String endpoint = BASE_PATH.concat("/emergency-evacuation-application");
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders
.post(endpoint, mockApplicationRequest);

AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.VALIDATION_ERROR;
aysMockMvc.perform(mockHttpServletRequestBuilder, mockErrorResponse)
.andExpect(AysMockResultMatchersBuilders.status()
.isBadRequest())
.andExpect(AysMockResultMatchersBuilders.subErrors()
.isNotEmpty());

// Verify
Mockito.verify(emergencyEvacuationApplicationService, Mockito.never())
.create(Mockito.any(EmergencyEvacuationApplicationRequest.class));
}

@Test
void givenInvalidEmergencyEvacuationApplicationRequest_whenSourceDistrictAndTargetDistrictAreBlank_thenReturnValidationError() throws Exception {
// Given
EmergencyEvacuationApplicationRequest mockApplicationRequest = new EmergencyEvacuationRequestBuilder()
.withValidValues()
.withSourceCity("Adana")
.withSourceDistrict("")
.withTargetCity("Adana")
.withTargetDistrict("")
.build();

// Then
String endpoint = BASE_PATH.concat("/emergency-evacuation-application");
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders
.post(endpoint, mockApplicationRequest);

AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.VALIDATION_ERROR;
aysMockMvc.perform(mockHttpServletRequestBuilder, mockErrorResponse)
.andExpect(AysMockResultMatchersBuilders.status()
.isBadRequest())
.andExpect(AysMockResultMatchersBuilders.subErrors()
.isNotEmpty());

// Verify
Mockito.verify(emergencyEvacuationApplicationService, Mockito.never())
.create(Mockito.any(EmergencyEvacuationApplicationRequest.class));
}

@Test
void givenInvalidEmergencyEvacuationApplicationRequest_whenAllCitiesAndDistrictsAreBlank_thenReturnValidationError() throws Exception {
// Given
EmergencyEvacuationApplicationRequest mockApplicationRequest = new EmergencyEvacuationRequestBuilder()
.withValidValues()
.withSourceCity("")
.withSourceDistrict("")
.withTargetCity("")
.withTargetDistrict("")
.build();

// Then
String endpoint = BASE_PATH.concat("/emergency-evacuation-application");
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders
.post(endpoint, mockApplicationRequest);

AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.VALIDATION_ERROR;
aysMockMvc.perform(mockHttpServletRequestBuilder, mockErrorResponse)
.andExpect(AysMockResultMatchersBuilders.status()
.isBadRequest())
.andExpect(AysMockResultMatchersBuilders.subErrors()
.isNotEmpty());

// Verify
Mockito.verify(emergencyEvacuationApplicationService, Mockito.never())
.create(Mockito.any(EmergencyEvacuationApplicationRequest.class));
}
agitrubard marked this conversation as resolved.
Show resolved Hide resolved

@Test
void givenValidIdAndValidUpdateRequest_whenApplicationUpdated_thenReturnSuccessResponse() throws Exception {
// Given
Expand Down
Loading