diff --git a/internal/form/enum_yesno.go b/internal/form/enum_yesno.go index 50c3f060d7..b8968600b7 100644 --- a/internal/form/enum_yesno.go +++ b/internal/form/enum_yesno.go @@ -1,4 +1,4 @@ -// Code generated by "enumerator -type YesNo -linecomment -empty"; DO NOT EDIT. +// Code generated by "enumerator -type YesNo -linecomment -trimprefix"; DO NOT EDIT. package form import ( @@ -10,18 +10,18 @@ func _() { // An "invalid array index" compiler error signifies that the constant values have changed. // Re-run the stringer command to generate them again. var x [1]struct{} + _ = x[YesNoUnknown-0] _ = x[Yes-1] _ = x[No-2] } -const _YesNo_name = "yesno" +const _YesNo_name = "Unknownyesno" -var _YesNo_index = [...]uint8{0, 3, 5} +var _YesNo_index = [...]uint8{0, 7, 10, 12} func (i YesNo) String() string { - i -= 1 if i >= YesNo(len(_YesNo_index)-1) { - return "YesNo(" + strconv.FormatInt(int64(i+1), 10) + ")" + return "YesNo(" + strconv.FormatInt(int64(i), 10) + ")" } return _YesNo_name[_YesNo_index[i]:_YesNo_index[i+1]] } @@ -30,6 +30,10 @@ func (i YesNo) MarshalText() ([]byte, error) { return []byte(i.String()), nil } +func (i YesNo) IsUnknown() bool { + return i == YesNoUnknown +} + func (i YesNo) IsYes() bool { return i == Yes } @@ -40,6 +44,8 @@ func (i YesNo) IsNo() bool { func ParseYesNo(s string) (YesNo, error) { switch s { + case "Unknown": + return YesNoUnknown, nil case "yes": return Yes, nil case "no": @@ -50,15 +56,13 @@ func ParseYesNo(s string) (YesNo, error) { } type YesNoOptions struct { - Yes YesNo - No YesNo + Unknown YesNo + Yes YesNo + No YesNo } var YesNoValues = YesNoOptions{ - Yes: Yes, - No: No, -} - -func (i YesNo) Empty() bool { - return i == YesNo(0) + Unknown: YesNoUnknown, + Yes: Yes, + No: No, } diff --git a/internal/form/names.go b/internal/form/names.go index 5570636b4f..9cb7fb54e0 100644 --- a/internal/form/names.go +++ b/internal/form/names.go @@ -10,11 +10,13 @@ var FieldNames = SharedFieldNames{ Postcode: "address-postcode", Action: "action", }, + YesNo: "yes-no", } type SharedFieldNames struct { Address AddressFieldNames LanguagePreference string + YesNo string } type AddressFieldNames struct { diff --git a/internal/form/yes_no.go b/internal/form/yes_no.go index 03f6c28496..a529459021 100644 --- a/internal/form/yes_no.go +++ b/internal/form/yes_no.go @@ -1,9 +1,10 @@ package form -//go:generate enumerator -type YesNo -linecomment -empty +//go:generate enumerator -type YesNo -linecomment -trimprefix type YesNo uint8 const ( - Yes YesNo = iota + 1 // yes - No // no + YesNoUnknown YesNo = iota + Yes // yes + No // no ) diff --git a/internal/form/yes_no_form.go b/internal/form/yes_no_form.go index 4be4c0056a..9558d8e99f 100644 --- a/internal/form/yes_no_form.go +++ b/internal/form/yes_no_form.go @@ -11,22 +11,23 @@ type YesNoForm struct { YesNo YesNo Error error ErrorLabel string + Options YesNoOptions + FieldName string } func ReadYesNoForm(r *http.Request, errorLabel string) *YesNoForm { - yesNo, err := ParseYesNo(PostFormString(r, "yes-no")) + form := NewYesNoForm(YesNoUnknown) - return &YesNoForm{ - YesNo: yesNo, - Error: err, - ErrorLabel: errorLabel, - } + form.YesNo, form.Error = ParseYesNo(PostFormString(r, form.FieldName)) + form.ErrorLabel = errorLabel + + return form } func (f *YesNoForm) Validate() validation.List { var errors validation.List - errors.Error("yes-no", f.ErrorLabel, f.Error, + errors.Error(f.FieldName, f.ErrorLabel, f.Error, validation.Selected()) return errors @@ -35,3 +36,11 @@ func (f *YesNoForm) Validate() validation.List { func PostFormString(r *http.Request, name string) string { return strings.TrimSpace(r.PostFormValue(name)) } + +func NewYesNoForm(yesNo YesNo) *YesNoForm { + return &YesNoForm{ + YesNo: yesNo, + Options: YesNoValues, + FieldName: FieldNames.YesNo, + } +} diff --git a/internal/form/yes_no_form_test.go b/internal/form/yes_no_form_test.go index 6ea72003d4..0cec761fcd 100644 --- a/internal/form/yes_no_form_test.go +++ b/internal/form/yes_no_form_test.go @@ -12,11 +12,11 @@ import ( ) func TestReadYesNoForm(t *testing.T) { - form := url.Values{"yes-no": {Yes.String()}} + form := url.Values{FieldNames.YesNo: {Yes.String()}} r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) r.Header.Add("Content-Type", "application/x-www-form-urlencoded") - assert.Equal(t, &YesNoForm{YesNo: Yes, ErrorLabel: "a-label"}, ReadYesNoForm(r, "a-label")) + assert.Equal(t, &YesNoForm{YesNo: Yes, ErrorLabel: "a-label", Options: YesNoValues, FieldName: FieldNames.YesNo}, ReadYesNoForm(r, "a-label")) } func TestYesNoFormValidate(t *testing.T) { @@ -25,11 +25,11 @@ func TestYesNoFormValidate(t *testing.T) { errors validation.List }{ "valid": { - form: &YesNoForm{}, + form: NewYesNoForm(YesNoUnknown), }, "invalid": { - form: &YesNoForm{Error: errors.New("err"), ErrorLabel: "a-label"}, - errors: validation.With("yes-no", validation.SelectError{Label: "a-label"}), + form: &YesNoForm{Error: errors.New("err"), ErrorLabel: "a-label", FieldName: FieldNames.YesNo}, + errors: validation.With(FieldNames.YesNo, validation.SelectError{Label: "a-label"}), }, } @@ -39,3 +39,13 @@ func TestYesNoFormValidate(t *testing.T) { }) } } + +func TestNewYesNoForm(t *testing.T) { + for _, yesNo := range []YesNo{Yes, No, YesNoUnknown} { + assert.Equal(t, &YesNoForm{ + YesNo: yesNo, + Options: YesNoValues, + FieldName: "yes-no", + }, NewYesNoForm(yesNo)) + } +} diff --git a/internal/page/attorney/would_like_second_signatory.go b/internal/page/attorney/would_like_second_signatory.go index 871b2386b1..4cc055a5b0 100644 --- a/internal/page/attorney/would_like_second_signatory.go +++ b/internal/page/attorney/would_like_second_signatory.go @@ -12,18 +12,16 @@ import ( ) type wouldLikeSecondSignatoryData struct { - App page.AppData - Errors validation.List - YesNo form.YesNo - Options form.YesNoOptions + App page.AppData + Errors validation.List + Form *form.YesNoForm } func WouldLikeSecondSignatory(tmpl template.Template, attorneyStore AttorneyStore, donorStore DonorStore, lpaStoreClient LpaStoreClient) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *actor.AttorneyProvidedDetails) error { data := &wouldLikeSecondSignatoryData{ - App: appData, - YesNo: attorneyProvidedDetails.WouldLikeSecondSignatory, - Options: form.YesNoValues, + App: appData, + Form: form.NewYesNoForm(attorneyProvidedDetails.WouldLikeSecondSignatory), } if r.Method == http.MethodPost { diff --git a/internal/page/attorney/would_like_second_signatory_test.go b/internal/page/attorney/would_like_second_signatory_test.go index 2dea0ca8ea..fc840f4f41 100644 --- a/internal/page/attorney/would_like_second_signatory_test.go +++ b/internal/page/attorney/would_like_second_signatory_test.go @@ -23,8 +23,8 @@ func TestGetWouldLikeSecondSignatory(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). Execute(w, &wouldLikeSecondSignatoryData{ - App: testAppData, - Options: form.YesNoValues, + App: testAppData, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(nil) @@ -42,8 +42,8 @@ func TestGetWouldLikeSecondSignatoryWhenTemplateErrors(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). Execute(w, &wouldLikeSecondSignatoryData{ - App: testAppData, - Options: form.YesNoValues, + App: testAppData, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(expectedError) @@ -56,7 +56,7 @@ func TestGetWouldLikeSecondSignatoryWhenTemplateErrors(t *testing.T) { func TestPostWouldLikeSecondSignatoryWhenYes(t *testing.T) { f := url.Values{ - "yes-no": {form.Yes.String()}, + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() @@ -89,7 +89,7 @@ func TestPostWouldLikeSecondSignatoryWhenNo(t *testing.T) { } f := url.Values{ - "yes-no": {form.No.String()}, + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() @@ -125,7 +125,7 @@ func TestPostWouldLikeSecondSignatoryWhenLpaStoreClientErrors(t *testing.T) { donor := &actor.DonorProvidedDetails{SignedAt: time.Now()} f := url.Values{ - "yes-no": {form.No.String()}, + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() @@ -153,7 +153,7 @@ func TestPostWouldLikeSecondSignatoryWhenLpaStoreClientErrors(t *testing.T) { func TestPostWouldLikeSecondSignatoryWhenDonorStoreErrors(t *testing.T) { f := url.Values{ - "yes-no": {form.No.String()}, + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() @@ -176,7 +176,7 @@ func TestPostWouldLikeSecondSignatoryWhenDonorStoreErrors(t *testing.T) { func TestPostWouldLikeSecondSignatoryWhenAttorneyStoreErrors(t *testing.T) { form := url.Values{ - "yes-no": {form.No.String()}, + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() @@ -193,15 +193,15 @@ func TestPostWouldLikeSecondSignatoryWhenAttorneyStoreErrors(t *testing.T) { } func TestPostWouldLikeSecondSignatoryWhenValidationError(t *testing.T) { - form := url.Values{ - "yes-no": {""}, + f := url.Values{ + form.FieldNames.YesNo: {""}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - validationError := validation.With("yes-no", validation.SelectError{Label: "yesIfWouldLikeSecondSignatory"}) + validationError := validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "yesIfWouldLikeSecondSignatory"}) template := newMockTemplate(t) template.EXPECT(). diff --git a/internal/page/data.go b/internal/page/data.go index bfdb2c1dd2..d55daf53b9 100644 --- a/internal/page/data.go +++ b/internal/page/data.go @@ -80,7 +80,7 @@ func ChooseReplacementAttorneysState(donor *actor.DonorProvidedDetails) actor.Ta } if donor.ReplacementAttorneys.Len() == 0 { - if donor.WantReplacementAttorneys.Empty() { + if donor.WantReplacementAttorneys.IsUnknown() { return actor.TaskNotStarted } diff --git a/internal/page/donor/are_you_applying_for_fee_discount_or_exemption.go b/internal/page/donor/are_you_applying_for_fee_discount_or_exemption.go index 36ba633a3f..f584032d38 100644 --- a/internal/page/donor/are_you_applying_for_fee_discount_or_exemption.go +++ b/internal/page/donor/are_you_applying_for_fee_discount_or_exemption.go @@ -10,20 +10,19 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) -type areYouApplyingForFeeDiscountOrExemption struct { +type areYouApplyingForFeeDiscountOrExemptionData struct { App page.AppData Errors validation.List CertificateProvider actor.CertificateProvider - Options form.YesNoOptions Form *form.YesNoForm } func AreYouApplyingForFeeDiscountOrExemption(tmpl template.Template, payer Payer, donorStore DonorStore) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { - data := &areYouApplyingForFeeDiscountOrExemption{ + data := &areYouApplyingForFeeDiscountOrExemptionData{ App: appData, CertificateProvider: donor.CertificateProvider, - Options: form.YesNoValues, + Form: form.NewYesNoForm(form.YesNoUnknown), } if r.Method == http.MethodPost { diff --git a/internal/page/donor/are_you_applying_for_fee_discount_or_exemption_test.go b/internal/page/donor/are_you_applying_for_fee_discount_or_exemption_test.go index 6a27984958..f0df4b6060 100644 --- a/internal/page/donor/are_you_applying_for_fee_discount_or_exemption_test.go +++ b/internal/page/donor/are_you_applying_for_fee_discount_or_exemption_test.go @@ -21,9 +21,9 @@ func TestGetAreYouApplyingForFeeDiscountOrExemption(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). - Execute(w, &areYouApplyingForFeeDiscountOrExemption{ - App: testAppData, - Options: form.YesNoValues, + Execute(w, &areYouApplyingForFeeDiscountOrExemptionData{ + App: testAppData, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(nil) @@ -40,9 +40,9 @@ func TestGetAreYouApplyingForFeeDiscountOrExemptionWhenTemplateErrors(t *testing template := newMockTemplate(t) template.EXPECT(). - Execute(w, &areYouApplyingForFeeDiscountOrExemption{ - App: testAppData, - Options: form.YesNoValues, + Execute(w, &areYouApplyingForFeeDiscountOrExemptionData{ + App: testAppData, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(expectedError) @@ -55,7 +55,7 @@ func TestGetAreYouApplyingForFeeDiscountOrExemptionWhenTemplateErrors(t *testing func TestPostAreYouApplyingForFeeDiscountOrExemption(t *testing.T) { f := url.Values{ - "yes-no": {form.No.String()}, + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() @@ -83,12 +83,12 @@ func TestPostAreYouApplyingForFeeDiscountOrExemption(t *testing.T) { } func TestPostAreYouApplyingForFeeDiscountOrExemptionWhenDonorStoreErrors(t *testing.T) { - form := url.Values{ - "yes-no": {form.No.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -101,12 +101,12 @@ func TestPostAreYouApplyingForFeeDiscountOrExemptionWhenDonorStoreErrors(t *test } func TestPostAreYouApplyingForFeeDiscountOrExemptionWhenPayerErrors(t *testing.T) { - form := url.Values{ - "yes-no": {form.No.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) payer := newMockPayer(t) @@ -125,7 +125,7 @@ func TestPostAreYouApplyingForFeeDiscountOrExemptionWhenPayerErrors(t *testing.T func TestPostAreYouApplyingForFeeDiscountOrExemptionWhenYes(t *testing.T) { f := url.Values{ - "yes-no": {form.Yes.String()}, + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() @@ -150,19 +150,19 @@ func TestPostAreYouApplyingForFeeDiscountOrExemptionWhenYes(t *testing.T) { } func TestPostAreYouApplyingForFeeDiscountOrExemptionWhenValidationError(t *testing.T) { - form := url.Values{ - "yes-no": {""}, + f := url.Values{ + form.FieldNames.YesNo: {""}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - validationError := validation.With("yes-no", validation.SelectError{Label: "whetherApplyingForDifferentFeeType"}) + validationError := validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "whetherApplyingForDifferentFeeType"}) template := newMockTemplate(t) template.EXPECT(). - Execute(w, mock.MatchedBy(func(data *areYouApplyingForFeeDiscountOrExemption) bool { + Execute(w, mock.MatchedBy(func(data *areYouApplyingForFeeDiscountOrExemptionData) bool { return assert.Equal(t, validationError, data.Errors) })). Return(nil) diff --git a/internal/page/donor/check_you_can_sign.go b/internal/page/donor/check_you_can_sign.go index c946e9f6b3..983c82d6de 100644 --- a/internal/page/donor/check_you_can_sign.go +++ b/internal/page/donor/check_you_can_sign.go @@ -11,20 +11,16 @@ import ( ) type checkYouCanSignData struct { - App page.AppData - Errors validation.List - Form *form.YesNoForm - Options form.YesNoOptions + App page.AppData + Errors validation.List + Form *form.YesNoForm } func CheckYouCanSign(tmpl template.Template, donorStore DonorStore) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { data := &checkYouCanSignData{ - App: appData, - Form: &form.YesNoForm{ - YesNo: donor.Donor.CanSign, - }, - Options: form.YesNoValues, + App: appData, + Form: form.NewYesNoForm(donor.Donor.CanSign), } if r.Method == http.MethodPost { diff --git a/internal/page/donor/check_you_can_sign_test.go b/internal/page/donor/check_you_can_sign_test.go index 58ffc9a78d..821064a641 100644 --- a/internal/page/donor/check_you_can_sign_test.go +++ b/internal/page/donor/check_you_can_sign_test.go @@ -22,10 +22,9 @@ func TestGetCheckYouCanSign(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). Execute(w, &checkYouCanSignData{ - App: testAppData, - Errors: nil, - Form: &form.YesNoForm{YesNo: form.No}, - Options: form.YesNoValues, + App: testAppData, + Errors: nil, + Form: form.NewYesNoForm(form.No), }). Return(nil) @@ -48,12 +47,12 @@ func TestPostCheckYouCanSign(t *testing.T) { for yesNo, redirect := range testcases { t.Run(yesNo.String(), func(t *testing.T) { - form := url.Values{ - "yes-no": {yesNo.String()}, + f := url.Values{ + form.FieldNames.YesNo: {yesNo.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -73,12 +72,12 @@ func TestPostCheckYouCanSign(t *testing.T) { } func TestPostCheckYouCanSignErrorOnPutStore(t *testing.T) { - form := url.Values{ - "yes-no": {form.Yes.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -95,15 +94,15 @@ func TestPostCheckYouCanSignErrorOnPutStore(t *testing.T) { } func TestCheckYouCanSignFormValidation(t *testing.T) { - form := url.Values{ - "yes-no": {""}, + f := url.Values{ + form.FieldNames.YesNo: {""}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - validationError := validation.With("yes-no", validation.SelectError{Label: "yesIfYouWillBeAbleToSignYourself"}) + validationError := validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "yesIfYouWillBeAbleToSignYourself"}) template := newMockTemplate(t) template.EXPECT(). diff --git a/internal/page/donor/choose_attorneys_summary.go b/internal/page/donor/choose_attorneys_summary.go index 4433a260e4..3a3e4cd353 100644 --- a/internal/page/donor/choose_attorneys_summary.go +++ b/internal/page/donor/choose_attorneys_summary.go @@ -12,11 +12,10 @@ import ( ) type chooseAttorneysSummaryData struct { - App page.AppData - Errors validation.List - Form *form.YesNoForm - Donor *actor.DonorProvidedDetails - Options form.YesNoOptions + App page.AppData + Errors validation.List + Form *form.YesNoForm + Donor *actor.DonorProvidedDetails } func ChooseAttorneysSummary(tmpl template.Template) Handler { @@ -26,10 +25,9 @@ func ChooseAttorneysSummary(tmpl template.Template) Handler { } data := &chooseAttorneysSummaryData{ - App: appData, - Donor: donor, - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + App: appData, + Donor: donor, + Form: form.NewYesNoForm(form.YesNoUnknown), } if r.Method == http.MethodPost { diff --git a/internal/page/donor/choose_attorneys_summary_test.go b/internal/page/donor/choose_attorneys_summary_test.go index dd700be818..c7f5c54383 100644 --- a/internal/page/donor/choose_attorneys_summary_test.go +++ b/internal/page/donor/choose_attorneys_summary_test.go @@ -33,10 +33,9 @@ func TestGetChooseAttorneysSummary(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). Execute(w, &chooseAttorneysSummaryData{ - App: testAppData, - Donor: donor, - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + App: testAppData, + Donor: donor, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(nil) @@ -86,12 +85,12 @@ func TestPostChooseAttorneysSummaryAddAttorney(t *testing.T) { for testname, tc := range testcases { t.Run(testname, func(t *testing.T) { - form := url.Values{ - "yes-no": {tc.addMoreFormValue.String()}, + f := url.Values{ + form.FieldNames.YesNo: {tc.addMoreFormValue.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) err := ChooseAttorneysSummary(nil)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", Attorneys: tc.Attorneys}) @@ -105,15 +104,15 @@ func TestPostChooseAttorneysSummaryAddAttorney(t *testing.T) { } func TestPostChooseAttorneysSummaryFormValidation(t *testing.T) { - form := url.Values{ - "yes-no": {""}, + f := url.Values{ + form.FieldNames.YesNo: {""}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - validationError := validation.With("yes-no", validation.SelectError{Label: "yesToAddAnotherAttorney"}) + validationError := validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "yesToAddAnotherAttorney"}) template := newMockTemplate(t) template.EXPECT(). diff --git a/internal/page/donor/choose_people_to_notify_summary.go b/internal/page/donor/choose_people_to_notify_summary.go index 2a539e6280..6bd9e747d7 100644 --- a/internal/page/donor/choose_people_to_notify_summary.go +++ b/internal/page/donor/choose_people_to_notify_summary.go @@ -12,11 +12,10 @@ import ( ) type choosePeopleToNotifySummaryData struct { - App page.AppData - Errors validation.List - Form *form.YesNoForm - Options form.YesNoOptions - Donor *actor.DonorProvidedDetails + App page.AppData + Errors validation.List + Form *form.YesNoForm + Donor *actor.DonorProvidedDetails } func ChoosePeopleToNotifySummary(tmpl template.Template) Handler { @@ -26,10 +25,9 @@ func ChoosePeopleToNotifySummary(tmpl template.Template) Handler { } data := &choosePeopleToNotifySummaryData{ - App: appData, - Donor: donor, - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + App: appData, + Donor: donor, + Form: form.NewYesNoForm(form.YesNoUnknown), } if r.Method == http.MethodPost { diff --git a/internal/page/donor/choose_people_to_notify_summary_test.go b/internal/page/donor/choose_people_to_notify_summary_test.go index 7289e57b81..f5003c0ac6 100644 --- a/internal/page/donor/choose_people_to_notify_summary_test.go +++ b/internal/page/donor/choose_people_to_notify_summary_test.go @@ -24,10 +24,9 @@ func TestGetChoosePeopleToNotifySummary(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). Execute(w, &choosePeopleToNotifySummaryData{ - App: testAppData, - Donor: donor, - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + App: testAppData, + Donor: donor, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(nil) @@ -62,12 +61,12 @@ func TestGetChoosePeopleToNotifySummaryWhenNoPeopleToNotify(t *testing.T) { } func TestPostChoosePeopleToNotifySummaryAddPersonToNotify(t *testing.T) { - form := url.Values{ - "yes-no": {form.Yes.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) err := ChoosePeopleToNotifySummary(nil)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", PeopleToNotify: actor.PeopleToNotify{{ID: "123"}}}) @@ -79,12 +78,12 @@ func TestPostChoosePeopleToNotifySummaryAddPersonToNotify(t *testing.T) { } func TestPostChoosePeopleToNotifySummaryNoFurtherPeopleToNotify(t *testing.T) { - form := url.Values{ - "yes-no": {form.No.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) err := ChoosePeopleToNotifySummary(nil)(testAppData, w, r, &actor.DonorProvidedDetails{ @@ -108,15 +107,15 @@ func TestPostChoosePeopleToNotifySummaryNoFurtherPeopleToNotify(t *testing.T) { } func TestPostChoosePeopleToNotifySummaryFormValidation(t *testing.T) { - form := url.Values{ - "yes-no": {""}, + f := url.Values{ + form.FieldNames.YesNo: {""}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - validationError := validation.With("yes-no", validation.SelectError{Label: "yesToAddAnotherPersonToNotify"}) + validationError := validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "yesToAddAnotherPersonToNotify"}) template := newMockTemplate(t) template.EXPECT(). diff --git a/internal/page/donor/choose_replacement_attorneys_summary.go b/internal/page/donor/choose_replacement_attorneys_summary.go index c66f12b625..f6bf2179a8 100644 --- a/internal/page/donor/choose_replacement_attorneys_summary.go +++ b/internal/page/donor/choose_replacement_attorneys_summary.go @@ -12,11 +12,10 @@ import ( ) type chooseReplacementAttorneysSummaryData struct { - App page.AppData - Errors validation.List - Form *form.YesNoForm - Donor *actor.DonorProvidedDetails - Options form.YesNoOptions + App page.AppData + Errors validation.List + Form *form.YesNoForm + Donor *actor.DonorProvidedDetails } func ChooseReplacementAttorneysSummary(tmpl template.Template) Handler { @@ -26,10 +25,9 @@ func ChooseReplacementAttorneysSummary(tmpl template.Template) Handler { } data := &chooseReplacementAttorneysSummaryData{ - App: appData, - Donor: donor, - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + App: appData, + Donor: donor, + Form: form.NewYesNoForm(form.YesNoUnknown), } if r.Method == http.MethodPost { diff --git a/internal/page/donor/choose_replacement_attorneys_summary_test.go b/internal/page/donor/choose_replacement_attorneys_summary_test.go index 89df6e9234..610ae07583 100644 --- a/internal/page/donor/choose_replacement_attorneys_summary_test.go +++ b/internal/page/donor/choose_replacement_attorneys_summary_test.go @@ -33,10 +33,9 @@ func TestGetChooseReplacementAttorneysSummary(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). Execute(w, &chooseReplacementAttorneysSummaryData{ - App: testAppData, - Donor: donor, - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + App: testAppData, + Donor: donor, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(nil) @@ -65,12 +64,12 @@ func TestGetChooseReplacementAttorneysSummaryWhenNoReplacementAttorneys(t *testi } func TestPostChooseReplacementAttorneysSummaryAddAttorney(t *testing.T) { - form := url.Values{ - "yes-no": {form.Yes.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) err := ChooseReplacementAttorneysSummary(nil)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id", ReplacementAttorneys: actor.Attorneys{Attorneys: []actor.Attorney{{}}}}) @@ -134,12 +133,12 @@ func TestPostChooseReplacementAttorneysSummaryDoNotAddAttorney(t *testing.T) { for testname, tc := range testcases { t.Run(testname, func(t *testing.T) { - form := url.Values{ - "yes-no": {form.No.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) err := ChooseReplacementAttorneysSummary(nil)(testAppData, w, r, &actor.DonorProvidedDetails{ @@ -165,15 +164,15 @@ func TestPostChooseReplacementAttorneysSummaryDoNotAddAttorney(t *testing.T) { } func TestPostChooseReplacementAttorneySummaryFormValidation(t *testing.T) { - form := url.Values{ - "yes-no": {""}, + f := url.Values{ + form.FieldNames.YesNo: {""}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - validationError := validation.With("yes-no", validation.SelectError{Label: "yesToAddAnotherReplacementAttorney"}) + validationError := validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "yesToAddAnotherReplacementAttorney"}) template := newMockTemplate(t) template.EXPECT(). diff --git a/internal/page/donor/confirm_your_certificate_provider_is_not_related_test.go b/internal/page/donor/confirm_your_certificate_provider_is_not_related_test.go index e2f2c67195..e7c8c253e7 100644 --- a/internal/page/donor/confirm_your_certificate_provider_is_not_related_test.go +++ b/internal/page/donor/confirm_your_certificate_provider_is_not_related_test.go @@ -77,7 +77,7 @@ func TestGetConfirmYourCertificateProviderIsNotRelatedWhenTemplateErrors(t *test func TestPostConfirmYourCertificateProviderIsNotRelated(t *testing.T) { f := url.Values{ - "yes-no": {form.Yes.String()}, + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() @@ -165,7 +165,7 @@ func TestPostConfirmYourCertificateProviderIsNotRelatedWhenStoreErrors(t *testin "action": {"choose-new"}, }, "submit": { - "yes-no": {form.Yes.String()}, + form.FieldNames.YesNo: {form.Yes.String()}, }, } @@ -199,7 +199,7 @@ func TestPostConfirmYourCertificateProviderIsNotRelatedWhenValidationErrors(t *t template := newMockTemplate(t) template.EXPECT(). Execute(w, mock.MatchedBy(func(data *confirmYourCertificateProviderIsNotRelatedData) bool { - return assert.Equal(t, validation.With("yes-no", validation.SelectError{Label: "theBoxToConfirmYourCertificateProviderIsNotRelated"}), data.Errors) + return assert.Equal(t, validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "theBoxToConfirmYourCertificateProviderIsNotRelated"}), data.Errors) })). Return(nil) diff --git a/internal/page/donor/do_you_want_to_notify_people.go b/internal/page/donor/do_you_want_to_notify_people.go index f46eea6c66..fee1c0f0af 100644 --- a/internal/page/donor/do_you_want_to_notify_people.go +++ b/internal/page/donor/do_you_want_to_notify_people.go @@ -13,7 +13,6 @@ import ( type doYouWantToNotifyPeopleData struct { App page.AppData Errors validation.List - Options form.YesNoOptions Form *form.YesNoForm Donor *actor.DonorProvidedDetails HowWorkTogether string @@ -28,10 +27,7 @@ func DoYouWantToNotifyPeople(tmpl template.Template, donorStore DonorStore) Hand data := &doYouWantToNotifyPeopleData{ App: appData, Donor: donor, - Form: &form.YesNoForm{ - YesNo: donor.DoYouWantToNotifyPeople, - }, - Options: form.YesNoValues, + Form: form.NewYesNoForm(donor.DoYouWantToNotifyPeople), } switch donor.AttorneyDecisions.How { diff --git a/internal/page/donor/do_you_want_to_notify_people_test.go b/internal/page/donor/do_you_want_to_notify_people_test.go index 3c1875c496..531b35ca2d 100644 --- a/internal/page/donor/do_you_want_to_notify_people_test.go +++ b/internal/page/donor/do_you_want_to_notify_people_test.go @@ -22,10 +22,9 @@ func TestGetDoYouWantToNotifyPeople(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). Execute(w, &doYouWantToNotifyPeopleData{ - App: testAppData, - Donor: &actor.DonorProvidedDetails{}, - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + App: testAppData, + Donor: &actor.DonorProvidedDetails{}, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(nil) @@ -47,10 +46,7 @@ func TestGetDoYouWantToNotifyPeopleFromStore(t *testing.T) { Donor: &actor.DonorProvidedDetails{ DoYouWantToNotifyPeople: form.Yes, }, - Form: &form.YesNoForm{ - YesNo: form.Yes, - }, - Options: form.YesNoValues, + Form: form.NewYesNoForm(form.Yes), }). Return(nil) @@ -95,10 +91,7 @@ func TestGetDoYouWantToNotifyPeopleHowAttorneysWorkTogether(t *testing.T) { DoYouWantToNotifyPeople: form.Yes, AttorneyDecisions: actor.AttorneyDecisions{How: tc.howWorkTogether}, }, - Form: &form.YesNoForm{ - YesNo: form.Yes, - }, - Options: form.YesNoValues, + Form: form.NewYesNoForm(form.Yes), HowWorkTogether: tc.expectedTransKey, }). Return(nil) @@ -173,12 +166,12 @@ func TestPostDoYouWantToNotifyPeople(t *testing.T) { for _, tc := range testCases { t.Run(tc.YesNo.String(), func(t *testing.T) { - form := url.Values{ - "yes-no": {tc.YesNo.String()}, + f := url.Values{ + form.FieldNames.YesNo: {tc.YesNo.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -221,7 +214,7 @@ func TestPostDoYouWantToNotifyPeople(t *testing.T) { func TestPostDoYouWantToNotifyPeopleWhenStoreErrors(t *testing.T) { f := url.Values{ - "yes-no": {form.Yes.String()}, + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() @@ -249,7 +242,7 @@ func TestPostDoYouWantToNotifyPeopleWhenValidationErrors(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). Execute(w, mock.MatchedBy(func(data *doYouWantToNotifyPeopleData) bool { - return assert.Equal(t, validation.With("yes-no", validation.SelectError{Label: "yesToNotifySomeoneAboutYourLpa"}), data.Errors) + return assert.Equal(t, validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "yesToNotifySomeoneAboutYourLpa"}), data.Errors) })). Return(nil) diff --git a/internal/page/donor/remove_attorney.go b/internal/page/donor/remove_attorney.go index cea476e519..e8e9ac2254 100644 --- a/internal/page/donor/remove_attorney.go +++ b/internal/page/donor/remove_attorney.go @@ -17,7 +17,6 @@ type removeAttorneyData struct { Name string Errors validation.List Form *form.YesNoForm - Options form.YesNoOptions } func RemoveAttorney(logger Logger, tmpl template.Template, donorStore DonorStore) Handler { @@ -33,8 +32,7 @@ func RemoveAttorney(logger Logger, tmpl template.Template, donorStore DonorStore App: appData, TitleLabel: "removeAnAttorney", Name: attorney.FullName(), - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + Form: form.NewYesNoForm(form.YesNoUnknown), } if r.Method == http.MethodPost { diff --git a/internal/page/donor/remove_attorney_test.go b/internal/page/donor/remove_attorney_test.go index 05d1901c52..8e520638dd 100644 --- a/internal/page/donor/remove_attorney_test.go +++ b/internal/page/donor/remove_attorney_test.go @@ -37,8 +37,7 @@ func TestGetRemoveAttorney(t *testing.T) { App: testAppData, TitleLabel: "removeAnAttorney", Name: "John Smith", - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(nil) @@ -123,12 +122,12 @@ func TestPostRemoveAttorney(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - form := url.Values{ - "yes-no": {form.Yes.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -151,12 +150,12 @@ func TestPostRemoveAttorney(t *testing.T) { } func TestPostRemoveAttorneyWithFormValueNo(t *testing.T) { - form := url.Values{ - "yes-no": {form.No.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -184,12 +183,12 @@ func TestPostRemoveAttorneyWithFormValueNo(t *testing.T) { } func TestPostRemoveAttorneyErrorOnPutStore(t *testing.T) { - form := url.Values{ - "yes-no": {form.Yes.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -225,12 +224,12 @@ func TestPostRemoveAttorneyErrorOnPutStore(t *testing.T) { } func TestRemoveAttorneyFormValidation(t *testing.T) { - form := url.Values{ - "yes-no": {""}, + f := url.Values{ + form.FieldNames.YesNo: {""}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) attorneyWithoutAddress := actor.Attorney{ @@ -238,7 +237,7 @@ func TestRemoveAttorneyFormValidation(t *testing.T) { Address: place.Address{}, } - validationError := validation.With("yes-no", validation.SelectError{Label: "yesToRemoveAttorney"}) + validationError := validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "yesToRemoveAttorney"}) template := newMockTemplate(t) template.EXPECT(). diff --git a/internal/page/donor/remove_person_to_notify.go b/internal/page/donor/remove_person_to_notify.go index 640bf76e40..5713f9553a 100644 --- a/internal/page/donor/remove_person_to_notify.go +++ b/internal/page/donor/remove_person_to_notify.go @@ -16,7 +16,6 @@ type removePersonToNotifyData struct { PersonToNotify actor.PersonToNotify Errors validation.List Form *form.YesNoForm - Options form.YesNoOptions } func RemovePersonToNotify(logger Logger, tmpl template.Template, donorStore DonorStore) Handler { @@ -31,8 +30,7 @@ func RemovePersonToNotify(logger Logger, tmpl template.Template, donorStore Dono data := &removePersonToNotifyData{ App: appData, PersonToNotify: person, - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + Form: form.NewYesNoForm(form.YesNoUnknown), } if r.Method == http.MethodPost { diff --git a/internal/page/donor/remove_person_to_notify_test.go b/internal/page/donor/remove_person_to_notify_test.go index 7ad962f793..78839fe177 100644 --- a/internal/page/donor/remove_person_to_notify_test.go +++ b/internal/page/donor/remove_person_to_notify_test.go @@ -35,8 +35,7 @@ func TestGetRemovePersonToNotify(t *testing.T) { App: testAppData, PersonToNotify: personToNotify, Errors: nil, - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(nil) @@ -73,12 +72,12 @@ func TestGetRemovePersonToNotifyAttorneyDoesNotExist(t *testing.T) { } func TestPostRemovePersonToNotify(t *testing.T) { - form := url.Values{ - "yes-no": {form.Yes.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -111,12 +110,12 @@ func TestPostRemovePersonToNotify(t *testing.T) { } func TestPostRemovePersonToNotifyWithFormValueNo(t *testing.T) { - form := url.Values{ - "yes-no": {form.No.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -144,12 +143,12 @@ func TestPostRemovePersonToNotifyWithFormValueNo(t *testing.T) { } func TestPostRemovePersonToNotifyErrorOnPutStore(t *testing.T) { - form := url.Values{ - "yes-no": {form.Yes.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -185,12 +184,12 @@ func TestPostRemovePersonToNotifyErrorOnPutStore(t *testing.T) { } func TestRemovePersonToNotifyFormValidation(t *testing.T) { - form := url.Values{ - "yes-no": {""}, + f := url.Values{ + form.FieldNames.YesNo: {""}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) personToNotifyWithoutAddress := actor.PersonToNotify{ @@ -198,7 +197,7 @@ func TestRemovePersonToNotifyFormValidation(t *testing.T) { Address: place.Address{}, } - validationError := validation.With("yes-no", validation.SelectError{Label: "yesToRemoveThisPerson"}) + validationError := validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "yesToRemoveThisPerson"}) template := newMockTemplate(t) template.EXPECT(). @@ -215,12 +214,12 @@ func TestRemovePersonToNotifyFormValidation(t *testing.T) { } func TestRemovePersonToNotifyRemoveLastPerson(t *testing.T) { - form := url.Values{ - "yes-no": {form.Yes.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) diff --git a/internal/page/donor/remove_replacement_attorney.go b/internal/page/donor/remove_replacement_attorney.go index c83daf2634..fc3b872c90 100644 --- a/internal/page/donor/remove_replacement_attorney.go +++ b/internal/page/donor/remove_replacement_attorney.go @@ -23,8 +23,7 @@ func RemoveReplacementAttorney(logger Logger, tmpl template.Template, donorStore App: appData, TitleLabel: "doYouWantToRemoveReplacementAttorney", Name: attorney.FullName(), - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + Form: form.NewYesNoForm(form.YesNoUnknown), } if r.Method == http.MethodPost { diff --git a/internal/page/donor/remove_replacement_attorney_test.go b/internal/page/donor/remove_replacement_attorney_test.go index 9c99d43133..29adc5d9f2 100644 --- a/internal/page/donor/remove_replacement_attorney_test.go +++ b/internal/page/donor/remove_replacement_attorney_test.go @@ -37,8 +37,7 @@ func TestGetRemoveReplacementAttorney(t *testing.T) { App: testAppData, TitleLabel: "doYouWantToRemoveReplacementAttorney", Name: "John Smith", - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(nil) @@ -123,12 +122,12 @@ func TestPostRemoveReplacementAttorney(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - form := url.Values{ - "yes-no": {form.Yes.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -151,12 +150,12 @@ func TestPostRemoveReplacementAttorney(t *testing.T) { } func TestPostRemoveReplacementAttorneyWithFormValueNo(t *testing.T) { - form := url.Values{ - "yes-no": {form.No.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) logger := newMockLogger(t) @@ -185,7 +184,7 @@ func TestPostRemoveReplacementAttorneyWithFormValueNo(t *testing.T) { func TestPostRemoveReplacementAttorneyErrorOnPutStore(t *testing.T) { f := url.Values{ - "yes-no": {form.Yes.String()}, + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() @@ -229,7 +228,7 @@ func TestPostRemoveReplacementAttorneyErrorOnPutStore(t *testing.T) { func TestRemoveReplacementAttorneyFormValidation(t *testing.T) { f := url.Values{ - "yes-no": {""}, + form.FieldNames.YesNo: {""}, } w := httptest.NewRecorder() @@ -241,7 +240,7 @@ func TestRemoveReplacementAttorneyFormValidation(t *testing.T) { Address: place.Address{}, } - validationError := validation.With("yes-no", validation.SelectError{Label: "yesToRemoveReplacementAttorney"}) + validationError := validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "yesToRemoveReplacementAttorney"}) template := newMockTemplate(t) template.EXPECT(). diff --git a/internal/page/donor/remove_trust_corporation.go b/internal/page/donor/remove_trust_corporation.go index 3b04f3e867..4df85d28b3 100644 --- a/internal/page/donor/remove_trust_corporation.go +++ b/internal/page/donor/remove_trust_corporation.go @@ -43,8 +43,7 @@ func RemoveTrustCorporation(tmpl template.Template, donorStore DonorStore, isRep App: appData, TitleLabel: titleLabel, Name: name, - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + Form: form.NewYesNoForm(form.YesNoUnknown), } if r.Method == http.MethodPost { diff --git a/internal/page/donor/remove_trust_corporation_test.go b/internal/page/donor/remove_trust_corporation_test.go index 812278d380..765b90e393 100644 --- a/internal/page/donor/remove_trust_corporation_test.go +++ b/internal/page/donor/remove_trust_corporation_test.go @@ -46,8 +46,7 @@ func TestGetRemoveTrustCorporation(t *testing.T) { App: testAppData, TitleLabel: tc.titleLabel, Name: "hey ltd", - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(nil) @@ -148,12 +147,12 @@ func TestPostRemoveTrustCorporation(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - form := url.Values{ - "yes-no": {form.Yes.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -175,12 +174,12 @@ func TestPostRemoveTrustCorporation(t *testing.T) { } func TestPostRemoveTrustCorporationWithFormValueNo(t *testing.T) { - form := url.Values{ - "yes-no": {form.No.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.No.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -207,12 +206,12 @@ func TestPostRemoveTrustCorporationWithFormValueNo(t *testing.T) { } func TestPostRemoveTrustCorporationErrorOnPutStore(t *testing.T) { - form := url.Values{ - "yes-no": {form.Yes.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) template := newMockTemplate(t) @@ -243,12 +242,12 @@ func TestPostRemoveTrustCorporationErrorOnPutStore(t *testing.T) { } func TestRemoveTrustCorporationFormValidation(t *testing.T) { - form := url.Values{ - "yes-no": {""}, + f := url.Values{ + form.FieldNames.YesNo: {""}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/?id=without-address", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) attorneyWithoutAddress := actor.Attorney{ @@ -256,7 +255,7 @@ func TestRemoveTrustCorporationFormValidation(t *testing.T) { Address: place.Address{}, } - validationError := validation.With("yes-no", validation.SelectError{Label: "yesToRemoveTrustCorporation"}) + validationError := validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "yesToRemoveTrustCorporation"}) template := newMockTemplate(t) template.EXPECT(). diff --git a/internal/page/donor/want_replacement_attorneys.go b/internal/page/donor/want_replacement_attorneys.go index 8213381791..47f9b73f62 100644 --- a/internal/page/donor/want_replacement_attorneys.go +++ b/internal/page/donor/want_replacement_attorneys.go @@ -11,11 +11,10 @@ import ( ) type wantReplacementAttorneysData struct { - App page.AppData - Errors validation.List - Form *form.YesNoForm - Options form.YesNoOptions - Donor *actor.DonorProvidedDetails + App page.AppData + Errors validation.List + Form *form.YesNoForm + Donor *actor.DonorProvidedDetails } func WantReplacementAttorneys(tmpl template.Template, donorStore DonorStore) Handler { @@ -23,10 +22,7 @@ func WantReplacementAttorneys(tmpl template.Template, donorStore DonorStore) Han data := &wantReplacementAttorneysData{ App: appData, Donor: donor, - Form: &form.YesNoForm{ - YesNo: donor.WantReplacementAttorneys, - }, - Options: form.YesNoValues, + Form: form.NewYesNoForm(donor.WantReplacementAttorneys), } if r.Method == http.MethodPost { diff --git a/internal/page/donor/want_replacement_attorneys_test.go b/internal/page/donor/want_replacement_attorneys_test.go index 0b62197c1c..6976c4969f 100644 --- a/internal/page/donor/want_replacement_attorneys_test.go +++ b/internal/page/donor/want_replacement_attorneys_test.go @@ -22,10 +22,9 @@ func TestGetWantReplacementAttorneys(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). Execute(w, &wantReplacementAttorneysData{ - App: testAppData, - Donor: &actor.DonorProvidedDetails{}, - Form: &form.YesNoForm{}, - Options: form.YesNoValues, + App: testAppData, + Donor: &actor.DonorProvidedDetails{}, + Form: form.NewYesNoForm(form.YesNoUnknown), }). Return(nil) @@ -59,10 +58,7 @@ func TestGetWantReplacementAttorneysFromStore(t *testing.T) { Execute(w, &wantReplacementAttorneysData{ App: testAppData, Donor: &actor.DonorProvidedDetails{WantReplacementAttorneys: form.Yes}, - Form: &form.YesNoForm{ - YesNo: form.Yes, - }, - Options: form.YesNoValues, + Form: form.NewYesNoForm(form.Yes), }). Return(nil) @@ -118,12 +114,12 @@ func TestPostWantReplacementAttorneys(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { - form := url.Values{ - "yes-no": {tc.yesNo.String()}, + f := url.Values{ + form.FieldNames.YesNo: {tc.yesNo.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -151,12 +147,12 @@ func TestPostWantReplacementAttorneys(t *testing.T) { } func TestPostWantReplacementAttorneysWhenStoreErrors(t *testing.T) { - form := url.Values{ - "yes-no": {form.Yes.String()}, + f := url.Values{ + form.FieldNames.YesNo: {form.Yes.String()}, } w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(form.Encode())) + r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) donorStore := newMockDonorStore(t) @@ -177,7 +173,7 @@ func TestPostWantReplacementAttorneysWhenValidationErrors(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). Execute(w, mock.MatchedBy(func(data *wantReplacementAttorneysData) bool { - return assert.Equal(t, validation.With("yes-no", validation.SelectError{Label: "yesToAddReplacementAttorneys"}), data.Errors) + return assert.Equal(t, validation.With(form.FieldNames.YesNo, validation.SelectError{Label: "yesToAddReplacementAttorneys"}), data.Errors) })). Return(nil) diff --git a/web/template/attorney/would_like_second_signatory.gohtml b/web/template/attorney/would_like_second_signatory.gohtml index 9fa1be38d5..0603f1369b 100644 --- a/web/template/attorney/would_like_second_signatory.gohtml +++ b/web/template/attorney/would_like_second_signatory.gohtml @@ -6,17 +6,17 @@