Skip to content

Commit

Permalink
Add review test, delete useless files
Browse files Browse the repository at this point in the history
  • Loading branch information
Fagorym committed May 21, 2024
1 parent 00905bd commit ca5e348
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 19 deletions.
1 change: 0 additions & 1 deletion images/1.svg

This file was deleted.

1 change: 0 additions & 1 deletion images/100.svg

This file was deleted.

Binary file removed images/ceh.jpg
Binary file not shown.
Binary file removed images/cir.jpg
Binary file not shown.
Binary file removed images/dev.jpg
Binary file not shown.
Binary file removed images/eleon.jpg
Binary file not shown.
Binary file removed images/inn.jpg
Binary file not shown.
Binary file removed images/mar.jpg
Binary file not shown.
Binary file removed images/mav.jpg
Binary file not shown.
Binary file removed images/naut.jpg
Binary file not shown.
Binary file removed images/orange.jpg
Binary file not shown.
Binary file removed images/papa.jpg
Binary file not shown.
Binary file removed images/resp.jpg
Binary file not shown.
Binary file removed images/scope.jpg
Binary file not shown.
Binary file removed images/shish.jpg
Binary file not shown.
Binary file removed images/vesna.jpg
Binary file not shown.
Binary file removed images/vr.jpg
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ public ResponseEntity<BaseResponse<Object>> handleException(BaseException except
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(SecurityException.class)
public ResponseEntity<BaseResponse<String>> handleException(SecurityException exception) {
BaseResponse<String> response = new BaseResponse<>("Пользователь не вошел в аккаунт", "SecurityException");
return new ResponseEntity<>(response, HttpStatus.FORBIDDEN);
}

@Override
public boolean supports(
@NonNull MethodParameter returnType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public void saveImages(Set<PhotoDto> photos, Establishment establishment) {
.map(photo -> getByLink(photo.getImage()).setEstablishment(establishment))
.toList();
imageRepository.saveAll(savedPhotos);
log.info("Was saved {}", photos);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,18 @@ public class SpotServiceImpl implements SpotService {

@Override
public List<SpotDto> getSpotsByEstablishment(Long establishmentId) {
log.info("Getting spots by establishment");
log.info("EstablishmentID: " + establishmentId);
Establishment establishment = establishmentRepository.findById(establishmentId).orElseThrow();
return spotMapper.toDtoList(spotRepository.findByEstablishment(establishment));
}

@Override
public SpotDto getSpotById(Long spotId) {
log.info("Getting spot by id");
log.info("SpotID: " + spotId);
return spotMapper.modelToDto(spotRepository.findById(spotId)
.orElseThrow(() -> new SpotNotFoundException(spotId)));
}

@Override
public void createSpot(Long localId, Long establishmentId) {
log.info("Saving new spot");
log.info("LocalID: " + localId);
log.info("EstablishmentID: " + establishmentId);
spotRepository.save(
new Spot().setLocalId(localId).setEstablishment(establishmentRepository.getReferenceById(establishmentId))
);
Expand All @@ -64,7 +57,6 @@ public void saveSpots(List<Spot> spots, Long establishmentId) {

@Override
public TimelineDto getSpotTimeline(Long localId, Long establishmentId) {
log.info("Getting spot timeline");
Establishment establishment = establishmentRepository.findById(establishmentId)
.orElseThrow(() -> new EstablishmentNotFoundException(establishmentId));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ public class WorkingHoursServiceImpl implements WorkingHoursService {

@Override
public void saveWorkingHours(Set<RequestWorkingHoursDto> responseWorkingHoursDto, Establishment establishment) {
log.info("Saving working hours");
Map<String, WorkingHours> workingHoursMap = new HashMap<>();
for (RequestWorkingHoursDto dto : responseWorkingHoursDto) {
log.info("Saving {}", dto);
for (String day : dto.getDays()) {
WorkingHours workingHours = mapper.map(dto, WorkingHours.class);
workingHours.setDayOfWeek(DayOfWeek.getDayByString(day));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ru.nsu.fit.directors.establishmentservice;

import com.github.springtestdbunit.annotation.DatabaseSetup;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@DisplayName("Проверка работы с отзывами")
@DatabaseSetup("/database/establishment/default_establishment.xml")
class EstablishmentReviewTest extends EstablishmentServiceApplicationTests {

@Test
@DisplayName("Получение отзывов")
@DatabaseSetup("/database/review/review_list.xml")
void getReviewsTest() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/establishment/review?establishmentId=100"))
.andExpect(status().is2xxSuccessful())
.andExpect(responseFromPath("http/response/review/review_list_response.json"));
}
}
21 changes: 21 additions & 0 deletions src/test/resources/database/review/review_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<dataset>
<review
id="10"
establishment_id="100"
score="5"
text="Отличное заведение!"
username="Петров"
date="2024-02-12"
answer="Спасибо за отзыв! Помогаете нам расти и становиться лучше!"
/>

<review
id="20"
establishment_id="100"
score="2"
text="Это отвратительно!"
username="Лера"
date="2024-03-12"
answer="Мы вас ненавидим!"
/>
</dataset>
17 changes: 17 additions & 0 deletions src/test/resources/http/response/review/review_list_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"result": [
{
"username": "Петров",
"text": "Отличное заведение!",
"score": 5,
"answer": "Спасибо за отзыв! Помогаете нам расти и становиться лучше!"
},
{
"username": "Лера",
"text": "Это отвратительно!",
"score": 2,
"answer": "Мы вас ненавидим!"
}
],
"exception": null
}

0 comments on commit ca5e348

Please sign in to comment.