Skip to content

Commit

Permalink
DTSSTCI-978 (#1885)
Browse files Browse the repository at this point in the history
DTSSTCI-978: Add integration tests for document mangement events

Co-authored-by: Tom Elliott <tomelliott@Toms-MacBook-Pro.local>
  • Loading branch information
tomxelliott and Tom Elliott authored Aug 27, 2024
1 parent 97c85a4 commit 3c0005a
Show file tree
Hide file tree
Showing 8 changed files with 620 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
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.ccd.sdk.type.Document;
import uk.gov.hmcts.sptribs.caseworker.model.CloseCase;
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 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_DOCUMENT_MANAGEMENT_AMEND;
import static uk.gov.hmcts.sptribs.document.model.DocumentType.APPLICATION_FORM;
import static uk.gov.hmcts.sptribs.document.model.DocumentType.WITNESS_STATEMENT;
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.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.getCaseworkerCICDocumentList;
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 CaseworkerDocumentManagementAmendIT {

@Autowired
private MockMvc mockMvc;

@Autowired
private ObjectMapper objectMapper;

@MockBean
private WebMvcConfig webMvcConfig;

private static final String CASEWORKER_DOCUMENT_MANAGEMENT_AMEND_ABOUT_TO_START_RESPONSE =
"classpath:responses/caseworker-document-management-amend-about-to-start-response.json";
private static final String CASEWORKER_DOCUMENT_MANAGEMENT_AMEND_ABOUT_TO_SUBMIT_RESPONSE =
"classpath:responses/caseworker-document-management-amend-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 shouldPopulateAmendDocumentsListOnAboutToStart() throws Exception {
final CaseData caseData = CaseData.builder()
.cicCase(CicCase.builder()
.applicantDocumentsUploaded(getCaseworkerCICDocumentList("evidence.pdf", APPLICATION_FORM))
.build()
)
.closeCase(CloseCase.builder()
.documents(getCaseworkerCICDocumentList())
.build()
)
.build();

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

assertThatJson(response)
.when(IGNORING_EXTRA_FIELDS)
.isEqualTo(json(expectedResponse(CASEWORKER_DOCUMENT_MANAGEMENT_AMEND_ABOUT_TO_START_RESPONSE)));
}

@Test
void shouldAmendDocumentsOnAboutToSubmit() throws Exception {
final CaseData caseData = CaseData.builder()
.cicCase(CicCase.builder()
.selectedDocumentType("CASE")
.selectedDocumentEmailContent("some amended email content")
.selectedDocumentLink(Document.builder()
.filename("test.pdf")
.binaryUrl("http://url/")
.url("http://url/")
.build())
.selectedDocumentCategory(WITNESS_STATEMENT)
.applicantDocumentsUploaded(getCaseworkerCICDocumentList())
.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_DOCUMENT_MANAGEMENT_AMEND)))
.accept(APPLICATION_JSON))
.andExpect(
status().isOk())
.andReturn()
.getResponse()
.getContentAsString();

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

assertThatJson(response)
.inPath(CONFIRMATION_HEADER)
.isString()
.contains("# Document Updated");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
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.caseworker.model.DocumentManagement;
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_DOCUMENT_MANAGEMENT;
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.getCaseworkerCICDocumentUploadList;
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 CaseworkerDocumentManagementIT {

@Autowired
private MockMvc mockMvc;

@Autowired
private ObjectMapper objectMapper;

@MockBean
private WebMvcConfig webMvcConfig;

private static final String CASEWORKER_DOCUMENT_MANAGEMENT_ABOUT_TO_SUBMIT_RESPONSE =
"classpath:responses/caseworker-document-management-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 shouldAddNewDocumentToAllCaseworkerCICDocumentListOnAboutToSubmit() throws Exception {
final CaseData caseData = caseData();
DocumentManagement documentManagement = DocumentManagement.builder()
.caseworkerCICDocumentUpload(getCaseworkerCICDocumentUploadList("file.pdf"))
.build();
caseData.setNewDocManagement(documentManagement);

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

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

assertThatJson(response)
.inPath(CONFIRMATION_HEADER)
.isString()
.contains("# Case Updated");
}
}
Loading

0 comments on commit 3c0005a

Please sign in to comment.