Skip to content

Commit

Permalink
DTSSTCI-977 (#1877)
Browse files Browse the repository at this point in the history
* 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 <tomelliott@Toms-MacBook-Pro.local>
  • Loading branch information
tomxelliott and Tom Elliott authored Aug 21, 2024
1 parent ebe9dbe commit 7bab9e5
Show file tree
Hide file tree
Showing 9 changed files with 723 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -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.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -248,39 +237,4 @@ void shouldReturnErrorMessageIfNotificationsFailOnSubmitted() throws Exception {

verifyNoInteractions(notificationServiceCIC);
}

private List<ListValue<Listing>> 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<ListValue<Listing>> hearingList = new ArrayList<>();
hearingList.add(new ListValue<>("1", listing1));
hearingList.add(new ListValue<>("2", listing2));

return hearingList;
}
}
Loading

0 comments on commit 7bab9e5

Please sign in to comment.