fix(build): switch from uber-jar to fast-jar for Docker compatibility

- Change quarkus.package.type from uber-jar to fast-jar
- Add EventShare entity and migration for share tracking
- Add establishment capacity field
- Improve event and establishment services
- Add comprehensive tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
dahoud
2026-01-31 20:27:27 +00:00
parent 9dc9ca591c
commit 0240442671
19 changed files with 574 additions and 62 deletions

View File

@@ -0,0 +1,55 @@
package com.lions.dev.repository;
import com.lions.dev.entity.establishment.Establishment;
import com.lions.dev.entity.events.Events;
import com.lions.dev.entity.users.Users;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.*;
@QuarkusTest
class EventsRepositoryTest {
@Inject
EventsRepository eventsRepository;
@Test
@DisplayName("countParticipantsForEstablishment sans événements retourne 0")
void countParticipantsForEstablishment_noEvents_returnsZero() {
UUID establishmentId = UUID.randomUUID();
long count = eventsRepository.countParticipantsForEstablishment(establishmentId);
assertEquals(0L, count);
}
@Test
@DisplayName("findEventsAfterDate retourne une liste (éventuellement vide)")
void findEventsAfterDate_returnsList() {
LocalDateTime future = LocalDateTime.now().plusDays(1);
var result = eventsRepository.findEventsAfterDate(future);
assertNotNull(result);
assertTrue(result.isEmpty() || result.stream().allMatch(e -> e.getStartDate().isAfter(future)));
}
@Test
@DisplayName("findEventsBetweenDates avec fin avant début retourne liste vide")
void findEventsBetweenDates_endBeforeStart_returnsEmpty() {
LocalDateTime start = LocalDateTime.now().plusDays(2);
LocalDateTime end = LocalDateTime.now().plusDays(1);
var result = eventsRepository.findEventsBetweenDates(start, end);
assertNotNull(result);
assertTrue(result.isEmpty());
}
}

View File

@@ -0,0 +1,51 @@
package com.lions.dev.resource;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.*;
@QuarkusTest
class EventsResourceTest {
@Test
@DisplayName("POST /events/{id}/share sans événement existant retourne 404")
void shareEvent_eventNotFound_returns404() {
String eventId = UUID.randomUUID().toString();
String userId = UUID.randomUUID().toString();
given()
.queryParam("userId", userId)
.when()
.post("/events/" + eventId + "/share")
.then()
.statusCode(404);
}
@Test
@DisplayName("GET /events/share-link avec id invalide retourne 404")
void getShareLink_eventNotFound_returns404() {
String eventId = UUID.randomUUID().toString();
given()
.when()
.get("/events/" + eventId + "/share-link")
.then()
.statusCode(404);
}
@Test
@DisplayName("GET /events retourne une liste (200)")
void getEvents_returnsOk() {
given()
.when()
.get("/events")
.then()
.statusCode(200)
.body(anyOf(is("[]"), startsWith("[")));
}
}

View File

@@ -0,0 +1,220 @@
package com.lions.dev.service;
import com.lions.dev.dto.request.establishment.EstablishmentRatingRequestDTO;
import com.lions.dev.entity.establishment.Establishment;
import com.lions.dev.entity.establishment.EstablishmentRating;
import com.lions.dev.entity.users.Users;
import com.lions.dev.repository.EstablishmentRatingRepository;
import com.lions.dev.repository.EstablishmentRepository;
import com.lions.dev.repository.UsersRepository;
import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.Map;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
@QuarkusTest
class EstablishmentRatingServiceTest {
@Inject
EstablishmentRatingService establishmentRatingService;
@InjectMock
EstablishmentRatingRepository ratingRepository;
@InjectMock
EstablishmentRepository establishmentRepository;
@InjectMock
UsersRepository usersRepository;
@InjectMock
NotificationService notificationService;
@Test
@DisplayName("submitRating avec données valides crée la note et met à jour les stats")
void submitRating_validData_createsRatingAndUpdatesStats() {
UUID establishmentId = UUID.randomUUID();
UUID userId = UUID.randomUUID();
Establishment establishment = new Establishment("Bar", "BAR", "1 rue Test", "Paris", "75001", new Users());
establishment.setId(establishmentId);
Users user = new Users();
user.setId(userId);
user.setFirstName("Jean");
user.setLastName("Dupont");
EstablishmentRatingRequestDTO requestDTO = new EstablishmentRatingRequestDTO();
requestDTO.setRating(4);
requestDTO.setComment("Très bien");
when(establishmentRepository.findById(establishmentId)).thenReturn(establishment);
when(usersRepository.findById(userId)).thenReturn(user);
when(ratingRepository.findByEstablishmentIdAndUserId(establishmentId, userId)).thenReturn(null);
when(ratingRepository.calculateAverageRating(establishmentId)).thenReturn(4.0);
when(ratingRepository.countByEstablishmentId(establishmentId)).thenReturn(1L);
when(ratingRepository.calculateRatingDistribution(establishmentId)).thenReturn(Map.of(4, 1));
Notification notif = new Notification("Nouvelle note", "Message", "rating", user);
when(notificationService.createNotification(anyString(), anyString(), anyString(), any(UUID.class), any())).thenReturn(notif);
EstablishmentRating result = establishmentRatingService.submitRating(establishmentId, userId, requestDTO);
assertNotNull(result);
verify(ratingRepository).persist(any(EstablishmentRating.class));
verify(establishmentRepository).persist(establishment);
}
@Test
@DisplayName("submitRating avec établissement inexistant lance RuntimeException")
void submitRating_establishmentNotFound_throws() {
UUID establishmentId = UUID.randomUUID();
UUID userId = UUID.randomUUID();
EstablishmentRatingRequestDTO requestDTO = new EstablishmentRatingRequestDTO();
requestDTO.setRating(5);
when(establishmentRepository.findById(establishmentId)).thenReturn(null);
assertThrows(RuntimeException.class, () ->
establishmentRatingService.submitRating(establishmentId, userId, requestDTO));
verify(ratingRepository, never()).persist(any());
}
@Test
@DisplayName("submitRating avec utilisateur inexistant lance RuntimeException")
void submitRating_userNotFound_throws() {
UUID establishmentId = UUID.randomUUID();
UUID userId = UUID.randomUUID();
Establishment establishment = new Establishment("Bar", "BAR", "1 rue Test", "Paris", "75001", new Users());
establishment.setId(establishmentId);
EstablishmentRatingRequestDTO requestDTO = new EstablishmentRatingRequestDTO();
requestDTO.setRating(5);
when(establishmentRepository.findById(establishmentId)).thenReturn(establishment);
when(usersRepository.findById(userId)).thenReturn(null);
assertThrows(RuntimeException.class, () ->
establishmentRatingService.submitRating(establishmentId, userId, requestDTO));
verify(ratingRepository, never()).persist(any());
}
@Test
@DisplayName("submitRating quand l'utilisateur a déjà noté lance RuntimeException")
void submitRating_alreadyRated_throws() {
UUID establishmentId = UUID.randomUUID();
UUID userId = UUID.randomUUID();
Establishment establishment = new Establishment("Bar", "BAR", "1 rue Test", "Paris", "75001", new Users());
establishment.setId(establishmentId);
Users user = new Users();
user.setId(userId);
EstablishmentRating existing = new EstablishmentRating(establishment, user, 3);
EstablishmentRatingRequestDTO requestDTO = new EstablishmentRatingRequestDTO();
requestDTO.setRating(5);
when(establishmentRepository.findById(establishmentId)).thenReturn(establishment);
when(usersRepository.findById(userId)).thenReturn(user);
when(ratingRepository.findByEstablishmentIdAndUserId(establishmentId, userId)).thenReturn(existing);
assertThrows(RuntimeException.class, () ->
establishmentRatingService.submitRating(establishmentId, userId, requestDTO));
verify(ratingRepository, never()).persist(any());
}
@Test
@DisplayName("getUserRating retourne la note si elle existe")
void getUserRating_exists_returnsRating() {
UUID establishmentId = UUID.randomUUID();
UUID userId = UUID.randomUUID();
Establishment establishment = new Establishment("Bar", "BAR", "1 rue Test", "Paris", "75001", new Users());
establishment.setId(establishmentId);
Users user = new Users();
user.setId(userId);
EstablishmentRating rating = new EstablishmentRating(establishment, user, 4);
when(ratingRepository.findByEstablishmentIdAndUserId(establishmentId, userId)).thenReturn(rating);
EstablishmentRating result = establishmentRatingService.getUserRating(establishmentId, userId);
assertNotNull(result);
assertEquals(4, result.getRating());
}
@Test
@DisplayName("getUserRating retourne null si pas de note")
void getUserRating_notExists_returnsNull() {
UUID establishmentId = UUID.randomUUID();
UUID userId = UUID.randomUUID();
when(ratingRepository.findByEstablishmentIdAndUserId(establishmentId, userId)).thenReturn(null);
EstablishmentRating result = establishmentRatingService.getUserRating(establishmentId, userId);
assertNull(result);
}
@Test
@DisplayName("getRatingStats retourne moyenne, total et distribution")
void getRatingStats_returnsMap() {
UUID establishmentId = UUID.randomUUID();
when(ratingRepository.calculateAverageRating(establishmentId)).thenReturn(4.2);
when(ratingRepository.countByEstablishmentId(establishmentId)).thenReturn(10L);
when(ratingRepository.calculateRatingDistribution(establishmentId)).thenReturn(Map.of(4, 6, 5, 4));
Map<String, Object> result = establishmentRatingService.getRatingStats(establishmentId);
assertNotNull(result);
assertEquals(4.2, result.get("averageRating"));
assertEquals(10, result.get("totalRatingsCount"));
@SuppressWarnings("unchecked")
Map<Integer, Integer> dist = (Map<Integer, Integer>) result.get("ratingDistribution");
assertNotNull(dist);
assertEquals(6, dist.get(4));
assertEquals(4, dist.get(5));
}
@Test
@DisplayName("updateRating avec note existante met à jour et met à jour les stats")
void updateRating_exists_updatesAndRefreshesStats() {
UUID establishmentId = UUID.randomUUID();
UUID userId = UUID.randomUUID();
Establishment establishment = new Establishment("Bar", "BAR", "1 rue Test", "Paris", "75001", new Users());
establishment.setId(establishmentId);
Users user = new Users();
user.setId(userId);
EstablishmentRating rating = new EstablishmentRating(establishment, user, 3);
EstablishmentRatingRequestDTO requestDTO = new EstablishmentRatingRequestDTO();
requestDTO.setRating(5);
requestDTO.setComment("Parfait");
when(ratingRepository.findByEstablishmentIdAndUserId(establishmentId, userId)).thenReturn(rating);
when(ratingRepository.calculateAverageRating(establishmentId)).thenReturn(5.0);
when(ratingRepository.countByEstablishmentId(establishmentId)).thenReturn(1L);
when(ratingRepository.calculateRatingDistribution(establishmentId)).thenReturn(Map.of(5, 1));
EstablishmentRating result = establishmentRatingService.updateRating(establishmentId, userId, requestDTO);
assertNotNull(result);
verify(ratingRepository).persist(rating);
verify(establishmentRepository).persist(establishment);
}
@Test
@DisplayName("updateRating quand la note n'existe pas lance RuntimeException")
void updateRating_notExists_throws() {
UUID establishmentId = UUID.randomUUID();
UUID userId = UUID.randomUUID();
EstablishmentRatingRequestDTO requestDTO = new EstablishmentRatingRequestDTO();
requestDTO.setRating(5);
when(ratingRepository.findByEstablishmentIdAndUserId(establishmentId, userId)).thenReturn(null);
assertThrows(RuntimeException.class, () ->
establishmentRatingService.updateRating(establishmentId, userId, requestDTO));
verify(ratingRepository, never()).persist(any());
}
}