-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MLPAB-1877: Add what is vouching page (#1316)
- Loading branch information
Showing
9 changed files
with
236 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
describe('what is vouching', () => { | ||
beforeEach(() => { | ||
cy.visit('/fixtures?redirect=/what-is-vouching&progress=payForTheLpa') | ||
cy.url().should('contain', '/what-is-vouching') | ||
cy.checkA11yApp() | ||
}) | ||
|
||
it('can confirm has a voucher', () => { | ||
cy.get('input[name="yes-no"]').check('yes', { force: true }); | ||
cy.contains('button', 'Save and continue').click(); | ||
|
||
cy.url().should('contain', '/enter-voucher') | ||
}) | ||
|
||
it('can confirm has not got a voucher', () => { | ||
cy.get('input[name="yes-no"]').check('no', { force: true }); | ||
cy.contains('button', 'Save and continue').click(); | ||
|
||
cy.url().should('contain', '/task-list') | ||
}) | ||
|
||
it('errors when option not selected', () => { | ||
cy.contains('button', 'Save and continue').click(); | ||
|
||
cy.url().should('contain', '/what-is-vouching') | ||
cy.checkA11yApp() | ||
|
||
cy.get('.govuk-error-summary').within(() => { | ||
cy.contains('Select yes if you know someone and they have agreed to vouch for you'); | ||
}); | ||
|
||
cy.contains('.govuk-error-message', 'Select yes if you know someone and they have agreed to vouch for you'); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package donor | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/ministryofjustice/opg-go-common/template" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/form" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/page" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation" | ||
) | ||
|
||
type whatIsVouchingData struct { | ||
App page.AppData | ||
Errors validation.List | ||
Form *form.YesNoForm | ||
} | ||
|
||
func WhatIsVouching(tmpl template.Template, donorStore DonorStore) Handler { | ||
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { | ||
data := &whatIsVouchingData{ | ||
App: appData, | ||
Form: form.NewYesNoForm(donor.HasAVoucher), | ||
} | ||
|
||
if r.Method == http.MethodPost { | ||
f := form.ReadYesNoForm(r, "yesIfHaveSomeoneCanVouchForYou") | ||
data.Errors = f.Validate() | ||
|
||
if data.Errors.None() { | ||
donor.HasAVoucher = f.YesNo | ||
if err := donorStore.Put(r.Context(), donor); err != nil { | ||
return err | ||
} | ||
|
||
if donor.HasAVoucher.IsYes() { | ||
return page.Paths.EnterVoucher.Redirect(w, r, appData, donor) | ||
} else { | ||
// temp until no flow built | ||
return page.Paths.TaskList.Redirect(w, r, appData, donor) | ||
} | ||
} | ||
} | ||
|
||
return tmpl(w, data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package donor | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/form" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/page" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func TestGetWhatIsVouching(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
r := httptest.NewRequest(http.MethodGet, "/", nil) | ||
|
||
template := newMockTemplate(t) | ||
template.EXPECT(). | ||
Execute(w, &whatIsVouchingData{ | ||
App: testAppData, | ||
Form: &form.YesNoForm{ | ||
YesNo: form.Yes, | ||
FieldName: form.FieldNames.YesNo, | ||
Options: form.YesNoValues, | ||
}, | ||
}). | ||
Return(nil) | ||
|
||
err := WhatIsVouching(template.Execute, nil)(testAppData, w, r, &actor.DonorProvidedDetails{HasAVoucher: form.Yes}) | ||
|
||
assert.Nil(t, err) | ||
} | ||
|
||
func TestGetWhatIsVouchingWhenTemplateError(t *testing.T) { | ||
w := httptest.NewRecorder() | ||
r := httptest.NewRequest(http.MethodGet, "/", nil) | ||
|
||
template := newMockTemplate(t) | ||
template.EXPECT(). | ||
Execute(mock.Anything, mock.Anything). | ||
Return(expectedError) | ||
|
||
err := WhatIsVouching(template.Execute, nil)(testAppData, w, r, &actor.DonorProvidedDetails{}) | ||
|
||
assert.Error(t, err) | ||
} | ||
|
||
func TestPostWhatIsVouching(t *testing.T) { | ||
testcases := map[form.YesNo]string{ | ||
form.Yes: page.Paths.EnterVoucher.Format("lpa-id"), | ||
form.No: page.Paths.TaskList.Format("lpa-id"), | ||
} | ||
|
||
for yesNo, path := range testcases { | ||
t.Run(yesNo.String(), func(t *testing.T) { | ||
f := url.Values{ | ||
"yes-no": {yesNo.String()}, | ||
} | ||
|
||
w := httptest.NewRecorder() | ||
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) | ||
r.Header.Add("Content-Type", page.FormUrlEncoded) | ||
|
||
donorStore := newMockDonorStore(t) | ||
donorStore.EXPECT(). | ||
Put(r.Context(), &actor.DonorProvidedDetails{LpaID: "lpa-id", HasAVoucher: yesNo}). | ||
Return(nil) | ||
|
||
err := WhatIsVouching(nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id"}) | ||
resp := w.Result() | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, http.StatusFound, resp.StatusCode) | ||
assert.Equal(t, path, resp.Header.Get("Location")) | ||
}) | ||
} | ||
} | ||
|
||
func TestPostWhatIsVouchingWhenDonorStoreError(t *testing.T) { | ||
f := url.Values{ | ||
"yes-no": {form.Yes.String()}, | ||
} | ||
|
||
w := httptest.NewRecorder() | ||
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode())) | ||
r.Header.Add("Content-Type", page.FormUrlEncoded) | ||
|
||
donorStore := newMockDonorStore(t) | ||
donorStore.EXPECT(). | ||
Put(mock.Anything, mock.Anything). | ||
Return(expectedError) | ||
|
||
err := WhatIsVouching(nil, donorStore)(testAppData, w, r, &actor.DonorProvidedDetails{LpaID: "lpa-id"}) | ||
resp := w.Result() | ||
|
||
assert.Error(t, err) | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{ template "page" . }} | ||
|
||
{{ define "pageTitle" }}{{ tr .App "whatIsVouching" }}{{ end }} | ||
|
||
{{ define "main" }} | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<form novalidate method="post"> | ||
<h1 class="govuk-heading-xl">{{ tr .App "whatIsVouching" }}</h1> | ||
|
||
{{ trHtml .App "whatIsVouchingContent" }} | ||
|
||
<div class="govuk-form-group {{ if .Errors.Has .Form.FieldName }}govuk-form-group--error{{ end }}"> | ||
<fieldset class="govuk-fieldset"> | ||
<legend class="govuk-fieldset__legend govuk-fieldset__legend--m">{{ tr .App "isThereSomeoneWhoCanVouchForYou" }}</legend> | ||
|
||
{{ template "error-message" (errorMessage . .Form.FieldName) }} | ||
|
||
{{ template "radios" (items . .Form.FieldName .Form.YesNo.String | ||
(item .Form.Options.Yes.String "yesIKnowSomeone") | ||
(item .Form.Options.No.String "noIDoNotKnowSomeone") | ||
) }} | ||
</fieldset> | ||
</div> | ||
|
||
{{ template "buttons" (button .App "saveAndContinue") }} | ||
|
||
{{ template "csrf-field" . }} | ||
</form> | ||
</div> | ||
</div> | ||
{{ end }} |