Skip to content

Commit

Permalink
MLPAB-1907 Add page for voucher to confirm own name (#1426)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Aug 14, 2024
2 parents d0622e5 + 9dcc35e commit 50af747
Show file tree
Hide file tree
Showing 20 changed files with 404 additions and 7 deletions.
4 changes: 4 additions & 0 deletions internal/actor/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const (
TypeVoucher
)

func (t Type) IsVoucher() bool {
return t == TypeVoucher
}

func (t Type) String() string {
switch t {
case TypeDonor:
Expand Down
11 changes: 11 additions & 0 deletions internal/lpastore/lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,16 @@ func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa {
})
}

var voucher lpadata.Voucher
if v := l.Voucher; v.Allowed {
voucher = lpadata.Voucher{
UID: v.UID,
FirstNames: v.FirstNames,
LastName: v.LastName,
Email: v.Email,
}
}

return &lpadata.Lpa{
LpaID: l.LpaID,
LpaUID: l.LpaUID,
Expand Down Expand Up @@ -523,6 +533,7 @@ func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa {
LastName: l.Correspondent.LastName,
Email: l.Correspondent.Email,
},
Voucher: voucher,
}
}

Expand Down
6 changes: 5 additions & 1 deletion internal/lpastore/lpadata/lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ type Lpa struct {
// cannot-register.
CannotRegister bool

// Correspondent is set using the data set by the donor for online
// Correspondent is set using the data provided by the donor for online
// applications, but is not set for paper applications.
Correspondent Correspondent

// Voucher is set using the data provided by the donor for online
// applications, but is not set for paper applications.
Voucher Voucher
}

func (l *Lpa) CorrespondentEmail() string {
Expand Down
10 changes: 10 additions & 0 deletions internal/lpastore/lpadata/voucher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package lpadata

import "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid"

type Voucher struct {
UID actoruid.UID
FirstNames string
LastName string
Email string
}
9 changes: 9 additions & 0 deletions internal/lpastore/resolving_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ func (s *ResolvingService) merge(lpa *lpadata.Lpa, donor *donordata.Provided) *l
Email: donor.Correspondent.Email,
}

if donor.Voucher.Allowed {
lpa.Voucher = lpadata.Voucher{
UID: donor.Voucher.UID,
FirstNames: donor.Voucher.FirstNames,
LastName: donor.Voucher.LastName,
Email: donor.Voucher.Email,
}
}

// copy the relationship as it isn't stored in the lpastore.
lpa.CertificateProvider.Relationship = donor.CertificateProvider.Relationship

Expand Down
24 changes: 24 additions & 0 deletions internal/lpastore/resolving_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestResolvingServiceGet(t *testing.T) {
RetrievedAt: time.Now(),
},
Correspondent: donordata.Correspondent{Email: "x"},
Voucher: donordata.Voucher{Allowed: true, Email: "y"},
},
resolved: &lpadata.Lpa{
LpaID: "1",
Expand All @@ -61,6 +62,7 @@ func TestResolvingServiceGet(t *testing.T) {
},
Donor: lpadata.Donor{Channel: lpadata.ChannelOnline},
Correspondent: lpadata.Correspondent{Email: "x"},
Voucher: lpadata.Voucher{Email: "y"},
},
},
"online with no lpastore record": {
Expand All @@ -84,6 +86,8 @@ func TestResolvingServiceGet(t *testing.T) {
Status: identity.StatusConfirmed,
RetrievedAt: time.Date(2020, time.January, 2, 12, 13, 14, 5, time.UTC),
},
Correspondent: donordata.Correspondent{Email: "x"},
Voucher: donordata.Voucher{Allowed: true, Email: "y"},
},
error: ErrNotFound,
expected: &lpadata.Lpa{
Expand All @@ -108,6 +112,8 @@ func TestResolvingServiceGet(t *testing.T) {
Attorneys: []lpadata.Attorney{{FirstNames: "c"}},
TrustCorporation: lpadata.TrustCorporation{Name: "d"},
},
Correspondent: lpadata.Correspondent{Email: "x"},
Voucher: lpadata.Voucher{Email: "y"},
},
},
"online with all false": {
Expand Down Expand Up @@ -144,6 +150,24 @@ func TestResolvingServiceGet(t *testing.T) {
Donor: lpadata.Donor{Channel: lpadata.ChannelPaper},
},
},
"voucher not allowed": {
donor: &donordata.Provided{
SK: dynamo.LpaOwnerKey(dynamo.OrganisationKey("S")),
LpaID: "1",
LpaUID: "M-1111",
Voucher: donordata.Voucher{Email: "y"},
},
resolved: &lpadata.Lpa{
LpaID: "1",
},
expected: &lpadata.Lpa{
LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("S")),
LpaID: "1",
LpaUID: "M-1111",
IsOrganisationDonor: true,
Donor: lpadata.Donor{Channel: lpadata.ChannelOnline},
},
},
}

for name, tc := range testcases {
Expand Down
10 changes: 9 additions & 1 deletion internal/page/fixtures/voucher.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func Voucher(tmpl template.Template, shareCodeStore *sharecode.Store, donorStore
Attorneys: []donordata.Attorney{makeAttorney(attorneyNames[0])},
}
donorDetails.Voucher = donordata.Voucher{
UID: actoruid.New(),
UID: actoruid.New(),
FirstNames: "Vivian",
LastName: "Vaughn",
Email: testEmail,
Allowed: true,
}

if shareCode != "" {
Expand All @@ -69,6 +73,10 @@ func Voucher(tmpl template.Template, shareCodeStore *sharecode.Store, donorStore
}
}

if err := donorStore.Put(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID, LpaID: donorDetails.LpaID}), donorDetails); err != nil {
return err
}

http.Redirect(w, r, page.PathVoucherStart.Format(), http.StatusFound)
return nil
}
Expand Down
11 changes: 9 additions & 2 deletions internal/templatefn/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/supporter"
"github.com/ministryofjustice/opg-modernising-lpa/internal/voucher"
)

type attorneyPaths struct {
Expand Down Expand Up @@ -92,7 +93,10 @@ type supporterPaths struct {
}

type voucherPaths struct {
Login page.Path
Login page.Path
Start page.Path
TaskList voucher.Path
YourName voucher.Path
}

type appPaths struct {
Expand Down Expand Up @@ -315,7 +319,10 @@ var paths = appPaths{
},

Voucher: voucherPaths{
Login: page.PathVoucherLogin,
Login: page.PathVoucherLogin,
Start: page.PathVoucherStart,
TaskList: voucher.PathTaskList,
YourName: voucher.PathYourName,
},

HealthCheck: healthCheckPaths{
Expand Down
47 changes: 47 additions & 0 deletions internal/voucher/mock_DynamoClient_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/voucher/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
const (
PathTaskList = Path("/task-list")
PathConfirmYourName = Path("/confirm-your-name")
PathYourName = Path("/your-name")
PathVerifyDonorDetails = Path("/verify-donor-details")
PathConfirmYourIdentity = Path("/confirm-your-identity")
PathSignTheDeclaration = Path("/sign-the-declaration")
Expand Down
6 changes: 6 additions & 0 deletions internal/voucher/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

type DynamoClient interface {
One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error
Put(ctx context.Context, v interface{}) error
WriteTransaction(ctx context.Context, transaction *dynamo.Transaction) error
}

Expand Down Expand Up @@ -78,3 +79,8 @@ func (s *Store) Get(ctx context.Context) (*voucherdata.Provided, error) {

return &provided, err
}

func (s *Store) Put(ctx context.Context, provided *voucherdata.Provided) error {
provided.UpdatedAt = s.now()
return s.dynamoClient.Put(ctx, provided)
}
18 changes: 18 additions & 0 deletions internal/voucher/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,21 @@ func TestVoucherStoreGetOnError(t *testing.T) {
_, err := store.Get(ctx)
assert.Equal(t, expectedError, err)
}

func TestVoucherStorePut(t *testing.T) {
ctx := context.Background()
now := time.Now()

dynamoClient := newMockDynamoClient(t)
dynamoClient.EXPECT().
Put(ctx, &voucherdata.Provided{PK: dynamo.LpaKey("123"), SK: dynamo.VoucherKey("456"), LpaID: "123", UpdatedAt: now}).
Return(expectedError)

store := &Store{
dynamoClient: dynamoClient,
now: func() time.Time { return now },
}

err := store.Put(ctx, &voucherdata.Provided{PK: dynamo.LpaKey("123"), SK: dynamo.VoucherKey("456"), LpaID: "123"})
assert.Equal(t, expectedError, err)
}
45 changes: 45 additions & 0 deletions internal/voucher/voucherpage/confirm_your_name.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package voucherpage

import (
"net/http"

"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/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 confirmYourNameData struct {
App appcontext.Data
Errors validation.List
Lpa *lpadata.Lpa
}

func ConfirmYourName(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, voucherStore VoucherStore) Handler {
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, provided *voucherdata.Provided) error {
if r.Method == http.MethodPost {
if provided.Tasks.ConfirmYourName.NotStarted() {
provided.Tasks.ConfirmYourName = task.StateInProgress

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

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

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

return tmpl(w, &confirmYourNameData{
App: appData,
Lpa: lpa,
})
}
}
Loading

0 comments on commit 50af747

Please sign in to comment.