-
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.
Add confirm your identity to voucher fixtures
- Loading branch information
Showing
11 changed files
with
432 additions
and
3 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,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'); | ||
}); | ||
}); |
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,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()) | ||
} |
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,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 | ||
} |
Oops, something went wrong.