Compare commits
3 Commits
bee47473d5
...
b672b2e9f9
Author | SHA1 | Date | |
---|---|---|---|
b672b2e9f9 | |||
193876e51c | |||
b8c7c6f587 |
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -174,21 +174,10 @@ paths:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: "./main.yaml#/components/schemas/appointment" # Assuming request uses same model structure
|
$ref: "./main.yaml#/components/schemas/appointment" # Assuming request uses same model structure
|
||||||
example:
|
|
||||||
value:
|
|
||||||
appointmentDate: "2025-06-01"
|
|
||||||
appointmentTime: "10:00:00"
|
|
||||||
appointmentDuration: "PT1H"
|
|
||||||
appointmentPlace: "Online"
|
|
||||||
appointmentSubject: "Follow-up on prototype"
|
|
||||||
# Potentially add projectId or targetUserId here
|
# Potentially add projectId or targetUserId here
|
||||||
responses:
|
responses:
|
||||||
"202": # Accepted seems appropriate for a request
|
"202": # Accepted seems appropriate for a request
|
||||||
description: Accepted - Appointment request submitted.
|
description: Accepted - Appointment request submitted.
|
||||||
content:
|
|
||||||
application/json: # Optionally return the pending appointment data
|
|
||||||
schema:
|
|
||||||
$ref: "./main.yaml#/components/schemas/appointment"
|
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request - Invalid appointment details.
|
description: Bad Request - Invalid appointment details.
|
||||||
|
|
||||||
|
@ -1947,7 +1947,6 @@
|
|||||||
"version": "4.0.4",
|
"version": "4.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/swagger-cli/-/swagger-cli-4.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/swagger-cli/-/swagger-cli-4.0.4.tgz",
|
||||||
"integrity": "sha512-Cp8YYuLny3RJFQ4CvOBTaqmOOgYsem52dPx1xM5S4EUWFblIh2Q8atppMZvXKUr1e9xH5RwipYpmdUzdPcxWcA==",
|
"integrity": "sha512-Cp8YYuLny3RJFQ4CvOBTaqmOOgYsem52dPx1xM5S4EUWFblIh2Q8atppMZvXKUr1e9xH5RwipYpmdUzdPcxWcA==",
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apidevtools/swagger-cli": "4.0.4"
|
"@apidevtools/swagger-cli": "4.0.4"
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user