Skip to content

Commit

Permalink
CCMSPUI-453: Tweaks to open-api-specification.yml, and NotificationCo…
Browse files Browse the repository at this point in the history
…ntrollerTests

Signed-off-by: Jamie Briggs <[email protected]>
  • Loading branch information
JamieBriggs-MoJ committed Dec 17, 2024
1 parent 2799af6 commit 57805eb
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 22 deletions.
18 changes: 1 addition & 17 deletions data-api/open-api-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ paths:
in: 'query'
schema:
type: boolean
allowEmptyValue: true
default: true
- name: 'notification-type'
in: 'query'
schema:
Expand All @@ -1029,13 +1029,6 @@ paths:
type: 'string'
example: "2017-01-01"
format: date
- name: 'sort'
in: 'query'
schema:
type: 'array'
items:
type: 'string'
- $ref: '#/components/parameters/maxRecords'
responses:
'200':
description: 'Successful operation'
Expand All @@ -1060,15 +1053,6 @@ components:
type: apiKey
in: header
name: Authorization
parameters:
maxRecords:
in: query
name: 'max-records'
required: false
schema:
type: 'integer'
default: 100
example: 123
schemas:
baseOffice:
type: 'object'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.gov.laa.ccms.data.controller;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
Expand All @@ -27,25 +26,48 @@ public class NotificationsController implements NotificationsApi {

private final NotificationService notificationService;

/**
* Retrieves a list of notifications based on various search criteria.
*
* @param caseReferenceNumber the case reference number to filter notifications
* @param providerCaseReference the provider-specific case reference to filter notifications
* @param assignedToUserId the user ID to filter notifications assigned to a specific user
* @param clientSurname the client's surname to filter notifications for a specific client
* @param feeEarnerId the ID of the fee earner to filter notifications associated with them
* @param includeClosed a flag to indicate whether to include closed notifications in the results
* @param notificationType the type of notifications to filter by
* @param dateFrom the starting date to filter notifications by a specific date range
* @param dateTo the ending date to filter notifications by a specific date range
* @param pageable the pagination and sorting information for the result set
* @return a {@code ResponseEntity} containing the retrieved list of notifications if found,
* or a {@code ResponseEntity} with HTTP status 404 if no notifications are found
*/
@Override
public ResponseEntity<Notifications> getNotifications(String caseReferenceNumber,
String providerCaseReference, String assignedToUserId, String clientSurname,
Integer feeEarnerId, Boolean includeClosed, String notificationType, LocalDate dateFrom,
LocalDate dateTo, List<String> sort, Integer maxRecords, Pageable pageable) {
LocalDate dateTo, Pageable pageable) {
Optional<Notifications> notifications = notificationService.getNotifications(
caseReferenceNumber,
providerCaseReference,
assignedToUserId,
clientSurname,
feeEarnerId,
includeClosed,
Boolean.TRUE.equals(includeClosed),
notificationType,
dateFrom,
dateTo,
pageable);
return notifications.map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build());
}

/**
* Retrieves a summary of user notifications for the specified login ID.
*
* @param loginId the login ID of the user for whom the notification summary is to be retrieved
* @return a {@code ResponseEntity} containing the {@code NotificationSummary} if found,
* or a {@code ResponseEntity} with HTTP status 404 if no summary is available
*/
@Override
public ResponseEntity<NotificationSummary> getUserNotificationSummary(String loginId) {
return notificationService.getUserNotificationSummary(loginId).map(ResponseEntity::ok)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Optional<NotificationSummary> getUserNotificationSummary(String userId) {
*/
public Optional<Notifications> getNotifications(String caseReferenceNumber,
String providerCaseReference, String assignedToUserId, String clientSurname,
Integer feeEarnerId, Boolean includeClosed, String notificationType, LocalDate dateFrom,
Integer feeEarnerId, boolean includeClosed, String notificationType, LocalDate dateFrom,
LocalDate dateTo, Pageable pageable) {
Page<Notification> byAssignedTo = notificationRepository.findAll(
NotificationSpecification.withFilters(caseReferenceNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper;
import uk.gov.laa.ccms.data.model.Notification;
import uk.gov.laa.ccms.data.model.NotificationSummary;
import uk.gov.laa.ccms.data.model.Notifications;
import uk.gov.laa.ccms.data.service.NotificationService;

@ExtendWith({SpringExtension.class})
Expand All @@ -44,7 +48,9 @@ class NotificationsControllerTest {

@BeforeEach
public void setup() {
mockMvc = standaloneSetup(notificationsController).build();
mockMvc = standaloneSetup(notificationsController)
.setCustomArgumentResolvers(new PageableHandlerMethodArgumentResolver())
.build();
objectMapper = new ObjectMapper();
}

Expand Down Expand Up @@ -74,4 +80,31 @@ void getUserNotificationSummary_notFound() throws Exception {
.andDo(print())
.andExpect(status().isNotFound());
}

@Test
@DisplayName("getNotifications: Returns data")
void getNotifications_returnsData() throws Exception {
//Given
Notifications expected = new Notifications().addContentItem(new Notification().notificationId("123"));
when(notificationService.getNotifications(Mockito.any(), Mockito.any(), Mockito.any(),
Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.any(), Mockito.any(),
Mockito.any(), Mockito.any())).thenReturn(Optional.of(
expected));
// Then
String jsonContent = objectMapper.writeValueAsString(expected);
this.mockMvc.perform(get("/notifications"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().json(jsonContent));
}

@Test
@DisplayName("getNotifications: Not found")
void getNotifications_notFound() throws Exception {
//Given
// Then
this.mockMvc.perform(get("/notifications"))
.andDo(print())
.andExpect(status().isNotFound());
}
}

0 comments on commit 57805eb

Please sign in to comment.