Skip to content

Commit

Permalink
DTSSTCI-979: Added integration tests for Caseworker edit cases (#1888)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajaram-nagarajan authored Sep 2, 2024
1 parent f864b85 commit e1b4b4f
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package uk.gov.hmcts.sptribs.caseworker.event;

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.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.testutil.IdamWireMock;

import java.util.HashSet;

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.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_EDIT_CASE;
import static uk.gov.hmcts.sptribs.ciccase.model.State.DSS_Submitted;
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.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.TestDataHelper.callbackRequest;
import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.caseData;
import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.cicCase;
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 CaseworkerEditCaseIT {

@Autowired
private MockMvc mockMvc;

@Autowired
private ObjectMapper objectMapper;

@MockBean
private WebMvcConfig webMvcConfig;

private static final String CASEWORKER_EDIT_CASE_ABOUT_TO_SUBMIT_RESPONSE =
"classpath:responses/caseworker-edit-case-about-to-submit-response.json";

private static final String CONFIRMATION_HEADER = "$.confirmation_header";

@BeforeAll
static void setUp() {
IdamWireMock.start();
}

@AfterAll
static void tearDown() {
IdamWireMock.stopAndReset();
}

@Test
void shouldEditCaseOnAboutToSubmit() throws Exception {
final CaseData caseData = caseData();
caseData.setCaseStatus(DSS_Submitted);

final CicCase cicCase = cicCase();
cicCase.setPartiesCIC(new HashSet<>());
caseData.setCicCase(cicCase);

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_EDIT_CASE)))
.accept(APPLICATION_JSON))
.andExpect(
status().isOk())
.andReturn()
.getResponse()
.getContentAsString();

assertThatJson(response)
.when(IGNORING_EXTRA_FIELDS)
.isEqualTo(json(expectedResponse(CASEWORKER_EDIT_CASE_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_EDIT_CASE)))
.accept(APPLICATION_JSON))
.andExpect(
status().isOk())
.andReturn()
.getResponse()
.getContentAsString();

assertThatJson(response)
.inPath(CONFIRMATION_HEADER)
.isString()
.contains("# Case Updated");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package uk.gov.hmcts.sptribs.caseworker.event;

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.sptribs.ciccase.model.CaseData;
import uk.gov.hmcts.sptribs.common.config.WebMvcConfig;
import uk.gov.hmcts.sptribs.testutil.IdamWireMock;

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.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_EDIT_CICA_CASE_DETAILS;
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.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.TestDataHelper.callbackRequest;
import static uk.gov.hmcts.sptribs.testutil.TestDataHelper.caseData;
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 CaseworkerEditCicaCaseDetailsIT {

@Autowired
private MockMvc mockMvc;

@Autowired
private ObjectMapper objectMapper;

@MockBean
private WebMvcConfig webMvcConfig;

private static final String CASEWORKER_EDIT_CICA_CASE_DETAILS_ABOUT_TO_SUBMIT_RESPONSE =
"classpath:responses/caseworker-edit-cica-case-details-about-to-submit-response.json";

private static final String CONFIRMATION_HEADER = "$.confirmation_header";

@BeforeAll
static void setUp() {
IdamWireMock.start();
}

@AfterAll
static void tearDown() {
IdamWireMock.stopAndReset();
}

@Test
void shouldEditCicaCaseDetailsOnAboutToSubmit() throws Exception {
final CaseData caseData = caseData();

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_EDIT_CICA_CASE_DETAILS)))
.accept(APPLICATION_JSON))
.andExpect(
status().isOk())
.andReturn()
.getResponse()
.getContentAsString();

assertThatJson(response)
.when(IGNORING_EXTRA_FIELDS)
.isEqualTo(json(expectedResponse(CASEWORKER_EDIT_CICA_CASE_DETAILS_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_EDIT_CICA_CASE_DETAILS)))
.accept(APPLICATION_JSON))
.andExpect(
status().isOk())
.andReturn()
.getResponse()
.getContentAsString();

assertThatJson(response)
.inPath(CONFIRMATION_HEADER)
.isString()
.contains("# Case details updated. ");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"data": {
"caseLinks": [],
"caseFlags": {
"details": []
},
"subjectFlags": {
"roleOnCase": "subject",
"details": []
},
"allCaseworkerCICDocument": [],
"allCaseworkerCICDocumentUpload": [],
"newCaseworkerCICDocument": [],
"newCaseworkerCICDocumentUpload": [],
"editCicaCaseDetails": {},
"contactParties": {},
"caseBundles": [],
"cicCasePartiesCIC": [],
"cicCaseRespondentName": "Appeals team",
"cicCaseRespondentOrganisation": "CICA",
"cicCaseRespondentEmail": "appeals.team@cica.gov.uk",
"cicCaseFirstDueDate": "",
"caseStatus": "DSS_Submitted",
"stayIsCaseStayed": "No",
"hearingList": [],
"hyphenatedCaseRef": "1616-5914-0147-3378",
"closedDayCount": "",
"firstHearingDate": "",
"dataVersion": 0,
"cicCaseSelectedDocument": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"data": {
"caseLinks": [],
"allCaseworkerCICDocument": [],
"allCaseworkerCICDocumentUpload": [],
"newCaseworkerCICDocument": [],
"newCaseworkerCICDocumentUpload": [],
"editCicaCaseDetails": {},
"contactParties": {},
"caseBundles": [],
"cicCaseRespondentName": "Appeals team",
"cicCaseRespondentOrganisation": "CICA",
"cicCaseRespondentEmail": "appeals.team@cica.gov.uk",
"cicCaseFirstDueDate": "",
"stayIsCaseStayed": "No",
"hearingList": [],
"closedDayCount": "",
"firstHearingDate": "",
"dataVersion": 0,
"cicCaseSelectedDocument": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,6 @@ public void configure(final ConfigBuilder<CaseData, State, UserRole> configBuild
editFurtherDetails.addTo(pageBuilder);
}

private PageBuilder addEventConfig(ConfigBuilder<CaseData, State, UserRole> configBuilder) {
Event.EventBuilder<CaseData, UserRole, State> eventBuilder = configBuilder
.event(CASEWORKER_EDIT_CASE)
.forStates(DSS_Submitted, Submitted, CaseManagement, ReadyToList, AwaitingHearing, AwaitingOutcome)
.name("Case: Edit case")
.description("Case: Edit case")
.showSummary()
.grant(CREATE_READ_UPDATE, SUPER_USER,
ST_CIC_CASEWORKER, ST_CIC_SENIOR_CASEWORKER, ST_CIC_HEARING_CENTRE_ADMIN,
ST_CIC_HEARING_CENTRE_TEAM_LEADER, ST_CIC_SENIOR_JUDGE, ST_CIC_RESPONDENT)
.grantHistoryOnly(ST_CIC_JUDGE)
.aboutToSubmitCallback(this::aboutToSubmit)
.submittedCallback(this::submitted);

if (isWorkAllocationEnabled) {
eventBuilder.publishToCamunda()
.grant(CREATE_READ_UPDATE, ST_CIC_WA_CONFIG_USER);
}

return new PageBuilder(eventBuilder);
}

public AboutToStartOrSubmitResponse<CaseData, State> aboutToSubmit(CaseDetails<CaseData, State> details,
CaseDetails<CaseData, State> beforeDetails) {
CaseData data = details.getData();
Expand Down Expand Up @@ -141,6 +119,28 @@ public SubmittedCallbackResponse submitted(CaseDetails<CaseData, State> details,
.build();
}

private PageBuilder addEventConfig(ConfigBuilder<CaseData, State, UserRole> configBuilder) {
Event.EventBuilder<CaseData, UserRole, State> eventBuilder = configBuilder
.event(CASEWORKER_EDIT_CASE)
.forStates(DSS_Submitted, Submitted, CaseManagement, ReadyToList, AwaitingHearing, AwaitingOutcome)
.name("Case: Edit case")
.description("Case: Edit case")
.showSummary()
.grant(CREATE_READ_UPDATE, SUPER_USER,
ST_CIC_CASEWORKER, ST_CIC_SENIOR_CASEWORKER, ST_CIC_HEARING_CENTRE_ADMIN,
ST_CIC_HEARING_CENTRE_TEAM_LEADER, ST_CIC_SENIOR_JUDGE, ST_CIC_RESPONDENT)
.grantHistoryOnly(ST_CIC_JUDGE)
.aboutToSubmitCallback(this::aboutToSubmit)
.submittedCallback(this::submitted);

if (isWorkAllocationEnabled) {
eventBuilder.publishToCamunda()
.grant(CREATE_READ_UPDATE, ST_CIC_WA_CONFIG_USER);
}

return new PageBuilder(eventBuilder);
}

private boolean checkNull(CaseData data) {
return null != data.getCicCase() && null != data.getCicCase().getPartiesCIC();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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.ciccase.model.DssCaseData;
import uk.gov.hmcts.sptribs.ciccase.model.HearingDate;
import uk.gov.hmcts.sptribs.ciccase.model.HearingFormat;
Expand Down Expand Up @@ -75,6 +76,11 @@ public static CaseData caseData() {
.build();
}

public static CicCase cicCase() {
return CicCase.builder()
.build();
}

public static CaseData closedCaseData() {
return CaseData.builder()
.caseStatus(State.CaseManagement)
Expand Down

0 comments on commit e1b4b4f

Please sign in to comment.