Skip to content

Commit

Permalink
feat: add further directions to order flow (FPLA-1105) (#760)
Browse files Browse the repository at this point in the history
* feat: add directions to order generation flow (FPLA-1105)
  • Loading branch information
swalker125 authored and SamanthaSJ committed Jan 13, 2020
1 parent 808b433 commit 89cc16e
Show file tree
Hide file tree
Showing 20 changed files with 302 additions and 26 deletions.
7 changes: 7 additions & 0 deletions ccd-definition/AuthorisationCaseField/court-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@
"UserRole": "caseworker-publiclaw-courtadmin",
"CRUD": "CRUD"
},
{
"LiveFrom": "01/01/2017",
"CaseTypeID": "CARE_SUPERVISION_EPO",
"CaseFieldID": "orderFurtherDirections",
"UserRole": "caseworker-publiclaw-courtadmin",
"CRUD": "CRUD"
},
{
"LiveFrom": "01/01/2017",
"CaseTypeID": "CARE_SUPERVISION_EPO",
Expand Down
7 changes: 7 additions & 0 deletions ccd-definition/AuthorisationCaseField/judiciary.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,12 @@
"CaseFieldID": "cmoEventId",
"UserRole": "caseworker-publiclaw-judiciary",
"CRUD": "CRU"
},
{
"LiveFrom": "01/01/2017",
"CaseTypeID": "CARE_SUPERVISION_EPO",
"CaseFieldID": "orderFurtherDirections",
"UserRole": "caseworker-publiclaw-judiciary",
"CRUD": "CRUD"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,20 @@
"PageColumnNumber": 1,
"ShowSummaryChangeOption": "Y",
"CallBackURLMidEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/create-order/mid-event"
},
{
"LiveFrom": "01/01/2017",
"CaseTypeID": "CARE_SUPERVISION_EPO",
"CaseEventID": "createOrder-PREPARE_FOR_HEARING",
"CaseFieldID": "orderFurtherDirections",
"PageFieldDisplayOrder": 1,
"DisplayContext": "OPTIONAL",
"PageID": "FurtherDirections",
"PageLabel": " ",
"PageDisplayOrder": 4,
"PageColumnNumber": 1,
"ShowSummaryChangeOption": "Y",
"PageShowCondition": "orderTypeAndDocument.type!=\"BLANK_ORDER\"",
"CallBackURLMidEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/create-order/mid-event"
}
]
15 changes: 15 additions & 0 deletions ccd-definition/CaseEventToFields/createOrder.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,20 @@
"PageColumnNumber": 1,
"ShowSummaryChangeOption": "Y",
"CallBackURLMidEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/create-order/mid-event"
},
{
"LiveFrom": "01/01/2017",
"CaseTypeID": "CARE_SUPERVISION_EPO",
"CaseEventID": "createOrder",
"CaseFieldID": "orderFurtherDirections",
"PageFieldDisplayOrder": 1,
"DisplayContext": "MANDATORY",
"PageID": "FurtherDirections",
"PageLabel": " ",
"PageDisplayOrder": 4,
"PageColumnNumber": 1,
"ShowSummaryChangeOption": "Y",
"PageShowCondition": "orderTypeAndDocument.type!=\"BLANK_ORDER\"",
"CallBackURLMidEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/create-order/mid-event"
}
]
15 changes: 15 additions & 0 deletions ccd-definition/CaseEventToFields/createOrderGatekeeping.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,20 @@
"PageColumnNumber": 1,
"ShowSummaryChangeOption": "Y",
"CallBackURLMidEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/create-order/mid-event"
},
{
"LiveFrom": "01/01/2017",
"CaseTypeID": "CARE_SUPERVISION_EPO",
"CaseEventID": "createOrderGatekeeping",
"CaseFieldID": "orderFurtherDirections",
"PageFieldDisplayOrder": 1,
"DisplayContext": "OPTIONAL",
"PageID": "FurtherDirections",
"PageLabel": " ",
"PageDisplayOrder": 4,
"PageColumnNumber": 1,
"ShowSummaryChangeOption": "Y",
"PageShowCondition": "orderTypeAndDocument.type!=\"BLANK_ORDER\"",
"CallBackURLMidEvent": "${CCD_DEF_CASE_SERVICE_BASE_URL}/callback/create-order/mid-event"
}
]
8 changes: 8 additions & 0 deletions ccd-definition/CaseField.json
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,14 @@
"FieldType": "OrderTypeAndDocument",
"SecurityClassification": "Public"
},
{
"LiveFrom": "01/01/2017",
"CaseTypeID": "CARE_SUPERVISION_EPO",
"ID": "orderFurtherDirections",
"Label": "Further directions",
"FieldType": "FurtherDirections",
"SecurityClassification": "Public"
},
{
"LiveFrom": "01/01/2017",
"CaseTypeID": "CARE_SUPERVISION_EPO",
Expand Down
19 changes: 19 additions & 0 deletions ccd-definition/ComplexTypes/1_furtherDirections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"LiveFrom": "01/01/2017",
"ID": "FurtherDirections",
"ListElementCode": "directionsNeeded",
"FieldType": "YesOrNo",
"ElementLabel": "Do you want to add further directions to the order?",
"SecurityClassification": "Public"
},
{
"LiveFrom": "01/01/2017",
"ID": "FurtherDirections",
"ListElementCode": "directions",
"FieldType": "TextArea",
"ElementLabel": "Give details",
"SecurityClassification": "Public",
"FieldShowCondition": "directionsNeeded = \"Yes\""
}
]
8 changes: 8 additions & 0 deletions ccd-definition/ComplexTypes/GeneratedOrder.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,13 @@
"FieldType": "JudgeAndLegalAdvisor",
"ElementLabel": "Judge and legal advisor",
"SecurityClassification": "Public"
},
{
"LiveFrom": "01/01/2017",
"ID": "GeneratedOrder",
"ListElementCode": "furtherDirections",
"FieldType": "FurtherDirections",
"ElementLabel": "Directions",
"SecurityClassification": "Public"
}
]
Binary file modified docker/docmosis/templates/FL-PLW-GOR-ENG-00218.docx
Binary file not shown.
10 changes: 10 additions & 0 deletions e2e/pages/events/createOrderEvent.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ module.exports = {
title: '#order_title',
details: '#order_details',
orderTypeList: '#orderTypeAndDocument_type',
directionsNeeded: {
yes: '#orderFurtherDirections_directionsNeeded-Yes',
no: '#orderFurtherDirections_directionsNeeded-No',
},
directions: '#orderFurtherDirections_directions',
},

selectType(type) {
Expand All @@ -25,4 +30,9 @@ module.exports = {
judgeAndLegalAdvisor.enterJudgeLastName(judgeLastName);
judgeAndLegalAdvisor.enterLegalAdvisorName(legalAdvisorName);
},

enterDirections(directions) {
I.click(this.fields.directionsNeeded.yes);
I.fillField(this.fields.directions, directions);
},
};
3 changes: 3 additions & 0 deletions e2e/tests/hmctsAdministersCaseAfterSubmission_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ Scenario('HMCTS admin creates multiple orders for the case', async (I, caseViewP
await createOrderEventPage.selectType(orders[1].type);
await I.retryUntilExists(() => I.click('Continue'), '#judgeAndLegalAdvisor_judgeTitle');
await createOrderEventPage.enterJudgeAndLegalAdvisor(orders[1].judgeAndLegalAdvisor.judgeLastName, orders[1].judgeAndLegalAdvisor.legalAdvisorName);
await I.retryUntilExists(() => I.click('Continue'), '#orderFurtherDirections_directionsNeeded');
await createOrderEventPage.enterDirections('example directions');
await I.completeEvent('Save and continue');
orderTime = new Date();

I.seeEventSubmissionConfirmation(config.administrationActions.createOrder);
caseViewPage.selectTab(caseViewPage.tabs.orders);
I.seeAnswerInTab(1, 'Order 2', 'Type of order', orders[1].type);
Expand Down
3 changes: 3 additions & 0 deletions e2e/tests/judiciaryAdministersCaseAfterSubmission_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ Scenario('Judiciary creates multiple orders for the case', async (I, caseViewPag
await createOrderEventPage.selectType(orders[1].type);
await I.retryUntilExists(() => I.click('Continue'), '#judgeAndLegalAdvisor_judgeTitle');
await createOrderEventPage.enterJudgeAndLegalAdvisor(orders[1].judgeAndLegalAdvisor.judgeLastName, orders[1].judgeAndLegalAdvisor.legalAdvisorName);
await I.retryUntilExists(() => I.click('Continue'), '#orderFurtherDirections_directionsNeeded');
await createOrderEventPage.enterDirections('example directions');
await I.completeEvent('Save and continue');
orderTime = new Date();

I.seeEventSubmissionConfirmation(config.administrationActions.createOrder);
caseViewPage.selectTab(caseViewPage.tabs.orders);
I.seeAnswerInTab(1, 'Order 2', 'Type of order', orders[1].type);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package uk.gov.hmcts.reform.fpl.controllers;

import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration;
Expand All @@ -12,7 +16,9 @@
import uk.gov.hmcts.reform.ccd.client.model.CaseDetails;
import uk.gov.hmcts.reform.document.domain.Document;
import uk.gov.hmcts.reform.fpl.model.CaseData;
import uk.gov.hmcts.reform.fpl.model.FurtherDirections;
import uk.gov.hmcts.reform.fpl.model.GeneratedOrder;
import uk.gov.hmcts.reform.fpl.model.OrderTypeAndDocument;
import uk.gov.hmcts.reform.fpl.model.common.DocmosisDocument;
import uk.gov.hmcts.reform.fpl.model.common.DocumentReference;
import uk.gov.hmcts.reform.fpl.model.common.Element;
Expand All @@ -32,6 +38,8 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static uk.gov.hmcts.reform.fpl.CaseDefinitionConstants.CASE_TYPE;
Expand Down Expand Up @@ -86,27 +94,6 @@ void aboutToStartShouldReturnErrorsWhenFamilymanNumberIsNotProvided() {
assertThat(callbackResponse.getErrors()).containsExactly("Enter Familyman case number");
}

@Test
void midEventShouldGenerateOrderDocument() throws Exception {
byte[] pdf = {1, 2, 3, 4, 5};
Document document = document();
DocmosisDocument docmosisDocument = new DocmosisDocument("order.pdf", pdf);

given(docmosisDocumentGeneratorService.generateDocmosisDocument(any(), any())).willReturn(docmosisDocument);
given(uploadDocumentService.uploadPDF(userId, userAuthToken, pdf, "blank_order_c21.pdf"))
.willReturn(document);

AboutToStartOrSubmitCallbackResponse callbackResponse = postMidEvent(callbackRequest());

CaseData caseData = mapper.convertValue(callbackResponse.getData(), CaseData.class);

assertThat(caseData.getOrderTypeAndDocument().getDocument()).isEqualTo(DocumentReference.builder()
.binaryUrl(document.links.binary.href)
.filename(document.originalDocumentName)
.url(document.links.self.href)
.build());
}

@Test
void aboutToSubmitShouldAddC21OrderToCaseDataAndRemoveTemporaryCaseDataOrderFields() throws Exception {
AboutToStartOrSubmitCallbackResponse callbackResponse = postAboutToSubmitEvent(callbackRequest());
Expand Down Expand Up @@ -174,11 +161,11 @@ private GeneratedOrder buildExpectedCareOrder() {
}

private void aboutToSubmitAssertions(CaseData caseData, GeneratedOrder expectedOrder) {

List<Element<GeneratedOrder>> orders = caseData.getOrderCollection();
assertThat(caseData.getOrderTypeAndDocument()).isEqualTo(null);
assertThat(caseData.getOrder()).isEqualTo(null);
assertThat(caseData.getJudgeAndLegalAdvisor()).isEqualTo(null);
assertThat(caseData.getOrderFurtherDirections()).isEqualTo(null);
assertThat(orders.get(0).getValue()).isEqualTo(expectedOrder);
}

Expand Down Expand Up @@ -216,4 +203,115 @@ private Map<String, Object> expectedOrderLocalAuthorityParameters() {
.put("localAuthorityOrCafcass", LOCAL_AUTHORITY_NAME)
.build();
}

@Nested
class MidEvent {
private final byte[] pdf = {1, 2, 3, 4, 5};
private Document document;

@BeforeEach
void setUp() {
document = document();
DocmosisDocument docmosisDocument = new DocmosisDocument("order.pdf", pdf);

given(docmosisDocumentGeneratorService.generateDocmosisDocument(any(), any())).willReturn(docmosisDocument);
given(uploadDocumentService.uploadPDF(any(), any(), any(), any())).willReturn(document);
}

@Test
void shouldGenerateOrderDocumentWhenOrderTypeIsBlankOrder() {
AboutToStartOrSubmitCallbackResponse callbackResponse = postMidEvent(generateBlankOrderCaseDetails());

CaseData caseData = mapper.convertValue(callbackResponse.getData(), CaseData.class);

verify(uploadDocumentService, times(1)).uploadPDF(userId, userAuthToken, pdf, "blank_order_c21.pdf");

assertThat(caseData.getOrderTypeAndDocument().getDocument()).isEqualTo(expectedDocument());
}

@Test
void shouldGenerateOrderDocumentWhenOrderTypeIsCareOrderWithFurtherDirections() {
final AboutToStartOrSubmitCallbackResponse callbackResponse = postMidEvent(
generateCareOrderCaseDetailsWithFurtherDirections());

verify(docmosisDocumentGeneratorService, times(1)).generateDocmosisDocument(any(), any());
verify(uploadDocumentService, times(1)).uploadPDF(userId, userAuthToken, pdf, "care_order.pdf");

final CaseData caseData = mapper.convertValue(callbackResponse.getData(), CaseData.class);

assertThat(caseData.getOrderTypeAndDocument().getDocument()).isEqualTo(expectedDocument());
}

@Test
void shouldNotGenerateOrderDocumentWhenOrderTypeIsCareOrderWithNoFurtherDirections() {
postMidEvent(generateCareOrderCaseDetailsWithoutFurtherDirections());

verify(docmosisDocumentGeneratorService, never()).generateDocmosisDocument(any(), any());
verify(uploadDocumentService, never()).uploadPDF(any(), any(), any(), any());
}

@AfterEach
void resetInvocations() {
reset(docmosisDocumentGeneratorService);
reset(uploadDocumentService);
}

private CaseDetails generateBlankOrderCaseDetails() {
final CaseData.CaseDataBuilder dataBuilder = CaseData.builder();

dataBuilder.order(GeneratedOrder.builder().details("").build());
dataBuilder.orderTypeAndDocument(OrderTypeAndDocument.builder().type(BLANK_ORDER).build());
generateDefaultValues(dataBuilder);

return CaseDetails.builder()
.data(mapper.convertValue(dataBuilder.build(), new TypeReference<>() {}))
.build();
}

private CaseDetails generateCareOrderCaseDetailsWithFurtherDirections() {
final CaseData.CaseDataBuilder dataBuilder = generateCommonCareOrderDetails();

dataBuilder.orderFurtherDirections(FurtherDirections.builder()
.directionsNeeded("Yes")
.directions("Some directions")
.build());

return CaseDetails.builder()
.data(mapper.convertValue(dataBuilder.build(), new TypeReference<>() {}))
.build();
}

private CaseDetails generateCareOrderCaseDetailsWithoutFurtherDirections() {
final CaseData.CaseDataBuilder dataBuilder = generateCommonCareOrderDetails();

return CaseDetails.builder()
.data(mapper.convertValue(dataBuilder.build(), new TypeReference<>() {}))
.build();
}

private CaseData.CaseDataBuilder generateCommonCareOrderDetails() {
final CaseData.CaseDataBuilder builder = CaseData.builder()
.orderTypeAndDocument(OrderTypeAndDocument.builder()
.type(CARE_ORDER)
.build());

generateDefaultValues(builder);

return builder;
}

private void generateDefaultValues(CaseData.CaseDataBuilder builder) {
builder.caseLocalAuthority(LOCAL_AUTHORITY_CODE);
builder.familyManCaseNumber(FAMILY_MAN_CASE_NUMBER);
builder.judgeAndLegalAdvisor(JudgeAndLegalAdvisor.builder().build());
}

private DocumentReference expectedDocument() {
return DocumentReference.builder()
.binaryUrl(document.links.binary.href)
.filename(document.originalDocumentName)
.url(document.links.self.href)
.build();
}
}
}

0 comments on commit 89cc16e

Please sign in to comment.