Skip to content

Commit

Permalink
Merge pull request #1446 from ministryofjustice/MLPAB-2330-confirm-al…
Browse files Browse the repository at this point in the history
…lowed-after-identity

MLPAB-2330 Voucher must confirm name if match after identity check
  • Loading branch information
hawx authored Aug 23, 2024
2 parents 63e1788 + 90cbd32 commit 0e15a72
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 136 deletions.
22 changes: 22 additions & 0 deletions cypress/e2e/voucher/confirm-your-identity.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ describe('Confirm your identity', () => {
cy.contains('I’m vouching for someone');
});

it('warns when matches another actor', () => {
cy.visitLpa('/your-name');
cy.get('#f-first-names').clear().type('Charlie');
cy.get('#f-last-name').clear().type('Cooper');
cy.contains('button', 'Save and continue').click();
cy.contains('button', 'Continue').click();
cy.visitLpa('/confirm-your-identity');

cy.checkA11yApp();
cy.contains('a', 'Continue').click();
cy.contains('label', 'Charlie Cooper').click();
cy.contains('button', 'Continue').click();

cy.url().should('contain', '/confirm-allowed-to-vouch');
cy.checkA11yApp();
cy.contains('Your confirmed identity details match someone');

cy.contains('label', 'Yes').click();
cy.contains('button', 'Continue').click();
cy.get('ul li:nth-child(3)').should('contain', 'Completed');
});

it('can fail', () => {
cy.contains('a', 'Continue').click();
cy.contains('label', 'Sam Smith').click();
Expand Down
21 changes: 21 additions & 0 deletions cypress/e2e/voucher/confirm-your-name.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ describe('Confirm your name', () => {

cy.url().should('contain', '/confirm-allowed-to-vouch');
cy.checkA11yApp();
cy.contains('surname matches your surname');

cy.contains('label', 'Yes').click();
cy.contains('button', 'Continue').click();
cy.get('ul li:first-child').should('contain', 'Completed');
});

it('warns when name matches another actor', () => {
cy.contains('div', 'Vivian').contains('a', 'Change').click();

cy.url().should('contain', '/your-name')
cy.checkA11yApp();
cy.get('#f-first-names').clear().type('Charlie');
cy.get('#f-last-name').clear().type('Cooper');
cy.contains('button', 'Save and continue').click();

cy.contains('button', 'Continue').click();

cy.url().should('contain', '/confirm-allowed-to-vouch');
cy.checkA11yApp();
cy.contains('You have entered a name that matches someone');

cy.contains('label', 'Yes').click();
cy.contains('button', 'Continue').click();
Expand Down
17 changes: 1 addition & 16 deletions internal/voucher/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package voucher

import (
"net/http"
"strings"

"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/voucher/voucherdata"
Expand Down Expand Up @@ -47,7 +46,7 @@ func (p Path) Redirect(w http.ResponseWriter, r *http.Request, appData appcontex
func (p Path) CanGoTo(provided *voucherdata.Provided) bool {
switch p {
case PathYourName:
return !provided.Tasks.ConfirmYourIdentity.IsCompleted()
return provided.Tasks.ConfirmYourIdentity.IsNotStarted()

case PathVerifyDonorDetails:
return provided.Tasks.ConfirmYourName.IsCompleted() &&
Expand All @@ -66,17 +65,3 @@ func (p Path) CanGoTo(provided *voucherdata.Provided) bool {
return true
}
}

func CanGoTo(provided *voucherdata.Provided, url string) bool {
path, _, _ := strings.Cut(url, "?")
if path == "" {
return false
}

if strings.HasPrefix(path, "/voucher/") {
_, voucherPath, _ := strings.Cut(strings.TrimPrefix(path, "/voucher/"), "/")
return Path("/" + voucherPath).CanGoTo(provided)
}

return true
}
31 changes: 13 additions & 18 deletions internal/voucher/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,53 +49,48 @@ func TestPathRedirectWhenFrom(t *testing.T) {
func TestCanGoTo(t *testing.T) {
testcases := map[string]struct {
provided *voucherdata.Provided
url string
path Path
expected bool
}{
"empty path": {
provided: &voucherdata.Provided{},
url: "",
expected: false,
},
"unexpected path": {
provided: &voucherdata.Provided{},
url: "/whatever",
path: Path("/whatever"),
expected: true,
},
"unrestricted path": {
provided: &voucherdata.Provided{},
url: PathTaskList.Format("123"),
path: PathTaskList,
expected: true,
},
"your name": {
provided: &voucherdata.Provided{},
url: PathYourName.Format("123"),
path: PathYourName,
expected: true,
},
"your name when identity completed": {
provided: &voucherdata.Provided{
Tasks: voucherdata.Tasks{ConfirmYourIdentity: task.StateCompleted},
},
url: PathYourName.Format("123"),
path: PathYourName,
expected: false,
},
"verify donor details": {
provided: &voucherdata.Provided{},
url: PathVerifyDonorDetails.Format("123"),
path: PathVerifyDonorDetails,
expected: false,
},
"verify donor details when previous task completed": {
provided: &voucherdata.Provided{
Tasks: voucherdata.Tasks{ConfirmYourName: task.StateCompleted},
},
url: PathVerifyDonorDetails.Format("123"),
path: PathVerifyDonorDetails,
expected: true,
},
"verify donor details when already verified": {
provided: &voucherdata.Provided{
Tasks: voucherdata.Tasks{ConfirmYourName: task.StateCompleted, VerifyDonorDetails: task.StateCompleted},
},
url: PathVerifyDonorDetails.Format("123"),
path: PathVerifyDonorDetails,
expected: false,
},
"confirm your identity": {
Expand All @@ -104,7 +99,7 @@ func TestCanGoTo(t *testing.T) {
ConfirmYourName: task.StateCompleted,
},
},
url: PathConfirmYourIdentity.Format("123"),
path: PathConfirmYourIdentity,
expected: false,
},
"confirm your identity when previous task completed": {
Expand All @@ -114,7 +109,7 @@ func TestCanGoTo(t *testing.T) {
VerifyDonorDetails: task.StateCompleted,
},
},
url: PathConfirmYourIdentity.Format("123"),
path: PathConfirmYourIdentity,
expected: true,
},
"sign the declaration": {
Expand All @@ -124,7 +119,7 @@ func TestCanGoTo(t *testing.T) {
VerifyDonorDetails: task.StateCompleted,
},
},
url: PathSignTheDeclaration.Format("123"),
path: PathSignTheDeclaration,
expected: false,
},
"sign the declaration when previous task completed": {
Expand All @@ -135,14 +130,14 @@ func TestCanGoTo(t *testing.T) {
ConfirmYourIdentity: task.StateCompleted,
},
},
url: PathSignTheDeclaration.Format("123"),
path: PathSignTheDeclaration,
expected: true,
},
}

for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.expected, CanGoTo(tc.provided, tc.url))
assert.Equal(t, tc.expected, tc.path.CanGoTo(tc.provided))
})
}
}
12 changes: 10 additions & 2 deletions internal/voucher/voucherpage/confirm_allowed_to_vouch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package voucherpage
import (
"errors"
"net/http"
"strings"

"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
Expand All @@ -20,6 +21,7 @@ type confirmAllowedToVouchData struct {
Form *form.YesNoForm
Lpa *lpadata.Lpa
SurnameMatchesDonor bool
MatchIdentity bool
}

func ConfirmAllowedToVouch(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, voucherStore VoucherStore) Handler {
Expand All @@ -33,7 +35,8 @@ func ConfirmAllowedToVouch(tmpl template.Template, lpaStoreResolvingService LpaS
App: appData,
Form: form.NewYesNoForm(form.YesNoUnknown),
Lpa: lpa,
SurnameMatchesDonor: provided.LastName == lpa.Donor.LastName,
SurnameMatchesDonor: strings.EqualFold(provided.LastName, lpa.Donor.LastName),
MatchIdentity: provided.Tasks.ConfirmYourIdentity.IsInProgress(),
}

if r.Method == http.MethodPost {
Expand All @@ -45,7 +48,12 @@ func ConfirmAllowedToVouch(tmpl template.Template, lpaStoreResolvingService LpaS
return errors.New("// TODO there should be a page here but it hasn't been built yet")
}

provided.Tasks.ConfirmYourName = task.StateCompleted
if provided.Tasks.ConfirmYourIdentity.IsInProgress() {
provided.Tasks.ConfirmYourIdentity = task.StateCompleted
} else {
provided.Tasks.ConfirmYourName = task.StateCompleted
}

if err := voucherStore.Put(r.Context(), provided); err != nil {
return err
}
Expand Down
Loading

0 comments on commit 0e15a72

Please sign in to comment.