diff --git a/internal/app/donor_store.go b/internal/app/donor_store.go index d0021b37d8..156de864fa 100644 --- a/internal/app/donor_store.go +++ b/internal/app/donor_store.go @@ -171,25 +171,6 @@ func (s *donorStore) Put(ctx context.Context, lpa *page.Lpa) error { } } - if lpa.UID != "" && lpa.EvidenceFormAddress.Line1 != "" && !lpa.HasSentEvidenceFormRequiredEvent { - if err := s.eventClient.Send(ctx, "evidence-form-required", evidenceFormRequiredEvent{ - UID: lpa.UID, - FirstNames: lpa.Donor.FirstNames, - LastName: lpa.Donor.LastName, - Address: address{ - Line1: lpa.EvidenceFormAddress.Line1, - Line2: lpa.EvidenceFormAddress.Line2, - Line3: lpa.EvidenceFormAddress.Line3, - TownOrCity: lpa.EvidenceFormAddress.TownOrCity, - Postcode: lpa.EvidenceFormAddress.Postcode, - }, - }); err != nil { - s.logger.Print(err) - } else { - lpa.HasSentEvidenceFormRequiredEvent = true - } - } - if lpa.UID != "" && lpa.Tasks.PayForLpa.IsPending() && lpa.HasUnsentReducedFeesEvidence() { var unsentKeys []string diff --git a/internal/app/donor_store_test.go b/internal/app/donor_store_test.go index dbb4cfc233..a1367d648e 100644 --- a/internal/app/donor_store_test.go +++ b/internal/app/donor_store_test.go @@ -453,127 +453,6 @@ func TestDonorStorePutWhenPreviousApplicationLinkedWhenError(t *testing.T) { assert.Nil(t, err) } -func TestDonorStorePutWhenEvidenceFormRequired(t *testing.T) { - ctx := context.Background() - now := time.Now() - - dynamoClient := newMockDynamoClient(t) - dynamoClient. - On("Put", ctx, &page.Lpa{ - PK: "LPA#5", - SK: "#DONOR#an-id", - ID: "5", - UID: "M-1111", - UpdatedAt: now, - Donor: actor.Donor{ - FirstNames: "John", - LastName: "Smithe", - }, - EvidenceFormAddress: place.Address{ - Line1: "line1", - Line2: "line2", - Line3: "line3", - TownOrCity: "town", - Postcode: "post", - }, - HasSentApplicationUpdatedEvent: true, - HasSentEvidenceFormRequiredEvent: true, - }). - Return(nil) - - eventClient := newMockEventClient(t) - eventClient. - On("Send", ctx, "evidence-form-required", evidenceFormRequiredEvent{ - UID: "M-1111", - FirstNames: "John", - LastName: "Smithe", - Address: address{ - Line1: "line1", - Line2: "line2", - Line3: "line3", - TownOrCity: "town", - Postcode: "post", - }, - }). - Return(nil) - - donorStore := &donorStore{dynamoClient: dynamoClient, eventClient: eventClient, now: func() time.Time { return now }} - - err := donorStore.Put(ctx, &page.Lpa{ - PK: "LPA#5", - SK: "#DONOR#an-id", - ID: "5", - UID: "M-1111", - Donor: actor.Donor{ - FirstNames: "John", - LastName: "Smithe", - }, - EvidenceFormAddress: place.Address{ - Line1: "line1", - Line2: "line2", - Line3: "line3", - TownOrCity: "town", - Postcode: "post", - }, - HasSentApplicationUpdatedEvent: true, - }) - assert.Nil(t, err) -} - -func TestDonorStorePutWhenEvidenceFormRequiredWontResend(t *testing.T) { - ctx := context.Background() - now := time.Now() - - dynamoClient := newMockDynamoClient(t) - dynamoClient. - On("Put", ctx, mock.Anything). - Return(nil) - - donorStore := &donorStore{dynamoClient: dynamoClient, now: func() time.Time { return now }} - - err := donorStore.Put(ctx, &page.Lpa{ - PK: "LPA#5", - SK: "#DONOR#an-id", - ID: "5", - UID: "M-1111", - EvidenceFormAddress: place.Address{Line1: "line"}, - HasSentApplicationUpdatedEvent: true, - HasSentEvidenceFormRequiredEvent: true, - }) - assert.Nil(t, err) -} - -func TestDonorStorePutWhenEvidenceFormRequiredWhenError(t *testing.T) { - ctx := context.Background() - now := time.Now() - - dynamoClient := newMockDynamoClient(t) - dynamoClient. - On("Put", ctx, mock.Anything). - Return(nil) - - eventClient := newMockEventClient(t) - eventClient. - On("Send", ctx, "evidence-form-required", mock.Anything). - Return(expectedError) - - logger := newMockLogger(t) - logger. - On("Print", expectedError) - - donorStore := &donorStore{dynamoClient: dynamoClient, eventClient: eventClient, logger: logger, now: func() time.Time { return now }} - - err := donorStore.Put(ctx, &page.Lpa{ - PK: "LPA#5", - SK: "#DONOR#an-id", - ID: "5", - UID: "M-1111", - EvidenceFormAddress: place.Address{Line1: "line"}, - HasSentApplicationUpdatedEvent: true, - }) - assert.Nil(t, err) -} - func TestDonorStorePutWhenReducedFeeRequested(t *testing.T) { ctx := context.Background() now := time.Now() diff --git a/internal/page/data.go b/internal/page/data.go index e58112bee8..ddf098781c 100644 --- a/internal/page/data.go +++ b/internal/page/data.go @@ -187,7 +187,6 @@ type Lpa struct { HasSentApplicationUpdatedEvent bool HasSentPreviousApplicationLinkedEvent bool - HasSentEvidenceFormRequiredEvent bool } type Evidence struct { diff --git a/internal/page/donor/can_evidence_be_uploaded.go b/internal/page/donor/can_evidence_be_uploaded.go index 0441a6411c..96521ee958 100644 --- a/internal/page/donor/can_evidence_be_uploaded.go +++ b/internal/page/donor/can_evidence_be_uploaded.go @@ -30,7 +30,7 @@ func CanEvidenceBeUploaded(tmpl template.Template) Handler { if form.YesNo.IsYes() { return appData.Redirect(w, r, lpa, page.Paths.UploadEvidence.Format(lpa.ID)) } else { - return appData.Redirect(w, r, lpa, page.Paths.PrintEvidenceForm.Format(lpa.ID)) + return appData.Redirect(w, r, lpa, page.Paths.HowToEmailOrPostEvidence.Format(lpa.ID)) } } } diff --git a/internal/page/donor/can_evidence_be_uploaded_test.go b/internal/page/donor/can_evidence_be_uploaded_test.go index 22653acccc..21dc358479 100644 --- a/internal/page/donor/can_evidence_be_uploaded_test.go +++ b/internal/page/donor/can_evidence_be_uploaded_test.go @@ -71,7 +71,7 @@ func TestGetCanEvidenceBeUploadedWhenTemplateErrors(t *testing.T) { func TestPostCanEvidenceBeUploaded(t *testing.T) { testcases := map[form.YesNo]page.LpaPath{ form.Yes: page.Paths.UploadEvidence, - form.No: page.Paths.PrintEvidenceForm, + form.No: page.Paths.HowToEmailOrPostEvidence, } for yesNo, redirect := range testcases { diff --git a/internal/page/donor/how_to_send_evidence.go b/internal/page/donor/how_to_email_or_post_evidence.go similarity index 75% rename from internal/page/donor/how_to_send_evidence.go rename to internal/page/donor/how_to_email_or_post_evidence.go index e7568cf7c1..031f5e072b 100644 --- a/internal/page/donor/how_to_send_evidence.go +++ b/internal/page/donor/how_to_email_or_post_evidence.go @@ -8,14 +8,14 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) -type howToSendEvidenceData struct { +type howToEmailOrPostEvidenceData struct { App page.AppData Errors validation.List } -func HowToSendEvidence(tmpl template.Template, payer Payer) Handler { +func HowToEmailOrPostEvidence(tmpl template.Template, payer Payer) Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error { - data := &howToSendEvidenceData{ + data := &howToEmailOrPostEvidenceData{ App: appData, } diff --git a/internal/page/donor/how_to_send_evidence_test.go b/internal/page/donor/how_to_email_or_post_evidence_test.go similarity index 64% rename from internal/page/donor/how_to_send_evidence_test.go rename to internal/page/donor/how_to_email_or_post_evidence_test.go index 40bf2484e8..150660cb9c 100644 --- a/internal/page/donor/how_to_send_evidence_test.go +++ b/internal/page/donor/how_to_email_or_post_evidence_test.go @@ -11,39 +11,39 @@ import ( "github.com/stretchr/testify/mock" ) -func TestGetHowToSendEvidence(t *testing.T) { +func TestGetHowToEmailOrPostEvidence(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/about-payment", nil) template := newMockTemplate(t) template. - On("Execute", w, &howToSendEvidenceData{App: testAppData}). + On("Execute", w, &howToEmailOrPostEvidenceData{App: testAppData}). Return(nil) - err := HowToSendEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{}) + err := HowToEmailOrPostEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{}) resp := w.Result() assert.Nil(t, err) assert.Equal(t, http.StatusOK, resp.StatusCode) } -func TestGetHowToSendEvidenceWhenTemplateErrors(t *testing.T) { +func TestGetHowToEmailOrPostEvidenceWhenTemplateErrors(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/about-payment", nil) template := newMockTemplate(t) template. - On("Execute", w, &howToSendEvidenceData{App: testAppData}). + On("Execute", w, &howToEmailOrPostEvidenceData{App: testAppData}). Return(expectedError) - err := HowToSendEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{}) + err := HowToEmailOrPostEvidence(template.Execute, nil)(testAppData, w, r, &page.Lpa{}) resp := w.Result() assert.Equal(t, expectedError, err) assert.Equal(t, http.StatusOK, resp.StatusCode) } -func TestPostHowToSendEvidence(t *testing.T) { +func TestPostHowToEmailOrPostEvidence(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "/about-payment", nil) @@ -54,11 +54,11 @@ func TestPostHowToSendEvidence(t *testing.T) { On("Pay", testAppData, w, r, lpa). Return(nil) - err := HowToSendEvidence(nil, payer)(testAppData, w, r, lpa) + err := HowToEmailOrPostEvidence(nil, payer)(testAppData, w, r, lpa) assert.Nil(t, err) } -func TestPostHowToSendEvidenceWhenPayerErrors(t *testing.T) { +func TestPostHowToEmailOrPostEvidenceWhenPayerErrors(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodPost, "/about-payment", nil) @@ -67,6 +67,6 @@ func TestPostHowToSendEvidenceWhenPayerErrors(t *testing.T) { On("Pay", testAppData, w, r, mock.Anything). Return(expectedError) - err := HowToSendEvidence(nil, payer)(testAppData, w, r, &page.Lpa{}) + err := HowToEmailOrPostEvidence(nil, payer)(testAppData, w, r, &page.Lpa{}) assert.Equal(t, expectedError, err) } diff --git a/internal/page/donor/provide_address_to_send_evidence_form.go b/internal/page/donor/provide_address_to_send_evidence_form.go deleted file mode 100644 index 07e73fff9c..0000000000 --- a/internal/page/donor/provide_address_to_send_evidence_form.go +++ /dev/null @@ -1,84 +0,0 @@ -package donor - -import ( - "net/http" - - "github.com/ministryofjustice/opg-go-common/template" - "github.com/ministryofjustice/opg-modernising-lpa/internal/form" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" - "github.com/ministryofjustice/opg-modernising-lpa/internal/place" -) - -func ProvideAddressToSendEvidenceForm(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, lpa *page.Lpa) error { - data := &chooseAddressData{ - App: appData, - Form: &form.AddressForm{}, - } - - if lpa.EvidenceFormAddress.Line1 != "" { - data.Form.Action = "manual" - data.Form.Address = &lpa.EvidenceFormAddress - } - - if r.Method == http.MethodPost { - data.Form = form.ReadAddressForm(r) - data.Errors = data.Form.Validate(false) - - setAddress := func(address place.Address) error { - lpa.EvidenceFormAddress = *data.Form.Address - - return donorStore.Put(r.Context(), lpa) - } - - switch data.Form.Action { - case "manual": - if data.Errors.None() { - if err := setAddress(*data.Form.Address); err != nil { - return err - } - - return appData.Redirect(w, r, lpa, page.Paths.HowToSendEvidence.Format(lpa.ID)) - } - - case "postcode-select": - if data.Errors.None() { - data.Form.Action = "manual" - } else { - lookupAddress(r.Context(), logger, addressClient, data, false) - } - - case "postcode-lookup": - if data.Errors.None() { - lookupAddress(r.Context(), logger, addressClient, data, false) - } else { - data.Form.Action = "postcode" - } - - case "reuse": - data.Addresses = lpa.ActorAddresses() - - case "reuse-select": - if data.Errors.None() { - if err := setAddress(*data.Form.Address); err != nil { - return err - } - - return appData.Redirect(w, r, lpa, page.Paths.HowToSendEvidence.Format(lpa.ID)) - } else { - data.Addresses = lpa.ActorAddresses() - } - } - } - - if r.Method == http.MethodGet { - action := r.FormValue("action") - if action == "manual" { - data.Form.Action = "manual" - data.Form.Address = &place.Address{} - } - } - - return tmpl(w, data) - } -} diff --git a/internal/page/donor/provide_address_to_send_evidence_form_test.go b/internal/page/donor/provide_address_to_send_evidence_form_test.go deleted file mode 100644 index ed6dc4008b..0000000000 --- a/internal/page/donor/provide_address_to_send_evidence_form_test.go +++ /dev/null @@ -1,490 +0,0 @@ -package donor - -import ( - "net/http" - "net/http/httptest" - "net/url" - "strings" - "testing" - - "github.com/ministryofjustice/opg-modernising-lpa/internal/form" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" - "github.com/ministryofjustice/opg-modernising-lpa/internal/place" - "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" -) - -func TestGetProvideAddressToSendEvidenceForm(t *testing.T) { - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/", nil) - - template := newMockTemplate(t) - template. - On("Execute", w, &chooseAddressData{ - App: testAppData, - Form: &form.AddressForm{}, - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(nil, template.Execute, nil, nil)(testAppData, w, r, &page.Lpa{}) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) -} - -func TestGetProvideAddressToSendEvidenceFormFromStore(t *testing.T) { - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/", nil) - - address := place.Address{Line1: "abc"} - - template := newMockTemplate(t) - template. - On("Execute", w, &chooseAddressData{ - App: testAppData, - Form: &form.AddressForm{ - Action: "manual", - Address: &address, - }, - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(nil, template.Execute, nil, nil)(testAppData, w, r, &page.Lpa{ - EvidenceFormAddress: address, - }) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) -} - -func TestGetProvideAddressToSendEvidenceFormManual(t *testing.T) { - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/?action=manual", nil) - - template := newMockTemplate(t) - template. - On("Execute", w, &chooseAddressData{ - App: testAppData, - Form: &form.AddressForm{ - Action: "manual", - Address: &place.Address{}, - }, - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(nil, template.Execute, nil, nil)(testAppData, w, r, &page.Lpa{}) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) -} - -func TestGetProvideAddressToSendEvidenceFormWhenTemplateErrors(t *testing.T) { - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/", nil) - - template := newMockTemplate(t) - template. - On("Execute", w, &chooseAddressData{ - App: testAppData, - Form: &form.AddressForm{}, - }). - Return(expectedError) - - err := ProvideAddressToSendEvidenceForm(nil, template.Execute, nil, nil)(testAppData, w, r, &page.Lpa{}) - resp := w.Result() - - assert.Equal(t, expectedError, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) -} - -func TestPostProvideAddressToSendEvidenceFormManual(t *testing.T) { - f := url.Values{ - "action": {"manual"}, - "address-line-1": {"a"}, - "address-line-2": {"b"}, - "address-line-3": {"c"}, - "address-town": {"d"}, - "address-postcode": {"e"}, - } - - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - donorStore := newMockDonorStore(t) - donorStore. - On("Put", r.Context(), &page.Lpa{ - ID: "lpa-id", - EvidenceFormAddress: testAddress, - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(nil, nil, nil, donorStore)(testAppData, w, r, &page.Lpa{ - ID: "lpa-id", - }) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusFound, resp.StatusCode) - assert.Equal(t, page.Paths.HowToSendEvidence.Format("lpa-id"), resp.Header.Get("Location")) -} - -func TestPostProvideAddressToSendEvidenceFormManualWhenStoreErrors(t *testing.T) { - f := url.Values{ - "action": {"manual"}, - "address-line-1": {"a"}, - "address-line-2": {"b"}, - "address-line-3": {"c"}, - "address-town": {"d"}, - "address-postcode": {"e"}, - } - - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - donorStore := newMockDonorStore(t) - donorStore. - On("Put", r.Context(), &page.Lpa{ - EvidenceFormAddress: testAddress, - }). - Return(expectedError) - - err := ProvideAddressToSendEvidenceForm(nil, nil, nil, donorStore)(testAppData, w, r, &page.Lpa{}) - - assert.Equal(t, expectedError, err) -} - -func TestPostProvideAddressToSendEvidenceFormManualFromStore(t *testing.T) { - f := url.Values{ - "action": {"manual"}, - "address-line-1": {"a"}, - "address-line-2": {"b"}, - "address-line-3": {"c"}, - "address-town": {"d"}, - "address-postcode": {"e"}, - } - - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - donorStore := newMockDonorStore(t) - donorStore. - On("Put", r.Context(), &page.Lpa{ - ID: "lpa-id", - EvidenceFormAddress: testAddress, - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(nil, nil, nil, donorStore)(testAppData, w, r, &page.Lpa{ - ID: "lpa-id", - EvidenceFormAddress: place.Address{Line1: "abc"}, - }) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusFound, resp.StatusCode) - assert.Equal(t, page.Paths.HowToSendEvidence.Format("lpa-id"), resp.Header.Get("Location")) -} - -func TestPostProvideAddressToSendEvidenceFormManualWhenValidationError(t *testing.T) { - f := url.Values{ - "action": {"manual"}, - "address-line-2": {"b"}, - "address-town": {"c"}, - "address-postcode": {"d"}, - } - - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - template := newMockTemplate(t) - template. - On("Execute", w, &chooseAddressData{ - App: testAppData, - Form: &form.AddressForm{ - Action: "manual", - Address: &place.Address{ - Line2: "b", - TownOrCity: "c", - Postcode: "D", - }, - }, - Errors: validation.With("address-line-1", validation.EnterError{Label: "addressLine1"}), - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(nil, template.Execute, nil, nil)(testAppData, w, r, &page.Lpa{}) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) -} - -func TestPostProvideAddressToSendEvidenceFormSelect(t *testing.T) { - expectedAddress := &place.Address{ - Line1: "a", - Line2: "b", - TownOrCity: "c", - Postcode: "d", - } - - f := url.Values{ - "action": {"postcode-select"}, - "lookup-postcode": {"NG1"}, - "select-address": {expectedAddress.Encode()}, - } - - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - template := newMockTemplate(t) - template. - On("Execute", w, &chooseAddressData{ - App: testAppData, - Form: &form.AddressForm{ - Action: "manual", - LookupPostcode: "NG1", - Address: expectedAddress, - }, - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(nil, template.Execute, nil, nil)(testAppData, w, r, &page.Lpa{}) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) -} - -func TestPostProvideAddressToSendEvidenceFormSelectWhenValidationError(t *testing.T) { - f := url.Values{ - "action": {"postcode-select"}, - "lookup-postcode": {"NG1"}, - } - - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - addresses := []place.Address{ - {Line1: "1 Road Way", TownOrCity: "Townville"}, - } - - addressClient := newMockAddressClient(t) - addressClient. - On("LookupPostcode", mock.Anything, "NG1"). - Return(addresses, nil) - - template := newMockTemplate(t) - template. - On("Execute", w, &chooseAddressData{ - App: testAppData, - Form: &form.AddressForm{ - Action: "postcode-select", - LookupPostcode: "NG1", - }, - Addresses: addresses, - Errors: validation.With("select-address", validation.SelectError{Label: "anAddressFromTheList"}), - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(nil, template.Execute, addressClient, nil)(testAppData, w, r, &page.Lpa{}) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) -} - -func TestPostProvideAddressToSendEvidenceFormLookup(t *testing.T) { - f := url.Values{ - "action": {"postcode-lookup"}, - "lookup-postcode": {"NG1"}, - } - - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - addresses := []place.Address{ - {Line1: "1 Road Way", TownOrCity: "Townville"}, - } - - addressClient := newMockAddressClient(t) - addressClient. - On("LookupPostcode", mock.Anything, "NG1"). - Return(addresses, nil) - - template := newMockTemplate(t) - template. - On("Execute", w, &chooseAddressData{ - App: testAppData, - Form: &form.AddressForm{ - Action: "postcode-lookup", - LookupPostcode: "NG1", - }, - Addresses: addresses, - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(nil, template.Execute, addressClient, nil)(testAppData, w, r, &page.Lpa{}) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) -} - -func TestPostProvideAddressToSendEvidenceFormLookupError(t *testing.T) { - f := url.Values{ - "action": {"postcode-lookup"}, - "lookup-postcode": {"NG1"}, - } - - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - logger := newMockLogger(t) - logger. - On("Print", expectedError) - - addressClient := newMockAddressClient(t) - addressClient. - On("LookupPostcode", mock.Anything, "NG1"). - Return([]place.Address{}, expectedError) - - template := newMockTemplate(t) - template. - On("Execute", w, &chooseAddressData{ - App: testAppData, - Form: &form.AddressForm{ - Action: "postcode", - LookupPostcode: "NG1", - }, - Addresses: []place.Address{}, - Errors: validation.With("lookup-postcode", validation.CustomError{Label: "couldNotLookupPostcode"}), - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(logger, template.Execute, addressClient, nil)(testAppData, w, r, &page.Lpa{}) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) -} - -func TestPostProvideAddressToSendEvidenceFormInvalidPostcodeError(t *testing.T) { - w := httptest.NewRecorder() - invalidPostcodeErr := place.BadRequestError{ - Statuscode: 400, - Message: "invalid postcode", - } - - f := url.Values{ - "action": {"postcode-lookup"}, - "lookup-postcode": {"XYZ"}, - } - - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - logger := newMockLogger(t) - logger. - On("Print", invalidPostcodeErr) - - addressClient := newMockAddressClient(t) - addressClient. - On("LookupPostcode", mock.Anything, "XYZ"). - Return([]place.Address{}, invalidPostcodeErr) - - template := newMockTemplate(t) - template. - On("Execute", w, &chooseAddressData{ - App: testAppData, - Form: &form.AddressForm{ - Action: "postcode", - LookupPostcode: "XYZ", - }, - Addresses: []place.Address{}, - Errors: validation.With("lookup-postcode", validation.EnterError{Label: "invalidPostcode"}), - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(logger, template.Execute, addressClient, nil)(testAppData, w, r, &page.Lpa{}) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) -} - -func TestPostProvideAddressToSendEvidenceFormValidPostcodeNoAddresses(t *testing.T) { - w := httptest.NewRecorder() - - f := url.Values{ - "action": {"postcode-lookup"}, - "lookup-postcode": {"XYZ"}, - } - - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - logger := newMockLogger(t) - - addressClient := newMockAddressClient(t) - addressClient. - On("LookupPostcode", mock.Anything, "XYZ"). - Return([]place.Address{}, nil) - - template := newMockTemplate(t) - template. - On("Execute", w, &chooseAddressData{ - App: testAppData, - Form: &form.AddressForm{ - Action: "postcode", - LookupPostcode: "XYZ", - }, - Addresses: []place.Address{}, - Errors: validation.With("lookup-postcode", validation.CustomError{Label: "noAddressesFound"}), - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(logger, template.Execute, addressClient, nil)(testAppData, w, r, &page.Lpa{}) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) -} - -func TestPostProvideAddressToSendEvidenceFormLookupWhenValidationError(t *testing.T) { - f := url.Values{ - "action": {"postcode-lookup"}, - } - - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) - r.Header.Add("Content-Type", page.FormUrlEncoded) - - template := newMockTemplate(t) - template. - On("Execute", w, &chooseAddressData{ - App: testAppData, - Form: &form.AddressForm{ - Action: "postcode", - }, - Errors: validation.With("lookup-postcode", validation.EnterError{Label: "aPostcode"}), - }). - Return(nil) - - err := ProvideAddressToSendEvidenceForm(nil, template.Execute, nil, nil)(testAppData, w, r, &page.Lpa{}) - resp := w.Result() - - assert.Nil(t, err) - assert.Equal(t, http.StatusOK, resp.StatusCode) -} diff --git a/internal/page/donor/register.go b/internal/page/donor/register.go index 2a1997b2c7..dea146092c 100644 --- a/internal/page/donor/register.go +++ b/internal/page/donor/register.go @@ -301,14 +301,8 @@ func Register( UploadEvidence(tmpls.Get("upload_evidence.gohtml"), payer, donorStore, random.UuidString, evidenceBucketName, s3Client)) handleWithLpa(page.Paths.WhatHappensAfterNoFee, None, Guidance(tmpls.Get("what_happens_after_no_fee.gohtml"))) - handleWithLpa(page.Paths.PrintEvidenceForm, CanGoBack, - Guidance(tmpls.Get("print_evidence_form.gohtml"))) - handleWithLpa(page.Paths.HowToPrintAndSendEvidence, CanGoBack, - Guidance(tmpls.Get("how_to_print_and_send_evidence.gohtml"))) - handleWithLpa(page.Paths.ProvideAddressToSendEvidenceForm, CanGoBack, - ProvideAddressToSendEvidenceForm(logger, tmpls.Get("provide_address_to_send_evidence_form.gohtml"), addressClient, donorStore)) - handleWithLpa(page.Paths.HowToSendEvidence, CanGoBack, - HowToSendEvidence(tmpls.Get("how_to_send_evidence.gohtml"), payer)) + handleWithLpa(page.Paths.HowToEmailOrPostEvidence, CanGoBack, + HowToEmailOrPostEvidence(tmpls.Get("how_to_email_or_post_evidence.gohtml"), payer)) handleWithLpa(page.Paths.FeeDenied, None, FeeDenied(tmpls.Get("fee_denied.gohtml"), payer)) handleWithLpa(page.Paths.PaymentConfirmation, None, diff --git a/internal/page/paths.go b/internal/page/paths.go index fa406ec820..96c2021c29 100644 --- a/internal/page/paths.go +++ b/internal/page/paths.go @@ -149,7 +149,7 @@ type AppPaths struct { HowShouldReplacementAttorneysMakeDecisions LpaPath HowShouldReplacementAttorneysStepIn LpaPath HowToConfirmYourIdentityAndSign LpaPath - HowToPrintAndSendEvidence LpaPath + HowToEmailOrPostEvidence LpaPath HowToSendEvidence LpaPath HowWouldCertificateProviderPreferToCarryOutTheirRole LpaPath IdentityConfirmed LpaPath @@ -169,9 +169,7 @@ type AppPaths struct { NeedHelpSigningConfirmation LpaPath PaymentConfirmation LpaPath PreviousApplicationNumber LpaPath - PrintEvidenceForm LpaPath Progress LpaPath - ProvideAddressToSendEvidenceForm LpaPath ReadYourLpa LpaPath RemoveAttorney LpaPath RemovePersonToNotify LpaPath @@ -300,7 +298,7 @@ var Paths = AppPaths{ HowShouldReplacementAttorneysMakeDecisions: "/how-should-replacement-attorneys-make-decisions", HowShouldReplacementAttorneysStepIn: "/how-should-replacement-attorneys-step-in", HowToConfirmYourIdentityAndSign: "/how-to-confirm-your-identity-and-sign", - HowToPrintAndSendEvidence: "/how-to-print-and-send-evidence", + HowToEmailOrPostEvidence: "/how-to-email-or-post-evidence", HowToSendEvidence: "/how-to-send-evidence", HowWouldCertificateProviderPreferToCarryOutTheirRole: "/how-would-certificate-provider-prefer-to-carry-out-their-role", IdentityConfirmed: "/identity-confirmed", @@ -322,9 +320,7 @@ var Paths = AppPaths{ NeedHelpSigningConfirmation: "/need-help-signing-confirmation", PaymentConfirmation: "/payment-confirmation", PreviousApplicationNumber: "/previous-application-number", - PrintEvidenceForm: "/print-evidence-form", Progress: "/progress", - ProvideAddressToSendEvidenceForm: "/provide-address-to-send-evidence-form", ReadYourLpa: "/read-your-lpa", RemoveAttorney: "/remove-attorney", RemovePersonToNotify: "/remove-person-to-notify", diff --git a/web/template/how_to_send_evidence.gohtml b/web/template/how_to_email_or_post_evidence.gohtml similarity index 73% rename from web/template/how_to_send_evidence.gohtml rename to web/template/how_to_email_or_post_evidence.gohtml index 77fdb3583e..0c18e1ffe1 100644 --- a/web/template/how_to_send_evidence.gohtml +++ b/web/template/how_to_email_or_post_evidence.gohtml @@ -1,13 +1,13 @@ {{ template "page" . }} -{{ define "pageTitle" }}{{ tr .App "howToSendEvidence" }}{{ end }} +{{ define "pageTitle" }}{{ tr .App "howToEmailOrPostEvidence" }}{{ end }} {{ define "main" }}
-

{{ tr .App "howToSendEvidence" }}

+

{{ tr .App "howToEmailOrPostEvidence" }}

- {{ trHtml .App "howToSendEvidenceContent" }} + {{ trHtml .App "howToEmailOrPostEvidenceContent" }}
diff --git a/web/template/how_to_print_and_send_evidence.gohtml b/web/template/how_to_print_and_send_evidence.gohtml deleted file mode 100644 index ff94ea915b..0000000000 --- a/web/template/how_to_print_and_send_evidence.gohtml +++ /dev/null @@ -1,18 +0,0 @@ -{{ template "page" . }} - -{{ define "pageTitle" }}{{ tr .App "howToPrintAndSendEvidence" }}{{ end }} - -{{ define "main" }} -
-
-

{{ tr .App "howToPrintAndSendEvidence" }}

- - {{ trHtml .App "howToPrintAndSendEvidenceContent" }} - - -
-
-{{ end }} diff --git a/web/template/print_evidence_form.gohtml b/web/template/print_evidence_form.gohtml deleted file mode 100644 index 40ecfd7ae2..0000000000 --- a/web/template/print_evidence_form.gohtml +++ /dev/null @@ -1,18 +0,0 @@ -{{ template "page" . }} - -{{ define "pageTitle" }}{{ tr .App "printEvidenceForm" }}{{ end }} - -{{ define "main" }} -
-
-

{{ tr .App "printEvidenceForm" }}

- - {{ trHtml .App "printEvidenceFormContent" }} - - -
-
-{{ end }} diff --git a/web/template/provide_address_to_send_evidence_form.gohtml b/web/template/provide_address_to_send_evidence_form.gohtml deleted file mode 100644 index 6147a4723d..0000000000 --- a/web/template/provide_address_to_send_evidence_form.gohtml +++ /dev/null @@ -1,175 +0,0 @@ -{{ template "page" . }} - -{{ define "pageTitle" }} - {{ if eq .Form.Action "manual" }} - {{ tr .App "addressToSendEvidenceForm" }} - {{ else if eq .Form.Action "postcode-select" "postcode-lookup" "reuse" "reuse-select" }} - {{ tr .App "selectAnAddressToSendEvidenceFormTo" }} - {{ else if eq .Form.Action "postcode" }} - {{ tr .App "whatIsThePostcodeOfAddressWeShouldSendTheEvidenceFormTo" }} - {{ else }} - {{ tr .App "provideAddressToSendEvidenceForm" }} - {{ end }} -{{ end }} - -{{ define "main" }} -
-
- - {{ if eq .Form.Action "manual" }} -
- -

- {{ template "pageTitle" . }} -

-
- - {{ template "input" (input . "address-line-1" "addressLine1" .Form.Address.Line1 "autocomplete" "address-line1") }} - {{ template "input" (input . "address-line-2" "addressLine2" .Form.Address.Line2 "autocomplete" "address-line2") }} - {{ template "input" (input . "address-line-3" "addressLine3" .Form.Address.Line3 "autocomplete" "address-line3") }} - {{ template "input" (input . "address-town" "townOrCity" .Form.Address.TownOrCity "classes" "govuk-!-width-two-thirds" "autocomplete" "address-level1") }} - {{ template "input" (input . "address-postcode" "postcode" .Form.Address.Postcode "classes" "govuk-input--width-10" "autocomplete" "postal-code") }} -
- -
- - - {{ if .CanSkip }} - - {{ end }} -
- - {{ else if eq .Form.Action "postcode-select" "postcode-lookup" }} -
-
- -

- {{ template "pageTitle" . }} -

-
- - - {{ template "error-message" (errorMessage . "select-address") }} - - -
-
- - - -

- - {{ tr .App "cantFindTheAddressInList" }} - -

- -
- - - {{ if .CanSkip }} - - {{ end }} -
- - {{ else if eq .Form.Action "postcode" }} -
-
- -

- {{ template "pageTitle" . }} -

-
- - - {{ template "error-message" (errorMessage . "lookup-postcode") }} - - -
-
- -

- - {{ tr .App "enterAddressManually" }} - -

- -
- - - {{ if .CanSkip }} - - {{ end }} -
- - {{ else if eq .Form.Action "reuse" "reuse-select" }} -
-
- -

- {{ template "pageTitle" . }} -

-
- {{ template "error-message" (errorMessage . "select-address") }} - -
- {{ range $i, $a := .Addresses }} -
- - -
- {{end}} -
-
-
- - {{ template "save-and-return-buttons" . }} - - - {{ else }} -
-
- -

- {{ template "pageTitle" . }} -

-
- {{ template "error-message" (errorMessage . "action") }} - - {{ template "radios" (items . "action" .Form.Action - (item "reuse" "useAnAddressYouAlreadyEntered") - (item "postcode" "enterNewAddress") - ) }} -
-
- - {{ template "continue-and-return-buttons" . }} - {{ end }} - - {{ template "csrf-field" . }} - -
-
-{{ end }}