front_foundation #9
@ -43,7 +43,6 @@ class TestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SpringBootTest
|
||||
@Transactional // Each @Test method runs in a transaction that is rolled back
|
||||
public class SharedApiServiceTest {
|
||||
@ -68,7 +67,6 @@ public class SharedApiServiceTest {
|
||||
private static Project staticUnauthorizedProject;
|
||||
private static String staticUnauthorizedMail;
|
||||
|
||||
|
||||
// --- Static Setup (Runs once before all tests) ---
|
||||
// Use @BeforeAll static method with injected services
|
||||
@BeforeAll
|
||||
@ -78,54 +76,90 @@ public class SharedApiServiceTest {
|
||||
@Autowired EntrepreneurService entrepreneurService) {
|
||||
|
||||
// Create and Save core test data here using injected services
|
||||
staticAuthorizedAdmin = administratorService.addAdministrator(getTestAdmin("static_authorized_admin"));
|
||||
staticAuthorizedAdmin =
|
||||
administratorService.addAdministrator(getTestAdmin("static_authorized_admin"));
|
||||
staticAuthorizedMail = staticAuthorizedAdmin.getPrimaryMail();
|
||||
|
||||
staticUnauthorizedProject = projectService.addNewProject(getTestProject("static_unauthorized_project", administratorService.addAdministrator(getTestAdmin("static_unauthorized_admin"))));
|
||||
staticUnauthorizedMail = administratorService.addAdministrator(getTestAdmin("static_unauthorized_user")).getPrimaryMail(); // User who is NOT admin of the unauthorized project
|
||||
staticUnauthorizedProject =
|
||||
projectService.addNewProject(
|
||||
getTestProject(
|
||||
"static_unauthorized_project",
|
||||
administratorService.addAdministrator(
|
||||
getTestAdmin("static_unauthorized_admin"))));
|
||||
staticUnauthorizedMail =
|
||||
administratorService
|
||||
.addAdministrator(getTestAdmin("static_unauthorized_user"))
|
||||
.getPrimaryMail(); // User who is NOT admin of the unauthorized project
|
||||
|
||||
staticAuthorizedProject = projectService.addNewProject(getTestProject("static_authorized_project", staticAuthorizedAdmin));
|
||||
staticAuthorizedProject =
|
||||
projectService.addNewProject(
|
||||
getTestProject("static_authorized_project", staticAuthorizedAdmin));
|
||||
|
||||
// Link a static entrepreneur to the authorized project if needed for some tests
|
||||
// Entrepreneur staticLinkedEntrepreneur = entrepreneurService.addEntrepreneur(getTestEntrepreneur("static_linked_entrepreneur"));
|
||||
// Entrepreneur staticLinkedEntrepreneur =
|
||||
// entrepreneurService.addEntrepreneur(getTestEntrepreneur("static_linked_entrepreneur"));
|
||||
// staticAuthorizedProject.updateListEntrepreneurParticipation(staticLinkedEntrepreneur);
|
||||
// projectService.addNewProject(staticAuthorizedProject); // Re-save the project after updating lists
|
||||
// projectService.addNewProject(staticAuthorizedProject); // Re-save the project after
|
||||
// updating lists
|
||||
}
|
||||
|
||||
// --- Per-Test Setup (Runs before each test method) ---
|
||||
@BeforeEach
|
||||
void setupForEach() {
|
||||
// Reset mock expectations before each test
|
||||
MockitoAnnotations.openMocks(this); // Needed for mocks if not using @ExtendWith(MockitoExtension.class)
|
||||
MockitoAnnotations.openMocks(
|
||||
this); // Needed for mocks if not using @ExtendWith(MockitoExtension.class)
|
||||
|
||||
// --- Configure the mock UtilsService based on the actual authorization rules ---
|
||||
|
||||
// Rule: Any admin can check any project.
|
||||
// Assuming staticAuthorizedMail is an admin:
|
||||
when(mockUtilsService.isAllowedToCheckProject(eq(staticAuthorizedMail), anyLong())).thenReturn(true); // Admin allowed for ANY project ID
|
||||
when(mockUtilsService.isAllowedToCheckProject(eq(staticAuthorizedMail), anyLong()))
|
||||
.thenReturn(true); // Admin allowed for ANY project ID
|
||||
|
||||
// Rule: An entrepreneur can only check their own stuff.
|
||||
// Assuming staticUnauthorizedMail is an entrepreneur NOT linked to staticAuthorizedProject or staticUnauthorizedProject:
|
||||
when(mockUtilsService.isAllowedToCheckProject(eq(staticUnauthorizedMail), anyLong())).thenReturn(false); // Unauthorized entrepreneur NOT allowed for ANY project ID by default
|
||||
// Assuming staticUnauthorizedMail is an entrepreneur NOT linked to staticAuthorizedProject
|
||||
// or staticUnauthorizedProject:
|
||||
when(mockUtilsService.isAllowedToCheckProject(eq(staticUnauthorizedMail), anyLong()))
|
||||
.thenReturn(
|
||||
false); // Unauthorized entrepreneur NOT allowed for ANY project ID by
|
||||
// default
|
||||
|
||||
// Add more specific mock setups here if needed for entrepreneur tests
|
||||
// E.g., If you have a test specifically for an entrepreneur accessing THEIR project:
|
||||
// Entrepreneur testEntrepreneur = entrepreneurService.addEntrepreneur(getTestEntrepreneur("specific_linked_entrepreneur"));
|
||||
// Project linkedProject = projectService.addNewProject(getTestProject("specific_linked_project", staticAuthorizedAdmin));
|
||||
// Entrepreneur testEntrepreneur =
|
||||
// entrepreneurService.addEntrepreneur(getTestEntrepreneur("specific_linked_entrepreneur"));
|
||||
// Project linkedProject =
|
||||
// projectService.addNewProject(getTestProject("specific_linked_project",
|
||||
// staticAuthorizedAdmin));
|
||||
// // Link testEntrepreneur to linkedProject in the database setup...
|
||||
// when(mockUtilsService.isAllowedToCheckProject(eq(testEntrepreneur.getPrimaryMail()), eq(linkedProject.getIdProject()))).thenReturn(true);
|
||||
// when(mockUtilsService.isAllowedToCheckProject(eq(testEntrepreneur.getPrimaryMail()), anyLong())).thenReturn(false); // Deny for other projects
|
||||
// when(mockUtilsService.isAllowedToCheckProject(eq(testEntrepreneur.getPrimaryMail()),
|
||||
// eq(linkedProject.getIdProject()))).thenReturn(true);
|
||||
// when(mockUtilsService.isAllowedToCheckProject(eq(testEntrepreneur.getPrimaryMail()),
|
||||
// anyLong())).thenReturn(false); // Deny for other projects
|
||||
|
||||
}
|
||||
|
||||
|
||||
// --- Helper Methods (Can remain non-static or static as needed) ---
|
||||
private static Administrator getTestAdmin(String name) {
|
||||
return new Administrator(name + "_surname", name, name + "@example.com", "secondary_" + name + "@example.com", "0123456789");
|
||||
return new Administrator(
|
||||
name + "_surname",
|
||||
name,
|
||||
name + "@example.com",
|
||||
"secondary_" + name + "@example.com",
|
||||
"0123456789");
|
||||
}
|
||||
|
||||
private static Entrepreneur getTestEntrepreneur(String name) {
|
||||
return new Entrepreneur(name + "_surname", name, name + "@example.com", "secondary_" + name + "@example.com", "0123456789", "Test School", "Test Course", false);
|
||||
return new Entrepreneur(
|
||||
name + "_surname",
|
||||
name,
|
||||
name + "@example.com",
|
||||
"secondary_" + name + "@example.com",
|
||||
"0123456789",
|
||||
"Test School",
|
||||
"Test Course",
|
||||
false);
|
||||
}
|
||||
|
||||
private static Project getTestProject(String name, Administrator admin) {
|
||||
@ -133,7 +167,8 @@ public class SharedApiServiceTest {
|
||||
return project;
|
||||
}
|
||||
|
||||
private static SectionCell getTestSectionCell(Project project, Long sectionId, String content, LocalDateTime date) {
|
||||
private static SectionCell getTestSectionCell(
|
||||
Project project, Long sectionId, String content, LocalDateTime date) {
|
||||
SectionCell sectionCell = new SectionCell();
|
||||
sectionCell.setProjectSectionCell(project);
|
||||
sectionCell.setSectionId(sectionId);
|
||||
@ -142,7 +177,14 @@ public class SharedApiServiceTest {
|
||||
return sectionCell;
|
||||
}
|
||||
|
||||
private static Appointment getTestAppointment(LocalDate date, LocalTime time, LocalTime duration, String place, String subject, List<SectionCell> sectionCells, Report report) {
|
||||
private static Appointment getTestAppointment(
|
||||
LocalDate date,
|
||||
LocalTime time,
|
||||
LocalTime duration,
|
||||
String place,
|
||||
String subject,
|
||||
List<SectionCell> sectionCells,
|
||||
Report report) {
|
||||
Appointment appointment = new Appointment();
|
||||
appointment.setAppointmentDate(date);
|
||||
appointment.setAppointmentTime(time);
|
||||
@ -168,8 +210,6 @@ public class SharedApiServiceTest {
|
||||
return report;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Tests retrieving section cells for a specific project and section ID before a given date
|
||||
* when the user is authorized but no matching cells exist.
|
||||
@ -182,7 +222,8 @@ public class SharedApiServiceTest {
|
||||
LocalDateTime dateFilter = LocalDateTime.now().plusDays(1);
|
||||
|
||||
// Act
|
||||
Iterable<SectionCell> result = sharedApiService.getSectionCells(
|
||||
Iterable<SectionCell> result =
|
||||
sharedApiService.getSectionCells(
|
||||
staticAuthorizedProject.getIdProject(),
|
||||
targetSectionId,
|
||||
dateFilter.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")),
|
||||
@ -202,19 +243,25 @@ public class SharedApiServiceTest {
|
||||
void testGetSectionCells_Unauthorized() {
|
||||
// Arrange: mockUtilsService configured in BeforeEach
|
||||
// Act & Assert
|
||||
ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> {
|
||||
ResponseStatusException exception =
|
||||
assertThrows(
|
||||
ResponseStatusException.class,
|
||||
() -> {
|
||||
sharedApiService.getSectionCells(
|
||||
staticAuthorizedProject.getIdProject(), // Project static user is not authorized for
|
||||
staticAuthorizedProject
|
||||
.getIdProject(), // Project static user is not
|
||||
// authorized for
|
||||
1L,
|
||||
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")),
|
||||
LocalDateTime.now()
|
||||
.format(
|
||||
DateTimeFormatter.ofPattern(
|
||||
"yyyy-MM-dd HH:mm")),
|
||||
staticUnauthorizedMail); // Static unauthorized user mail
|
||||
});
|
||||
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Tests retrieving all section cells for a project when the user is authorized
|
||||
* but the project has no section cells.
|
||||
@ -224,9 +271,9 @@ public class SharedApiServiceTest {
|
||||
void testGetAllSectionCells_Authorized_NoCells() {
|
||||
// Arrange: staticAuthorizedProject has no section cells initially in BeforeAll
|
||||
// Act
|
||||
Iterable<SectionCell> result = sharedApiService.getAllSectionCells(
|
||||
staticAuthorizedProject.getIdProject(),
|
||||
staticAuthorizedMail);
|
||||
Iterable<SectionCell> result =
|
||||
sharedApiService.getAllSectionCells(
|
||||
staticAuthorizedProject.getIdProject(), staticAuthorizedMail);
|
||||
|
||||
List<SectionCell> resultList = TestUtils.toList(result);
|
||||
|
||||
@ -242,18 +289,17 @@ public class SharedApiServiceTest {
|
||||
void testGetAllSectionCells_Unauthorized() {
|
||||
// Arrange: mockUtilsService configured in BeforeEach
|
||||
// Act & Assert
|
||||
ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> {
|
||||
ResponseStatusException exception =
|
||||
assertThrows(
|
||||
ResponseStatusException.class,
|
||||
() -> {
|
||||
sharedApiService.getAllSectionCells(
|
||||
staticAuthorizedProject.getIdProject(),
|
||||
staticUnauthorizedMail);
|
||||
staticAuthorizedProject.getIdProject(), staticUnauthorizedMail);
|
||||
});
|
||||
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Tests retrieving entrepreneurs linked to a project when the user is authorized
|
||||
* but no entrepreneurs are linked.
|
||||
@ -263,9 +309,9 @@ public class SharedApiServiceTest {
|
||||
void testGetEntrepreneursByProjectId_Authorized_NotFound() {
|
||||
// Arrange: staticAuthorizedProject has no entrepreneurs linked initially in BeforeAll
|
||||
// Act
|
||||
Iterable<Entrepreneur> result = sharedApiService.getEntrepreneursByProjectId(
|
||||
staticAuthorizedProject.getIdProject(),
|
||||
staticAuthorizedMail);
|
||||
Iterable<Entrepreneur> result =
|
||||
sharedApiService.getEntrepreneursByProjectId(
|
||||
staticAuthorizedProject.getIdProject(), staticAuthorizedMail);
|
||||
|
||||
List<Entrepreneur> resultList = TestUtils.toList(result);
|
||||
|
||||
@ -281,10 +327,12 @@ public class SharedApiServiceTest {
|
||||
void testGetEntrepreneursByProjectId_Unauthorized() {
|
||||
// Arrange: mockUtilsService configured in BeforeEach
|
||||
// Act & Assert
|
||||
ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> {
|
||||
ResponseStatusException exception =
|
||||
assertThrows(
|
||||
ResponseStatusException.class,
|
||||
() -> {
|
||||
sharedApiService.getEntrepreneursByProjectId(
|
||||
staticAuthorizedProject.getIdProject(),
|
||||
staticUnauthorizedMail);
|
||||
staticAuthorizedProject.getIdProject(), staticUnauthorizedMail);
|
||||
});
|
||||
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatusCode());
|
||||
@ -300,9 +348,9 @@ public class SharedApiServiceTest {
|
||||
void testGetAdminByProjectId_Authorized_Found() {
|
||||
// Arrange: staticAuthorizedProject is created with staticAuthorizedAdmin in BeforeAll
|
||||
// Act
|
||||
Administrator result = sharedApiService.getAdminByProjectId(
|
||||
staticAuthorizedProject.getIdProject(),
|
||||
staticAuthorizedMail);
|
||||
Administrator result =
|
||||
sharedApiService.getAdminByProjectId(
|
||||
staticAuthorizedProject.getIdProject(), staticAuthorizedMail);
|
||||
|
||||
// Assert
|
||||
assertNotNull(result);
|
||||
@ -317,18 +365,17 @@ public class SharedApiServiceTest {
|
||||
void testGetAdminByProjectId_Unauthorized() {
|
||||
// Arrange: mockUtilsService configured in BeforeEach
|
||||
// Act & Assert
|
||||
ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> {
|
||||
ResponseStatusException exception =
|
||||
assertThrows(
|
||||
ResponseStatusException.class,
|
||||
() -> {
|
||||
sharedApiService.getAdminByProjectId(
|
||||
staticAuthorizedProject.getIdProject(),
|
||||
staticUnauthorizedMail);
|
||||
staticAuthorizedProject.getIdProject(), staticUnauthorizedMail);
|
||||
});
|
||||
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Tests retrieving appointments linked to a project's section cells when the user is authorized
|
||||
* but no such appointments exist.
|
||||
@ -338,9 +385,9 @@ public class SharedApiServiceTest {
|
||||
void testGetAppointmentsByProjectId_Authorized_NotFound() {
|
||||
// Arrange: staticAuthorizedProject has no linked section cells or appointments initially
|
||||
// Act
|
||||
Iterable<Appointment> result = sharedApiService.getAppointmentsByProjectId(
|
||||
staticAuthorizedProject.getIdProject(),
|
||||
staticAuthorizedMail);
|
||||
Iterable<Appointment> result =
|
||||
sharedApiService.getAppointmentsByProjectId(
|
||||
staticAuthorizedProject.getIdProject(), staticAuthorizedMail);
|
||||
|
||||
List<Appointment> resultList = TestUtils.toList(result);
|
||||
|
||||
@ -356,10 +403,12 @@ public class SharedApiServiceTest {
|
||||
void testGetAppointmentsByProjectId_Unauthorized() {
|
||||
// Arrange: mockUtilsService configured in BeforeEach
|
||||
// Act & Assert
|
||||
ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> {
|
||||
ResponseStatusException exception =
|
||||
assertThrows(
|
||||
ResponseStatusException.class,
|
||||
() -> {
|
||||
sharedApiService.getAppointmentsByProjectId(
|
||||
staticAuthorizedProject.getIdProject(),
|
||||
staticUnauthorizedMail);
|
||||
staticAuthorizedProject.getIdProject(), staticUnauthorizedMail);
|
||||
});
|
||||
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatusCode());
|
||||
@ -372,7 +421,8 @@ public class SharedApiServiceTest {
|
||||
*/
|
||||
@Test
|
||||
void testCreateAppointmentRequest_Unauthorized() {
|
||||
// Arrange: Create transient appointment linked to a cell in the static *unauthorized* project
|
||||
// Arrange: Create transient appointment linked to a cell in the static *unauthorized*
|
||||
// project
|
||||
LocalDate date = LocalDate.parse("2026-01-01");
|
||||
LocalTime time = LocalTime.parse("10:00:00");
|
||||
LocalTime duration = LocalTime.parse("00:30:00");
|
||||
@ -380,23 +430,35 @@ public class SharedApiServiceTest {
|
||||
String subject = "Discuss Project";
|
||||
String reportContent = "Initial Report";
|
||||
|
||||
SectionCell linkedCell = sectionCellService.addNewSectionCell(getTestSectionCell(staticUnauthorizedProject, 1L, "Related Section Content", LocalDateTime.now()));
|
||||
SectionCell linkedCell =
|
||||
sectionCellService.addNewSectionCell(
|
||||
getTestSectionCell(
|
||||
staticUnauthorizedProject,
|
||||
1L,
|
||||
"Related Section Content",
|
||||
LocalDateTime.now()));
|
||||
|
||||
Report newReport = getTestReport(reportContent);
|
||||
Appointment newAppointment = getTestAppointment(date, time, duration, place, subject, List.of(linkedCell), newReport);
|
||||
Appointment newAppointment =
|
||||
getTestAppointment(
|
||||
date, time, duration, place, subject, List.of(linkedCell), newReport);
|
||||
|
||||
// mockUtilsService is configured in BeforeEach to deny staticUnauthorizedMail for staticUnauthorizedProject
|
||||
// mockUtilsService is configured in BeforeEach to deny staticUnauthorizedMail for
|
||||
// staticUnauthorizedProject
|
||||
|
||||
// Act & Assert
|
||||
ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> {
|
||||
sharedApiService.createAppointmentRequest(newAppointment, staticUnauthorizedMail); // Unauthorized user mail
|
||||
ResponseStatusException exception =
|
||||
assertThrows(
|
||||
ResponseStatusException.class,
|
||||
() -> {
|
||||
sharedApiService.createAppointmentRequest(
|
||||
newAppointment,
|
||||
staticUnauthorizedMail); // Unauthorized user mail
|
||||
});
|
||||
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
_____ _ _ _
|
||||
@ -412,7 +474,6 @@ public class SharedApiServiceTest {
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/* these tests fail because of the use of mockito's eq(),
|
||||
* and since thee instances are technically not the same as
|
||||
* as the classes used to turn them into persistant data
|
||||
@ -427,21 +488,41 @@ public class SharedApiServiceTest {
|
||||
* Verifies that no authorization exception is thrown. (Note: File I/O is mocked).
|
||||
*/
|
||||
// Tests getPDFReport (Focus on authorization and data retrieval flow)
|
||||
/*@Test*/ // Commenting out failing test
|
||||
/*@Test*/
|
||||
// Commenting out failing test
|
||||
void testGetPDFReport_Authorized() throws DocumentException, URISyntaxException, IOException {
|
||||
// Arrange: Create a specific appointment linked to the static authorized project
|
||||
SectionCell cell = sectionCellService.addNewSectionCell(getTestSectionCell(staticAuthorizedProject, 1L, "Cell for PDF Test", LocalDateTime.now()));
|
||||
Report report = new Report(null, "PDF Report Content // Point 2 PDF Content"); // ID set by DB
|
||||
Appointment appointment = getTestAppointment(LocalDate.now().plusDays(20), LocalTime.of(14,0), LocalTime.of(0, 45), "Salle PDF", "PDF Subject", List.of(cell), report);
|
||||
SectionCell cell =
|
||||
sectionCellService.addNewSectionCell(
|
||||
getTestSectionCell(
|
||||
staticAuthorizedProject,
|
||||
1L,
|
||||
"Cell for PDF Test",
|
||||
LocalDateTime.now()));
|
||||
Report report =
|
||||
new Report(null, "PDF Report Content // Point 2 PDF Content"); // ID set by DB
|
||||
Appointment appointment =
|
||||
getTestAppointment(
|
||||
LocalDate.now().plusDays(20),
|
||||
LocalTime.of(14, 0),
|
||||
LocalTime.of(0, 45),
|
||||
"Salle PDF",
|
||||
"PDF Subject",
|
||||
List.of(cell),
|
||||
report);
|
||||
Appointment savedAppointment = appointmentService.addNewAppointment(appointment);
|
||||
|
||||
|
||||
// Mock getAppointmentById to return the saved appointment for the service to use
|
||||
when(appointmentService.getAppointmentById(eq(savedAppointment.getIdAppointment()))).thenReturn(savedAppointment);
|
||||
// mockUtilsService is configured in BeforeEach to allow staticAuthorizedMail for staticAuthorizedProject
|
||||
when(appointmentService.getAppointmentById(eq(savedAppointment.getIdAppointment())))
|
||||
.thenReturn(savedAppointment);
|
||||
// mockUtilsService is configured in BeforeEach to allow staticAuthorizedMail for
|
||||
// staticAuthorizedProject
|
||||
|
||||
// Act & Assert (Just assert no authorization exception is thrown)
|
||||
assertDoesNotThrow(() -> sharedApiService.getPDFReport(savedAppointment.getIdAppointment(), staticAuthorizedMail));
|
||||
assertDoesNotThrow(
|
||||
() ->
|
||||
sharedApiService.getPDFReport(
|
||||
savedAppointment.getIdAppointment(), staticAuthorizedMail));
|
||||
|
||||
// Note: Actual PDF generation and file operations are not tested here,
|
||||
// as that requires mocking external libraries and file system operations.
|
||||
@ -452,21 +533,43 @@ public class SharedApiServiceTest {
|
||||
* for the project linked to the appointment's section cell.
|
||||
* Verifies that an Unauthorized ResponseStatusException is thrown.
|
||||
*/
|
||||
/*@Test*/ // Commenting out failing test
|
||||
/*@Test*/
|
||||
// Commenting out failing test
|
||||
void testGetPDFReport_Unauthorized() {
|
||||
// Arrange: Create a specific appointment linked to the static *unauthorized* project
|
||||
SectionCell cell = sectionCellService.addNewSectionCell(getTestSectionCell(staticUnauthorizedProject, 1L, "Cell for Unauthorized PDF Test", LocalDateTime.now()));
|
||||
SectionCell cell =
|
||||
sectionCellService.addNewSectionCell(
|
||||
getTestSectionCell(
|
||||
staticUnauthorizedProject,
|
||||
1L,
|
||||
"Cell for Unauthorized PDF Test",
|
||||
LocalDateTime.now()));
|
||||
Report report = new Report(null, "Unauthorized PDF Report Content");
|
||||
Appointment appointment = getTestAppointment(LocalDate.now().plusDays(21), LocalTime.of(15,0), LocalTime.of(0, 30), "Salle Unauthorized PDF", "Unauthorized PDF Subject", List.of(cell), report);
|
||||
Appointment appointment =
|
||||
getTestAppointment(
|
||||
LocalDate.now().plusDays(21),
|
||||
LocalTime.of(15, 0),
|
||||
LocalTime.of(0, 30),
|
||||
"Salle Unauthorized PDF",
|
||||
"Unauthorized PDF Subject",
|
||||
List.of(cell),
|
||||
report);
|
||||
Appointment savedAppointment = appointmentService.addNewAppointment(appointment);
|
||||
|
||||
// Mock getAppointmentById to return the saved appointment
|
||||
when(appointmentService.getAppointmentById(eq(savedAppointment.getIdAppointment()))).thenReturn(savedAppointment);
|
||||
// mockUtilsService is configured in BeforeEach to DENY staticUnauthorizedMail for staticUnauthorizedProject
|
||||
when(appointmentService.getAppointmentById(eq(savedAppointment.getIdAppointment())))
|
||||
.thenReturn(savedAppointment);
|
||||
// mockUtilsService is configured in BeforeEach to DENY staticUnauthorizedMail for
|
||||
// staticUnauthorizedProject
|
||||
|
||||
// Act & Assert
|
||||
ResponseStatusException exception = assertThrows(ResponseStatusException.class, () -> {
|
||||
sharedApiService.getPDFReport(savedAppointment.getIdAppointment(), staticUnauthorizedMail); // Unauthorized user mail
|
||||
ResponseStatusException exception =
|
||||
assertThrows(
|
||||
ResponseStatusException.class,
|
||||
() -> {
|
||||
sharedApiService.getPDFReport(
|
||||
savedAppointment.getIdAppointment(),
|
||||
staticUnauthorizedMail); // Unauthorized user mail
|
||||
});
|
||||
|
||||
assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatusCode());
|
||||
@ -478,7 +581,8 @@ public class SharedApiServiceTest {
|
||||
* Verifies that the appointment and its relationships are saved correctly in the database.
|
||||
*/
|
||||
// Tests createAppointmentRequest
|
||||
/*@Test*/ // Commenting out failing test
|
||||
/*@Test*/
|
||||
// Commenting out failing test
|
||||
void testCreateAppointmentRequest_Authorized_Success() {
|
||||
// Arrange: Create transient appointment linked to a cell in the static authorized project
|
||||
LocalDate date = LocalDate.parse("2026-01-01");
|
||||
@ -488,28 +592,52 @@ public class SharedApiServiceTest {
|
||||
String subject = "Discuss Project Integrated";
|
||||
String reportContent = "Initial Report Integrated";
|
||||
|
||||
SectionCell linkedCell = sectionCellService.addNewSectionCell(getTestSectionCell(staticAuthorizedProject, 1L, "Related Section Content Integrated", LocalDateTime.now()));
|
||||
SectionCell linkedCell =
|
||||
sectionCellService.addNewSectionCell(
|
||||
getTestSectionCell(
|
||||
staticAuthorizedProject,
|
||||
1L,
|
||||
"Related Section Content Integrated",
|
||||
LocalDateTime.now()));
|
||||
|
||||
Report newReport = getTestReport(reportContent); // Uses no-arg constructor
|
||||
Appointment newAppointment = getTestAppointment(date, time, duration, place, subject, List.of(linkedCell), newReport);
|
||||
Appointment newAppointment =
|
||||
getTestAppointment(
|
||||
date, time, duration, place, subject, List.of(linkedCell), newReport);
|
||||
|
||||
// mockUtilsService is configured in BeforeEach to allow staticAuthorizedMail for staticAuthorizedProject
|
||||
// mockUtilsService is configured in BeforeEach to allow staticAuthorizedMail for
|
||||
// staticAuthorizedProject
|
||||
|
||||
// Act
|
||||
// Allow the service method to call the actual appointmentService.addNewAppointment
|
||||
assertDoesNotThrow(() -> sharedApiService.createAppointmentRequest(newAppointment, staticAuthorizedMail));
|
||||
assertDoesNotThrow(
|
||||
() ->
|
||||
sharedApiService.createAppointmentRequest(
|
||||
newAppointment, staticAuthorizedMail));
|
||||
|
||||
// Assert: Retrieve the appointment from the DB and verify it and its relationships were saved
|
||||
// Assert: Retrieve the appointment from the DB and verify it and its relationships were
|
||||
// saved
|
||||
// We find it by looking for appointments linked to the authorized project's cells
|
||||
Iterable<SectionCell> projectCells = sectionCellService.getSectionCellsByProject(staticAuthorizedProject, 1L); // Fetch relevant cells
|
||||
Iterable<SectionCell> projectCells =
|
||||
sectionCellService.getSectionCellsByProject(
|
||||
staticAuthorizedProject, 1L); // Fetch relevant cells
|
||||
List<Appointment> projectAppointmentsList = new ArrayList<>();
|
||||
projectCells.forEach(cell -> projectAppointmentsList.addAll(sectionCellService.getAppointmentsBySectionCellId(cell.getIdSectionCell()))); // Get appointments for those cells
|
||||
projectCells.forEach(
|
||||
cell ->
|
||||
projectAppointmentsList.addAll(
|
||||
sectionCellService.getAppointmentsBySectionCellId(
|
||||
cell
|
||||
.getIdSectionCell()))); // Get appointments for
|
||||
// those cells
|
||||
|
||||
Optional<Appointment> createdAppointmentOpt = projectAppointmentsList.stream()
|
||||
.filter(a -> a.getAppointmentDate().equals(date) &&
|
||||
a.getAppointmentTime().equals(time) &&
|
||||
a.getAppointmentPlace().equals(place) &&
|
||||
a.getAppointmentSubject().equals(subject))
|
||||
Optional<Appointment> createdAppointmentOpt =
|
||||
projectAppointmentsList.stream()
|
||||
.filter(
|
||||
a ->
|
||||
a.getAppointmentDate().equals(date)
|
||||
&& a.getAppointmentTime().equals(time)
|
||||
&& a.getAppointmentPlace().equals(place)
|
||||
&& a.getAppointmentSubject().equals(subject))
|
||||
.findFirst();
|
||||
|
||||
assertTrue(createdAppointmentOpt.isPresent());
|
||||
@ -518,16 +646,30 @@ public class SharedApiServiceTest {
|
||||
assertNotNull(createdAppointment.getAppointmentReport());
|
||||
assertEquals(reportContent, createdAppointment.getAppointmentReport().getReportContent());
|
||||
// FIX: Corrected bidirectional link check
|
||||
assertEquals(createdAppointment.getIdAppointment(), createdAppointment.getAppointmentReport().getAppointmentReport().getIdAppointment());
|
||||
assertEquals(
|
||||
createdAppointment.getIdAppointment(),
|
||||
createdAppointment
|
||||
.getAppointmentReport()
|
||||
.getAppointmentReport()
|
||||
.getIdAppointment());
|
||||
assertEquals(1, createdAppointment.getAppointmentListSectionCell().size());
|
||||
assertTrue(createdAppointment.getAppointmentListSectionCell().stream().anyMatch(sc -> sc.getIdSectionCell().equals(linkedCell.getIdSectionCell())));
|
||||
assertTrue(
|
||||
createdAppointment.getAppointmentListSectionCell().stream()
|
||||
.anyMatch(
|
||||
sc -> sc.getIdSectionCell().equals(linkedCell.getIdSectionCell())));
|
||||
|
||||
List<Appointment> appointmentsLinkedToCell = TestUtils.toList(sectionCellService.getAppointmentsBySectionCellId(linkedCell.getIdSectionCell()));
|
||||
assertTrue(appointmentsLinkedToCell.stream().anyMatch(a -> a.getIdAppointment().equals(createdAppointment.getIdAppointment())));
|
||||
List<Appointment> appointmentsLinkedToCell =
|
||||
TestUtils.toList(
|
||||
sectionCellService.getAppointmentsBySectionCellId(
|
||||
linkedCell.getIdSectionCell()));
|
||||
assertTrue(
|
||||
appointmentsLinkedToCell.stream()
|
||||
.anyMatch(
|
||||
a ->
|
||||
a.getIdAppointment()
|
||||
.equals(createdAppointment.getIdAppointment())));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// --- Test Methods (Use static data from @BeforeAll where possible) ---
|
||||
|
||||
/*
|
||||
@ -535,19 +677,39 @@ public class SharedApiServiceTest {
|
||||
* when the user is authorized and matching cells exist.
|
||||
* Verifies that only the correct cells are returned.
|
||||
*/
|
||||
/*@Test*/ // Commenting out failing test
|
||||
/*@Test*/
|
||||
// Commenting out failing test
|
||||
void testGetSectionCells_Authorized_Found() {
|
||||
// Arrange: Create specific SectionCells for this test scenario
|
||||
Long targetSectionId = 1L;
|
||||
LocalDateTime dateFilter = LocalDateTime.now().plusDays(1);
|
||||
|
||||
sectionCellService.addNewSectionCell(getTestSectionCell(staticAuthorizedProject, targetSectionId, "Old Content", LocalDateTime.now().minusDays(2)));
|
||||
SectionCell recentCell = sectionCellService.addNewSectionCell(getTestSectionCell(staticAuthorizedProject, targetSectionId, "Recent Content", LocalDateTime.now().minusDays(1)));
|
||||
sectionCellService.addNewSectionCell(getTestSectionCell(staticAuthorizedProject, 2L, "Other Section", LocalDateTime.now()));
|
||||
sectionCellService.addNewSectionCell(getTestSectionCell(staticAuthorizedProject, targetSectionId, "Future Content", LocalDateTime.now().plusDays(2)));
|
||||
sectionCellService.addNewSectionCell(
|
||||
getTestSectionCell(
|
||||
staticAuthorizedProject,
|
||||
targetSectionId,
|
||||
"Old Content",
|
||||
LocalDateTime.now().minusDays(2)));
|
||||
SectionCell recentCell =
|
||||
sectionCellService.addNewSectionCell(
|
||||
getTestSectionCell(
|
||||
staticAuthorizedProject,
|
||||
targetSectionId,
|
||||
"Recent Content",
|
||||
LocalDateTime.now().minusDays(1)));
|
||||
sectionCellService.addNewSectionCell(
|
||||
getTestSectionCell(
|
||||
staticAuthorizedProject, 2L, "Other Section", LocalDateTime.now()));
|
||||
sectionCellService.addNewSectionCell(
|
||||
getTestSectionCell(
|
||||
staticAuthorizedProject,
|
||||
targetSectionId,
|
||||
"Future Content",
|
||||
LocalDateTime.now().plusDays(2)));
|
||||
|
||||
// Act
|
||||
Iterable<SectionCell> result = sharedApiService.getSectionCells(
|
||||
Iterable<SectionCell> result =
|
||||
sharedApiService.getSectionCells(
|
||||
staticAuthorizedProject.getIdProject(), // Use static project ID
|
||||
targetSectionId,
|
||||
dateFilter.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")),
|
||||
@ -566,36 +728,54 @@ public class SharedApiServiceTest {
|
||||
* Verifies that only the latest version of each referenced cell is returned.
|
||||
*/
|
||||
// Tests getAllSectionCells
|
||||
/*@Test*/ // Commenting out failing test
|
||||
/*@Test*/
|
||||
// Commenting out failing test
|
||||
void testGetAllSectionCells_Authorized_FoundLatest() {
|
||||
// Arrange: Create specific SectionCells for this test
|
||||
Long refId1 = 101L;
|
||||
Long refId2 = 102L;
|
||||
|
||||
SectionCell tempOldCell1 = getTestSectionCell(staticAuthorizedProject, 1L, "Ref1 Old", LocalDateTime.now().minusDays(3));
|
||||
SectionCell tempOldCell1 =
|
||||
getTestSectionCell(
|
||||
staticAuthorizedProject, 1L, "Ref1 Old", LocalDateTime.now().minusDays(3));
|
||||
tempOldCell1.setIdReference(refId1);
|
||||
final SectionCell oldCell1 = sectionCellService.addNewSectionCell(tempOldCell1);
|
||||
|
||||
SectionCell tempNewerCell1 = getTestSectionCell(staticAuthorizedProject, 1L, "Ref1 Newer", LocalDateTime.now().minusDays(2));
|
||||
SectionCell tempNewerCell1 =
|
||||
getTestSectionCell(
|
||||
staticAuthorizedProject,
|
||||
1L,
|
||||
"Ref1 Newer",
|
||||
LocalDateTime.now().minusDays(2));
|
||||
tempNewerCell1.setIdReference(refId1);
|
||||
final SectionCell newerCell1 = sectionCellService.addNewSectionCell(tempNewerCell1);
|
||||
|
||||
SectionCell tempOldCell2 = getTestSectionCell(staticAuthorizedProject, 2L, "Ref2 Old", LocalDateTime.now().minusDays(1));
|
||||
SectionCell tempOldCell2 =
|
||||
getTestSectionCell(
|
||||
staticAuthorizedProject, 2L, "Ref2 Old", LocalDateTime.now().minusDays(1));
|
||||
tempOldCell2.setIdReference(refId2);
|
||||
final SectionCell oldCell2 = sectionCellService.addNewSectionCell(tempOldCell2);
|
||||
|
||||
SectionCell tempNewerCell2 = getTestSectionCell(staticAuthorizedProject, 2L, "Ref2 Newer", LocalDateTime.now());
|
||||
SectionCell tempNewerCell2 =
|
||||
getTestSectionCell(staticAuthorizedProject, 2L, "Ref2 Newer", LocalDateTime.now());
|
||||
tempNewerCell2.setIdReference(refId2);
|
||||
final SectionCell newerCell2 = sectionCellService.addNewSectionCell(tempNewerCell2);
|
||||
|
||||
Project otherProject = projectService.addNewProject(getTestProject("other_project_for_cell_test", administratorService.addAdministrator(getTestAdmin("other_admin_cell_test"))));
|
||||
SectionCell tempOtherProjectCell = getTestSectionCell(otherProject, 1L, "Other Project Cell", LocalDateTime.now());
|
||||
Project otherProject =
|
||||
projectService.addNewProject(
|
||||
getTestProject(
|
||||
"other_project_for_cell_test",
|
||||
administratorService.addAdministrator(
|
||||
getTestAdmin("other_admin_cell_test"))));
|
||||
SectionCell tempOtherProjectCell =
|
||||
getTestSectionCell(otherProject, 1L, "Other Project Cell", LocalDateTime.now());
|
||||
tempOtherProjectCell.setIdReference(103L);
|
||||
final SectionCell otherProjectCell = sectionCellService.addNewSectionCell(tempOtherProjectCell);
|
||||
|
||||
final SectionCell otherProjectCell =
|
||||
sectionCellService.addNewSectionCell(tempOtherProjectCell);
|
||||
|
||||
// Act
|
||||
Iterable<SectionCell> result = sharedApiService.getAllSectionCells(
|
||||
Iterable<SectionCell> result =
|
||||
sharedApiService.getAllSectionCells(
|
||||
staticAuthorizedProject.getIdProject(), // Use static project ID
|
||||
staticAuthorizedMail); // Use static authorized mail
|
||||
|
||||
@ -604,12 +784,37 @@ public class SharedApiServiceTest {
|
||||
// Assert
|
||||
assertEquals(2, resultList.size()); // Expect 2 cells (one per idReference)
|
||||
|
||||
assertTrue(resultList.stream().anyMatch(cell -> cell.getIdSectionCell().equals(newerCell1.getIdSectionCell())));
|
||||
assertTrue(resultList.stream().anyMatch(cell -> cell.getIdSectionCell().equals(newerCell2.getIdSectionCell())));
|
||||
assertTrue(
|
||||
resultList.stream()
|
||||
.anyMatch(
|
||||
cell ->
|
||||
cell.getIdSectionCell()
|
||||
.equals(newerCell1.getIdSectionCell())));
|
||||
assertTrue(
|
||||
resultList.stream()
|
||||
.anyMatch(
|
||||
cell ->
|
||||
cell.getIdSectionCell()
|
||||
.equals(newerCell2.getIdSectionCell())));
|
||||
|
||||
assertFalse(resultList.stream().anyMatch(cell -> cell.getIdSectionCell().equals(oldCell1.getIdSectionCell())));
|
||||
assertFalse(resultList.stream().anyMatch(cell -> cell.getIdSectionCell().equals(oldCell2.getIdSectionCell())));
|
||||
assertFalse(resultList.stream().anyMatch(cell -> cell.getIdSectionCell().equals(otherProjectCell.getIdSectionCell())));
|
||||
assertFalse(
|
||||
resultList.stream()
|
||||
.anyMatch(
|
||||
cell ->
|
||||
cell.getIdSectionCell()
|
||||
.equals(oldCell1.getIdSectionCell())));
|
||||
assertFalse(
|
||||
resultList.stream()
|
||||
.anyMatch(
|
||||
cell ->
|
||||
cell.getIdSectionCell()
|
||||
.equals(oldCell2.getIdSectionCell())));
|
||||
assertFalse(
|
||||
resultList.stream()
|
||||
.anyMatch(
|
||||
cell ->
|
||||
cell.getIdSectionCell()
|
||||
.equals(otherProjectCell.getIdSectionCell())));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -618,28 +823,37 @@ public class SharedApiServiceTest {
|
||||
* Verifies that the correct entrepreneurs are returned.
|
||||
*/
|
||||
// Tests getEntrepreneursByProjectId
|
||||
/*@Test*/ // Commenting out failing test
|
||||
/*@Test*/
|
||||
// Commenting out failing test
|
||||
void testGetEntrepreneursByProjectId_Authorized_Found() {
|
||||
// Arrange: Create entrepreneur and link to static project for this test
|
||||
Entrepreneur linkedEntrepreneur = entrepreneurService.addEntrepreneur(getTestEntrepreneur("linked_entrepreneur_test"));
|
||||
Entrepreneur linkedEntrepreneur =
|
||||
entrepreneurService.addEntrepreneur(
|
||||
getTestEntrepreneur("linked_entrepreneur_test"));
|
||||
// Fetch the static project to update its list
|
||||
Project projectToUpdate = projectService.getProjectById(staticAuthorizedProject.getIdProject());
|
||||
Project projectToUpdate =
|
||||
projectService.getProjectById(staticAuthorizedProject.getIdProject());
|
||||
projectToUpdate.updateListEntrepreneurParticipation(linkedEntrepreneur);
|
||||
projectService.addNewProject(projectToUpdate); // Save the updated project
|
||||
|
||||
Entrepreneur otherEntrepreneur = entrepreneurService.addEntrepreneur(getTestEntrepreneur("other_entrepreneur_test"));
|
||||
Entrepreneur otherEntrepreneur =
|
||||
entrepreneurService.addEntrepreneur(getTestEntrepreneur("other_entrepreneur_test"));
|
||||
|
||||
// Act
|
||||
Iterable<Entrepreneur> result = sharedApiService.getEntrepreneursByProjectId(
|
||||
staticAuthorizedProject.getIdProject(),
|
||||
staticAuthorizedMail);
|
||||
Iterable<Entrepreneur> result =
|
||||
sharedApiService.getEntrepreneursByProjectId(
|
||||
staticAuthorizedProject.getIdProject(), staticAuthorizedMail);
|
||||
|
||||
List<Entrepreneur> resultList = TestUtils.toList(result);
|
||||
|
||||
// Assert
|
||||
assertEquals(1, resultList.size());
|
||||
assertTrue(resultList.stream().anyMatch(e -> e.getIdUser().equals(linkedEntrepreneur.getIdUser())));
|
||||
assertFalse(resultList.stream().anyMatch(e -> e.getIdUser().equals(otherEntrepreneur.getIdUser())));
|
||||
assertTrue(
|
||||
resultList.stream()
|
||||
.anyMatch(e -> e.getIdUser().equals(linkedEntrepreneur.getIdUser())));
|
||||
assertFalse(
|
||||
resultList.stream()
|
||||
.anyMatch(e -> e.getIdUser().equals(otherEntrepreneur.getIdUser())));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -648,26 +862,68 @@ public class SharedApiServiceTest {
|
||||
* Verifies that the correct appointments are returned.
|
||||
*/
|
||||
// Tests getAppointmentsByProjectId
|
||||
/*@Test*/ // Commenting out failing test
|
||||
/*@Test*/
|
||||
// Commenting out failing test
|
||||
void testGetAppointmentsByProjectId_Authorized_Found() {
|
||||
// Arrange: Create specific SectionCells and Appointments for this test
|
||||
SectionCell cell1 = sectionCellService.addNewSectionCell(getTestSectionCell(staticAuthorizedProject, 1L, "Cell 1 Test", LocalDateTime.now()));
|
||||
SectionCell cell2 = sectionCellService.addNewSectionCell(getTestSectionCell(staticAuthorizedProject, 2L, "Cell 2 Test", LocalDateTime.now()));
|
||||
Project otherProject = projectService.addNewProject(getTestProject("other_project_app_test", administratorService.addAdministrator(getTestAdmin("other_admin_app_test"))));
|
||||
SectionCell otherProjectCell = sectionCellService.addNewSectionCell(getTestSectionCell(otherProject, 1L, "Other Project Cell App Test", LocalDateTime.now()));
|
||||
SectionCell cell1 =
|
||||
sectionCellService.addNewSectionCell(
|
||||
getTestSectionCell(
|
||||
staticAuthorizedProject, 1L, "Cell 1 Test", LocalDateTime.now()));
|
||||
SectionCell cell2 =
|
||||
sectionCellService.addNewSectionCell(
|
||||
getTestSectionCell(
|
||||
staticAuthorizedProject, 2L, "Cell 2 Test", LocalDateTime.now()));
|
||||
Project otherProject =
|
||||
projectService.addNewProject(
|
||||
getTestProject(
|
||||
"other_project_app_test",
|
||||
administratorService.addAdministrator(
|
||||
getTestAdmin("other_admin_app_test"))));
|
||||
SectionCell otherProjectCell =
|
||||
sectionCellService.addNewSectionCell(
|
||||
getTestSectionCell(
|
||||
otherProject,
|
||||
1L,
|
||||
"Other Project Cell App Test",
|
||||
LocalDateTime.now()));
|
||||
|
||||
Appointment app1 = getTestAppointment(LocalDate.now().plusDays(10), LocalTime.NOON, LocalTime.of(0, 30), "Place 1 App Test", "Subject 1 App Test", List.of(cell1), null);
|
||||
Appointment app1 =
|
||||
getTestAppointment(
|
||||
LocalDate.now().plusDays(10),
|
||||
LocalTime.NOON,
|
||||
LocalTime.of(0, 30),
|
||||
"Place 1 App Test",
|
||||
"Subject 1 App Test",
|
||||
List.of(cell1),
|
||||
null);
|
||||
Appointment savedApp1 = appointmentService.addNewAppointment(app1);
|
||||
|
||||
Appointment app2 = getTestAppointment(LocalDate.now().plusDays(11), LocalTime.NOON.plusHours(1), LocalTime.of(1, 0), "Place 2 App Test", "Subject 2 App Test", List.of(cell1, cell2), null);
|
||||
Appointment app2 =
|
||||
getTestAppointment(
|
||||
LocalDate.now().plusDays(11),
|
||||
LocalTime.NOON.plusHours(1),
|
||||
LocalTime.of(1, 0),
|
||||
"Place 2 App Test",
|
||||
"Subject 2 App Test",
|
||||
List.of(cell1, cell2),
|
||||
null);
|
||||
Appointment savedApp2 = appointmentService.addNewAppointment(app2);
|
||||
|
||||
Appointment otherApp = getTestAppointment(LocalDate.now().plusDays(12), LocalTime.MIDNIGHT, LocalTime.of(0, 15), "Other Place App Test", "Other Subject App Test", List.of(otherProjectCell), null);
|
||||
Appointment otherApp =
|
||||
getTestAppointment(
|
||||
LocalDate.now().plusDays(12),
|
||||
LocalTime.MIDNIGHT,
|
||||
LocalTime.of(0, 15),
|
||||
"Other Place App Test",
|
||||
"Other Subject App Test",
|
||||
List.of(otherProjectCell),
|
||||
null);
|
||||
appointmentService.addNewAppointment(otherApp);
|
||||
|
||||
|
||||
// Act
|
||||
Iterable<Appointment> result = sharedApiService.getAppointmentsByProjectId(
|
||||
Iterable<Appointment> result =
|
||||
sharedApiService.getAppointmentsByProjectId(
|
||||
staticAuthorizedProject.getIdProject(), // Use static project ID
|
||||
staticAuthorizedMail); // Use static authorized mail
|
||||
|
||||
@ -676,10 +932,21 @@ public class SharedApiServiceTest {
|
||||
// Assert
|
||||
assertEquals(2, resultList.size());
|
||||
|
||||
assertTrue(resultList.stream().anyMatch(a -> a.getIdAppointment().equals(savedApp1.getIdAppointment())));
|
||||
assertTrue(resultList.stream().anyMatch(a -> a.getIdAppointment().equals(savedApp2.getIdAppointment())));
|
||||
|
||||
assertFalse(resultList.stream().anyMatch(a -> a.getIdAppointment().equals(otherApp.getIdAppointment()))); // Ensure appointment from other project is not included
|
||||
assertTrue(
|
||||
resultList.stream()
|
||||
.anyMatch(a -> a.getIdAppointment().equals(savedApp1.getIdAppointment())));
|
||||
assertTrue(
|
||||
resultList.stream()
|
||||
.anyMatch(a -> a.getIdAppointment().equals(savedApp2.getIdAppointment())));
|
||||
|
||||
assertFalse(
|
||||
resultList.stream()
|
||||
.anyMatch(
|
||||
a ->
|
||||
a.getIdAppointment()
|
||||
.equals(
|
||||
otherApp
|
||||
.getIdAppointment()))); // Ensure
|
||||
// appointment from other project is not included
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user