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

Resequence and rename to match updated prototype flow #76

Merged
merged 1 commit into from Sep 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/internal/page/app.go
Expand Up @@ -82,10 +82,10 @@ func App(
LpaType(tmpls.Get("lpa_type.gohtml"), dataStore))
handle(whoIsTheLpaForPath, RequireSession,
WhoIsTheLpaFor(tmpls.Get("who_is_the_lpa_for.gohtml"), dataStore))
handle(donorDetailsPath, RequireSession,
DonorDetails(tmpls.Get("donor_details.gohtml"), dataStore))
handle(donorAddressPath, RequireSession,
DonorAddress(logger, tmpls.Get("donor_address.gohtml"), addressClient, dataStore))
handle(yourDetailsPath, RequireSession,
YourDetails(tmpls.Get("your_details.gohtml"), dataStore))
handle(yourAddressPath, RequireSession,
YourAddress(logger, tmpls.Get("your_address.gohtml"), addressClient, dataStore))
handle(howWouldYouLikeToBeContactedPath, RequireSession,
HowWouldYouLikeToBeContacted(tmpls.Get("how_would_you_like_to_be_contacted.gohtml"), dataStore))
handle(taskListPath, RequireSession,
Expand Down
2 changes: 1 addition & 1 deletion app/internal/page/auth_redirect.go
Expand Up @@ -49,6 +49,6 @@ func AuthRedirect(logger Logger, c authRedirectClient, store sessions.Store) htt
return
}

http.Redirect(w, r, lpaTypePath, http.StatusFound)
http.Redirect(w, r, yourDetailsPath, http.StatusFound)
}
}
2 changes: 1 addition & 1 deletion app/internal/page/auth_redirect_test.go
Expand Up @@ -49,7 +49,7 @@ func TestAuthRedirect(t *testing.T) {
resp := w.Result()

assert.Equal(t, http.StatusFound, resp.StatusCode)
assert.Equal(t, resp.Header.Get("Location"), lpaTypePath)
assert.Equal(t, yourDetailsPath, resp.Header.Get("Location"))
mock.AssertExpectationsForObjects(t, client, sessionsStore)
}

Expand Down
4 changes: 2 additions & 2 deletions app/internal/page/data.go
Expand Up @@ -7,14 +7,14 @@ import (
)

type Lpa struct {
Donor Donor
You Person
Attorney Attorney
WhoFor string
Contact []string
Type string
}

type Donor struct {
type Person struct {
FirstNames string
LastName string
OtherNames string
Expand Down
2 changes: 1 addition & 1 deletion app/internal/page/lpa_type.go
Expand Up @@ -33,7 +33,7 @@ func LpaType(tmpl template.Template, dataStore DataStore) Handler {
if err := dataStore.Put(r.Context(), appData.SessionID, lpa); err != nil {
return err
}
appData.Lang.Redirect(w, r, whoIsTheLpaForPath, http.StatusFound)
appData.Lang.Redirect(w, r, taskListPath, http.StatusFound)
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/internal/page/lpa_type_test.go
Expand Up @@ -128,7 +128,7 @@ func TestPostLpaType(t *testing.T) {

assert.Nil(t, err)
assert.Equal(t, http.StatusFound, resp.StatusCode)
assert.Equal(t, whoIsTheLpaForPath, resp.Header.Get("Location"))
assert.Equal(t, taskListPath, resp.Header.Get("Location"))
mock.AssertExpectationsForObjects(t, dataStore)
}

Expand Down
4 changes: 2 additions & 2 deletions app/internal/page/paths.go
Expand Up @@ -6,8 +6,8 @@ const (

startPath = "/start"
homePath = "/home"
donorDetailsPath = "/donor-details"
donorAddressPath = "/donor-address"
yourDetailsPath = "/your-details"
yourAddressPath = "/your-address"
whoIsTheLpaForPath = "/who-is-the-lpa-for"
howWouldYouLikeToBeContactedPath = "/how-would-you-like-to-be-contacted"
lpaTypePath = "/lpa-type"
Expand Down
3 changes: 1 addition & 2 deletions app/internal/page/task_list.go
Expand Up @@ -36,8 +36,7 @@ func TaskList(tmpl template.Template, dataStore DataStore) Handler {
{
Heading: "fillInTheLpa",
Items: []taskListItem{
{Name: "provideDonorDetails", Path: donorDetailsPath, Completed: lpa.Donor.Address.Line1 != ""},
{Name: "chooseYourContactPreferences", Path: howWouldYouLikeToBeContactedPath, Completed: len(lpa.Contact) > 0},
{Name: "provideDonorDetails", Path: yourDetailsPath, Completed: lpa.You.Address.Line1 != ""},
{Name: "chooseYourAttorneys", Path: chooseAttorneysPath, Completed: lpa.Attorney.Address.Line1 != ""},
{Name: "chooseYourReplacementAttorneys"},
{Name: "chooseWhenTheLpaCanBeUsed"},
Expand Down
8 changes: 3 additions & 5 deletions app/internal/page/task_list_test.go
Expand Up @@ -25,8 +25,7 @@ func TestGetTaskList(t *testing.T) {
{
Heading: "fillInTheLpa",
Items: []taskListItem{
{Name: "provideDonorDetails", Path: donorDetailsPath},
{Name: "chooseYourContactPreferences", Path: howWouldYouLikeToBeContactedPath},
{Name: "provideDonorDetails", Path: yourDetailsPath},
{Name: "chooseYourAttorneys", Path: chooseAttorneysPath},
{Name: "chooseYourReplacementAttorneys"},
{Name: "chooseWhenTheLpaCanBeUsed"},
Expand Down Expand Up @@ -72,7 +71,7 @@ func TestGetTaskListWhenComplete(t *testing.T) {

dataStore := &mockDataStore{
data: Lpa{
Donor: Donor{
You: Person{
Address: Address{
Line1: "this",
},
Expand All @@ -97,8 +96,7 @@ func TestGetTaskListWhenComplete(t *testing.T) {
{
Heading: "fillInTheLpa",
Items: []taskListItem{
{Name: "provideDonorDetails", Path: donorDetailsPath, Completed: true},
{Name: "chooseYourContactPreferences", Path: howWouldYouLikeToBeContactedPath, Completed: true},
{Name: "provideDonorDetails", Path: yourDetailsPath, Completed: true},
{Name: "chooseYourAttorneys", Path: chooseAttorneysPath, Completed: true},
{Name: "chooseYourReplacementAttorneys"},
{Name: "chooseWhenTheLpaCanBeUsed"},
Expand Down
2 changes: 1 addition & 1 deletion app/internal/page/who_is_the_lpa_for.go
Expand Up @@ -33,7 +33,7 @@ func WhoIsTheLpaFor(tmpl template.Template, dataStore DataStore) Handler {
if err := dataStore.Put(r.Context(), appData.SessionID, lpa); err != nil {
return err
}
appData.Lang.Redirect(w, r, donorDetailsPath, http.StatusFound)
appData.Lang.Redirect(w, r, lpaTypePath, http.StatusFound)
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/internal/page/who_is_the_lpa_for_test.go
Expand Up @@ -128,7 +128,7 @@ func TestPostWhoIsTheLpaFor(t *testing.T) {

assert.Nil(t, err)
assert.Equal(t, http.StatusFound, resp.StatusCode)
assert.Equal(t, donorDetailsPath, resp.Header.Get("Location"))
assert.Equal(t, lpaTypePath, resp.Header.Get("Location"))
mock.AssertExpectationsForObjects(t, dataStore)
}

Expand Down
Expand Up @@ -6,40 +6,40 @@ import (
"github.com/ministryofjustice/opg-go-common/template"
)

type donorAddressData struct {
type yourAddressData struct {
App AppData
Errors map[string]string
Addresses []Address
Form *donorAddressForm
Form *yourAddressForm
}

func DonorAddress(logger Logger, tmpl template.Template, addressClient AddressClient, dataStore DataStore) Handler {
func YourAddress(logger Logger, tmpl template.Template, addressClient AddressClient, dataStore DataStore) Handler {
return func(appData AppData, w http.ResponseWriter, r *http.Request) error {
var lpa Lpa
if err := dataStore.Get(r.Context(), appData.SessionID, &lpa); err != nil {
return err
}

data := &donorAddressData{
data := &yourAddressData{
App: appData,
Form: &donorAddressForm{},
Form: &yourAddressForm{},
}

if lpa.Donor.Address.Line1 != "" {
if lpa.You.Address.Line1 != "" {
data.Form.Action = "manual"
data.Form.Address = &lpa.Donor.Address
data.Form.Address = &lpa.You.Address
}

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

if (data.Form.Action == "manual" || data.Form.Action == "select") && len(data.Errors) == 0 {
lpa.Donor.Address = *data.Form.Address
lpa.You.Address = *data.Form.Address
if err := dataStore.Put(r.Context(), appData.SessionID, lpa); err != nil {
return err
}
appData.Lang.Redirect(w, r, howWouldYouLikeToBeContactedPath, http.StatusFound)
appData.Lang.Redirect(w, r, whoIsTheLpaForPath, http.StatusFound)
return nil
}

Expand All @@ -66,14 +66,14 @@ func DonorAddress(logger Logger, tmpl template.Template, addressClient AddressCl
}
}

type donorAddressForm struct {
type yourAddressForm struct {
Action string
LookupPostcode string
Address *Address
}

func readDonorAddressForm(r *http.Request) *donorAddressForm {
d := &donorAddressForm{}
func readYourAddressForm(r *http.Request) *yourAddressForm {
d := &yourAddressForm{}
d.Action = r.PostFormValue("action")

switch d.Action {
Expand All @@ -99,7 +99,7 @@ func readDonorAddressForm(r *http.Request) *donorAddressForm {
return d
}

func (d *donorAddressForm) Validate() map[string]string {
func (d *yourAddressForm) Validate() map[string]string {
errors := map[string]string{}

switch d.Action {
Expand Down