From 7bab9e599086929ee4a2de05e989b4a885285301 Mon Sep 17 00:00:00 2001 From: Tom Elliott Date: Wed, 21 Aug 2024 09:09:50 +0100 Subject: [PATCH] DTSSTCI-977 (#1877) * DTSSTCI-977: Begin writing integration tests for create draft order and create hearing summary * DTSSTCI-977: Add additional test cases * DTSSTCI-977: Update test name --------- Co-authored-by: Tom Elliott --- .../CaseWorkerCreateDraftOrderIT.java | 237 ++++++++++++++++++ .../caseworker/CaseworkerCancelHearingIT.java | 48 +--- .../CaseworkerCreateHearingSummaryIT.java | 116 ++++++++- ...-draft-order-about-to-submit-response.json | 104 ++++++++ ...create-draft-order-mid-event-response.json | 90 +++++++ ...aring-summary-about-to-start-response.json | 136 ++++++++++ ...ing-summary-about-to-submit-response.json} | 0 .../event/CaseWorkerCreateDraftOrder.java | 6 +- .../sptribs/testutil/TestDataHelper.java | 41 +++ 9 files changed, 723 insertions(+), 55 deletions(-) create mode 100644 src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/CaseWorkerCreateDraftOrderIT.java create mode 100644 src/integrationTest/resources/caseworker-create-draft-order-about-to-submit-response.json create mode 100644 src/integrationTest/resources/caseworker-create-draft-order-mid-event-response.json create mode 100644 src/integrationTest/resources/caseworker-create-hearing-summary-about-to-start-response.json rename src/integrationTest/resources/{caseworker-create-hearing-summary-response.json => caseworker-create-hearing-summary-about-to-submit-response.json} (100%) diff --git a/src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/CaseWorkerCreateDraftOrderIT.java b/src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/CaseWorkerCreateDraftOrderIT.java new file mode 100644 index 0000000000..f708a8b59d --- /dev/null +++ b/src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/CaseWorkerCreateDraftOrderIT.java @@ -0,0 +1,237 @@ +package uk.gov.hmcts.sptribs.caseworker; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.web.servlet.MockMvc; +import uk.gov.hmcts.ccd.sdk.type.Document; +import uk.gov.hmcts.reform.idam.client.models.User; +import uk.gov.hmcts.reform.idam.client.models.UserDetails; +import uk.gov.hmcts.sptribs.caseworker.model.DraftOrderContentCIC; +import uk.gov.hmcts.sptribs.ciccase.model.CaseData; +import uk.gov.hmcts.sptribs.ciccase.model.CicCase; +import uk.gov.hmcts.sptribs.common.config.WebMvcConfig; +import uk.gov.hmcts.sptribs.document.DocAssemblyService; +import uk.gov.hmcts.sptribs.document.model.DocumentInfo; +import uk.gov.hmcts.sptribs.idam.IdamService; +import uk.gov.hmcts.sptribs.testutil.IdamWireMock; + +import java.util.List; + +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; +import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.springframework.http.MediaType.APPLICATION_JSON; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static uk.gov.hmcts.sptribs.caseworker.util.EventConstants.CASEWORKER_CREATE_DRAFT_ORDER; +import static uk.gov.hmcts.sptribs.ciccase.model.LanguagePreference.ENGLISH; +import static uk.gov.hmcts.sptribs.ciccase.model.OrderTemplate.CIC3_RULE_27; +import static uk.gov.hmcts.sptribs.ciccase.model.SchemeCic.Year2012; +import static uk.gov.hmcts.sptribs.testutil.TestConstants.ABOUT_TO_SUBMIT_URL; +import static uk.gov.hmcts.sptribs.testutil.TestConstants.AUTHORIZATION; +import static uk.gov.hmcts.sptribs.testutil.TestConstants.CASE_DATA_CIC_ID; +import static uk.gov.hmcts.sptribs.testutil.TestConstants.CASE_DATA_FILE_CIC; +import static uk.gov.hmcts.sptribs.testutil.TestConstants.SERVICE_AUTHORIZATION; +import static uk.gov.hmcts.sptribs.testutil.TestConstants.SUBMITTED_URL; +import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_AUTHORIZATION_TOKEN; +import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_CASE_ID; +import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_URL; +import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.callbackRequest; +import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.caseData; +import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.getHearingList; +import static uk.gov.hmcts.sptribs.testutil.TestResourceUtil.expectedResponse; + +@ExtendWith(SpringExtension.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@AutoConfigureMockMvc +@ContextConfiguration(initializers = {IdamWireMock.PropertiesInitializer.class}) +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +public class CaseWorkerCreateDraftOrderIT { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private ObjectMapper objectMapper; + + @MockBean + private WebMvcConfig webMvcConfig; + + @MockBean + private IdamService idamService; + + @MockBean + private DocAssemblyService docAssemblyService; + + private static final String CASEWORKER_CREATE_DRAFT_ORDER_MID_EVENT_RESPONSE = + "classpath:caseworker-create-draft-order-mid-event-response.json"; + private static final String CASEWORKER_CREATE_DRAFT_ORDER_ABOUT_TO_SUBMIT_RESPONSE = + "classpath:caseworker-create-draft-order-about-to-submit-response.json"; + + public static final String CREATE_DRAFT_ORDER_ADD_FOOTER_MID_EVENT_URL = + "/callbacks/mid-event?page=createDraftOrderAddDocumentFooter"; + private static final String CONFIRMATION_HEADER = "$.confirmation_header"; + + @BeforeAll + static void setUp() { + IdamWireMock.start(); + } + + @AfterAll + static void tearDown() { + IdamWireMock.stopAndReset(); + } + + @Test + void shouldGenerateOrderFileOnMidEvent() throws Exception { + final CaseData caseData = CaseData.builder() + .cicCase(CicCase.builder() + .fullName("Test Name") + .schemeCic(Year2012) + .build() + ) + .hearingList(getHearingList()) + .draftOrderContentCIC(DraftOrderContentCIC.builder() + .orderTemplate(CIC3_RULE_27) + .orderSignature("Mr Judge") + .mainContent("Draft Order Content") + .build() + ) + .build(); + + final User user = new User( + TEST_AUTHORIZATION_TOKEN, + UserDetails.builder() + .roles(List.of("caseworker-st_cic")) + .build() + ); + + final DocumentInfo documentInfo = new DocumentInfo( + TEST_URL, + CASE_DATA_FILE_CIC, + CASE_DATA_FILE_CIC, + CASE_DATA_CIC_ID + ); + + when(idamService.retrieveUser(eq(TEST_AUTHORIZATION_TOKEN))) + .thenReturn(user); + + when(docAssemblyService.renderDocument( + anyMap(), + eq(TEST_CASE_ID), + eq(TEST_AUTHORIZATION_TOKEN), + eq(CIC3_RULE_27.getId()), + eq(ENGLISH), + anyString() + )).thenReturn(documentInfo); + + String response = mockMvc.perform(post(CREATE_DRAFT_ORDER_ADD_FOOTER_MID_EVENT_URL) + .contentType(APPLICATION_JSON) + .header(SERVICE_AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) + .header(AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) + .content(objectMapper.writeValueAsString( + callbackRequest( + caseData, + CASEWORKER_CREATE_DRAFT_ORDER))) + .accept(APPLICATION_JSON)) + .andExpect( + status().isOk()) + .andReturn() + .getResponse() + .getContentAsString(); + + assertThatJson(response) + .when(IGNORING_EXTRA_FIELDS) + .isEqualTo(json(expectedResponse(CASEWORKER_CREATE_DRAFT_ORDER_MID_EVENT_RESPONSE))); + + verify(docAssemblyService).renderDocument( + anyMap(), + eq(TEST_CASE_ID), + eq(TEST_AUTHORIZATION_TOKEN), + eq(CIC3_RULE_27.getId()), + eq(ENGLISH), + anyString() + ); + } + + @Test + void shouldUpdateDraftOrderListOnAboutToSubmit() throws Exception { + final CaseData caseData = CaseData.builder() + .cicCase(CicCase.builder() + .fullName("Test Name") + .schemeCic(Year2012) + .orderTemplateIssued(Document.builder() + .categoryId("CIC") + .binaryUrl("TestUrl/binary") + .filename("SENT :Order--[Subject AutoTesting]--29-05-2024 13:36:27.pdf") + .url("TestUrl") + .build()) + .build() + ) + .hearingList(getHearingList()) + .draftOrderContentCIC(DraftOrderContentCIC.builder() + .orderTemplate(CIC3_RULE_27) + .orderSignature("Mr Judge") + .mainContent("Draft Order Content") + .build() + ) + .build(); + + String response = mockMvc.perform(post(ABOUT_TO_SUBMIT_URL) + .contentType(APPLICATION_JSON) + .header(SERVICE_AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) + .header(AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) + .content(objectMapper.writeValueAsString( + callbackRequest( + caseData, + CASEWORKER_CREATE_DRAFT_ORDER))) + .accept(APPLICATION_JSON)) + .andExpect( + status().isOk()) + .andReturn() + .getResponse() + .getContentAsString(); + + assertThatJson(response) + .when(IGNORING_EXTRA_FIELDS) + .isEqualTo(json(expectedResponse(CASEWORKER_CREATE_DRAFT_ORDER_ABOUT_TO_SUBMIT_RESPONSE))); + } + + @Test + void shouldReturnConfirmationMessageOnSubmitted() throws Exception { + String response = mockMvc.perform(post(SUBMITTED_URL) + .contentType(APPLICATION_JSON) + .header(SERVICE_AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) + .header(AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) + .content(objectMapper.writeValueAsString( + callbackRequest( + caseData(), + CASEWORKER_CREATE_DRAFT_ORDER))) + .accept(APPLICATION_JSON)) + .andExpect( + status().isOk()) + .andReturn() + .getResponse() + .getContentAsString(); + + assertThatJson(response) + .inPath(CONFIRMATION_HEADER) + .isString() + .contains("# Draft order created."); + } +} diff --git a/src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/CaseworkerCancelHearingIT.java b/src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/CaseworkerCancelHearingIT.java index 44d9f2e174..84072b359e 100644 --- a/src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/CaseworkerCancelHearingIT.java +++ b/src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/CaseworkerCancelHearingIT.java @@ -15,21 +15,16 @@ import org.springframework.test.web.servlet.MockMvc; import uk.gov.hmcts.ccd.sdk.type.DynamicList; import uk.gov.hmcts.ccd.sdk.type.DynamicListElement; -import uk.gov.hmcts.ccd.sdk.type.ListValue; -import uk.gov.hmcts.sptribs.caseworker.model.Listing; import uk.gov.hmcts.sptribs.ciccase.model.CaseData; import uk.gov.hmcts.sptribs.ciccase.model.CicCase; import uk.gov.hmcts.sptribs.common.config.WebMvcConfig; import uk.gov.hmcts.sptribs.notification.NotificationServiceCIC; import uk.gov.hmcts.sptribs.testutil.IdamWireMock; -import java.time.LocalDate; -import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.UUID; -import static java.util.Collections.emptySet; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; import static net.javacrumbs.jsonunit.assertj.JsonAssertions.json; import static net.javacrumbs.jsonunit.core.Option.IGNORING_EXTRA_FIELDS; @@ -41,13 +36,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.YES; import static uk.gov.hmcts.sptribs.caseworker.util.EventConstants.CASEWORKER_CANCEL_HEARING; import static uk.gov.hmcts.sptribs.ciccase.model.ContactPreferenceType.EMAIL; -import static uk.gov.hmcts.sptribs.ciccase.model.HearingFormat.FACE_TO_FACE; -import static uk.gov.hmcts.sptribs.ciccase.model.HearingState.Listed; -import static uk.gov.hmcts.sptribs.ciccase.model.HearingType.FINAL; -import static uk.gov.hmcts.sptribs.ciccase.model.HearingType.INTERLOCUTORY; import static uk.gov.hmcts.sptribs.ciccase.model.NotificationParties.APPLICANT; import static uk.gov.hmcts.sptribs.ciccase.model.NotificationParties.REPRESENTATIVE; import static uk.gov.hmcts.sptribs.ciccase.model.NotificationParties.RESPONDENT; @@ -61,8 +51,7 @@ import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_CASE_ID_HYPHENATED; import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.callbackRequest; import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.caseData; -import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.getMockedHearingVenueData; -import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.getMockedRegionData; +import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.getHearingList; import static uk.gov.hmcts.sptribs.testutil.TestResourceUtil.expectedResponse; @ExtendWith(SpringExtension.class) @@ -248,39 +237,4 @@ void shouldReturnErrorMessageIfNotificationsFailOnSubmitted() throws Exception { verifyNoInteractions(notificationServiceCIC); } - - private List> getHearingList() { - final Listing listing1 = Listing.builder() - .date(LocalDate.of(2024, 8, 14)) - .hearingType(FINAL) - .hearingTime("10:00") - .regionList(getMockedRegionData()) - .hearingVenues(getMockedHearingVenueData()) - .venueNotListedOption(emptySet()) - .roomAtVenue("G.01") - .addlInstr("Ground floor") - .hearingFormat(FACE_TO_FACE) - .shortNotice(YES) - .hearingStatus(Listed) - .build(); - final Listing listing2 = Listing.builder() - .date(LocalDate.of(2024, 8, 14)) - .hearingType(INTERLOCUTORY) - .hearingTime("14:00") - .regionList(getMockedRegionData()) - .hearingVenues(getMockedHearingVenueData()) - .venueNotListedOption(emptySet()) - .roomAtVenue("G.01") - .addlInstr("Ground floor") - .hearingFormat(FACE_TO_FACE) - .shortNotice(YES) - .hearingStatus(Listed) - .build(); - - final List> hearingList = new ArrayList<>(); - hearingList.add(new ListValue<>("1", listing1)); - hearingList.add(new ListValue<>("2", listing2)); - - return hearingList; - } } diff --git a/src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/CaseworkerCreateHearingSummaryIT.java b/src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/CaseworkerCreateHearingSummaryIT.java index c202b19600..bbc09e9b4b 100644 --- a/src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/CaseworkerCreateHearingSummaryIT.java +++ b/src/integrationTest/java/uk/gov/hmcts/sptribs/caseworker/CaseworkerCreateHearingSummaryIT.java @@ -15,30 +15,48 @@ import org.springframework.test.web.servlet.MockMvc; import uk.gov.hmcts.ccd.sdk.type.DynamicList; import uk.gov.hmcts.ccd.sdk.type.DynamicListElement; +import uk.gov.hmcts.reform.authorisation.generators.AuthTokenGenerator; +import uk.gov.hmcts.reform.idam.client.models.User; +import uk.gov.hmcts.reform.idam.client.models.UserDetails; import uk.gov.hmcts.sptribs.caseworker.model.HearingSummary; import uk.gov.hmcts.sptribs.caseworker.model.Listing; import uk.gov.hmcts.sptribs.ciccase.model.CaseData; import uk.gov.hmcts.sptribs.ciccase.model.CicCase; import uk.gov.hmcts.sptribs.common.config.WebMvcConfig; +import uk.gov.hmcts.sptribs.idam.IdamService; +import uk.gov.hmcts.sptribs.judicialrefdata.JudicialClient; +import uk.gov.hmcts.sptribs.judicialrefdata.JudicialUsersRequest; +import uk.gov.hmcts.sptribs.judicialrefdata.model.UserProfileRefreshResponse; import uk.gov.hmcts.sptribs.testutil.IdamWireMock; +import java.util.List; + import static java.util.Collections.emptySet; +import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; import static org.springframework.http.MediaType.APPLICATION_JSON; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.YES; import static uk.gov.hmcts.sptribs.ciccase.model.HearingFormat.FACE_TO_FACE; +import static uk.gov.hmcts.sptribs.common.config.ControllerConstants.ACCEPT_VALUE; +import static uk.gov.hmcts.sptribs.constants.CommonConstants.ST_CIC_JURISDICTION; import static uk.gov.hmcts.sptribs.testutil.IdamWireMock.ST_CIC_CASEWORKER; import static uk.gov.hmcts.sptribs.testutil.IdamWireMock.stubForIdamDetails; +import static uk.gov.hmcts.sptribs.testutil.TestConstants.ABOUT_TO_START_URL; import static uk.gov.hmcts.sptribs.testutil.TestConstants.ABOUT_TO_SUBMIT_URL; import static uk.gov.hmcts.sptribs.testutil.TestConstants.AUTHORIZATION; import static uk.gov.hmcts.sptribs.testutil.TestConstants.CASEWORKER_USER_ID; import static uk.gov.hmcts.sptribs.testutil.TestConstants.SERVICE_AUTHORIZATION; +import static uk.gov.hmcts.sptribs.testutil.TestConstants.SUBMITTED_URL; import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_AUTHORIZATION_TOKEN; +import static uk.gov.hmcts.sptribs.testutil.TestConstants.TEST_SERVICE_AUTH_TOKEN; import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.callbackRequest; import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.caseData; import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.getDynamicList; +import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.getHearingList; import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.getMembers; import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.getMockedHearingVenueData; import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.getMockedRegionData; @@ -51,8 +69,11 @@ @ContextConfiguration(initializers = {IdamWireMock.PropertiesInitializer.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) public class CaseworkerCreateHearingSummaryIT { - private static final String CASEWORKER_CREATE_HEARING_SUMMARY_RESPONSE = - "classpath:caseworker-create-hearing-summary-response.json"; + + private static final String CASEWORKER_CREATE_HEARING_SUMMARY_ABOUT_TO_START_RESPONSE = + "classpath:caseworker-create-hearing-summary-about-to-start-response.json"; + private static final String CASEWORKER_CREATE_HEARING_SUMMARY_ABOUT_TO_SUBMIT_RESPONSE = + "classpath:caseworker-create-hearing-summary-about-to-submit-response.json"; @Autowired private MockMvc mockMvc; @@ -63,6 +84,17 @@ public class CaseworkerCreateHearingSummaryIT { @MockBean private WebMvcConfig webMvcConfig; + @MockBean + private IdamService idamService; + + @MockBean + private AuthTokenGenerator authTokenGenerator; + + @MockBean + private JudicialClient judicialClient; + + private static final String CONFIRMATION_HEADER = "$.confirmation_header"; + @BeforeAll static void setUp() { IdamWireMock.start(); @@ -74,7 +106,45 @@ static void tearDown() { } @Test - void shouldSuccessfullyCreateHearingSummary() throws Exception { + void shouldPopulateHearingListAndJudgeListOnAboutToStart() throws Exception { + final CaseData caseData = caseData(); + caseData.setHearingList(getHearingList()); + + final User user = new User( + TEST_AUTHORIZATION_TOKEN, + UserDetails.builder() + .roles(List.of("caseworker-st_cic", "caseworker-sptribs-systemupdate")) + .build() + ); + + stubForIdamDetails(TEST_AUTHORIZATION_TOKEN, CASEWORKER_USER_ID, ST_CIC_CASEWORKER); + when(authTokenGenerator.generate()).thenReturn(TEST_SERVICE_AUTH_TOKEN); + when(idamService.retrieveSystemUpdateUserDetails()).thenReturn(user); + when(judicialClient.getUserProfiles( + eq(TEST_SERVICE_AUTH_TOKEN), + eq(TEST_AUTHORIZATION_TOKEN), + eq(ACCEPT_VALUE), + eq(JudicialUsersRequest.builder().ccdServiceName(ST_CIC_JURISDICTION).build()) + )).thenReturn(getUserProfiles()); + + mockMvc.perform(post(ABOUT_TO_START_URL) + .contentType(APPLICATION_JSON) + .header(SERVICE_AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) + .header(AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) + .content(objectMapper.writeValueAsString( + callbackRequest( + caseData, + CASEWORKER_CREATE_HEARING_SUMMARY))) + .accept(APPLICATION_JSON)) + .andExpect( + status().isOk()) + .andExpect( + content().json(expectedResponse(CASEWORKER_CREATE_HEARING_SUMMARY_ABOUT_TO_START_RESPONSE)) + ); + } + + @Test + void shouldSuccessfullyCreateHearingSummaryOnAboutToSubmit() throws Exception { final CaseData caseData = caseData(); final HearingSummary hearingSummary = HearingSummary.builder() .judge(getDynamicList()) @@ -116,7 +186,45 @@ void shouldSuccessfullyCreateHearingSummary() throws Exception { .andExpect( status().isOk()) .andExpect( - content().json(expectedResponse(CASEWORKER_CREATE_HEARING_SUMMARY_RESPONSE)) + content().json(expectedResponse(CASEWORKER_CREATE_HEARING_SUMMARY_ABOUT_TO_SUBMIT_RESPONSE)) ); } + + @Test + void shouldReturnConfirmationMessageOnSubmitted() throws Exception { + String response = mockMvc.perform(post(SUBMITTED_URL) + .contentType(APPLICATION_JSON) + .header(SERVICE_AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) + .header(AUTHORIZATION, TEST_AUTHORIZATION_TOKEN) + .content(objectMapper.writeValueAsString( + callbackRequest( + caseData(), + CASEWORKER_CREATE_HEARING_SUMMARY))) + .accept(APPLICATION_JSON)) + .andExpect( + status().isOk()) + .andReturn() + .getResponse() + .getContentAsString(); + + assertThatJson(response) + .inPath(CONFIRMATION_HEADER) + .isString() + .contains("# Hearing summary created \n## This hearing summary has been added to the case record."); + } + + private List getUserProfiles() { + final UserProfileRefreshResponse userResponse1 = UserProfileRefreshResponse + .builder() + .fullName("John Smith") + .personalCode("12345") + .build(); + final UserProfileRefreshResponse userResponse2 = UserProfileRefreshResponse + .builder() + .fullName("John Doe") + .personalCode("98765") + .build(); + + return List.of(userResponse1, userResponse2); + } } diff --git a/src/integrationTest/resources/caseworker-create-draft-order-about-to-submit-response.json b/src/integrationTest/resources/caseworker-create-draft-order-about-to-submit-response.json new file mode 100644 index 0000000000..37d8a9672f --- /dev/null +++ b/src/integrationTest/resources/caseworker-create-draft-order-about-to-submit-response.json @@ -0,0 +1,104 @@ +{ + "data": { + "cicCaseDraftOrderDynamicList": { + "list_items": [ + { + "label": "CIC3 - Rule 27--29-05-2024 13:36:27.pdf--draft.pdf" + } + ] + }, + "cicCaseDraftOrderCICList": [ + { + "id": "1", + "value": { + "templateGeneratedDocument": { + "document_url": "TestUrl", + "document_filename": "SENT :Order--[Subject AutoTesting]--29-05-2024 13:36:27.pdf", + "document_binary_url": "TestUrl/binary", + "category_id": "CIC" + }, + "orderContentOrderTemplate": "CIC3_Rule_27", + "orderContentMainContent": "Draft Order Content", + "orderContentOrderSignature": "Mr Judge" + } + } + ], + "cicCaseFullName": "Test Name", + "cicCaseSchemeCic": "Year2012", + "hearingList": [ + { + "id": "1", + "value": { + "hearingStatus": "Listed", + "hearingType": "Final", + "hearingFormat": "Face to Face", + "shortNotice": "Yes", + "hearingVenues": { + "value": { + "label": "courtname-courtAddress" + }, + "list_items": [ + { + "label": "courtname-courtAddress" + } + ], + "valueLabel": "courtname-courtAddress" + }, + "regionList": { + "value": { + "label": "1-region" + }, + "list_items": [ + { + "label": "1-region" + } + ], + "valueLabel": "1-region" + }, + "venueNotListedOption": [], + "roomAtVenue": "G.01", + "addlInstr": "Ground floor", + "date": "2024-08-14", + "hearingTime": "10:00" + } + }, + { + "id": "2", + "value": { + "hearingStatus": "Listed", + "hearingType": "Interlocutory", + "hearingFormat": "Face to Face", + "shortNotice": "Yes", + "hearingVenues": { + "value": { + "label": "courtname-courtAddress" + }, + "list_items": [ + { + "label": "courtname-courtAddress" + } + ], + "valueLabel": "courtname-courtAddress" + }, + "regionList": { + "value": { + "label": "1-region" + }, + "list_items": [ + { + "label": "1-region" + } + ], + "valueLabel": "1-region" + }, + "venueNotListedOption": [], + "roomAtVenue": "G.01", + "addlInstr": "Ground floor", + "date": "2024-08-14", + "hearingTime": "14:00" + } + } + ], + "firstHearingDate": "14 Aug 2024" + } +} diff --git a/src/integrationTest/resources/caseworker-create-draft-order-mid-event-response.json b/src/integrationTest/resources/caseworker-create-draft-order-mid-event-response.json new file mode 100644 index 0000000000..56fb62bab0 --- /dev/null +++ b/src/integrationTest/resources/caseworker-create-draft-order-mid-event-response.json @@ -0,0 +1,90 @@ +{ + "data": { + "orderContentOrderTemplate": "CIC3_Rule_27", + "orderContentMainContent": "Draft Order Content", + "orderContentOrderSignature": "Mr Judge", + "cicCaseOrderTemplateIssued": { + "document_url": "TestUrl", + "document_filename": "CICCaseData.json", + "document_binary_url": "CICCaseData.json", + "category_id": "CIC" + }, + "cicCaseFullName": "Test Name", + "cicCaseSchemeCic": "Year2012", + "hearingList": [ + { + "id": "1", + "value": { + "hearingStatus": "Listed", + "hearingType": "Final", + "hearingFormat": "Face to Face", + "shortNotice": "Yes", + "hearingVenues": { + "value": { + "label": "courtname-courtAddress" + }, + "list_items": [ + { + "label": "courtname-courtAddress" + } + ], + "valueLabel": "courtname-courtAddress" + }, + "regionList": { + "value": { + "label": "1-region" + }, + "list_items": [ + { + "label": "1-region" + } + ], + "valueLabel": "1-region" + }, + "venueNotListedOption": [], + "roomAtVenue": "G.01", + "addlInstr": "Ground floor", + "date": "2024-08-14", + "hearingTime": "10:00" + } + }, + { + "id": "2", + "value": { + "hearingStatus": "Listed", + "hearingType": "Interlocutory", + "hearingFormat": "Face to Face", + "shortNotice": "Yes", + "hearingVenues": { + "value": { + "label": "courtname-courtAddress" + }, + "list_items": [ + { + "label": "courtname-courtAddress" + } + ], + "valueLabel": "courtname-courtAddress" + }, + "regionList": { + "value": { + "label": "1-region" + }, + "list_items": [ + { + "label": "1-region" + } + ], + "valueLabel": "1-region" + }, + "venueNotListedOption": [], + "roomAtVenue": "G.01", + "addlInstr": "Ground floor", + "date": "2024-08-14", + "hearingTime": "14:00" + } + } + ], + "firstHearingDate": "14 Aug 2024" + } +} diff --git a/src/integrationTest/resources/caseworker-create-hearing-summary-about-to-start-response.json b/src/integrationTest/resources/caseworker-create-hearing-summary-about-to-start-response.json new file mode 100644 index 0000000000..7acda62f3e --- /dev/null +++ b/src/integrationTest/resources/caseworker-create-hearing-summary-about-to-start-response.json @@ -0,0 +1,136 @@ +{ + "data": { + "cicCaseHearingList": { + "list_items": [ + { + "label": "1 - Final - 14 Aug 2024 10:00" + }, + { + "label": "2 - Interlocutory - 14 Aug 2024 14:00" + } + ] + }, + "cicCaseRespondentName": "Appeals team", + "cicCaseRespondentOrganisation": "CICA", + "cicCaseRespondentEmail": "appeals.team@cica.gov.uk", + "judge": { + "list_items": [ + { + "label": "John Doe" + }, + { + "label": "John Smith" + } + ] + }, + "judgeList": [ + { + "id": "1", + "value": { + "judgeFullName": "John Smith", + "personalCode": "12345" + } + }, + { + "id": "2", + "value": { + "judgeFullName": "John Doe", + "personalCode": "98765" + } + } + ], + "memberList": [ + { + "id": "1", + "value": { + "name": { + "list_items": [ + { + "label": "John Doe" + }, + { + "label": "John Smith" + } + ] + } + } + } + ], + "hearingList": [ + { + "id": "1", + "value": { + "hearingStatus": "Listed", + "hearingType": "Final", + "hearingFormat": "Face to Face", + "shortNotice": "Yes", + "hearingVenues": { + "value": { + "label": "courtname-courtAddress" + }, + "list_items": [ + { + "label": "courtname-courtAddress" + } + ], + "valueLabel": "courtname-courtAddress" + }, + "regionList": { + "value": { + "label": "1-region" + }, + "list_items": [ + { + "label": "1-region" + } + ], + "valueLabel": "1-region" + }, + "venueNotListedOption": [], + "roomAtVenue": "G.01", + "addlInstr": "Ground floor", + "date": "2024-08-14", + "hearingTime": "10:00" + } + }, + { + "id": "2", + "value": { + "hearingStatus": "Listed", + "hearingType": "Interlocutory", + "hearingFormat": "Face to Face", + "shortNotice": "Yes", + "hearingVenues": { + "value": { + "label": "courtname-courtAddress" + }, + "list_items": [ + { + "label": "courtname-courtAddress" + } + ], + "valueLabel": "courtname-courtAddress" + }, + "regionList": { + "value": { + "label": "1-region" + }, + "list_items": [ + { + "label": "1-region" + } + ], + "valueLabel": "1-region" + }, + "venueNotListedOption": [], + "roomAtVenue": "G.01", + "addlInstr": "Ground floor", + "date": "2024-08-14", + "hearingTime": "14:00" + } + } + ], + "currentEvent": "create-hearing-summary", + "firstHearingDate": "14 Aug 2024" + } +} diff --git a/src/integrationTest/resources/caseworker-create-hearing-summary-response.json b/src/integrationTest/resources/caseworker-create-hearing-summary-about-to-submit-response.json similarity index 100% rename from src/integrationTest/resources/caseworker-create-hearing-summary-response.json rename to src/integrationTest/resources/caseworker-create-hearing-summary-about-to-submit-response.json diff --git a/src/main/java/uk/gov/hmcts/sptribs/caseworker/event/CaseWorkerCreateDraftOrder.java b/src/main/java/uk/gov/hmcts/sptribs/caseworker/event/CaseWorkerCreateDraftOrder.java index 7b56f6d1a5..7562675659 100644 --- a/src/main/java/uk/gov/hmcts/sptribs/caseworker/event/CaseWorkerCreateDraftOrder.java +++ b/src/main/java/uk/gov/hmcts/sptribs/caseworker/event/CaseWorkerCreateDraftOrder.java @@ -112,10 +112,8 @@ private void createDraftOrderAddDocumentFooter(PageBuilder pageBuilder) { .done(); } - public AboutToStartOrSubmitResponse midEvent( - CaseDetails details, - CaseDetails detailsBefore - ) { + public AboutToStartOrSubmitResponse midEvent(CaseDetails details, + CaseDetails detailsBefore) { Calendar cal = Calendar.getInstance(); String date = simpleDateFormat.format(cal.getTime()); diff --git a/src/test/java/uk/gov/hmcts/sptribs/testutil/TestDataHelper.java b/src/test/java/uk/gov/hmcts/sptribs/testutil/TestDataHelper.java index 211da05fb2..eb54a180cc 100644 --- a/src/test/java/uk/gov/hmcts/sptribs/testutil/TestDataHelper.java +++ b/src/test/java/uk/gov/hmcts/sptribs/testutil/TestDataHelper.java @@ -46,7 +46,13 @@ import static feign.Request.HttpMethod.GET; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Collections.emptySet; import static org.apache.commons.lang3.StringUtils.EMPTY; +import static uk.gov.hmcts.ccd.sdk.type.YesOrNo.YES; +import static uk.gov.hmcts.sptribs.ciccase.model.HearingFormat.FACE_TO_FACE; +import static uk.gov.hmcts.sptribs.ciccase.model.HearingState.Listed; +import static uk.gov.hmcts.sptribs.ciccase.model.HearingType.FINAL; +import static uk.gov.hmcts.sptribs.ciccase.model.HearingType.INTERLOCUTORY; import static uk.gov.hmcts.sptribs.testutil.TestConstants.HEARING_DATE_1; import static uk.gov.hmcts.sptribs.testutil.TestConstants.HEARING_DATE_2; import static uk.gov.hmcts.sptribs.testutil.TestConstants.HEARING_TIME; @@ -579,4 +585,39 @@ public static DssCaseData getDssCaseData() { .otherInfoDocuments(dssCaseDataOtherInfoDocuments) .build(); } + + public static List> getHearingList() { + final Listing listing1 = Listing.builder() + .date(LocalDate.of(2024, 8, 14)) + .hearingType(FINAL) + .hearingTime("10:00") + .regionList(getMockedRegionData()) + .hearingVenues(getMockedHearingVenueData()) + .venueNotListedOption(emptySet()) + .roomAtVenue("G.01") + .addlInstr("Ground floor") + .hearingFormat(FACE_TO_FACE) + .shortNotice(YES) + .hearingStatus(Listed) + .build(); + final Listing listing2 = Listing.builder() + .date(LocalDate.of(2024, 8, 14)) + .hearingType(INTERLOCUTORY) + .hearingTime("14:00") + .regionList(getMockedRegionData()) + .hearingVenues(getMockedHearingVenueData()) + .venueNotListedOption(emptySet()) + .roomAtVenue("G.01") + .addlInstr("Ground floor") + .hearingFormat(FACE_TO_FACE) + .shortNotice(YES) + .hearingStatus(Listed) + .build(); + + final List> hearingList = new ArrayList<>(); + hearingList.add(new ListValue<>("1", listing1)); + hearingList.add(new ListValue<>("2", listing2)); + + return hearingList; + } }