Skip to content

Commit

Permalink
MLPAB-397: How should the attorneys make decisions (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
acsauk authored Nov 4, 2022
1 parent 390d5bb commit e5709cf
Show file tree
Hide file tree
Showing 22 changed files with 684 additions and 58 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ else
yarn run cypress:run
endif

run-cypress-headed: ##@testing Runs cypress e2e tests in a browser. To run a specific spec file pass in spec e.g. make run-cypress spec=start
ifdef spec
yarn run cypress:run --spec "cypress/e2e/$(spec).cy.js" --headed --no-exit
else
yarn run cypress:run --headed --no-exit
endif

run-cypress-parallel: ##@testing Runs cypress e2e tests in parallel across 4 processor threads
yarn run cypress:parallel

Expand Down
2 changes: 2 additions & 0 deletions app/internal/page/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ func App(
ChooseAttorneySummary(logger, tmpls.Get("choose_attorneys_summary.gohtml"), lpaStore))
handle(removeAttorneyPath, RequireSession|CanGoBack,
RemoveAttorney(logger, tmpls.Get("remove_attorney.gohtml"), lpaStore))
handle(howShouldAttorneysMakeDecisionsPath, RequireSession|CanGoBack,
HowShouldAttorneysMakeDecisions(tmpls.Get("how_should_attorneys_make_decisions.gohtml"), lpaStore))
handle(wantReplacementAttorneysPath, RequireSession|CanGoBack,
WantReplacementAttorneys(tmpls.Get("want_replacement_attorneys.gohtml"), lpaStore))
handle(whenCanTheLpaBeUsedPath, RequireSession|CanGoBack,
Expand Down
22 changes: 16 additions & 6 deletions app/internal/page/check_your_lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ import (
)

type checkYourLpaData struct {
App AppData
Errors map[string]string
Lpa *Lpa
Form *checkYourLpaForm
Completed bool
App AppData
Errors map[string]string
Lpa *Lpa
Form *checkYourLpaForm
Completed bool
HowAttorneysMakeDecisionsPath string
ChooseAttorneysPath string
WhenCanLpaBeUsedPath string
RestrictionsPath string
CertificatesProviderPath string
}

func CheckYourLpa(tmpl template.Template, lpaStore LpaStore) Handler {
Expand All @@ -28,7 +33,12 @@ func CheckYourLpa(tmpl template.Template, lpaStore LpaStore) Handler {
Checked: lpa.Checked,
Happy: lpa.HappyToShare,
},
Completed: lpa.Tasks.CheckYourLpa == TaskCompleted,
Completed: lpa.Tasks.CheckYourLpa == TaskCompleted,
HowAttorneysMakeDecisionsPath: howShouldAttorneysMakeDecisionsPath,
ChooseAttorneysPath: chooseAttorneysPath,
WhenCanLpaBeUsedPath: whenCanTheLpaBeUsedPath,
RestrictionsPath: restrictionsPath,
CertificatesProviderPath: certificateProviderDetailsPath,
}

if r.Method == http.MethodPost {
Expand Down
16 changes: 13 additions & 3 deletions app/internal/page/check_your_lpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ func TestGetCheckYourLpa(t *testing.T) {
template := &mockTemplate{}
template.
On("Func", w, &checkYourLpaData{
App: appData,
Form: &checkYourLpaForm{},
Lpa: &Lpa{},
App: appData,
Form: &checkYourLpaForm{},
Lpa: &Lpa{},
HowAttorneysMakeDecisionsPath: howShouldAttorneysMakeDecisionsPath,
ChooseAttorneysPath: chooseAttorneysPath,
WhenCanLpaBeUsedPath: whenCanTheLpaBeUsedPath,
RestrictionsPath: restrictionsPath,
CertificatesProviderPath: certificateProviderDetailsPath,
}).
Return(nil)

Expand Down Expand Up @@ -77,6 +82,11 @@ func TestGetCheckYourLpaFromStore(t *testing.T) {
Checked: true,
Happy: true,
},
HowAttorneysMakeDecisionsPath: howShouldAttorneysMakeDecisionsPath,
ChooseAttorneysPath: chooseAttorneysPath,
WhenCanLpaBeUsedPath: whenCanTheLpaBeUsedPath,
RestrictionsPath: restrictionsPath,
CertificatesProviderPath: certificateProviderDetailsPath,
}).
Return(nil)

Expand Down
5 changes: 5 additions & 0 deletions app/internal/page/choose_attorney_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ func ChooseAttorneySummary(logger Logger, tmpl template.Template, lpaStore LpaSt
if len(data.Errors) == 0 {
redirectUrl := wantReplacementAttorneysPath

if len(lpa.Attorneys) > 1 {
redirectUrl = howShouldAttorneysMakeDecisionsPath
}

if data.Form.AddAttorney == "yes" {
redirectUrl = fmt.Sprintf("%s?addAnother=1", data.AttorneyDetailsPath)
}

appData.Lang.Redirect(w, r, redirectUrl, http.StatusFound)
return nil
}

}
Expand Down
39 changes: 17 additions & 22 deletions app/internal/page/choose_attorneys_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,22 @@ func TestPostChooseAttorneysSummaryAddAttorney(t *testing.T) {
testcases := map[string]struct {
addMoreFormValue string
expectedUrl string
Attorneys []Attorney
}{
"add-attorney": {
"yes",
"/choose-attorneys?addAnother=1",
"add attorney": {
addMoreFormValue: "yes",
expectedUrl: "/choose-attorneys?addAnother=1",
Attorneys: []Attorney{},
},
"do-not-add-attorney": {
"no",
"/want-replacement-attorneys",
"do not add attorney - with single attorney": {
addMoreFormValue: "no",
expectedUrl: "/want-replacement-attorneys",
Attorneys: []Attorney{{ID: "123"}},
},
"do not add attorney - with multiple attorneys": {
addMoreFormValue: "no",
expectedUrl: "/how-should-attorneys-make-decisions",
Attorneys: []Attorney{{ID: "123"}, {ID: "456"}},
},
}

Expand All @@ -85,20 +93,7 @@ func TestPostChooseAttorneysSummaryAddAttorney(t *testing.T) {
lpaStore := &mockLpaStore{}
lpaStore.
On("Get", mock.Anything, "session-id").
Return(&Lpa{}, nil)

template := &mockTemplate{}
template.
On("Func", w, &chooseAttorneysSummaryData{
App: appData,
Lpa: &Lpa{},
AttorneyAddressPath: chooseAttorneysAddressPath,
AttorneyDetailsPath: chooseAttorneysPath,
RemoveAttorneyPath: removeAttorneyPath,
Form: chooseAttorneysSummaryForm{AddAttorney: tc.addMoreFormValue},
Errors: map[string]string{},
}).
Return(nil)
Return(&Lpa{Attorneys: tc.Attorneys}, nil)

form := url.Values{
"add-attorney": {tc.addMoreFormValue},
Expand All @@ -107,13 +102,13 @@ func TestPostChooseAttorneysSummaryAddAttorney(t *testing.T) {
r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode()))
r.Header.Add("Content-Type", formUrlEncoded)

err := ChooseAttorneySummary(nil, template.Func, lpaStore)(appData, w, r)
err := ChooseAttorneySummary(nil, nil, lpaStore)(appData, w, r)
resp := w.Result()

assert.Nil(t, err)
assert.Equal(t, http.StatusFound, resp.StatusCode)
assert.Equal(t, tc.expectedUrl, resp.Header.Get("Location"))
mock.AssertExpectationsForObjects(t, lpaStore, template)
mock.AssertExpectationsForObjects(t, lpaStore)
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/internal/page/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type Lpa struct {
SignatureEmailID string
IdentityOptions IdentityOptions
YotiUserData identity.UserData
DecisionsType string
DecisionsDetails string
}

type PaymentDetails struct {
Expand Down
79 changes: 79 additions & 0 deletions app/internal/page/how_should_attorneys_make_decisions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package page

import (
"net/http"

"github.com/ministryofjustice/opg-go-common/template"
)

type howShouldAttorneysMakeDecisionsData struct {
App AppData
Errors map[string]string
Form *howShouldAttorneysMakeDecisionsForm
}

type howShouldAttorneysMakeDecisionsForm struct {
DecisionsType string
DecisionsDetails string
}

func HowShouldAttorneysMakeDecisions(tmpl template.Template, lpaStore LpaStore) Handler {
return func(appData AppData, w http.ResponseWriter, r *http.Request) error {
lpa, err := lpaStore.Get(r.Context(), appData.SessionID)
if err != nil {
return err
}

data := &howShouldAttorneysMakeDecisionsData{
App: appData,
Form: &howShouldAttorneysMakeDecisionsForm{
DecisionsType: lpa.DecisionsType,
DecisionsDetails: lpa.DecisionsDetails,
},
}

if r.Method == http.MethodPost {
data.Form = readHowShouldAttorneysMakeDecisionsForm(r)
data.Errors = data.Form.Validate()

if len(data.Errors) == 0 {
lpa.DecisionsType = data.Form.DecisionsType

if data.Form.DecisionsType != "mixed" {
lpa.DecisionsDetails = ""
} else {
lpa.DecisionsDetails = data.Form.DecisionsDetails
}

if err := lpaStore.Put(r.Context(), appData.SessionID, lpa); err != nil {
return err
}
appData.Lang.Redirect(w, r, wantReplacementAttorneysPath, http.StatusFound)
return nil
}
}

return tmpl(w, data)
}
}

func readHowShouldAttorneysMakeDecisionsForm(r *http.Request) *howShouldAttorneysMakeDecisionsForm {
return &howShouldAttorneysMakeDecisionsForm{
DecisionsType: postFormString(r, "decision-type"),
DecisionsDetails: postFormString(r, "mixed-details"),
}
}

func (f *howShouldAttorneysMakeDecisionsForm) Validate() map[string]string {
errors := map[string]string{}

if f.DecisionsType != "jointly-and-severally" && f.DecisionsType != "jointly" && f.DecisionsType != "mixed" {
errors["decision-type"] = "chooseADecisionType"
}

if f.DecisionsType == "mixed" && f.DecisionsDetails == "" {
errors["mixed-details"] = "provideDecisionDetails"
}

return errors
}
Loading

0 comments on commit e5709cf

Please sign in to comment.