Skip to content

Commit

Permalink
Show progress banner when LPA is submitted
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx committed Dec 9, 2024
1 parent 0fcd72b commit 62c02b5
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 16 deletions.
8 changes: 8 additions & 0 deletions cypress/e2e/donor/progress.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,12 @@ describe('Progress', () => {
cy.contains('Important:').should('not.exist');
cy.visitLpa('/progress');
});

it('shows a notification when the lpa is submitted', () => {
cy.visit('/fixtures?redirect=/progress&progress=signTheLpa');
cy.checkA11yApp();
cy.contains('Important:')
cy.contains('1 notification from OPG');
cy.contains('You’ve submitted your LPA to the Office of the Public Guardian');
});
});
13 changes: 12 additions & 1 deletion internal/donor/donorpage/progress.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package donorpage

import (
"errors"
"net/http"

"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)
Expand All @@ -23,7 +25,7 @@ type progressData struct {
InfoNotifications []progressNotification
}

func Progress(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, progressTracker ProgressTracker) Handler {
func Progress(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, progressTracker ProgressTracker, certificateProviderStore CertificateProviderStore) Handler {
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error {
lpa, err := lpaStoreResolvingService.Get(r.Context())
if err != nil {
Expand All @@ -43,6 +45,15 @@ func Progress(tmpl template.Template, lpaStoreResolvingService LpaStoreResolving
})
}

if lpa.Submitted && lpa.CertificateProvider.SignedAt.IsZero() {
if _, err := certificateProviderStore.GetAny(r.Context()); errors.Is(err, dynamo.NotFoundError{}) {
data.InfoNotifications = append(data.InfoNotifications, progressNotification{
Heading: "youveSubmittedYourLpaToOpg",
Body: "opgIsCheckingYourLpa",
})
}
}

return tmpl(w, data)
}
}
105 changes: 93 additions & 12 deletions internal/donor/donorpage/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import (
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
"github.com/stretchr/testify/assert"
Expand All @@ -14,56 +17,121 @@ import (

func TestGetProgress(t *testing.T) {
testCases := map[string]struct {
provided *donordata.Provided
infoNotifications []progressNotification
donor *donordata.Provided
setupCertificateProviderStore func(*mockCertificateProviderStore_GetAny_Call)
lpa *lpadata.Lpa
infoNotifications []progressNotification
}{
"none": {
provided: &donordata.Provided{LpaUID: "lpa-uid"},
donor: &donordata.Provided{LpaUID: "lpa-uid"},
lpa: &lpadata.Lpa{LpaUID: "lpa-uid"},
},

// you have chosen to confirm your identity at a post office
"going to the post office": {
provided: &donordata.Provided{
donor: &donordata.Provided{
LpaUID: "lpa-uid",
Tasks: donordata.Tasks{
ConfirmYourIdentity: task.IdentityStatePending,
},
},
lpa: &lpadata.Lpa{LpaUID: "lpa-uid"},
infoNotifications: []progressNotification{
{
Heading: "youHaveChosenToConfirmYourIdentityAtPostOffice",
Body: "whenYouHaveConfirmedAtPostOfficeReturnToTaskList",
},
},
},
"confirmed identity": {
donor: &donordata.Provided{
LpaUID: "lpa-uid",
Tasks: donordata.Tasks{
ConfirmYourIdentity: task.IdentityStateCompleted,
},
},
lpa: &lpadata.Lpa{LpaUID: "lpa-uid"},
},

// you've submitted your lpa to the opg
"submitted": {
donor: &donordata.Provided{
LpaUID: "lpa-uid",
SubmittedAt: time.Now(),
},
lpa: &lpadata.Lpa{
LpaUID: "lpa-uid",
Submitted: true,
},
setupCertificateProviderStore: func(call *mockCertificateProviderStore_GetAny_Call) {
call.Return(nil, dynamo.NotFoundError{})
},
infoNotifications: []progressNotification{
{
Heading: "youveSubmittedYourLpaToOpg",
Body: "opgIsCheckingYourLpa",
},
},
},
"submitted and certificate provider started": {
donor: &donordata.Provided{
LpaUID: "lpa-uid",
SubmittedAt: time.Now(),
},
lpa: &lpadata.Lpa{
LpaUID: "lpa-uid",
Submitted: true,
},
setupCertificateProviderStore: func(call *mockCertificateProviderStore_GetAny_Call) {
call.Return(&certificateproviderdata.Provided{}, nil)
},
},
"submitted and certificate provider finished": {
donor: &donordata.Provided{
LpaUID: "lpa-uid",
SubmittedAt: time.Now(),
},
lpa: &lpadata.Lpa{
LpaUID: "lpa-uid",
Submitted: true,
CertificateProvider: lpadata.CertificateProvider{
SignedAt: time.Now(),
},
},
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequest(http.MethodGet, "/", nil)

lpa := &lpadata.Lpa{LpaUID: "lpa-uid"}

lpaStoreResolvingService := newMockLpaStoreResolvingService(t)
lpaStoreResolvingService.EXPECT().
Get(r.Context()).
Return(lpa, nil)
Return(tc.lpa, nil)

progressTracker := newMockProgressTracker(t)
progressTracker.EXPECT().
Progress(lpa).
Progress(tc.lpa).
Return(task.Progress{DonorSigned: task.ProgressTask{Done: true}})

certificateProviderStore := newMockCertificateProviderStore(t)
if tc.setupCertificateProviderStore != nil {
tc.setupCertificateProviderStore(certificateProviderStore.EXPECT().GetAny(r.Context()))
}

template := newMockTemplate(t)
template.EXPECT().
Execute(w, &progressData{
App: testAppData,
Donor: tc.provided,
Donor: tc.donor,
Progress: task.Progress{DonorSigned: task.ProgressTask{Done: true}},
InfoNotifications: tc.infoNotifications,
}).
Return(nil)

err := Progress(template.Execute, lpaStoreResolvingService, progressTracker)(testAppData, w, r, tc.provided)
err := Progress(template.Execute, lpaStoreResolvingService, progressTracker, certificateProviderStore)(testAppData, w, r, tc.donor)
resp := w.Result()

assert.Nil(t, err)
Expand All @@ -81,7 +149,20 @@ func TestGetProgressWhenLpaStoreClientErrors(t *testing.T) {
Get(r.Context()).
Return(nil, expectedError)

err := Progress(nil, lpaStoreResolvingService, nil)(testAppData, w, r, &donordata.Provided{LpaUID: "lpa-uid"})
err := Progress(nil, lpaStoreResolvingService, nil, nil)(testAppData, w, r, &donordata.Provided{LpaUID: "lpa-uid"})
assert.Equal(t, expectedError, err)
}

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

lpaStoreResolvingService := newMockLpaStoreResolvingService(t)
lpaStoreResolvingService.EXPECT().
Get(r.Context()).
Return(&lpadata.Lpa{}, nil)

err := Progress(nil, lpaStoreResolvingService, nil, nil)(testAppData, w, r, &donordata.Provided{LpaUID: "lpa-uid"})
assert.Equal(t, expectedError, err)
}

Expand All @@ -104,6 +185,6 @@ func TestGetProgressOnTemplateError(t *testing.T) {
Execute(w, mock.Anything).
Return(expectedError)

err := Progress(template.Execute, lpaStoreResolvingService, progressTracker)(testAppData, w, r, &donordata.Provided{LpaUID: "lpa-uid"})
err := Progress(template.Execute, lpaStoreResolvingService, progressTracker, nil)(testAppData, w, r, &donordata.Provided{LpaUID: "lpa-uid"})
assert.Equal(t, expectedError, err)
}
2 changes: 1 addition & 1 deletion internal/donor/donorpage/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func Register(
Guidance(tmpls.Get("you_have_submitted_your_lpa.gohtml")))

handleWithDonor(donor.PathProgress, page.None,
Progress(tmpls.Get("progress.gohtml"), lpaStoreResolvingService, progressTracker))
Progress(tmpls.Get("progress.gohtml"), lpaStoreResolvingService, progressTracker, certificateProviderStore))

handleWithDonor(donor.PathUploadEvidenceSSE, page.None,
UploadEvidenceSSE(documentStore, 3*time.Minute, 2*time.Second, time.Now))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func WitnessingAsCertificateProvider(

if data.Errors.None() {
provided.Tasks.SignTheLpa = task.StateCompleted
provided.SubmittedAt = now()

provided.WitnessCodeLimiter = nil
if provided.WitnessedByCertificateProviderAt.IsZero() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func TestPostWitnessingAsCertificateProvider(t *testing.T) {
CertificateProviderCodes: donordata.WitnessCodes{{Code: "1234", Created: testNow}},
CertificateProvider: donordata.CertificateProvider{FirstNames: "Fred"},
WitnessedByCertificateProviderAt: testNow,
SubmittedAt: testNow,
Tasks: donordata.Tasks{
PayForLpa: task.PaymentStateCompleted,
SignTheLpa: task.StateCompleted,
Expand Down Expand Up @@ -158,6 +159,7 @@ func TestPostWitnessingAsCertificateProviderWhenPaymentPending(t *testing.T) {
CertificateProvider: donordata.CertificateProvider{Email: "name@example.com"},
CertificateProviderCodes: donordata.WitnessCodes{{Code: "1234", Created: testNow}},
WitnessedByCertificateProviderAt: testNow,
SubmittedAt: testNow,
Tasks: donordata.Tasks{
PayForLpa: task.PaymentStatePending,
SignTheLpa: task.StateCompleted,
Expand Down
1 change: 1 addition & 0 deletions internal/page/fixtures/donor.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ func updateLPAProgress(
donorDetails.SignedAt = time.Date(2023, time.January, 2, 3, 4, 5, 6, time.UTC)
donorDetails.WitnessedByCertificateProviderAt = time.Date(2023, time.January, 2, 3, 4, 5, 6, time.UTC)
donorDetails.Tasks.SignTheLpa = task.StateCompleted
donorDetails.SubmittedAt = time.Date(2023, time.January, 2, 3, 4, 5, 6, time.UTC)
}

var certificateProviderUID actoruid.UID
Expand Down
4 changes: 3 additions & 1 deletion lang/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1500,5 +1500,7 @@
"other": "{{.PluralCount}} Welsh"
},
"youHaveChosenToConfirmYourIdentityAtPostOffice": "Welsh",
"whenYouHaveConfirmedAtPostOfficeReturnToTaskList": "Welsh"
"whenYouHaveConfirmedAtPostOfficeReturnToTaskList": "Welsh",
"youveSubmittedYourLpaToOpg": "Welsh",
"opgIsCheckingYourLpa": "Welsh"
}
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1396,5 +1396,7 @@
"other": "{{.PluralCount}} notifications from OPG"
},
"youHaveChosenToConfirmYourIdentityAtPostOffice": "You have chosen to confirm your identity at a Post Office",
"whenYouHaveConfirmedAtPostOfficeReturnToTaskList": "When you have confirmed your identity at a Post Office, return to your task list for the steps you must take to complete this process."
"whenYouHaveConfirmedAtPostOfficeReturnToTaskList": "When you have confirmed your identity at a Post Office, return to your task list for the steps you must take to complete this process.",
"youveSubmittedYourLpaToOpg": "You’ve submitted your LPA to the Office of the Public Guardian (OPG)",
"opgIsCheckingYourLpa": "OPG is checking your LPA. We will contact you if there is anything you need to do."
}

0 comments on commit 62c02b5

Please sign in to comment.