Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLPAB-2334 Add task list for voucher #1424

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func App(
shareCodeStore,
dashboardStore,
errorHandler,
lpaStoreResolvingService,
)

supporterpage.Register(
Expand Down
13 changes: 13 additions & 0 deletions internal/dynamo/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
memberPrefix = "MEMBER"
memberInvitePrefix = "MEMBERINVITE"
memberIDPrefix = "MEMBERID"
voucherPrefix = "VOUCHER"
metadataPrefix = "METADATA"
donorSharePrefix = "DONORSHARE"
donorInvitePrefix = "DONORINVITE"
Expand Down Expand Up @@ -68,6 +69,8 @@ func readKey(s string) (any, error) {
return MetadataKeyType(s), nil
case donorInvitePrefix:
return DonorInviteKeyType(s), nil
case voucherPrefix:
return VoucherKeyType(s), nil
default:
return nil, errors.New("unknown key prefix")
}
Expand Down Expand Up @@ -194,6 +197,16 @@ func MemberIDKey(memberID string) MemberIDKeyType {
return MemberIDKeyType(memberIDPrefix + "#" + memberID)
}

type VoucherKeyType string

func (t VoucherKeyType) SK() string { return string(t) }

// VoucherKey is used as the SK (with LpaKey as PK) for voucher entered
// information.
func VoucherKey(s string) VoucherKeyType {
return VoucherKeyType(voucherPrefix + "#" + s)
}

type MetadataKeyType string

func (t MetadataKeyType) SK() string { return string(t) }
Expand Down
1 change: 1 addition & 0 deletions internal/dynamo/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestSK(t *testing.T) {
"OrganisationKey": {OrganisationKey("S"), "ORGANISATION#S"},
"MetadataKey": {MetadataKey("S"), "METADATA#S"},
"DonorInviteKey": {DonorInviteKey(OrganisationKey("org-id"), LpaKey("lpa-id")), "DONORINVITE#org-id#lpa-id"},
"VoucherKey": {VoucherKey("S"), "VOUCHER#S"},
}

for name, tc := range testcases {
Expand Down
2 changes: 2 additions & 0 deletions internal/templatefn/fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/voucher"
)

// Globals contains values that are used in templates and do not change as the
Expand Down Expand Up @@ -87,6 +88,7 @@ func All(globals *Globals) map[string]any {
"checkboxEq": checkboxEq,
"lpaDecisions": lpaDecisions,
"summaryRow": summaryRow,
"voucherCanGoTo": voucher.CanGoTo,
}
}

Expand Down
133 changes: 133 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.

41 changes: 40 additions & 1 deletion internal/voucher/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ package voucher

import (
"net/http"
"strings"

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

const (
PathTaskList = Path("/task-list")
PathTaskList = Path("/task-list")
PathConfirmYourName = Path("/confirm-your-name")
PathVerifyDonorDetails = Path("/verify-donor-details")
PathConfirmYourIdentity = Path("/confirm-your-identity")
PathSignTheDeclaration = Path("/sign-the-declaration")
)

type Path string
Expand All @@ -29,3 +35,36 @@ func (p Path) Redirect(w http.ResponseWriter, r *http.Request, appData appcontex
http.Redirect(w, r, appData.Lang.URL(rurl), http.StatusFound)
return nil
}

func (p Path) canVisit(provided *voucherdata.Provided) bool {
switch p {
case PathVerifyDonorDetails:
return provided.Tasks.ConfirmYourName.Completed()

case PathConfirmYourIdentity:
return provided.Tasks.ConfirmYourName.Completed() &&
provided.Tasks.VerifyDonorDetails.Completed()

case PathSignTheDeclaration:
return provided.Tasks.ConfirmYourName.Completed() &&
provided.Tasks.VerifyDonorDetails.Completed() &&
provided.Tasks.ConfirmYourIdentity.Completed()

default:
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).canVisit(provided)
}

return true
}
84 changes: 84 additions & 0 deletions internal/voucher/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
"github.com/ministryofjustice/opg-modernising-lpa/internal/voucher/voucherdata"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -43,3 +45,85 @@ func TestPathRedirectWhenFrom(t *testing.T) {
assert.Equal(t, http.StatusFound, resp.StatusCode)
assert.Equal(t, "/x", resp.Header.Get("Location"))
}

func TestCanGoTo(t *testing.T) {
testcases := map[string]struct {
provided *voucherdata.Provided
url string
expected bool
}{
"empty path": {
provided: &voucherdata.Provided{},
url: "",
expected: false,
},
"unexpected path": {
provided: &voucherdata.Provided{},
url: "/whatever",
expected: true,
},
"unrestricted path": {
provided: &voucherdata.Provided{},
url: PathTaskList.Format("123"),
expected: true,
},
"verify donor details": {
provided: &voucherdata.Provided{},
url: PathVerifyDonorDetails.Format("123"),
expected: false,
},
"verify donor details when previous task completed": {
provided: &voucherdata.Provided{
Tasks: voucherdata.Tasks{ConfirmYourName: task.StateCompleted},
},
url: PathVerifyDonorDetails.Format("123"),
expected: true,
},
"confirm your identity": {
provided: &voucherdata.Provided{
Tasks: voucherdata.Tasks{
ConfirmYourName: task.StateCompleted,
},
},
url: PathConfirmYourIdentity.Format("123"),
expected: false,
},
"confirm your identity when previous task completed": {
provided: &voucherdata.Provided{
Tasks: voucherdata.Tasks{
ConfirmYourName: task.StateCompleted,
VerifyDonorDetails: task.StateCompleted,
},
},
url: PathConfirmYourIdentity.Format("123"),
expected: true,
},
"sign the declaration": {
provided: &voucherdata.Provided{
Tasks: voucherdata.Tasks{
ConfirmYourName: task.StateCompleted,
VerifyDonorDetails: task.StateCompleted,
},
},
url: PathSignTheDeclaration.Format("123"),
expected: false,
},
"sign the declaration when previous task completed": {
provided: &voucherdata.Provided{
Tasks: voucherdata.Tasks{
ConfirmYourName: task.StateCompleted,
VerifyDonorDetails: task.StateCompleted,
ConfirmYourIdentity: task.StateCompleted,
},
},
url: PathSignTheDeclaration.Format("123"),
expected: true,
},
}

for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
assert.Equal(t, tc.expected, CanGoTo(tc.provided, tc.url))
})
}
}
Loading