diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index 063e7ba18..0cd58739a 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -21,9 +21,3 @@ services: - SYS_PTRACE ports: - "2345:2345" - - mock-pay: - image: outofcoffee/imposter:latest - container_name: mock-pay - volumes: - - ./mock-pay/:/opt/imposter/config/ diff --git a/internal/donor/donorpage/progress.go b/internal/donor/donorpage/progress.go index 5d684b405..93410cbb6 100644 --- a/internal/donor/donorpage/progress.go +++ b/internal/donor/donorpage/progress.go @@ -19,12 +19,19 @@ type progressData struct { App appcontext.Data Errors validation.List Donor *donordata.Provided - Voucher *voucherdata.Provided Progress task.Progress InfoNotifications []progressNotification SuccessNotifications []progressNotification } +func (d *progressData) addInfo(heading, body string) { + d.InfoNotifications = append(d.InfoNotifications, progressNotification{Heading: heading, Body: body}) +} + +func (d *progressData) addSuccess(heading, body string) { + d.SuccessNotifications = append(d.SuccessNotifications, progressNotification{Heading: heading, Body: body}) +} + type progressNotification struct { Heading string Body string @@ -42,6 +49,14 @@ func Progress(tmpl template.Template, lpaStoreResolvingService LpaStoreResolving return certificateProviderErr } + var voucher *voucherdata.Provided + if donor.Voucher.FirstNames != "" { + voucher, err = voucherStore.GetAny(r.Context()) + if err != nil && !errors.Is(err, dynamo.NotFoundError{}) { + return err + } + } + data := &progressData{ App: appData, Donor: donor, @@ -49,219 +64,208 @@ func Progress(tmpl template.Template, lpaStoreResolvingService LpaStoreResolving } if !donor.WithdrawnAt.IsZero() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: "lpaRevoked", - Body: appData.Localizer.Format( + data.addInfo("lpaRevoked", + appData.Localizer.Format( "weContactedYouOnAboutLPARevokedOPGWillNotRegister", map[string]any{"ContactedDate": appData.Localizer.FormatDate(donor.WithdrawnAt)}, ), - }) + ) return tmpl(w, data) } - if donor.IdentityUserData.Status.IsUnknown() && donor.Tasks.ConfirmYourIdentity.IsPending() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: "youHaveChosenToConfirmYourIdentityAtPostOffice", - Body: "whenYouHaveConfirmedAtPostOfficeReturnToTaskList", - }) + if lpa.Submitted && + (lpa.CertificateProvider.SignedAt == nil || lpa.CertificateProvider.SignedAt.IsZero()) && + errors.Is(certificateProviderErr, dynamo.NotFoundError{}) { + data.addInfo("youveSubmittedYourLpaToOpg", "opgIsCheckingYourLpa") } - if lpa.Submitted && (lpa.CertificateProvider.SignedAt == nil || lpa.CertificateProvider.SignedAt.IsZero()) { - if errors.Is(certificateProviderErr, dynamo.NotFoundError{}) { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: "youveSubmittedYourLpaToOpg", - Body: "opgIsCheckingYourLpa", - }) - } + if donor.IdentityUserData.Status.IsUnknown() && + donor.Tasks.ConfirmYourIdentity.IsPending() { + data.addInfo("youHaveChosenToConfirmYourIdentityAtPostOffice", "whenYouHaveConfirmedAtPostOfficeReturnToTaskList") } if donor.Tasks.PayForLpa.IsMoreEvidenceRequired() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: "weNeedMoreEvidenceToMakeADecisionAboutYourLPAFee", - Body: appData.Localizer.Format( + data.addInfo( + "weNeedMoreEvidenceToMakeADecisionAboutYourLPAFee", + appData.Localizer.Format( "weContactedYouOnWithGuidanceAboutWhatToDoNext", map[string]any{"ContactedDate": appData.Localizer.FormatDate(donor.MoreEvidenceRequiredAt)}, + )) + } + + if !donor.Tasks.ConfirmYourIdentity.IsCompleted() && + donor.Voucher.FirstNames != "" && + donor.VoucherInvitedAt.IsZero() && + !donor.Tasks.PayForLpa.IsCompleted() { + data.addInfo( + "youMustPayForYourLPA", + appData.Localizer.Format( + "returnToTaskListToPayForLPAWeWillThenContactVoucher", + map[string]any{"VoucherFullName": donor.Voucher.FullName()}, ), - }) + ) } - if !donor.Tasks.ConfirmYourIdentity.IsCompleted() && donor.Voucher.FirstNames != "" { - if donor.VoucherInvitedAt.IsZero() && !donor.Tasks.PayForLpa.IsCompleted() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: "youMustPayForYourLPA", - Body: appData.Localizer.Format( - "returnToTaskListToPayForLPAWeWillThenContactVoucher", - map[string]any{"VoucherFullName": donor.Voucher.FullName()}, - ), - }) - } else if !donor.VoucherInvitedAt.IsZero() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.Format( - "weHaveContactedVoucherToConfirmYourIdentity", - map[string]any{"VoucherFullName": donor.Voucher.FullName()}, - ), - Body: "youDoNotNeedToTakeAnyAction", - }) - } + if !donor.Tasks.ConfirmYourIdentity.IsCompleted() && + donor.Voucher.FirstNames != "" && + !donor.VoucherInvitedAt.IsZero() { + data.addInfo( + appData.Localizer.Format( + "weHaveContactedVoucherToConfirmYourIdentity", + map[string]any{"VoucherFullName": donor.Voucher.FullName()}, + ), + "youDoNotNeedToTakeAnyAction", + ) } if !donor.Tasks.ConfirmYourIdentity.IsCompleted() && !donor.FailedVoucher.FailedAt.IsZero() && !donor.WantVoucher.IsNo() && donor.Voucher.FirstNames == "" { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.Format( + data.addInfo( + appData.Localizer.Format( "voucherHasBeenUnableToConfirmYourIdentity", map[string]any{"VoucherFullName": donor.FailedVoucher.FullName()}, ), - Body: appData.Localizer.Format( + appData.Localizer.Format( "weContactedYouOnWithGuidanceAboutWhatToDoNext", map[string]any{"ContactedDate": appData.Localizer.FormatDate(donor.FailedVoucher.FailedAt)}, ), - }) + ) } - if lpa.Status.IsDoNotRegister() && !donor.DoNotRegisterAt.IsZero() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.T("thereIsAProblemWithYourLpa"), - Body: appData.Localizer.Format( + if lpa.Status.IsDoNotRegister() && + !donor.DoNotRegisterAt.IsZero() { + data.addInfo( + "thereIsAProblemWithYourLpa", + appData.Localizer.Format( "weContactedYouOnWithGuidanceAboutWhatToDoNext", map[string]any{"ContactedDate": appData.Localizer.FormatDate(donor.DoNotRegisterAt)}, ), - }) + ) } if donor.IdentityUserData.Status.IsFailed() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.T("youHaveBeenUnableToConfirmYourIdentity"), - Body: appData.Localizer.Format( + data.addInfo( + "youHaveBeenUnableToConfirmYourIdentity", + appData.Localizer.Format( "weContactedYouOnWithGuidanceAboutWhatToDoNext", map[string]any{"ContactedDate": appData.Localizer.FormatDate(donor.IdentityUserData.CheckedAt)}, ), - }) + ) } - if certificateProviderErr == nil && certificateProvider.IdentityUserData.Status.IsFailed() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.Format( + if certificateProviderErr == nil && + certificateProvider.IdentityUserData.Status.IsFailed() { + data.addInfo( + appData.Localizer.Format( "certificateProviderHasBeenUnableToConfirmIdentity", map[string]any{"CertificateProviderFullName": lpa.CertificateProvider.FullName()}, ), - Body: appData.Localizer.Format( + appData.Localizer.Format( "weContactedYouOnWithGuidanceAboutWhatToDoNext", map[string]any{"ContactedDate": appData.Localizer.FormatDate(certificateProvider.IdentityUserData.CheckedAt)}, ), - }) + ) } if !donor.HasSeenSuccessfulVouchBanner && donor.Tasks.ConfirmYourIdentity.IsCompleted() && - donor.Voucher.FirstNames != "" { - voucher, err := voucherStore.GetAny(r.Context()) - if err != nil && !errors.Is(err, dynamo.NotFoundError{}) { - return err - } + !donor.Tasks.SignTheLpa.IsCompleted() && + voucher != nil && + !voucher.SignedAt.IsZero() { + data.addSuccess( + appData.Localizer.Format( + "voucherHasConfirmedYourIdentity", + map[string]any{"VoucherFullName": voucher.FullName()}, + ), + "returnToYourTaskListForInformationAboutWhatToDoNext", + ) - if voucher != nil && !voucher.SignedAt.IsZero() { - body := "returnToYourTaskListForInformationAboutWhatToDoNext" - if donor.Tasks.SignTheLpa.IsCompleted() { - body = "youDoNotNeedToTakeAnyAction" - } - - data.SuccessNotifications = append(data.SuccessNotifications, progressNotification{ - Heading: appData.Localizer.Format( - "voucherHasConfirmedYourIdentity", - map[string]any{"VoucherFullName": voucher.FullName()}, - ), - Body: body, - }) - - donor.HasSeenSuccessfulVouchBanner = true - - if err = donorStore.Put(r.Context(), donor); err != nil { - return err - } - } + donor.HasSeenSuccessfulVouchBanner = true } - if donor.Tasks.PayForLpa.IsPending() && donor.FeeAmount() == 0 { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.T("weAreReviewingTheEvidenceYouSent"), - Body: appData.Localizer.T("ifYourEvidenceIsApprovedWillShowPaid"), - }) + if !donor.HasSeenSuccessfulVouchBanner && + donor.Tasks.ConfirmYourIdentity.IsCompleted() && + donor.Tasks.SignTheLpa.IsCompleted() && + voucher != nil && + !voucher.SignedAt.IsZero() { + data.addSuccess( + appData.Localizer.Format( + "voucherHasConfirmedYourIdentity", + map[string]any{"VoucherFullName": voucher.FullName()}, + ), + "youDoNotNeedToTakeAnyAction", + ) + + donor.HasSeenSuccessfulVouchBanner = true + } + + if donor.Tasks.PayForLpa.IsPending() && + donor.FeeAmount() == 0 { + data.addInfo("weAreReviewingTheEvidenceYouSent", "ifYourEvidenceIsApprovedWillShowPaid") } if !donor.HasSeenReducedFeeApprovalNotification && !donor.ReducedFeeApprovedAt.IsZero() && donor.Tasks.PayForLpa.IsCompleted() { - data.SuccessNotifications = append(data.SuccessNotifications, progressNotification{ - Heading: "weHaveApprovedYourLPAFeeRequest", - Body: "yourLPAIsNowPaid", - }) + data.addSuccess("weHaveApprovedYourLPAFeeRequest", "yourLPAIsNowPaid") donor.HasSeenReducedFeeApprovalNotification = true + } - if err = donorStore.Put(r.Context(), donor); err != nil { - return fmt.Errorf("failed to update donor: %v", err) - } + if donor.RegisteringWithCourtOfProtection && + donor.Tasks.PayForLpa.IsCompleted() && + !donor.WitnessedByCertificateProviderAt.IsZero() { + data.addInfo("yourLpaMustBeReviewedByCourtOfProtection", "opgIsCompletingChecksSoYouCanSubmitToCourtOfProtection") } - if donor.RegisteringWithCourtOfProtection { - if donor.Tasks.PayForLpa.IsCompleted() && !donor.WitnessedByCertificateProviderAt.IsZero() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.T("yourLpaMustBeReviewedByCourtOfProtection"), - Body: appData.Localizer.T("opgIsCompletingChecksSoYouCanSubmitToCourtOfProtection"), - }) - } else if donor.Tasks.PayForLpa.IsCompleted() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.T("yourLpaMustBeReviewedByCourtOfProtection"), - Body: appData.Localizer.T("returnToYourTaskListToSignThenOpgWillCheck"), - }) - } else if !donor.WitnessedByCertificateProviderAt.IsZero() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.T("yourLpaMustBeReviewedByCourtOfProtection"), - Body: appData.Localizer.T("whenYouHavePaidOpgWillCheck"), - }) - } + if donor.RegisteringWithCourtOfProtection && + donor.Tasks.PayForLpa.IsCompleted() && + donor.WitnessedByCertificateProviderAt.IsZero() { + data.addInfo("yourLpaMustBeReviewedByCourtOfProtection", "returnToYourTaskListToSignThenOpgWillCheck") } - if now().After(donor.IdentityDeadline()) && donor.Tasks.SignTheLpa.IsCompleted() && !donor.Tasks.ConfirmYourIdentity.IsCompleted() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.T("yourLPACannotBeRegisteredByOPG"), - Body: appData.Localizer.T("youDidNotConfirmYourIdentityWithinSixMonthsOfSigning"), - }) + if donor.RegisteringWithCourtOfProtection && + !donor.Tasks.PayForLpa.IsCompleted() && + !donor.WitnessedByCertificateProviderAt.IsZero() { + data.addInfo("yourLpaMustBeReviewedByCourtOfProtection", "whenYouHavePaidOpgWillCheck") } - if donor.IdentityUserData.Status.IsExpired() && !donor.Tasks.SignTheLpa.IsCompleted() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.T("youMustConfirmYourIdentityAgain"), - Body: appData.Localizer.T("youDidNotSignYourLPAWithinSixMonthsOfConfirmingYourIdentity"), - }) + if now().After(donor.IdentityDeadline()) && + donor.Tasks.SignTheLpa.IsCompleted() && + !donor.Tasks.ConfirmYourIdentity.IsCompleted() { + data.addInfo("yourLPACannotBeRegisteredByOPG", "youDidNotConfirmYourIdentityWithinSixMonthsOfSigning") + } + + if donor.IdentityUserData.Status.IsExpired() && + !donor.Tasks.SignTheLpa.IsCompleted() { + data.addInfo("youMustConfirmYourIdentityAgain", "youDidNotSignYourLPAWithinSixMonthsOfConfirmingYourIdentity") } if lpa.Status.IsStatutoryWaitingPeriod() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.T("yourLpaIsAwaitingRegistration"), - Body: appData.Localizer.T("theOpgWillRegisterYourLpaAtEndOfWaitingPeriod"), - }) + data.addInfo("yourLpaIsAwaitingRegistration", "theOpgWillRegisterYourLpaAtEndOfWaitingPeriod") } - if donor.Tasks.ConfirmYourIdentity.IsPending() && donor.ContinueWithMismatchedIdentity { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.T("confirmationOfIdentityPending"), - Body: appData.Localizer.T("youDoNotNeedToTakeAnyAction"), - }) + if donor.Tasks.ConfirmYourIdentity.IsPending() && + donor.ContinueWithMismatchedIdentity { + data.addInfo("confirmationOfIdentityPending", "youDoNotNeedToTakeAnyAction") } - if !lpa.Status.IsRegistered() && !donor.PriorityCorrespondenceSentAt.IsZero() { - data.InfoNotifications = append(data.InfoNotifications, progressNotification{ - Heading: appData.Localizer.T("thereIsAProblemWithYourLpa"), - Body: appData.Localizer.Format( + if !lpa.Status.IsRegistered() && + !donor.PriorityCorrespondenceSentAt.IsZero() { + data.addInfo( + "thereIsAProblemWithYourLpa", + appData.Localizer.Format( "weContactedYouOnWithGuidanceAboutWhatToDoNext", map[string]any{"ContactedDate": appData.Localizer.FormatDate(donor.PriorityCorrespondenceSentAt)}, ), - }) + ) + } + + if err := donorStore.Put(r.Context(), donor); err != nil { + return fmt.Errorf("failed to update donor: %v", err) } return tmpl(w, data) diff --git a/internal/donor/donorpage/progress_test.go b/internal/donor/donorpage/progress_test.go index 239863289..fe1c059f0 100644 --- a/internal/donor/donorpage/progress_test.go +++ b/internal/donor/donorpage/progress_test.go @@ -26,6 +26,16 @@ func TestGetProgress(t *testing.T) { call.Return(nil, dynamo.NotFoundError{}) } + voucherStoreNotFound := func(call *mockVoucherStore_GetAny_Call) { + call.Return(nil, dynamo.NotFoundError{}) + } + + donorStoreNoUpdate := func(_ *testing.T, s *mockDonorStore) { + s.EXPECT(). + Put(mock.Anything, mock.Anything). + Return(nil) + } + testCases := map[string]struct { donor *donordata.Provided setupCertificateProviderStore func(*mockCertificateProviderStore_GetAny_Call) @@ -40,6 +50,7 @@ func TestGetProgress(t *testing.T) { donor: &donordata.Provided{LpaUID: "lpa-uid"}, lpa: &lpadata.Lpa{LpaUID: "lpa-uid"}, setupCertificateProviderStore: certificateProviderStoreNotFound, + setupDonorStore: donorStoreNoUpdate, }, // you have chosen to confirm your identity at a post office @@ -58,6 +69,7 @@ func TestGetProgress(t *testing.T) { Body: "whenYouHaveConfirmedAtPostOfficeReturnToTaskList", }, }, + setupDonorStore: donorStoreNoUpdate, }, "confirmed identity": { donor: &donordata.Provided{ @@ -68,6 +80,7 @@ func TestGetProgress(t *testing.T) { }, lpa: &lpadata.Lpa{LpaUID: "lpa-uid"}, setupCertificateProviderStore: certificateProviderStoreNotFound, + setupDonorStore: donorStoreNoUpdate, }, // you've submitted your lpa to the opg @@ -87,6 +100,7 @@ func TestGetProgress(t *testing.T) { Body: "opgIsCheckingYourLpa", }, }, + setupDonorStore: donorStoreNoUpdate, }, "submitted and certificate provider started": { donor: &donordata.Provided{ @@ -99,6 +113,7 @@ func TestGetProgress(t *testing.T) { setupCertificateProviderStore: func(call *mockCertificateProviderStore_GetAny_Call) { call.Return(&certificateproviderdata.Provided{}, nil) }, + setupDonorStore: donorStoreNoUpdate, }, "submitted and certificate provider finished": { donor: &donordata.Provided{ @@ -114,6 +129,7 @@ func TestGetProgress(t *testing.T) { setupCertificateProviderStore: func(call *mockCertificateProviderStore_GetAny_Call) { call.Return(&certificateproviderdata.Provided{}, nil) }, + setupDonorStore: donorStoreNoUpdate, }, "more evidence required": { donor: &donordata.Provided{ @@ -143,6 +159,7 @@ func TestGetProgress(t *testing.T) { return l }, + setupDonorStore: donorStoreNoUpdate, }, "voucher has been contacted": { donor: &donordata.Provided{ @@ -170,6 +187,8 @@ func TestGetProgress(t *testing.T) { Return("H") return l }, + setupVoucherStore: voucherStoreNotFound, + setupDonorStore: donorStoreNoUpdate, }, "voucher has been chosen but not contacted": { donor: &donordata.Provided{ @@ -197,6 +216,8 @@ func TestGetProgress(t *testing.T) { Return("B") return l }, + setupVoucherStore: voucherStoreNotFound, + setupDonorStore: donorStoreNoUpdate, }, "voucher was unsuccessful": { donor: &donordata.Provided{ @@ -237,6 +258,7 @@ func TestGetProgress(t *testing.T) { return l }, + setupDonorStore: donorStoreNoUpdate, }, "do not register": { donor: &donordata.Provided{ @@ -250,15 +272,12 @@ func TestGetProgress(t *testing.T) { setupCertificateProviderStore: certificateProviderStoreNotFound, infoNotifications: []progressNotification{ { - Heading: "H", + Heading: "thereIsAProblemWithYourLpa", Body: "B", }, }, setupLocalizer: func(t *testing.T) *mockLocalizer { l := newMockLocalizer(t) - l.EXPECT(). - T("thereIsAProblemWithYourLpa"). - Return("H") l.EXPECT(). Format( "weContactedYouOnWithGuidanceAboutWhatToDoNext", @@ -270,6 +289,7 @@ func TestGetProgress(t *testing.T) { Return("translated date") return l }, + setupDonorStore: donorStoreNoUpdate, }, "donor identity check failed": { donor: &donordata.Provided{ @@ -283,15 +303,12 @@ func TestGetProgress(t *testing.T) { setupCertificateProviderStore: certificateProviderStoreNotFound, infoNotifications: []progressNotification{ { - Heading: "H", + Heading: "youHaveBeenUnableToConfirmYourIdentity", Body: "B", }, }, setupLocalizer: func(t *testing.T) *mockLocalizer { l := newMockLocalizer(t) - l.EXPECT(). - T("youHaveBeenUnableToConfirmYourIdentity"). - Return("H") l.EXPECT(). Format( "weContactedYouOnWithGuidanceAboutWhatToDoNext", @@ -303,6 +320,7 @@ func TestGetProgress(t *testing.T) { Return("translated date") return l }, + setupDonorStore: donorStoreNoUpdate, }, "certificate provider identity check failed": { donor: &donordata.Provided{LpaUID: "lpa-uid"}, @@ -346,6 +364,7 @@ func TestGetProgress(t *testing.T) { Return("translated date") return l }, + setupDonorStore: donorStoreNoUpdate, }, "voucher has vouched, lpa not signed": { donor: &donordata.Provided{ @@ -441,6 +460,10 @@ func TestGetProgress(t *testing.T) { }, lpa: &lpadata.Lpa{LpaUID: "lpa-uid"}, setupCertificateProviderStore: certificateProviderStoreNotFound, + setupVoucherStore: func(call *mockVoucherStore_GetAny_Call) { + call.Return(&voucherdata.Provided{FirstNames: "c", LastName: "d", SignedAt: signedAt}, nil) + }, + setupDonorStore: donorStoreNoUpdate, }, "reduced fee approved payment task complete": { donor: &donordata.Provided{ @@ -476,6 +499,7 @@ func TestGetProgress(t *testing.T) { }, lpa: &lpadata.Lpa{LpaUID: "lpa-uid"}, setupCertificateProviderStore: certificateProviderStoreNotFound, + setupDonorStore: donorStoreNoUpdate, }, "applied for reduced fee": { donor: &donordata.Provided{ @@ -488,14 +512,9 @@ func TestGetProgress(t *testing.T) { lpa: &lpadata.Lpa{}, setupCertificateProviderStore: certificateProviderStoreNotFound, infoNotifications: []progressNotification{ - {Heading: "H", Body: "B"}, - }, - setupLocalizer: func(t *testing.T) *mockLocalizer { - l := newMockLocalizer(t) - l.EXPECT().T("weAreReviewingTheEvidenceYouSent").Return("H") - l.EXPECT().T("ifYourEvidenceIsApprovedWillShowPaid").Return("B") - return l + {Heading: "weAreReviewingTheEvidenceYouSent", Body: "ifYourEvidenceIsApprovedWillShowPaid"}, }, + setupDonorStore: donorStoreNoUpdate, }, "applying to court of protection and signed and paid": { donor: &donordata.Provided{ @@ -508,14 +527,9 @@ func TestGetProgress(t *testing.T) { lpa: &lpadata.Lpa{}, setupCertificateProviderStore: certificateProviderStoreNotFound, infoNotifications: []progressNotification{ - {Heading: "H", Body: "B"}, - }, - setupLocalizer: func(t *testing.T) *mockLocalizer { - l := newMockLocalizer(t) - l.EXPECT().T("yourLpaMustBeReviewedByCourtOfProtection").Return("H") - l.EXPECT().T("opgIsCompletingChecksSoYouCanSubmitToCourtOfProtection").Return("B") - return l + {Heading: "yourLpaMustBeReviewedByCourtOfProtection", Body: "opgIsCompletingChecksSoYouCanSubmitToCourtOfProtection"}, }, + setupDonorStore: donorStoreNoUpdate, }, "applying to court of protection and signed": { donor: &donordata.Provided{ @@ -525,14 +539,9 @@ func TestGetProgress(t *testing.T) { lpa: &lpadata.Lpa{}, setupCertificateProviderStore: certificateProviderStoreNotFound, infoNotifications: []progressNotification{ - {Heading: "H", Body: "B"}, - }, - setupLocalizer: func(t *testing.T) *mockLocalizer { - l := newMockLocalizer(t) - l.EXPECT().T("yourLpaMustBeReviewedByCourtOfProtection").Return("H") - l.EXPECT().T("whenYouHavePaidOpgWillCheck").Return("B") - return l + {Heading: "yourLpaMustBeReviewedByCourtOfProtection", Body: "whenYouHavePaidOpgWillCheck"}, }, + setupDonorStore: donorStoreNoUpdate, }, "applying to court of protection and paid": { donor: &donordata.Provided{ @@ -544,14 +553,9 @@ func TestGetProgress(t *testing.T) { lpa: &lpadata.Lpa{}, setupCertificateProviderStore: certificateProviderStoreNotFound, infoNotifications: []progressNotification{ - {Heading: "H", Body: "B"}, - }, - setupLocalizer: func(t *testing.T) *mockLocalizer { - l := newMockLocalizer(t) - l.EXPECT().T("yourLpaMustBeReviewedByCourtOfProtection").Return("H") - l.EXPECT().T("returnToYourTaskListToSignThenOpgWillCheck").Return("B") - return l + {Heading: "yourLpaMustBeReviewedByCourtOfProtection", Body: "returnToYourTaskListToSignThenOpgWillCheck"}, }, + setupDonorStore: donorStoreNoUpdate, }, "withdrawn": { donor: &donordata.Provided{ @@ -593,14 +597,9 @@ func TestGetProgress(t *testing.T) { lpa: &lpadata.Lpa{}, setupCertificateProviderStore: certificateProviderStoreNotFound, infoNotifications: []progressNotification{ - {Heading: "H", Body: "B"}, - }, - setupLocalizer: func(t *testing.T) *mockLocalizer { - l := newMockLocalizer(t) - l.EXPECT().T("yourLPACannotBeRegisteredByOPG").Return("H") - l.EXPECT().T("youDidNotConfirmYourIdentityWithinSixMonthsOfSigning").Return("B") - return l + {Heading: "yourLPACannotBeRegisteredByOPG", Body: "youDidNotConfirmYourIdentityWithinSixMonthsOfSigning"}, }, + setupDonorStore: donorStoreNoUpdate, }, "identity expired and LPA not signed": { donor: &donordata.Provided{ @@ -610,14 +609,9 @@ func TestGetProgress(t *testing.T) { lpa: &lpadata.Lpa{}, setupCertificateProviderStore: certificateProviderStoreNotFound, infoNotifications: []progressNotification{ - {Heading: "H", Body: "B"}, - }, - setupLocalizer: func(t *testing.T) *mockLocalizer { - l := newMockLocalizer(t) - l.EXPECT().T("youMustConfirmYourIdentityAgain").Return("H") - l.EXPECT().T("youDidNotSignYourLPAWithinSixMonthsOfConfirmingYourIdentity").Return("B") - return l + {Heading: "youMustConfirmYourIdentityAgain", Body: "youDidNotSignYourLPAWithinSixMonthsOfConfirmingYourIdentity"}, }, + setupDonorStore: donorStoreNoUpdate, }, "statutory waiting period": { donor: &donordata.Provided{}, @@ -626,14 +620,9 @@ func TestGetProgress(t *testing.T) { }, setupCertificateProviderStore: certificateProviderStoreNotFound, infoNotifications: []progressNotification{ - {Heading: "H", Body: "B"}, - }, - setupLocalizer: func(t *testing.T) *mockLocalizer { - l := newMockLocalizer(t) - l.EXPECT().T("yourLpaIsAwaitingRegistration").Return("H") - l.EXPECT().T("theOpgWillRegisterYourLpaAtEndOfWaitingPeriod").Return("B") - return l + {Heading: "yourLpaIsAwaitingRegistration", Body: "theOpgWillRegisterYourLpaAtEndOfWaitingPeriod"}, }, + setupDonorStore: donorStoreNoUpdate, }, "identity mismatch pending": { donor: &donordata.Provided{ @@ -646,14 +635,9 @@ func TestGetProgress(t *testing.T) { lpa: &lpadata.Lpa{}, setupCertificateProviderStore: certificateProviderStoreNotFound, infoNotifications: []progressNotification{ - {Heading: "H", Body: "B"}, - }, - setupLocalizer: func(t *testing.T) *mockLocalizer { - l := newMockLocalizer(t) - l.EXPECT().T("confirmationOfIdentityPending").Return("H") - l.EXPECT().T("youDoNotNeedToTakeAnyAction").Return("B") - return l + {Heading: "confirmationOfIdentityPending", Body: "youDoNotNeedToTakeAnyAction"}, }, + setupDonorStore: donorStoreNoUpdate, }, "priority correspondence sent": { donor: &donordata.Provided{ @@ -662,15 +646,15 @@ func TestGetProgress(t *testing.T) { lpa: &lpadata.Lpa{}, setupCertificateProviderStore: certificateProviderStoreNotFound, infoNotifications: []progressNotification{ - {Heading: "H", Body: "B"}, + {Heading: "thereIsAProblemWithYourLpa", Body: "B"}, }, setupLocalizer: func(t *testing.T) *mockLocalizer { l := newMockLocalizer(t) - l.EXPECT().T("thereIsAProblemWithYourLpa").Return("H") l.EXPECT().Format("weContactedYouOnWithGuidanceAboutWhatToDoNext", map[string]any{"ContactedDate": "translated date"}).Return("B") l.EXPECT().FormatDate(testNow).Return("translated date") return l }, + setupDonorStore: donorStoreNoUpdate, }, "priority correspondence sent registered": { donor: &donordata.Provided{ @@ -680,6 +664,7 @@ func TestGetProgress(t *testing.T) { Status: lpadata.StatusRegistered, }, setupCertificateProviderStore: certificateProviderStoreNotFound, + setupDonorStore: donorStoreNoUpdate, }, } @@ -776,11 +761,6 @@ func TestGetProgressWhenVoucherStoreErrors(t *testing.T) { Get(mock.Anything). Return(&lpadata.Lpa{}, nil) - progressTracker := newMockProgressTracker(t) - progressTracker.EXPECT(). - Progress(mock.Anything). - Return(task.Progress{}) - certificateProviderStore := newMockCertificateProviderStore(t) certificateProviderStore.EXPECT(). GetAny(mock.Anything). @@ -791,7 +771,7 @@ func TestGetProgressWhenVoucherStoreErrors(t *testing.T) { GetAny(mock.Anything). Return(nil, expectedError) - err := Progress(nil, lpaStoreResolvingService, progressTracker, certificateProviderStore, voucherStore, nil, testNowFn)(testAppData, w, r, &donordata.Provided{ + err := Progress(nil, lpaStoreResolvingService, nil, certificateProviderStore, voucherStore, nil, testNowFn)(testAppData, w, r, &donordata.Provided{ LpaUID: "lpa-uid", Tasks: donordata.Tasks{ConfirmYourIdentity: task.IdentityStateCompleted}, Voucher: donordata.Voucher{FirstNames: "a"}, @@ -799,7 +779,7 @@ func TestGetProgressWhenVoucherStoreErrors(t *testing.T) { assert.Equal(t, expectedError, err) } -func TestGetProgressWhenDonorStoreErrors(t *testing.T) { +func TestGetProgressOnTemplateError(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/", nil) @@ -818,56 +798,17 @@ func TestGetProgressWhenDonorStoreErrors(t *testing.T) { GetAny(mock.Anything). Return(nil, dynamo.NotFoundError{}) - voucherStore := newMockVoucherStore(t) - voucherStore.EXPECT(). - GetAny(mock.Anything). - Return(&voucherdata.Provided{SignedAt: time.Now()}, nil) - donorStore := newMockDonorStore(t) donorStore.EXPECT(). Put(mock.Anything, mock.Anything). - Return(expectedError) - - localizer := newMockLocalizer(t) - localizer.EXPECT(). - Format(mock.Anything, mock.Anything). - Return("") - - testAppData.Localizer = localizer - - err := Progress(nil, lpaStoreResolvingService, progressTracker, certificateProviderStore, voucherStore, donorStore, time.Now)(testAppData, w, r, &donordata.Provided{ - LpaUID: "lpa-uid", - Tasks: donordata.Tasks{ConfirmYourIdentity: task.IdentityStateCompleted}, - Voucher: donordata.Voucher{FirstNames: "a"}, - }) - assert.Equal(t, expectedError, err) -} - -func TestGetProgressOnTemplateError(t *testing.T) { - w := httptest.NewRecorder() - r, _ := http.NewRequest(http.MethodGet, "/", nil) - - lpaStoreResolvingService := newMockLpaStoreResolvingService(t) - lpaStoreResolvingService.EXPECT(). - Get(mock.Anything). - Return(&lpadata.Lpa{}, nil) - - progressTracker := newMockProgressTracker(t) - progressTracker.EXPECT(). - Progress(mock.Anything). - Return(task.Progress{}) - - certificateProviderStore := newMockCertificateProviderStore(t) - certificateProviderStore.EXPECT(). - GetAny(mock.Anything). - Return(nil, dynamo.NotFoundError{}) + Return(nil) template := newMockTemplate(t) template.EXPECT(). Execute(w, mock.Anything). Return(expectedError) - err := Progress(template.Execute, lpaStoreResolvingService, progressTracker, certificateProviderStore, nil, nil, testNowFn)(testAppData, w, r, &donordata.Provided{LpaUID: "lpa-uid"}) + err := Progress(template.Execute, lpaStoreResolvingService, progressTracker, certificateProviderStore, nil, donorStore, testNowFn)(testAppData, w, r, &donordata.Provided{LpaUID: "lpa-uid"}) assert.Equal(t, expectedError, err) }