-
Notifications
You must be signed in to change notification settings - Fork 80
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
7817 fix api response status 500 instead of 400 when coordinates not specified #7850
Merged
Cr1stal423
merged 10 commits into
dev
from
7817-fix-api-response-status-500-instead-of-400-when-coordinates-not-specified
Dec 5, 2024
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c4da69e
add changes to EventServiceImpl
Cr1stal423 3cd6645
Change exception type to BadRequestException
Cr1stal423 e423b69
add new ErrorMessage
Cr1stal423 c7e2d8e
adapt test for new logic
Cr1stal423 bedca83
Comment out test
Cr1stal423 499a317
Refactoring and replacing wildcard imports with specific imports
Cr1stal423 837a9a9
Refactor test to avoid multiple potential exceptions in lambda expres…
Cr1stal423 e86e160
Refactor ModelUtils and validation logic: move AddressDto creation to…
Cr1stal423 b0fc84e
Refactor coordinate validation: replace explicit range checks with Ma…
Cr1stal423 ada75f4
Removed the double method usage
Cr1stal423 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,8 @@ void save() { | |
}.getType())).thenReturn(tags); | ||
when(googleApiService.getResultFromGeoCodeByCoordinates(any())) | ||
.thenReturn(ModelUtils.getAddressLatLngResponse()); | ||
AddressDto build = ModelUtils.getLongitudeAndLatitude(); | ||
when(modelMapper.map(ModelUtils.getAddressLatLngResponse(), AddressDto.class)).thenReturn(build); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this AddressDto builder to ModelsUtils class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected |
||
when(eventRepo.findFavoritesAmongEventIds(eventIds, user.getId())).thenReturn(List.of(event)); | ||
when(eventRepo.findSubscribedAmongEventIds(eventIds, user.getId())).thenReturn(List.of()); | ||
|
||
|
@@ -184,38 +186,16 @@ void save() { | |
@Test | ||
void saveEventWithoutAddress() { | ||
User user = ModelUtils.getUser(); | ||
EventDto eventDtoWithoutCoordinatesDto = ModelUtils.getEventDtoWithoutAddress(); | ||
List<Long> eventIds = List.of(eventDtoWithoutCoordinatesDto.getId()); | ||
AddEventDtoRequest addEventDtoWithoutCoordinates = ModelUtils.addEventDtoWithoutAddressRequest; | ||
Event eventWithoutCoordinates = ModelUtils.getEventWithoutAddress(); | ||
List<Tag> tags = ModelUtils.getEventTags(); | ||
|
||
String email = user.getEmail(); | ||
when(modelMapper.map(addEventDtoWithoutCoordinates, Event.class)).thenReturn(eventWithoutCoordinates); | ||
when(restClient.findByEmail(user.getEmail())).thenReturn(testUserVo); | ||
when(modelMapper.map(testUserVo, User.class)).thenReturn(user); | ||
when(eventRepo.save(eventWithoutCoordinates)).thenReturn(eventWithoutCoordinates); | ||
when(modelMapper.map(eventWithoutCoordinates, EventDto.class)).thenReturn(eventDtoWithoutCoordinatesDto); | ||
List<TagVO> tagVOList = Collections.singletonList(ModelUtils.getTagVO()); | ||
when(tagService.findTagsWithAllTranslationsByNamesAndType(addEventDtoWithoutCoordinates.getTags(), | ||
TagType.EVENT)).thenReturn(tagVOList); | ||
when(modelMapper.map(tagVOList, new TypeToken<List<Tag>>() { | ||
}.getType())).thenReturn(tags); | ||
when(eventRepo.findFavoritesAmongEventIds(eventIds, user.getId())).thenReturn(List.of(eventWithoutCoordinates)); | ||
when(eventRepo.findSubscribedAmongEventIds(eventIds, user.getId())) | ||
.thenReturn(List.of(eventWithoutCoordinates)); | ||
|
||
EventDto resultEventDto = eventService.save(addEventDtoWithoutCoordinates, user.getEmail(), null); | ||
|
||
assertEquals(eventDtoWithoutCoordinatesDto, resultEventDto); | ||
assertTrue(resultEventDto.isSubscribed()); | ||
assertTrue(resultEventDto.isFavorite()); | ||
|
||
verify(restClient).findByEmail(user.getEmail()); | ||
verify(eventRepo).save(eventWithoutCoordinates); | ||
verify(tagService).findTagsWithAllTranslationsByNamesAndType(addEventDtoWithoutCoordinates.getTags(), | ||
TagType.EVENT); | ||
verify(eventRepo).findFavoritesAmongEventIds(eventIds, user.getId()); | ||
verify(eventRepo).findSubscribedAmongEventIds(eventIds, user.getId()); | ||
when(eventRepo.save(any(Event.class))).thenReturn(eventWithoutCoordinates); | ||
BadRequestException exception = assertThrows( | ||
BadRequestException.class, | ||
() -> eventService.save(addEventDtoWithoutCoordinates, email, null)); | ||
assertEquals(ErrorMessage.INVALID_COORDINATES, exception.getMessage()); | ||
verify(eventRepo, times(0)).save(eventWithoutCoordinates); | ||
} | ||
|
||
@Test | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need constants INVALID_LONGITUDE and INVALID_LATITUDE?
You don't use them anywhere.