Feature/manage reviews #2

Merged
Patrick FELIX-VIMALARATNAM merged 20 commits from feature/manage_reviews into main 2026-06-12 20:48:07 +02:00
Showing only changes of commit 58e4a53196 - Show all commits
@@ -0,0 +1,82 @@
package fr.iut_fbleau.but3.dev62.mylibrary.reviews.converter;
import java.time.LocalDate;
import java.util.UUID;
import fr.iut_fbleau.but3.dev62.mylibrary.customer.CustomerDTO;
import fr.iut_fbleau.but3.dev62.mylibrary.customer.converter.CustomerConverter;
import fr.iut_fbleau.but3.dev62.mylibrary.customer.entity.Customer;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@DisplayName("ReviewConverterTest Unit Tests")
public class ReviewConverterTest {
@Nested
@DisplayName("toDomain() method tests")
class ToDomainTests {
@Test
@DisplayName("Should convert ReviewInfo to Review domain object")
void shouldConvertReviewInfoToDomain() {
// Given
LocalDate date = LocalDate.of(2026, 3, 24);
ReviewInfo reviewInfo = new ReviewInfo(5, "tres bon livre", date);
// When
Review result = ReviewConverter.toDomain(reviewInfo);
// Then
assertNotNull(result);
assertEquals(reviewInfo.note(), result.getNote());
assertEquals(reviewInfo.comment(), result.getComment());
assertEquals(reviewInfo.purchaseDate(), result.getPurchaseDate());
}
}
@Nested
@DisplayName("toDTO() method tests")
class ToDTOTests {
@Test
@DisplayName("Should convert Review domain object to ReviewDTO with all fields mapped correctly")
void shouldConvertReviewToDTO() {
LocalDate date = LocalDate.of(2026, 3, 24);
Review review = Review.builder()
.customerId(UUID.randomUUID())
.bookId(UUID.randomUUID())
.note(5)
.comment("très bon livre")
.purchaseDate(date)
.build();
ReviewDTO result = ReviewConverter.toDTO(review);
assertNotNull(result);
assertEquals(review.getCustomerId(), result.getCustomerId());
assertEquals(review.getBookId(), result.getBookId());
assertEquals(review.getNote(), result.getNote());
assertEquals(review.getComment(), result.getComment());
assertEquals(review.getPurchaseDate(), result.getPurchaseDate());
}
}
@Test
@DisplayName("Should preserve empty string values during conversion")
void shouldPreserveEmptyStrings() {
LocalDate date = LocalDate.of(2026, 3, 24);
ReviewInfo reviewInfo = new ReviewInfo(5, "", date);
Review domainResult = ReviewConverter.toDomain(reviewInfo);
ReviewDTO dtoResult = ReviewConverter.toDTO(domainResult);
assertEquals(5, dtoResult.getNote());
assertEquals("", dtoResult.getComment());
assertEquals(date, dtoResult.getPurchaseDate());
}
}