-
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.
Move stores to root packages and paths for actors (#1405)
- Loading branch information
Showing
65 changed files
with
1,820 additions
and
1,471 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
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
2 changes: 1 addition & 1 deletion
2
...donor/donordata/mock_DynamoClient_test.go → internal/attorney/mock_DynamoClient_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
internal/donor/donordata/mock_test.go → internal/attorney/mock_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package donordata | ||
package attorney | ||
|
||
import ( | ||
"context" | ||
|
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,76 @@ | ||
package attorney | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
|
||
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" | ||
) | ||
|
||
const ( | ||
PathCodeOfConduct = Path("/code-of-conduct") | ||
PathConfirmDontWantToBeAttorney = Path("/confirm-you-do-not-want-to-be-an-attorney") | ||
PathConfirmYourDetails = Path("/confirm-your-details") | ||
PathMobileNumber = Path("/mobile-number") | ||
PathProgress = Path("/progress") | ||
PathReadTheLpa = Path("/read-the-lpa") | ||
PathRightsAndResponsibilities = Path("/legal-rights-and-responsibilities") | ||
PathSign = Path("/sign") | ||
PathTaskList = Path("/task-list") | ||
PathWhatHappensNext = Path("/what-happens-next") | ||
PathWhatHappensWhenYouSign = Path("/what-happens-when-you-sign-the-lpa") | ||
PathWouldLikeSecondSignatory = Path("/would-like-second-signatory") | ||
PathYourPreferredLanguage = Path("/your-preferred-language") | ||
) | ||
|
||
type Path string | ||
|
||
func (p Path) String() string { | ||
return "/attorney/{id}" + string(p) | ||
} | ||
|
||
func (p Path) Format(id string) string { | ||
return "/attorney/" + id + string(p) | ||
} | ||
|
||
func (p Path) Redirect(w http.ResponseWriter, r *http.Request, appData appcontext.Data, lpaID string) error { | ||
http.Redirect(w, r, appData.Lang.URL(p.Format(lpaID)), http.StatusFound) | ||
return nil | ||
} | ||
|
||
func (p Path) RedirectQuery(w http.ResponseWriter, r *http.Request, appData appcontext.Data, lpaID string, query url.Values) error { | ||
http.Redirect(w, r, appData.Lang.URL(p.Format(lpaID))+"?"+query.Encode(), http.StatusFound) | ||
return nil | ||
} | ||
|
||
func (p Path) canVisit(attorney *attorneydata.Provided) bool { | ||
switch p { | ||
case PathRightsAndResponsibilities, | ||
PathWhatHappensWhenYouSign, | ||
PathSign, | ||
PathWhatHappensNext: | ||
return attorney.Tasks.ConfirmYourDetails.Completed() && attorney.Tasks.ReadTheLpa.Completed() | ||
|
||
case PathWouldLikeSecondSignatory: | ||
return attorney.Tasks.ConfirmYourDetails.Completed() && attorney.Tasks.ReadTheLpa.Completed() && attorney.IsTrustCorporation | ||
|
||
default: | ||
return true | ||
} | ||
} | ||
|
||
func CanGoTo(attorney *attorneydata.Provided, url string) bool { | ||
path, _, _ := strings.Cut(url, "?") | ||
if path == "" { | ||
return false | ||
} | ||
|
||
if strings.HasPrefix(path, "/attorney/") { | ||
_, attorneyPath, _ := strings.Cut(strings.TrimPrefix(path, "/attorney/"), "/") | ||
return Path("/" + attorneyPath).canVisit(attorney) | ||
} | ||
|
||
return true | ||
} |
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,118 @@ | ||
package attorney | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize" | ||
"github.com/ministryofjustice/opg-modernising-lpa/internal/task" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAttorneyPathString(t *testing.T) { | ||
assert.Equal(t, "/attorney/{id}/anything", Path("/anything").String()) | ||
} | ||
|
||
func TestAttorneyPathFormat(t *testing.T) { | ||
assert.Equal(t, "/attorney/abc/anything", Path("/anything").Format("abc")) | ||
} | ||
|
||
func TestAttorneyPathRedirect(t *testing.T) { | ||
r, _ := http.NewRequest(http.MethodGet, "/", nil) | ||
w := httptest.NewRecorder() | ||
p := Path("/something") | ||
|
||
err := p.Redirect(w, r, appcontext.Data{Lang: localize.En}, "lpa-id") | ||
resp := w.Result() | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, http.StatusFound, resp.StatusCode) | ||
assert.Equal(t, p.Format("lpa-id"), resp.Header.Get("Location")) | ||
} | ||
|
||
func TestAttorneyPathRedirectQuery(t *testing.T) { | ||
r, _ := http.NewRequest(http.MethodGet, "/", nil) | ||
w := httptest.NewRecorder() | ||
p := Path("/something") | ||
|
||
err := p.RedirectQuery(w, r, appcontext.Data{Lang: localize.En}, "lpa-id", url.Values{"q": {"1"}}) | ||
resp := w.Result() | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, http.StatusFound, resp.StatusCode) | ||
assert.Equal(t, p.Format("lpa-id")+"?q=1", resp.Header.Get("Location")) | ||
} | ||
|
||
func TestAttorneyCanGoTo(t *testing.T) { | ||
testCases := map[string]struct { | ||
attorney *attorneydata.Provided | ||
url string | ||
expected bool | ||
}{ | ||
"empty path": { | ||
attorney: &attorneydata.Provided{}, | ||
url: "", | ||
expected: false, | ||
}, | ||
"unexpected path": { | ||
attorney: &attorneydata.Provided{}, | ||
url: "/whatever", | ||
expected: true, | ||
}, | ||
"unrestricted path": { | ||
attorney: &attorneydata.Provided{}, | ||
url: PathConfirmYourDetails.Format("123"), | ||
expected: true, | ||
}, | ||
"sign without task": { | ||
attorney: &attorneydata.Provided{ | ||
Tasks: attorneydata.Tasks{ | ||
ConfirmYourDetails: task.StateCompleted, | ||
}, | ||
}, | ||
url: PathSign.Format("123"), | ||
expected: false, | ||
}, | ||
"sign with task": { | ||
attorney: &attorneydata.Provided{ | ||
Tasks: attorneydata.Tasks{ | ||
ConfirmYourDetails: task.StateCompleted, | ||
ReadTheLpa: task.StateCompleted, | ||
}, | ||
}, | ||
url: PathSign.Format("123"), | ||
expected: true, | ||
}, | ||
"would like second signatory not trust corp": { | ||
attorney: &attorneydata.Provided{ | ||
Tasks: attorneydata.Tasks{ | ||
ConfirmYourDetails: task.StateCompleted, | ||
ReadTheLpa: task.StateCompleted, | ||
}, | ||
}, | ||
url: PathWouldLikeSecondSignatory.Format("123"), | ||
expected: false, | ||
}, | ||
"would like second signatory as trust corp": { | ||
attorney: &attorneydata.Provided{ | ||
Tasks: attorneydata.Tasks{ | ||
ConfirmYourDetails: task.StateCompleted, | ||
ReadTheLpa: task.StateCompleted, | ||
}, | ||
IsTrustCorporation: true, | ||
}, | ||
url: PathWouldLikeSecondSignatory.Format("123"), | ||
expected: true, | ||
}, | ||
} | ||
|
||
for name, tc := range testCases { | ||
t.Run(name, func(t *testing.T) { | ||
assert.Equal(t, tc.expected, CanGoTo(tc.attorney, tc.url)) | ||
}) | ||
} | ||
} |
Oops, something went wrong.