backend-test #10
@ -610,102 +610,10 @@ public class SharedApiServiceTest {
|
|||||||
* as the classes used to turn them into persistant data
|
* as the classes used to turn them into persistant data
|
||||||
* (for e.g id are set by DB) so I have to add some equal functions
|
* (for e.g id are set by DB) so I have to add some equal functions
|
||||||
* probably and look at peer tests to see what they have done but for now
|
* probably and look at peer tests to see what they have done but for now
|
||||||
* I pushed this half-humain code.
|
* I pushed this half-human code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* Tests generating a PDF report for an appointment when the user is authorized
|
|
||||||
* for the project linked to the appointment's section cell.
|
|
||||||
* 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
|
|
||||||
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);
|
|
||||||
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
|
|
||||||
|
|
||||||
// Act & Assert (Just assert no authorization exception is thrown)
|
|
||||||
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.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Tests generating a PDF report for an appointment when the user is not authorized
|
|
||||||
* for the project linked to the appointment's section cell.
|
|
||||||
* Verifies that an Unauthorized ResponseStatusException is thrown.
|
|
||||||
*/
|
|
||||||
/*@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()));
|
|
||||||
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 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
|
|
||||||
|
|
||||||
// Act & Assert
|
|
||||||
ResponseStatusException exception =
|
|
||||||
assertThrows(
|
|
||||||
ResponseStatusException.class,
|
|
||||||
() -> {
|
|
||||||
sharedApiService.getPDFReport(
|
|
||||||
savedAppointment.getIdAppointment(),
|
|
||||||
staticUnauthorizedMail); // Unauthorized user mail
|
|
||||||
});
|
|
||||||
|
|
||||||
assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatusCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Test Methods (Use static data from @BeforeAll where possible) ---
|
// --- Test Methods (Use static data from @BeforeAll where possible) ---
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -983,4 +891,98 @@ public class SharedApiServiceTest {
|
|||||||
.equals(otherApp.getIdAppointment()))); // Ensure
|
.equals(otherApp.getIdAppointment()))); // Ensure
|
||||||
// appointment from other project is not included
|
// appointment from other project is not included
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests generating a PDF report for an appointment when the user is authorized
|
||||||
|
* for the project linked to the appointment's section cell.
|
||||||
|
* 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
|
||||||
|
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);
|
||||||
|
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
|
||||||
|
|
||||||
|
// Act & Assert (Just assert no authorization exception is thrown)
|
||||||
|
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.
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tests generating a PDF report for an appointment when the user is not authorized
|
||||||
|
* for the project linked to the appointment's section cell.
|
||||||
|
* Verifies that an Unauthorized ResponseStatusException is thrown.
|
||||||
|
*/
|
||||||
|
/*@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()));
|
||||||
|
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 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
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
ResponseStatusException exception =
|
||||||
|
assertThrows(
|
||||||
|
ResponseStatusException.class,
|
||||||
|
() -> {
|
||||||
|
sharedApiService.getPDFReport(
|
||||||
|
savedAppointment.getIdAppointment(),
|
||||||
|
staticUnauthorizedMail); // Unauthorized user mail
|
||||||
|
});
|
||||||
|
|
||||||
|
assertEquals(HttpStatus.UNAUTHORIZED, exception.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user