Skip to content

Commit

Permalink
Add confirm your identity to voucher fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx committed Aug 20, 2024
1 parent 63bea83 commit 3a9f5c5
Show file tree
Hide file tree
Showing 11 changed files with 432 additions and 3 deletions.
14 changes: 14 additions & 0 deletions cypress/e2e/voucher/your-declaration.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe('Confirm your identity', () => {
beforeEach(() => {
cy.visit('/fixtures/voucher?redirect=/sign-the-declaration&progress=confirmYourIdentity');
});

it('can be signed', () => {
cy.checkA11yApp();
cy.contains('label', 'To the best of my knowledge').click();
cy.contains('button', 'Submit my signature').click();

// TODO: this will change when the next ticket is picked up
cy.url().should('contain', '/task-list');
});
});
6 changes: 6 additions & 0 deletions internal/voucher/voucherdata/provided.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ type Provided struct {
// IdentityUserData records the results of the identity check taken by the
// voucher.
IdentityUserData identity.UserData
// SignedAt is the time the declaration was signed.
SignedAt time.Time
}

func (p Provided) FullName() string {
return p.FirstNames + " " + p.LastName
}

func (p Provided) IdentityConfirmed() bool {
Expand Down
48 changes: 48 additions & 0 deletions internal/voucher/voucherdata/provided_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package voucherdata

import (
"testing"

"github.com/ministryofjustice/opg-modernising-lpa/internal/identity"
"github.com/stretchr/testify/assert"
)

func TestProvidedFullName(t *testing.T) {
assert.Equal(t, "John Smith", Provided{FirstNames: "John", LastName: "Smith"}.FullName())
}

func TestProvidedIdentityConfirmed(t *testing.T) {
assert.True(t, Provided{
FirstNames: "X",
LastName: "Y",
IdentityUserData: identity.UserData{
Status: identity.StatusConfirmed,
FirstNames: "X",
LastName: "Y",
},
}.IdentityConfirmed())
}

func TestProvidedIdentityConfirmedWhenNameNotMatch(t *testing.T) {
assert.False(t, Provided{
FirstNames: "A",
LastName: "Y",
IdentityUserData: identity.UserData{
Status: identity.StatusConfirmed,
FirstNames: "X",
LastName: "Y",
},
}.IdentityConfirmed())
}

func TestProvidedIdentityConfirmedWhenNotConfirmed(t *testing.T) {
assert.False(t, Provided{
FirstNames: "X",
LastName: "Y",
IdentityUserData: identity.UserData{
Status: identity.StatusFailed,
FirstNames: "X",
LastName: "Y",
},
}.IdentityConfirmed())
}
3 changes: 3 additions & 0 deletions internal/voucher/voucherpage/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package voucherpage

import (
"errors"
"time"

"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
)

var (
expectedError = errors.New("err")
testAppData = appcontext.Data{LpaID: "lpa-id"}
testNow = time.Now()
testNowFn = func() time.Time { return testNow }
)
4 changes: 4 additions & 0 deletions internal/voucher/voucherpage/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"io"
"net/http"
"time"

"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
Expand Down Expand Up @@ -130,6 +131,9 @@ func Register(
Guidance(tmpls.Get("one_login_identity_details.gohtml"), lpaStoreResolvingService))
handleVoucher(voucher.PathUnableToConfirmIdentity, None,
Guidance(tmpls.Get("unable_to_confirm_identity.gohtml"), lpaStoreResolvingService))

handleVoucher(voucher.PathSignTheDeclaration, None,
YourDeclaration(tmpls.Get("your_declaration.gohtml"), lpaStoreResolvingService, voucherStore, time.Now))
}

type handleOpt byte
Expand Down
79 changes: 79 additions & 0 deletions internal/voucher/voucherpage/your_declaration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package voucherpage

import (
"net/http"
"time"

"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
"github.com/ministryofjustice/opg-modernising-lpa/internal/voucher"
"github.com/ministryofjustice/opg-modernising-lpa/internal/voucher/voucherdata"
)

type yourDeclarationData struct {
App appcontext.Data
Errors validation.List
Form *yourDeclarationForm
Lpa *lpadata.Lpa
Voucher *voucherdata.Provided
}

func YourDeclaration(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, voucherStore VoucherStore, now func() time.Time) Handler {
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, provided *voucherdata.Provided) error {
if !provided.SignedAt.IsZero() {
return voucher.PathTaskList.Redirect(w, r, appData, appData.LpaID)
}

lpa, err := lpaStoreResolvingService.Get(r.Context())
if err != nil {
return err
}

data := &yourDeclarationData{
App: appData,
Form: &yourDeclarationForm{},
Lpa: lpa,
Voucher: provided,
}

if r.Method == http.MethodPost {
data.Form = readYourDeclarationForm(r)
data.Errors = data.Form.Validate()

if data.Errors.None() {
provided.SignedAt = now()
provided.Tasks.SignTheDeclaration = task.StateCompleted
if err := voucherStore.Put(r.Context(), provided); err != nil {
return err
}

return voucher.PathTaskList.Redirect(w, r, appData, appData.LpaID)
}
}

return tmpl(w, data)
}
}

type yourDeclarationForm struct {
Confirm bool
}

func readYourDeclarationForm(r *http.Request) *yourDeclarationForm {
return &yourDeclarationForm{
Confirm: page.PostFormString(r, "confirm") == "1",
}
}

func (f *yourDeclarationForm) Validate() validation.List {
var errors validation.List

errors.Bool("confirm", "youMustSelectTheBoxToVouch", f.Confirm,
validation.Selected().CustomError())

return errors
}
Loading

0 comments on commit 3a9f5c5

Please sign in to comment.