Skip to content

Commit

Permalink
MLPAB-1650, MLPAB-1651: Update and always show DOB warning, update na…
Browse files Browse the repository at this point in the history
…me warning (#948)
  • Loading branch information
acsauk authored Jan 3, 2024
1 parent cdd61ef commit 53e0172
Show file tree
Hide file tree
Showing 46 changed files with 483 additions and 105 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/certificate-provider/enter-date-of-birth.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Enter date of birth', () => {
cy.contains('button', 'Save and continue').click();

cy.url().should('contain', '/enter-date-of-birth');
cy.contains('By saving this section, you confirm that the person is more than 100 years old')
cy.contains('By continuing, you confirm that this person is more than 100 years old. If not, please change their date of birth.')

cy.checkA11yApp();

Expand Down
42 changes: 41 additions & 1 deletion cypress/e2e/donor/choose-attorneys.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,47 @@ describe('Choose attorneys', () => {
cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/choose-attorneys');

cy.contains('The donor’s name is also Sam Smith.');
cy.contains('The donor’s name is also Sam Smith. The donor cannot also be an attorney. By saving this section, you are confirming that these are two different people with the same name.');

cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/choose-attorneys-address');
});

it('permanently warns when date of birth is under 18', () => {
cy.visit('/fixtures?redirect=/choose-replacement-attorneys&progress=provideYourDetails');

cy.get('#f-first-names').type('John');
cy.get('#f-last-name').type('Doe');
cy.get('#f-date-of-birth').type('1');
cy.get('#f-date-of-birth-month').type('2');
cy.get('#f-date-of-birth-year').type(new Date().getFullYear() - 1);
cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/choose-replacement-attorneys');

cy.contains('This attorney is under 18 years old. You can continue making your LPA but you will not be able to sign it until they are 18.');

cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/choose-replacement-attorneys-address');

cy.visitLpa("/choose-replacement-attorneys-summary")
cy.contains('a', 'Change').click()
cy.url().should('contain', '/choose-replacement-attorneys');

cy.contains('This attorney is under 18 years old. You can continue making your LPA but you will not be able to sign it until they are 18.');
});

it('warns when date of birth is over 100', () => {
cy.visit('/fixtures?redirect=/choose-attorneys&progress=provideYourDetails');

cy.get('#f-first-names').type('John');
cy.get('#f-last-name').type('Doe');
cy.get('#f-date-of-birth').type('1');
cy.get('#f-date-of-birth-month').type('2');
cy.get('#f-date-of-birth-year').type('1900');
cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/choose-attorneys');

cy.contains('By continuing, you confirm that this person is more than 100 years old. If not, please change their date of birth.');

cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/choose-attorneys-address');
Expand Down
42 changes: 41 additions & 1 deletion cypress/e2e/donor/choose-replacement-attorneys.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,47 @@ describe('Choose replacement attorneys', () => {
cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/choose-replacement-attorneys');

cy.contains('The donor’s name is also Sam Smith.');
cy.contains('The donor’s name is also Sam Smith. The donor cannot also be a replacement attorney. By saving this section, you are confirming that these are two different people with the same name.');

cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/choose-replacement-attorneys-address');
});

it('permanently warns when date of birth is under 18', () => {
cy.visit('/fixtures?redirect=/choose-replacement-attorneys&progress=provideYourDetails');

cy.get('#f-first-names').type('John');
cy.get('#f-last-name').type('Doe');
cy.get('#f-date-of-birth').type('1');
cy.get('#f-date-of-birth-month').type('2');
cy.get('#f-date-of-birth-year').type(new Date().getFullYear() - 1);
cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/choose-replacement-attorneys');

cy.contains('This attorney is under 18 years old. You can continue making your LPA but you will not be able to sign it until they are 18.');

cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/choose-replacement-attorneys-address');

cy.visitLpa("/choose-replacement-attorneys-summary")
cy.contains('a', 'Change').click()
cy.url().should('contain', '/choose-replacement-attorneys');

cy.contains('This attorney is under 18 years old. You can continue making your LPA but you will not be able to sign it until they are 18.');
});

it('warns when date of birth is over 100', () => {
cy.visit('/fixtures?redirect=/choose-replacement-attorneys&progress=provideYourDetails');

cy.get('#f-first-names').type('John');
cy.get('#f-last-name').type('Doe');
cy.get('#f-date-of-birth').type('1');
cy.get('#f-date-of-birth-month').type('2');
cy.get('#f-date-of-birth-year').type('1900');
cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/choose-replacement-attorneys');

cy.contains('By continuing, you confirm that this person is more than 100 years old. If not, please change their date of birth.');

cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/choose-replacement-attorneys-address');
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/donor/you-cannot-sign-your-lpa-yet.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ describe('You cannot sign your LPA yet', () => {
cy.visit('/fixtures?redirect=/choose-attorneys-summary&progress=peopleToNotifyAboutYourLpa');

cy.contains('.govuk-summary-card', 'Jessie Jones').contains('a', 'Change').click();
cy.get('#f-date-of-birth-year').clear().type(today.getFullYear())
cy.get('#f-date-of-birth-year').clear().type(today.getFullYear() - 1)
cy.contains('button', 'Save and continue').click()
cy.contains('button', 'Save and continue').click()
cy.visitLpa('/choose-replacement-attorneys-summary')

cy.contains('.govuk-summary-card', 'Blake Buckley').contains('a', 'Change').click();
cy.get('#f-date-of-birth-year').clear().type(today.getFullYear())
cy.get('#f-date-of-birth-year').clear().type(today.getFullYear() - 1)
cy.contains('button', 'Save and continue').click()
cy.contains('button', 'Save and continue').click()
cy.contains('a', 'Return to task list').click()
Expand Down
40 changes: 39 additions & 1 deletion cypress/e2e/donor/your-details.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,48 @@ describe('Donor details', () => {
cy.contains('button', 'Continue').click();
cy.url().should('contain', '/your-details');

cy.contains('There is also an attorney called Jessie Jones.');
cy.contains('There is also an attorney called Jessie Jones. An attorney cannot also be the donor. By saving this section, you are confirming that these are two different people with the same name.');

cy.get('#f-can-sign').check();
cy.contains('button', 'Continue').click();
cy.url().should('contain', '/your-address');
});

it('permanently warns when date of birth is under 18', () => {
cy.get('#f-first-names').type('John');
cy.get('#f-last-name').type('Doe');
cy.get('#f-date-of-birth').type('1');
cy.get('#f-date-of-birth-month').type('2');
cy.get('#f-date-of-birth-year').type(new Date().getFullYear() - 1);
cy.get('#f-can-sign').check();
cy.contains('button', 'Continue').click();
cy.url().should('contain', '/your-details');

cy.contains('You are under 18. By continuing, you understand that you must be at least 18 years old on the date you sign the LPA, or it will be rejected.');

cy.contains('button', 'Continue').click();
cy.url().should('contain', '/your-address');

cy.visitLpa("/task-list")
cy.contains('a', 'Provide your details').click()
cy.url().should('contain', '/your-details');

cy.contains('You are under 18. By continuing, you understand that you must be at least 18 years old on the date you sign the LPA, or it will be rejected.');
});

it('warns when date of birth is over 100', () => {
cy.get('#f-first-names').type('John');
cy.get('#f-last-name').type('Doe');
cy.get('#f-date-of-birth').type('1');
cy.get('#f-date-of-birth-month').type('2');
cy.get('#f-date-of-birth-year').type('1900');
cy.get('#f-can-sign').check();
cy.contains('button', 'Continue').click();
cy.url().should('contain', '/your-details');

cy.contains('By continuing, you confirm that this person is more than 100 years old. If not, please change their date of birth.');

cy.contains('button', 'Continue').click();
cy.url().should('contain', '/your-address');
});
});
6 changes: 3 additions & 3 deletions internal/actor/same_name_warning.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func NewSameNameWarning(actor, matches Type, firstNames, lastName string) *SameN

func (w *SameNameWarning) Format(l localize.Localizer) string {
return l.Format(w.translationKey(), map[string]any{
"Type": l.T(w.actorType()),
"FirstNames": w.firstNames,
"LastName": w.lastName,
"ArticleAndType": l.T(w.actorType()),
"FirstNames": w.firstNames,
"LastName": w.lastName,
})
}

Expand Down
20 changes: 14 additions & 6 deletions internal/page/donor/choose_attorneys.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func ChooseAttorneys(tmpl template.Template, donorStore DonorStore, uuidString f
data.Form.LastName,
)

if data.Errors.Any() || data.Form.IgnoreDobWarning != dobWarning {
if data.Form.Dob != attorney.DateOfBirth && (data.Errors.Any() || data.Form.IgnoreDobWarning != dobWarning) {
data.DobWarning = dobWarning
}

if data.Errors.Any() || data.Form.IgnoreNameWarning != nameWarning.String() {
if data.Form.NameHasChanged(attorney) && (data.Errors.Any() || data.Form.IgnoreNameWarning != nameWarning.String()) {
data.NameWarning = nameWarning
}

Expand All @@ -86,6 +86,10 @@ func ChooseAttorneys(tmpl template.Template, donorStore DonorStore, uuidString f
}
}

if !attorney.DateOfBirth.IsZero() {
data.DobWarning = data.Form.DobWarning()
}

return tmpl(w, data)
}
}
Expand Down Expand Up @@ -137,18 +141,18 @@ func (f *chooseAttorneysForm) Validate() validation.List {
return errors
}

func (d *chooseAttorneysForm) DobWarning() string {
func (f *chooseAttorneysForm) DobWarning() string {
var (
today = date.Today()
hundredYearsEarlier = today.AddDate(-100, 0, 0)
eighteenYearsEarlier = today.AddDate(-18, 0, 0)
)

if !d.Dob.IsZero() {
if d.Dob.Before(hundredYearsEarlier) {
if !f.Dob.IsZero() {
if f.Dob.Before(hundredYearsEarlier) {
return "dateOfBirthIsOver100"
}
if d.Dob.Before(today) && d.Dob.After(eighteenYearsEarlier) {
if f.Dob.Before(today) && f.Dob.After(eighteenYearsEarlier) {
return "attorneyDateOfBirthIsUnder18"
}
}
Expand Down Expand Up @@ -197,3 +201,7 @@ func attorneyMatches(donor *actor.DonorProvidedDetails, id, firstNames, lastName

return actor.TypeNone
}

func (f *chooseAttorneysForm) NameHasChanged(attorney actor.Attorney) bool {
return attorney.FirstNames != f.FirstNames || attorney.LastName != f.LastName
}
78 changes: 78 additions & 0 deletions internal/page/donor/choose_attorneys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,39 @@ func TestGetChooseAttorneysFromStore(t *testing.T) {
assert.Equal(t, page.Paths.ChooseAttorneysSummary.Format("lpa-id"), resp.Header.Get("Location"))
}

func TestGetChooseAttorneysDobWarningIsAlwaysShown(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequest(http.MethodGet, "/?id=1", nil)

template := newMockTemplate(t)
template.
On("Execute", w, &chooseAttorneysData{
App: testAppData,
Donor: &actor.DonorProvidedDetails{
Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{
{ID: "1", DateOfBirth: date.New("1900", "1", "2")},
}},
},
Form: &chooseAttorneysForm{
Dob: date.New("1900", "1", "2"),
},
ShowDetails: false,
DobWarning: "dateOfBirthIsOver100",
}).
Return(nil)

err := ChooseAttorneys(template.Execute, nil, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{
Donor: actor.Donor{},
Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{
{ID: "1", DateOfBirth: date.New("1900", "1", "2")},
}},
})
resp := w.Result()

assert.Nil(t, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
}

func TestGetChooseAttorneysWhenTemplateErrors(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequest(http.MethodGet, "/", nil)
Expand Down Expand Up @@ -270,6 +303,51 @@ func TestPostChooseAttorneysAttorneyExists(t *testing.T) {
}
}

func TestPostChooseAttorneysNameWarningOnlyShownWhenAttorneyAndFormNamesAreDifferent(t *testing.T) {
form := url.Values{
"first-names": {"Jane"},
"last-name": {"Doe"},
"date-of-birth-day": {"2"},
"date-of-birth-month": {"1"},
"date-of-birth-year": {"2000"},
}

w := httptest.NewRecorder()
r, _ := http.NewRequest(http.MethodPost, "/?id=123", strings.NewReader(form.Encode()))
r.Header.Add("Content-Type", page.FormUrlEncoded)

donorStore := newMockDonorStore(t)
donorStore.
On("Put", r.Context(), &actor.DonorProvidedDetails{
LpaID: "lpa-id",
Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"},
Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{
{
FirstNames: "Jane",
LastName: "Doe",
ID: "123",
Address: place.Address{Line1: "abc"},
DateOfBirth: date.New("2000", "1", "2"),
},
}},
Tasks: actor.DonorTasks{ChooseAttorneys: actor.TaskCompleted},
}).
Return(nil)

err := ChooseAttorneys(nil, donorStore, mockUuidString)(testAppData, w, r, &actor.DonorProvidedDetails{
LpaID: "lpa-id",
Donor: actor.Donor{FirstNames: "Jane", LastName: "Doe"},
Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{
{FirstNames: "Jane", LastName: "Doe", ID: "123", Address: place.Address{Line1: "abc"}},
}},
})
resp := w.Result()

assert.Nil(t, err)
assert.Equal(t, http.StatusFound, resp.StatusCode)
assert.Equal(t, page.Paths.ChooseAttorneysAddress.Format("lpa-id")+"?id=123", resp.Header.Get("Location"))
}

func TestPostChooseAttorneysWhenInputRequired(t *testing.T) {
testCases := map[string]struct {
form url.Values
Expand Down
8 changes: 6 additions & 2 deletions internal/page/donor/choose_replacement_attorneys.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func ChooseReplacementAttorneys(tmpl template.Template, donorStore DonorStore, u
data.Form.LastName,
)

if data.Errors.Any() || data.Form.IgnoreDobWarning != dobWarning {
if data.Form.Dob != attorney.DateOfBirth && (data.Errors.Any() || data.Form.IgnoreDobWarning != dobWarning) {
data.DobWarning = dobWarning
}

if data.Errors.Any() || data.Form.IgnoreNameWarning != nameWarning.String() {
if data.Form.NameHasChanged(attorney) && (data.Errors.Any() || data.Form.IgnoreNameWarning != nameWarning.String()) {
data.NameWarning = nameWarning
}

Expand All @@ -82,6 +82,10 @@ func ChooseReplacementAttorneys(tmpl template.Template, donorStore DonorStore, u
}
}

if !attorney.DateOfBirth.IsZero() {
data.DobWarning = data.Form.DobWarning()
}

return tmpl(w, data)
}
}
Expand Down
Loading

0 comments on commit 53e0172

Please sign in to comment.