Skip to content

Commit

Permalink
Merge 0d5d57f into be0cdfe
Browse files Browse the repository at this point in the history
  • Loading branch information
acsauk authored Mar 13, 2024
2 parents be0cdfe + 0d5d57f commit 4a698fb
Show file tree
Hide file tree
Showing 12 changed files with 280 additions and 20 deletions.
7 changes: 1 addition & 6 deletions cypress/e2e/supporter/dashboard.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ describe('Dashboard', () => {
cy.contains('Property and affairs');
cy.contains('In progress');

cy.contains('a', 'M-').click();
cy.contains('Provide your details').click();
cy.get('#f-first-names').type('2');
cy.contains('button', 'Continue').click();
cy.contains('a', 'Dashboard').click();
cy.contains('Sam2 Smith');
cy.contains('a', 'M-');
});

it('can start a new LPA', () => {
Expand Down
33 changes: 33 additions & 0 deletions cypress/e2e/supporter/view-lpa.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe('View LPA', () => {
beforeEach(() => {
cy.visit('/fixtures/supporter?organisation=1&redirect=/dashboard&lpa=1');
cy.checkA11yApp();
});

it('can continue making an LPA', () => {
cy.contains('a', 'M-FAKE').click()

cy.url().should('contain', '/view-lpa');
cy.checkA11yApp();

cy.contains('h1', 'Property and affairs LPA')
cy.contains('div', 'M-FAKE')

cy.contains('a', 'Donor access')
cy.contains('a', 'View LPA summary')
cy.contains('a', 'Go to task list').click()

cy.url().should('contain', '/task-list');
cy.checkA11yApp();

cy.contains('Provide your details').click()

cy.url().should('contain', '/your-details');
cy.checkA11yApp();

cy.get('#f-first-names').type('2');
cy.contains('button', 'Continue').click();
cy.contains('a', 'Dashboard').click();
cy.contains('Sam2 Smith');
});
})
2 changes: 2 additions & 0 deletions internal/page/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ type SupporterPaths struct {
ManageTeamMembers SupporterPath
OrganisationCreated SupporterPath
OrganisationDetails SupporterPath
ViewLPA SupporterPath
}

type AppPaths struct {
Expand Down Expand Up @@ -441,6 +442,7 @@ var Paths = AppPaths{
ManageTeamMembers: "/manage-organisation/manage-team-members",
OrganisationCreated: "/organisation-or-company-created",
OrganisationDetails: "/manage-organisation/organisation-details",
ViewLPA: "/view-lpa",
},

HealthCheck: HealthCheckPaths{
Expand Down
58 changes: 58 additions & 0 deletions internal/page/supporter/mock_DonorStore_test.go

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

18 changes: 9 additions & 9 deletions internal/page/supporter/mock_Template_test.go

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

5 changes: 4 additions & 1 deletion internal/page/supporter/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type MemberStore interface {
}

type DonorStore interface {
Get(ctx context.Context) (*actor.DonorProvidedDetails, error)
GetByKeys(ctx context.Context, keys []dynamo.Key) ([]actor.DonorProvidedDetails, error)
}

Expand All @@ -64,7 +65,7 @@ type NotifyClient interface {
SendEmail(context context.Context, to string, email notify.Email) error
}

type Template func(io.Writer, interface{}) error
type Template func(w io.Writer, data interface{}) error

type Handler func(data page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation) error

Expand Down Expand Up @@ -115,6 +116,8 @@ func Register(
ConfirmDonorCanInteractOnline(tmpls.Get("confirm_donor_can_interact_online.gohtml"), organisationStore))
handleWithSupporter(paths.ContactOPGForPaperForms, None,
Guidance(tmpls.Get("contact_opg_for_paper_forms.gohtml")))
handleWithSupporter(paths.ViewLPA, CanGoBack,
ViewLPA(tmpls.Get("view_lpa.gohtml"), donorStore))

handleWithSupporter(paths.OrganisationDetails, RequireAdmin,
Guidance(tmpls.Get("organisation_details.gohtml")))
Expand Down
45 changes: 45 additions & 0 deletions internal/page/supporter/view_lpa.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package supporter

import (
"errors"
"net/http"

"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)

type viewLPAData struct {
App page.AppData
Errors validation.List
Donor *actor.DonorProvidedDetails
}

func ViewLPA(tmpl template.Template, donorStore DonorStore) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation) error {
sessionData, err := page.SessionDataFromContext(r.Context())
if err != nil {
return err
}

lpaID := r.FormValue("id")
if lpaID == "" {
return errors.New("lpaID missing from query")
}

sessionData.LpaID = lpaID

ctx := page.ContextWithSessionData(r.Context(), sessionData)

donor, err := donorStore.Get(ctx)
if err != nil {
return err
}

return tmpl(w, &viewLPAData{
App: appData,
Donor: donor,
})
}
}
92 changes: 92 additions & 0 deletions internal/page/supporter/view_lpa_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package supporter

import (
"context"
"net/http"
"net/http/httptest"
"testing"

"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/stretchr/testify/assert"
)

func TestGetViewLPA(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{}), http.MethodGet, "/?id=lpa-id", nil)

donor := &actor.DonorProvidedDetails{LpaID: "lpa-id"}

donorStore := newMockDonorStore(t)
donorStore.EXPECT().
Get(page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: "lpa-id"})).
Return(donor, nil)

template := newMockTemplate(t)
template.EXPECT().
Execute(w, &viewLPAData{
App: testAppData,
Donor: donor,
}).
Return(nil)

err := ViewLPA(template.Execute, donorStore)(testAppData, w, r, &actor.Organisation{})

assert.Nil(t, err)
}

func TestGetViewLPAWithSessionMissing(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{}), http.MethodGet, "/", nil)

err := ViewLPA(nil, nil)(testAppData, w, r, &actor.Organisation{})

assert.Error(t, err)
}

func TestGetViewLPAMissingLPAId(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequest(http.MethodGet, "/", nil)

err := ViewLPA(nil, nil)(testAppData, w, r, &actor.Organisation{})

assert.Error(t, err)
}

func TestGetViewLPAWithDonorStoreError(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{}), http.MethodGet, "/?id=lpa-id", nil)

donorStore := newMockDonorStore(t)
donorStore.EXPECT().
Get(page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: "lpa-id"})).
Return(nil, expectedError)

err := ViewLPA(nil, donorStore)(testAppData, w, r, &actor.Organisation{})

assert.Error(t, err)
}

func TestGetViewLPAWhenTemplateError(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{}), http.MethodGet, "/?id=lpa-id", nil)

donor := &actor.DonorProvidedDetails{LpaID: "lpa-id"}

donorStore := newMockDonorStore(t)
donorStore.EXPECT().
Get(page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: "lpa-id"})).
Return(donor, nil)

template := newMockTemplate(t)
template.EXPECT().
Execute(w, &viewLPAData{
App: testAppData,
Donor: donor,
}).
Return(expectedError)

err := ViewLPA(template.Execute, donorStore)(testAppData, w, r, &actor.Organisation{})

assert.Error(t, err)
}
6 changes: 5 additions & 1 deletion lang/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1125,5 +1125,9 @@
"enterYourName": "Welsh",
"thisWillBeHowYourNameIsDisplayed": "Welsh",
"accessSuspended": "Welsh",
"accessSuspendedContent": "Welsh {{.OrganisationName}}"
"accessSuspendedContent": "Welsh {{.OrganisationName}}",
"lpa": "Welsh",
"viewLPASummary": "Welsh",
"donorAccess": "Welsh",
"viewLPA": "Welsh"
}
6 changes: 5 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1057,5 +1057,9 @@
"enterYourName": "Enter your name",
"thisWillBeHowYourNameIsDisplayed": "This will be how your name is displayed to others in your organisation.",
"accessSuspended": "Access suspended",
"accessSuspendedContent": "<p class=\"govuk-body\">Your access to <span class=\"govuk-!-font-weight-bold\">{{.OrganisationName}}</span> has been temporarily suspended.</p><p class=\"govuk-body\">Contact an admin at your organisation to get access again.</p>"
"accessSuspendedContent": "<p class=\"govuk-body\">Your access to <span class=\"govuk-!-font-weight-bold\">{{.OrganisationName}}</span> has been temporarily suspended.</p><p class=\"govuk-body\">Contact an admin at your organisation to get access again.</p>",
"lpa": "LPA",
"viewLPASummary": "View LPA summary",
"donorAccess": "Donor access",
"viewLPA": "View LPA"
}
4 changes: 2 additions & 2 deletions web/template/supporter/dashboard.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{{ if gt (len .Pagination.Pages) 1 }}
<p class="govuk-body">{{ tr .App "showing" }} <span class="govuk-!-font-weight-bold">{{ .Pagination.Start }}</span> {{ tr .App "to" }} {{ .Pagination.End }} {{ tr .App "of" }} <span class="govuk-!-font-weight-bold">{{ .Pagination.Total }}</span> {{ tr .App "lpas" }}</p>
{{ end }}

<table class="govuk-table">
<thead class="govuk-table__head">
<tr class="govuk-table__row">
Expand All @@ -49,7 +49,7 @@
<span class="govuk-!-font-weight-bold">{{ .Donor.FullName }}</span><br/>
{{ .Donor.Address.Postcode }}
</td>
<td class="govuk-table__cell"><a class="govuk-link" href="{{ link $.App (global.Paths.TaskList.Format .LpaID) }}">{{ .LpaUID }}</a></td>
<td class="govuk-table__cell"><a class="govuk-link" href="{{ link $.App (global.Paths.Supporter.ViewLPA.Format) }}?id={{ .LpaID }}">{{ .LpaUID }}</a></td>
<td class="govuk-table__cell">{{ tr $.App .Type.String }}</td>
<td class="govuk-table__cell">
{{ if not .SignedAt.IsZero }}
Expand Down
24 changes: 24 additions & 0 deletions web/template/supporter/view_lpa.gohtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{ template "page" . }}

{{ define "pageTitle" }}{{ trFormat .App "viewLPA" }}{{ end }}

{{ define "main" }}
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<span class="govuk-caption-xl">{{ .Donor.Donor.FullName }}</span>
<h1 class="govuk-heading-xl">{{ tr .App .Donor.Type.String }} {{tr .App "lpa"}}</h1>

<div class="govuk-inset-text">
<span class="govuk-!-font-weight-bold">{{ tr .App "referenceNumber" }}</span> {{ .Donor.LpaUID }}
</div>

<div class="govuk-button-group">
<a class="govuk-button govuk-button--secondary" href="{{ link $.App (global.Paths.TaskList.Format .Donor.LpaID) }}" data-module="govuk-button">{{ tr .App "goToTaskList" }}</a>
<a class="govuk-button govuk-button--secondary" href="#" data-module="govuk-button">{{ tr .App "viewLPASummary" }}</a>
<a class="govuk-button govuk-button--secondary" href="#" data-module="govuk-button">{{ tr .App "donorAccess" }}</a>
</div>

<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible">
</div>
</div>
{{ end }}

0 comments on commit 4a698fb

Please sign in to comment.