diff --git a/internal/app/app.go b/internal/app/app.go index 930be4dcb8..a0fb3a3125 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -113,7 +113,7 @@ func App( progressTracker := task.ProgressTracker{Localizer: localizer} shareCodeSender := sharecode.NewSender(shareCodeStore, notifyClient, appPublicURL, random.String, eventClient) - witnessCodeSender := donor.NewWitnessCodeSender(donorStore, notifyClient, localizer) + witnessCodeSender := donor.NewWitnessCodeSender(donorStore, certificateProviderStore, notifyClient, localizer) lpaStoreResolvingService := lpastore.NewResolvingService(donorStore, lpaStoreClient) diff --git a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney.go b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney.go index 9e1e847f34..4eb36fde59 100644 --- a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney.go +++ b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney.go @@ -47,7 +47,7 @@ func ConfirmDontWantToBeAttorney(tmpl template.Template, lpaStoreResolvingServic DonorStartPageURL: appPublicURL + page.PathStart.Format(), } - if err := notifyClient.SendActorEmail(r.Context(), lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { + if err := notifyClient.SendActorEmail(r.Context(), lpa.Donor.ContactLanguagePreference, lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { return err } diff --git a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out.go b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out.go index add6f0dff6..d52f4eb9e4 100644 --- a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out.go +++ b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out.go @@ -59,7 +59,7 @@ func ConfirmDontWantToBeAttorneyLoggedOut(tmpl template.Template, shareCodeStore DonorStartPageURL: appPublicURL + page.PathStart.Format(), } - if err := notifyClient.SendActorEmail(ctx, lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { + if err := notifyClient.SendActorEmail(ctx, lpa.Donor.ContactLanguagePreference, lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { return err } diff --git a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out_test.go b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out_test.go index 832f5dd750..54116dc43b 100644 --- a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out_test.go +++ b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out_test.go @@ -10,6 +10,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -157,6 +158,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) { SignedAt: time.Now(), Donor: lpadata.Donor{ FirstNames: "a b", LastName: "c", Email: "a@example.com", + ContactLanguagePreference: localize.En, }, Attorneys: lpadata.Attorneys{ TrustCorporation: lpadata.TrustCorporation{UID: trustCorporationUID, Name: "trusty"}, @@ -202,7 +204,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) { EmailGreeting(lpa). Return("Dear donor") notifyClient.EXPECT(). - SendActorEmail(ctx, "a@example.com", "lpa-uid", notify.AttorneyOptedOutEmail{ + SendActorEmail(ctx, localize.En, "a@example.com", "lpa-uid", notify.AttorneyOptedOutEmail{ Greeting: "Dear donor", AttorneyFullName: tc.attorneyFullName, DonorFullName: "a b c", @@ -357,7 +359,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOutErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("Dear donor") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) return client @@ -395,7 +397,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOutErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("Dear donor") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) return client @@ -443,7 +445,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOutErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("Dear donor") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) return client diff --git a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_test.go b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_test.go index 8c20c86c6a..50ca7c4cb4 100644 --- a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_test.go +++ b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_test.go @@ -11,6 +11,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "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/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -94,6 +95,7 @@ func TestPostConfirmDontWantToBeAttorney(t *testing.T) { SignedAt: time.Now(), Donor: lpadata.Donor{ FirstNames: "a b", LastName: "c", Email: "a@example.com", + ContactLanguagePreference: localize.En, }, Attorneys: lpadata.Attorneys{ Attorneys: []lpadata.Attorney{ @@ -120,7 +122,7 @@ func TestPostConfirmDontWantToBeAttorney(t *testing.T) { EmailGreeting(mock.Anything). Return("Dear donor") notifyClient.EXPECT(). - SendActorEmail(r.Context(), "a@example.com", "lpa-uid", notify.AttorneyOptedOutEmail{ + SendActorEmail(r.Context(), localize.En, "a@example.com", "lpa-uid", notify.AttorneyOptedOutEmail{ Greeting: "Dear donor", AttorneyFullName: "d e f", DonorFullName: "a b c", @@ -184,7 +186,7 @@ func TestPostConfirmDontWantToBeAttorneyErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) return client @@ -204,7 +206,7 @@ func TestPostConfirmDontWantToBeAttorneyErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) return client @@ -232,7 +234,7 @@ func TestPostConfirmDontWantToBeAttorneyErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) return client diff --git a/internal/attorney/attorneypage/mock_NotifyClient_test.go b/internal/attorney/attorneypage/mock_NotifyClient_test.go index a456a44497..86ec7a691c 100644 --- a/internal/attorney/attorneypage/mock_NotifyClient_test.go +++ b/internal/attorney/attorneypage/mock_NotifyClient_test.go @@ -5,7 +5,9 @@ package attorneypage import ( context "context" + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" lpadata "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" + mock "github.com/stretchr/testify/mock" notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" @@ -70,17 +72,17 @@ func (_c *mockNotifyClient_EmailGreeting_Call) RunAndReturn(run func(*lpadata.Lp return _c } -// SendActorEmail provides a mock function with given fields: ctx, to, lpaUID, email -func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, to string, lpaUID string, email notify.Email) error { - ret := _m.Called(ctx, to, lpaUID, email) +// SendActorEmail provides a mock function with given fields: ctx, lang, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email) error { + ret := _m.Called(ctx, lang, to, lpaUID, email) if len(ret) == 0 { panic("no return value specified for SendActorEmail") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.Email) error); ok { - r0 = rf(ctx, to, lpaUID, email) + if rf, ok := ret.Get(0).(func(context.Context, localize.Lang, string, string, notify.Email) error); ok { + r0 = rf(ctx, lang, to, lpaUID, email) } else { r0 = ret.Error(0) } @@ -95,16 +97,17 @@ type mockNotifyClient_SendActorEmail_Call struct { // SendActorEmail is a helper method to define mock.On call // - ctx context.Context +// - lang localize.Lang // - to string // - lpaUID string // - email notify.Email -func (_e *mockNotifyClient_Expecter) SendActorEmail(ctx interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { - return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", ctx, to, lpaUID, email)} +func (_e *mockNotifyClient_Expecter) SendActorEmail(ctx interface{}, lang interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { + return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", ctx, lang, to, lpaUID, email)} } -func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.Email)) + run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.Email)) }) return _c } @@ -114,7 +117,7 @@ func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyCli return _c } -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { _c.Call.Return(run) return _c } diff --git a/internal/attorney/attorneypage/register.go b/internal/attorney/attorneypage/register.go index 7f5b674f2f..3d99526992 100644 --- a/internal/attorney/attorneypage/register.go +++ b/internal/attorney/attorneypage/register.go @@ -15,6 +15,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dashboard/dashboarddata" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" @@ -87,7 +88,7 @@ type LpaStoreClient interface { type NotifyClient interface { EmailGreeting(lpa *lpadata.Lpa) string - SendActorEmail(ctx context.Context, to, lpaUID string, email notify.Email) error + SendActorEmail(ctx context.Context, lang localize.Lang, to, lpaUID string, email notify.Email) error } type ErrorHandler func(http.ResponseWriter, *http.Request, error) diff --git a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider.go b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider.go index bf0ba0e52b..a3386642e5 100644 --- a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider.go +++ b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider.go @@ -80,7 +80,7 @@ func ConfirmDontWantToBeCertificateProvider(tmpl template.Template, lpaStoreReso return err } - if err := notifyClient.SendActorEmail(r.Context(), lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { + if err := notifyClient.SendActorEmail(r.Context(), lpa.Donor.ContactLanguagePreference, lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { return err } diff --git a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out.go b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out.go index b44b67ba80..500b8a3238 100644 --- a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out.go +++ b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out.go @@ -89,7 +89,7 @@ func ConfirmDontWantToBeCertificateProviderLoggedOut(tmpl template.Template, sha } } - if err := notifyClient.SendActorEmail(ctx, lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { + if err := notifyClient.SendActorEmail(ctx, lpa.Donor.ContactLanguagePreference, lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { return err } diff --git a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out_test.go b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out_test.go index 095ec3d4f6..b7469a7c54 100644 --- a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out_test.go +++ b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out_test.go @@ -11,6 +11,7 @@ import ( "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/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -149,6 +150,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { WitnessedByCertificateProviderAt: time.Now(), Donor: lpadata.Donor{ FirstNames: "a b", LastName: "c", Email: "a@example.com", + ContactLanguagePreference: localize.En, }, CertificateProvider: lpadata.CertificateProvider{ FirstNames: "d e", LastName: "f", @@ -179,7 +181,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { LpaUID: "lpa-uid", SignedAt: time.Now(), WitnessedByCertificateProviderAt: time.Now(), - Donor: lpadata.Donor{FirstNames: "a b", LastName: "c", Email: "a@example.com"}, + Donor: lpadata.Donor{FirstNames: "a b", LastName: "c", Email: "a@example.com", ContactLanguagePreference: localize.En}, CertificateProvider: lpadata.CertificateProvider{ FirstNames: "d e", LastName: "f", }, @@ -203,6 +205,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { LpaUID: "lpa-uid", Donor: lpadata.Donor{ FirstNames: "a b", LastName: "c", Email: "a@example.com", + ContactLanguagePreference: localize.En, }, }, lpaStoreClient: func() *mockLpaStoreClient { return nil }, @@ -283,7 +286,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { EmailGreeting(&tc.lpa). Return("Dear donor") notifyClient.EXPECT(). - SendActorEmail(ctx, "a@example.com", "lpa-uid", tc.email). + SendActorEmail(ctx, localize.En, "a@example.com", "lpa-uid", tc.email). Return(nil) localizer := newMockLocalizer(t) @@ -530,7 +533,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOutErrors(t *testing.T) EmailGreeting(mock.Anything). Return("") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) return client @@ -577,7 +580,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOutErrors(t *testing.T) EmailGreeting(mock.Anything). Return("") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) return client diff --git a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_test.go b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_test.go index 7c70594b55..c924456628 100644 --- a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_test.go +++ b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_test.go @@ -10,6 +10,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -113,6 +114,7 @@ func TestPostConfirmDontWantToBeCertificateProvider(t *testing.T) { WitnessedByCertificateProviderAt: time.Now(), Donor: lpadata.Donor{ FirstNames: "a b", LastName: "c", Email: "a@example.com", + ContactLanguagePreference: localize.En, }, CertificateProvider: lpadata.CertificateProvider{ FirstNames: "d e", LastName: "f", UID: uid, @@ -145,6 +147,7 @@ func TestPostConfirmDontWantToBeCertificateProvider(t *testing.T) { WitnessedByCertificateProviderAt: time.Now(), Donor: lpadata.Donor{ FirstNames: "a b", LastName: "c", Email: "a@example.com", + ContactLanguagePreference: localize.En, }, CertificateProvider: lpadata.CertificateProvider{ FirstNames: "d e", LastName: "f", UID: uid, @@ -167,7 +170,7 @@ func TestPostConfirmDontWantToBeCertificateProvider(t *testing.T) { "not witnessed and signed": { lpa: lpadata.Lpa{ LpaUID: "lpa-uid", - Donor: lpadata.Donor{FirstNames: "a b", LastName: "c", Email: "a@example.com"}, + Donor: lpadata.Donor{FirstNames: "a b", LastName: "c", Email: "a@example.com", ContactLanguagePreference: localize.En}, }, lpaStoreClient: func() *mockLpaStoreClient { return nil }, donorStore: func() *mockDonorStore { @@ -241,7 +244,7 @@ func TestPostConfirmDontWantToBeCertificateProvider(t *testing.T) { EmailGreeting(mock.Anything). Return("Dear donor") notifyClient.EXPECT(). - SendActorEmail(r.Context(), "a@example.com", "lpa-uid", tc.email). + SendActorEmail(r.Context(), localize.En, "a@example.com", "lpa-uid", tc.email). Return(nil) err := ConfirmDontWantToBeCertificateProvider(nil, lpaStoreResolvingService, tc.lpaStoreClient(), tc.donorStore(), certificateProviderStore, notifyClient, "example.com")(testAppData, w, r, nil) @@ -467,7 +470,7 @@ func TestPostConfirmDontWantToBeCertificateProviderErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("Dear donor") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) return client diff --git a/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback.go b/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback.go index 7143ef5ac7..cac3be93a8 100644 --- a/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback.go +++ b/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback.go @@ -87,7 +87,7 @@ func IdentityWithOneLoginCallback(oneLoginClient OneLoginClient, sessionStore Se } if lpa.SignedForDonor() { - if err := notifyClient.SendActorEmail(r.Context(), lpa.CorrespondentEmail(), lpa.LpaUID, notify.CertificateProviderFailedIDCheckEmail{ + if err := notifyClient.SendActorEmail(r.Context(), lpa.Donor.ContactLanguagePreference, lpa.CorrespondentEmail(), lpa.LpaUID, notify.CertificateProviderFailedIdentityCheckEmail{ Greeting: notifyClient.EmailGreeting(lpa), DonorFullName: lpa.Donor.FullName(), CertificateProviderFullName: lpa.CertificateProvider.FullName(), diff --git a/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback_test.go b/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback_test.go index fb4b46a78e..efa844eb88 100644 --- a/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback_test.go +++ b/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback_test.go @@ -13,6 +13,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" @@ -205,7 +206,7 @@ func TestGetIdentityWithOneLoginCallbackWhenIdentityCheckFailed(t *testing.T) { Return(&lpadata.Lpa{ LpaUID: "lpa-uid", CertificateProvider: lpadata.CertificateProvider{FirstNames: "a", LastName: "b"}, - Donor: lpadata.Donor{Email: "a@example.com", FirstNames: "c", LastName: "d"}, + Donor: lpadata.Donor{Email: "a@example.com", FirstNames: "c", LastName: "d", ContactLanguagePreference: localize.En}, Type: lpadata.LpaTypePersonalWelfare, SignedAt: time.Now(), WitnessedByCertificateProviderAt: time.Now(), @@ -239,7 +240,7 @@ func TestGetIdentityWithOneLoginCallbackWhenIdentityCheckFailed(t *testing.T) { EmailGreeting(mock.Anything). Return("Dear donor") notifyClient.EXPECT(). - SendActorEmail(r.Context(), "a@example.com", "lpa-uid", notify.CertificateProviderFailedIDCheckEmail{ + SendActorEmail(r.Context(), localize.En, "a@example.com", "lpa-uid", notify.CertificateProviderFailedIdentityCheckEmail{ Greeting: "Dear donor", DonorFullName: "c d", CertificateProviderFullName: "a b", @@ -324,7 +325,7 @@ func TestGetIdentityWithOneLoginCallbackWhenSendingEmailError(t *testing.T) { EmailGreeting(mock.Anything). Return("") notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) eventClient := newMockEventClient(t) diff --git a/internal/certificateprovider/certificateproviderpage/mock_NotifyClient_test.go b/internal/certificateprovider/certificateproviderpage/mock_NotifyClient_test.go index 23e68d1ab1..dadf3bea35 100644 --- a/internal/certificateprovider/certificateproviderpage/mock_NotifyClient_test.go +++ b/internal/certificateprovider/certificateproviderpage/mock_NotifyClient_test.go @@ -5,7 +5,9 @@ package certificateproviderpage import ( context "context" + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" lpadata "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" + mock "github.com/stretchr/testify/mock" notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" @@ -70,17 +72,17 @@ func (_c *mockNotifyClient_EmailGreeting_Call) RunAndReturn(run func(*lpadata.Lp return _c } -// SendActorEmail provides a mock function with given fields: ctx, to, lpaUID, email -func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, to string, lpaUID string, email notify.Email) error { - ret := _m.Called(ctx, to, lpaUID, email) +// SendActorEmail provides a mock function with given fields: ctx, lang, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email) error { + ret := _m.Called(ctx, lang, to, lpaUID, email) if len(ret) == 0 { panic("no return value specified for SendActorEmail") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.Email) error); ok { - r0 = rf(ctx, to, lpaUID, email) + if rf, ok := ret.Get(0).(func(context.Context, localize.Lang, string, string, notify.Email) error); ok { + r0 = rf(ctx, lang, to, lpaUID, email) } else { r0 = ret.Error(0) } @@ -95,16 +97,17 @@ type mockNotifyClient_SendActorEmail_Call struct { // SendActorEmail is a helper method to define mock.On call // - ctx context.Context +// - lang localize.Lang // - to string // - lpaUID string // - email notify.Email -func (_e *mockNotifyClient_Expecter) SendActorEmail(ctx interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { - return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", ctx, to, lpaUID, email)} +func (_e *mockNotifyClient_Expecter) SendActorEmail(ctx interface{}, lang interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { + return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", ctx, lang, to, lpaUID, email)} } -func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.Email)) + run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.Email)) }) return _c } @@ -114,55 +117,7 @@ func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyCli return _c } -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { - _c.Call.Return(run) - return _c -} - -// SendEmail provides a mock function with given fields: ctx, to, email -func (_m *mockNotifyClient) SendEmail(ctx context.Context, to string, email notify.Email) error { - ret := _m.Called(ctx, to, email) - - if len(ret) == 0 { - panic("no return value specified for SendEmail") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, notify.Email) error); ok { - r0 = rf(ctx, to, email) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// mockNotifyClient_SendEmail_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendEmail' -type mockNotifyClient_SendEmail_Call struct { - *mock.Call -} - -// SendEmail is a helper method to define mock.On call -// - ctx context.Context -// - to string -// - email notify.Email -func (_e *mockNotifyClient_Expecter) SendEmail(ctx interface{}, to interface{}, email interface{}) *mockNotifyClient_SendEmail_Call { - return &mockNotifyClient_SendEmail_Call{Call: _e.mock.On("SendEmail", ctx, to, email)} -} - -func (_c *mockNotifyClient_SendEmail_Call) Run(run func(ctx context.Context, to string, email notify.Email)) *mockNotifyClient_SendEmail_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(notify.Email)) - }) - return _c -} - -func (_c *mockNotifyClient_SendEmail_Call) Return(_a0 error) *mockNotifyClient_SendEmail_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockNotifyClient_SendEmail_Call) RunAndReturn(run func(context.Context, string, notify.Email) error) *mockNotifyClient_SendEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { _c.Call.Return(run) return _c } diff --git a/internal/certificateprovider/certificateproviderpage/provide_certificate.go b/internal/certificateprovider/certificateproviderpage/provide_certificate.go index b73d18787a..21fbd2de0c 100644 --- a/internal/certificateprovider/certificateproviderpage/provide_certificate.go +++ b/internal/certificateprovider/certificateproviderpage/provide_certificate.go @@ -77,7 +77,7 @@ func ProvideCertificate( certificateProvider.SignedAt = lpa.CertificateProvider.SignedAt } - if err := notifyClient.SendActorEmail(r.Context(), certificateProvider.Email, lpa.LpaUID, notify.CertificateProviderCertificateProvidedEmail{ + if err := notifyClient.SendActorEmail(r.Context(), certificateProvider.ContactLanguagePreference, certificateProvider.Email, lpa.LpaUID, notify.CertificateProviderCertificateProvidedEmail{ DonorFullNamePossessive: appData.Localizer.Possessive(lpa.Donor.FullName()), DonorFirstNamesPossessive: appData.Localizer.Possessive(lpa.Donor.FirstNames), LpaType: localize.LowerFirst(appData.Localizer.T(lpa.Type.String())), diff --git a/internal/certificateprovider/certificateproviderpage/provide_certificate_test.go b/internal/certificateprovider/certificateproviderpage/provide_certificate_test.go index 065d9450cd..bdf968d1f3 100644 --- a/internal/certificateprovider/certificateproviderpage/provide_certificate_test.go +++ b/internal/certificateprovider/certificateproviderpage/provide_certificate_test.go @@ -11,6 +11,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -133,7 +134,8 @@ func TestPostProvideCertificate(t *testing.T) { Tasks: certificateproviderdata.Tasks{ ProvideTheCertificate: task.StateCompleted, }, - Email: "a@example.com", + ContactLanguagePreference: localize.En, + Email: "a@example.com", } lpaStoreResolvingService := newMockLpaStoreResolvingService(t) @@ -164,7 +166,7 @@ func TestPostProvideCertificate(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(r.Context(), "a@example.com", "lpa-uid", notify.CertificateProviderCertificateProvidedEmail{ + SendActorEmail(r.Context(), localize.En, "a@example.com", "lpa-uid", notify.CertificateProviderCertificateProvidedEmail{ DonorFullNamePossessive: "the possessive full name", DonorFirstNamesPossessive: "the possessive first names", LpaType: "the translated term", @@ -183,7 +185,7 @@ func TestPostProvideCertificate(t *testing.T) { SendCertificateProvider(r.Context(), certificateProvider, lpa). Return(nil) - err := ProvideCertificate(nil, lpaStoreResolvingService, certificateProviderStore, notifyClient, shareCodeSender, lpaStoreClient, func() time.Time { return now })(testAppData, w, r, &certificateproviderdata.Provided{LpaID: "lpa-id", Email: "a@example.com"}) + err := ProvideCertificate(nil, lpaStoreResolvingService, certificateProviderStore, notifyClient, shareCodeSender, lpaStoreClient, func() time.Time { return now })(testAppData, w, r, &certificateproviderdata.Provided{LpaID: "lpa-id", Email: "a@example.com", ContactLanguagePreference: localize.En}) resp := w.Result() assert.Nil(t, err) @@ -224,7 +226,8 @@ func TestPostProvideCertificateWhenSignedInLpaStore(t *testing.T) { Tasks: certificateproviderdata.Tasks{ ProvideTheCertificate: task.StateCompleted, }, - Email: "a@example.com", + ContactLanguagePreference: localize.En, + Email: "a@example.com", } lpaStoreResolvingService := newMockLpaStoreResolvingService(t) @@ -255,7 +258,7 @@ func TestPostProvideCertificateWhenSignedInLpaStore(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(r.Context(), "a@example.com", "lpa-uid", notify.CertificateProviderCertificateProvidedEmail{ + SendActorEmail(r.Context(), localize.En, "a@example.com", "lpa-uid", notify.CertificateProviderCertificateProvidedEmail{ DonorFullNamePossessive: "the possessive full name", DonorFirstNamesPossessive: "the possessive first names", LpaType: "the translated term", @@ -269,7 +272,7 @@ func TestPostProvideCertificateWhenSignedInLpaStore(t *testing.T) { SendAttorneys(r.Context(), testAppData, lpa). Return(nil) - err := ProvideCertificate(nil, lpaStoreResolvingService, certificateProviderStore, notifyClient, shareCodeSender, nil, func() time.Time { return now })(testAppData, w, r, &certificateproviderdata.Provided{LpaID: "lpa-id", Email: "a@example.com"}) + err := ProvideCertificate(nil, lpaStoreResolvingService, certificateProviderStore, notifyClient, shareCodeSender, nil, func() time.Time { return now })(testAppData, w, r, &certificateproviderdata.Provided{LpaID: "lpa-id", Email: "a@example.com", ContactLanguagePreference: localize.En}) resp := w.Result() assert.Nil(t, err) @@ -360,7 +363,7 @@ func TestPostProvideCertificateOnStoreError(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) shareCodeSender := newMockShareCodeSender(t) @@ -457,7 +460,7 @@ func TestPostProvideCertificateOnNotifyClientError(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) testAppData.Localizer = localizer @@ -514,7 +517,7 @@ func TestPostProvideCertificateWhenShareCodeSenderErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) shareCodeSender := newMockShareCodeSender(t) diff --git a/internal/certificateprovider/certificateproviderpage/register.go b/internal/certificateprovider/certificateproviderpage/register.go index 07040da649..b2fd38f051 100644 --- a/internal/certificateprovider/certificateproviderpage/register.go +++ b/internal/certificateprovider/certificateproviderpage/register.go @@ -18,6 +18,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" @@ -77,8 +78,7 @@ type SessionStore interface { type NotifyClient interface { EmailGreeting(lpa *lpadata.Lpa) string - SendEmail(ctx context.Context, to string, email notify.Email) error - SendActorEmail(ctx context.Context, to, lpaUID string, email notify.Email) error + SendActorEmail(ctx context.Context, lang localize.Lang, to, lpaUID string, email notify.Email) error } type ShareCodeSender interface { diff --git a/internal/donor/donorpage/check_your_lpa.go b/internal/donor/donorpage/check_your_lpa.go index 152c37845f..08985e5849 100644 --- a/internal/donor/donorpage/check_your_lpa.go +++ b/internal/donor/donorpage/check_your_lpa.go @@ -61,7 +61,7 @@ func (n *checkYourLpaNotifier) sendPaperNotification(ctx context.Context, appDat } } - return n.notifyClient.SendActorSMS(ctx, provided.CertificateProvider.Mobile, provided.LpaUID, sms) + return n.notifyClient.SendActorSMS(ctx, localize.En, provided.CertificateProvider.Mobile, provided.LpaUID, sms) } func (n *checkYourLpaNotifier) sendOnlineNotification(ctx context.Context, appData appcontext.Data, donor *donordata.Provided, wasCompleted bool) error { @@ -99,7 +99,7 @@ func (n *checkYourLpaNotifier) sendOnlineNotification(ctx context.Context, appDa } } - return n.notifyClient.SendActorSMS(ctx, donor.CertificateProvider.Mobile, donor.LpaUID, sms) + return n.notifyClient.SendActorSMS(ctx, certificateProvider.ContactLanguagePreference, donor.CertificateProvider.Mobile, donor.LpaUID, sms) } func CheckYourLpa(tmpl template.Template, donorStore DonorStore, shareCodeSender ShareCodeSender, notifyClient NotifyClient, certificateProviderStore CertificateProviderStore, now func() time.Time, appPublicURL string) Handler { diff --git a/internal/donor/donorpage/check_your_lpa_test.go b/internal/donor/donorpage/check_your_lpa_test.go index 9939298c9c..146db87b4e 100644 --- a/internal/donor/donorpage/check_your_lpa_test.go +++ b/internal/donor/donorpage/check_your_lpa_test.go @@ -11,6 +11,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -227,7 +228,7 @@ func TestPostCheckYourLpaDigitalCertificateProviderOnSubsequentChecks(t *testing notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(r.Context(), "07700900000", "lpa-uid", tc.expectedSms). + SendActorSMS(r.Context(), localize.Cy, "07700900000", "lpa-uid", tc.expectedSms). Return(nil) donorStore := newMockDonorStore(t) @@ -239,7 +240,8 @@ func TestPostCheckYourLpaDigitalCertificateProviderOnSubsequentChecks(t *testing certificateProviderStore.EXPECT(). GetAny(r.Context()). Return(&certificateproviderdata.Provided{ - Tasks: certificateproviderdata.Tasks{ConfirmYourDetails: tc.certificateProviderDetailsTaskState}, + ContactLanguagePreference: localize.Cy, + Tasks: certificateproviderdata.Tasks{ConfirmYourDetails: tc.certificateProviderDetailsTaskState}, }, nil) err := CheckYourLpa(nil, donorStore, nil, notifyClient, certificateProviderStore, testNowFn, "http://example.org")(testAppData, w, r, provided) @@ -325,7 +327,7 @@ func TestPostCheckYourLpaPaperCertificateProviderOnFirstCheck(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(r.Context(), "07700900000", "lpa-uid", notify.CertificateProviderActingOnPaperMeetingPromptSMS{ + SendActorSMS(r.Context(), localize.En, "07700900000", "lpa-uid", notify.CertificateProviderActingOnPaperMeetingPromptSMS{ DonorFullName: "Teneil Throssell", LpaType: "property and affairs", DonorFirstNames: "Teneil", @@ -370,7 +372,7 @@ func TestPostCheckYourLpaPaperCertificateProviderOnSubsequentCheck(t *testing.T) notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(r.Context(), "07700900000", "lpa-uid", notify.CertificateProviderActingOnPaperDetailsChangedSMS{ + SendActorSMS(r.Context(), localize.En, "07700900000", "lpa-uid", notify.CertificateProviderActingOnPaperDetailsChangedSMS{ DonorFullName: "Teneil Throssell", DonorFirstNames: "Teneil", LpaUID: "lpa-uid", @@ -407,7 +409,7 @@ func TestPostCheckYourLpaWhenStoreErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(r.Context(), mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(r.Context(), mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) donorStore := newMockDonorStore(t) @@ -467,7 +469,7 @@ func TestPostCheckYourLpaWhenNotifyClientErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) err := CheckYourLpa(nil, nil, nil, notifyClient, nil, testNowFn, "http://example.org")(testAppData, w, r, &donordata.Provided{Hash: 5, CertificateProvider: donordata.CertificateProvider{CarryOutBy: lpadata.ChannelPaper}}) diff --git a/internal/donor/donorpage/mock_NotifyClient_test.go b/internal/donor/donorpage/mock_NotifyClient_test.go index d65374bf56..33fadf442e 100644 --- a/internal/donor/donorpage/mock_NotifyClient_test.go +++ b/internal/donor/donorpage/mock_NotifyClient_test.go @@ -5,8 +5,10 @@ package donorpage import ( context "context" - notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" mock "github.com/stretchr/testify/mock" + + notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" ) // mockNotifyClient is an autogenerated mock type for the NotifyClient type @@ -22,17 +24,17 @@ func (_m *mockNotifyClient) EXPECT() *mockNotifyClient_Expecter { return &mockNotifyClient_Expecter{mock: &_m.Mock} } -// SendActorSMS provides a mock function with given fields: ctx, to, lpaUID, sms -func (_m *mockNotifyClient) SendActorSMS(ctx context.Context, to string, lpaUID string, sms notify.SMS) error { - ret := _m.Called(ctx, to, lpaUID, sms) +// SendActorSMS provides a mock function with given fields: ctx, lang, to, lpaUID, sms +func (_m *mockNotifyClient) SendActorSMS(ctx context.Context, lang localize.Lang, to string, lpaUID string, sms notify.SMS) error { + ret := _m.Called(ctx, lang, to, lpaUID, sms) if len(ret) == 0 { panic("no return value specified for SendActorSMS") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.SMS) error); ok { - r0 = rf(ctx, to, lpaUID, sms) + if rf, ok := ret.Get(0).(func(context.Context, localize.Lang, string, string, notify.SMS) error); ok { + r0 = rf(ctx, lang, to, lpaUID, sms) } else { r0 = ret.Error(0) } @@ -47,16 +49,17 @@ type mockNotifyClient_SendActorSMS_Call struct { // SendActorSMS is a helper method to define mock.On call // - ctx context.Context +// - lang localize.Lang // - to string // - lpaUID string // - sms notify.SMS -func (_e *mockNotifyClient_Expecter) SendActorSMS(ctx interface{}, to interface{}, lpaUID interface{}, sms interface{}) *mockNotifyClient_SendActorSMS_Call { - return &mockNotifyClient_SendActorSMS_Call{Call: _e.mock.On("SendActorSMS", ctx, to, lpaUID, sms)} +func (_e *mockNotifyClient_Expecter) SendActorSMS(ctx interface{}, lang interface{}, to interface{}, lpaUID interface{}, sms interface{}) *mockNotifyClient_SendActorSMS_Call { + return &mockNotifyClient_SendActorSMS_Call{Call: _e.mock.On("SendActorSMS", ctx, lang, to, lpaUID, sms)} } -func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(ctx context.Context, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.SMS)) + run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.SMS)) }) return _c } @@ -66,22 +69,22 @@ func (_c *mockNotifyClient_SendActorSMS_Call) Return(_a0 error) *mockNotifyClien return _c } -func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { _c.Call.Return(run) return _c } -// SendEmail provides a mock function with given fields: ctx, to, email -func (_m *mockNotifyClient) SendEmail(ctx context.Context, to string, email notify.Email) error { - ret := _m.Called(ctx, to, email) +// SendEmail provides a mock function with given fields: ctx, lang, to, email +func (_m *mockNotifyClient) SendEmail(ctx context.Context, lang localize.Lang, to string, email notify.Email) error { + ret := _m.Called(ctx, lang, to, email) if len(ret) == 0 { panic("no return value specified for SendEmail") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, notify.Email) error); ok { - r0 = rf(ctx, to, email) + if rf, ok := ret.Get(0).(func(context.Context, localize.Lang, string, notify.Email) error); ok { + r0 = rf(ctx, lang, to, email) } else { r0 = ret.Error(0) } @@ -96,15 +99,16 @@ type mockNotifyClient_SendEmail_Call struct { // SendEmail is a helper method to define mock.On call // - ctx context.Context +// - lang localize.Lang // - to string // - email notify.Email -func (_e *mockNotifyClient_Expecter) SendEmail(ctx interface{}, to interface{}, email interface{}) *mockNotifyClient_SendEmail_Call { - return &mockNotifyClient_SendEmail_Call{Call: _e.mock.On("SendEmail", ctx, to, email)} +func (_e *mockNotifyClient_Expecter) SendEmail(ctx interface{}, lang interface{}, to interface{}, email interface{}) *mockNotifyClient_SendEmail_Call { + return &mockNotifyClient_SendEmail_Call{Call: _e.mock.On("SendEmail", ctx, lang, to, email)} } -func (_c *mockNotifyClient_SendEmail_Call) Run(run func(ctx context.Context, to string, email notify.Email)) *mockNotifyClient_SendEmail_Call { +func (_c *mockNotifyClient_SendEmail_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, email notify.Email)) *mockNotifyClient_SendEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(notify.Email)) + run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(notify.Email)) }) return _c } @@ -114,7 +118,7 @@ func (_c *mockNotifyClient_SendEmail_Call) Return(_a0 error) *mockNotifyClient_S return _c } -func (_c *mockNotifyClient_SendEmail_Call) RunAndReturn(run func(context.Context, string, notify.Email) error) *mockNotifyClient_SendEmail_Call { +func (_c *mockNotifyClient_SendEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, notify.Email) error) *mockNotifyClient_SendEmail_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/payment_confirmation.go b/internal/donor/donorpage/payment_confirmation.go index 7f22dcb69f..09533da2bf 100644 --- a/internal/donor/donorpage/payment_confirmation.go +++ b/internal/donor/donorpage/payment_confirmation.go @@ -12,6 +12,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/donor" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" ) @@ -49,7 +50,7 @@ func PaymentConfirmation(logger Logger, payClient PayClient, donorStore DonorSto } } - if err := notifyClient.SendEmail(r.Context(), payment.Email, notify.PaymentConfirmationEmail{ + if err := notifyClient.SendEmail(r.Context(), localize.En, payment.Email, notify.PaymentConfirmationEmail{ DonorFullNamesPossessive: appData.Localizer.Possessive(provided.Donor.FullName()), LpaType: appData.Localizer.T(provided.Type.String()), PaymentCardFullName: payment.CardDetails.CardholderName, diff --git a/internal/donor/donorpage/payment_confirmation_test.go b/internal/donor/donorpage/payment_confirmation_test.go index f71de854bc..693a53c5a7 100644 --- a/internal/donor/donorpage/payment_confirmation_test.go +++ b/internal/donor/donorpage/payment_confirmation_test.go @@ -13,6 +13,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/donor" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" @@ -733,7 +734,7 @@ func TestGetPaymentConfirmationWhenNotifyClientError(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(mock.Anything, mock.Anything, mock.Anything). + SendEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) localizer := newMockLocalizer(t). @@ -984,7 +985,7 @@ func (m *mockLocalizer) withEmailLocalizations() *mockLocalizer { func (m *mockNotifyClient) withEmailPersonalizations(ctx context.Context, amount string) *mockNotifyClient { m.EXPECT(). - SendEmail(ctx, "a@example.com", notify.PaymentConfirmationEmail{ + SendEmail(ctx, localize.En, "a@example.com", notify.PaymentConfirmationEmail{ DonorFullNamesPossessive: "donor name possessive", LpaType: "translated type", PaymentCardFullName: "a b", diff --git a/internal/donor/donorpage/register.go b/internal/donor/donorpage/register.go index a55d1d2f64..47bfd3a22b 100644 --- a/internal/donor/donorpage/register.go +++ b/internal/donor/donorpage/register.go @@ -18,6 +18,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" @@ -96,8 +97,8 @@ type OneLoginClient interface { } type NotifyClient interface { - SendActorSMS(ctx context.Context, to, lpaUID string, sms notify.SMS) error - SendEmail(ctx context.Context, to string, email notify.Email) error + SendActorSMS(ctx context.Context, lang localize.Lang, to, lpaUID string, sms notify.SMS) error + SendEmail(ctx context.Context, lang localize.Lang, to string, email notify.Email) error } type SessionStore interface { diff --git a/internal/donor/mock_CertificateProviderStore_test.go b/internal/donor/mock_CertificateProviderStore_test.go new file mode 100644 index 0000000000..2b81f52e9a --- /dev/null +++ b/internal/donor/mock_CertificateProviderStore_test.go @@ -0,0 +1,96 @@ +// Code generated by mockery v2.46.1. DO NOT EDIT. + +package donor + +import ( + context "context" + + certificateproviderdata "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" + + mock "github.com/stretchr/testify/mock" +) + +// mockCertificateProviderStore is an autogenerated mock type for the CertificateProviderStore type +type mockCertificateProviderStore struct { + mock.Mock +} + +type mockCertificateProviderStore_Expecter struct { + mock *mock.Mock +} + +func (_m *mockCertificateProviderStore) EXPECT() *mockCertificateProviderStore_Expecter { + return &mockCertificateProviderStore_Expecter{mock: &_m.Mock} +} + +// GetAny provides a mock function with given fields: _a0 +func (_m *mockCertificateProviderStore) GetAny(_a0 context.Context) (*certificateproviderdata.Provided, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for GetAny") + } + + var r0 *certificateproviderdata.Provided + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*certificateproviderdata.Provided, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(context.Context) *certificateproviderdata.Provided); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*certificateproviderdata.Provided) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockCertificateProviderStore_GetAny_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetAny' +type mockCertificateProviderStore_GetAny_Call struct { + *mock.Call +} + +// GetAny is a helper method to define mock.On call +// - _a0 context.Context +func (_e *mockCertificateProviderStore_Expecter) GetAny(_a0 interface{}) *mockCertificateProviderStore_GetAny_Call { + return &mockCertificateProviderStore_GetAny_Call{Call: _e.mock.On("GetAny", _a0)} +} + +func (_c *mockCertificateProviderStore_GetAny_Call) Run(run func(_a0 context.Context)) *mockCertificateProviderStore_GetAny_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *mockCertificateProviderStore_GetAny_Call) Return(_a0 *certificateproviderdata.Provided, _a1 error) *mockCertificateProviderStore_GetAny_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockCertificateProviderStore_GetAny_Call) RunAndReturn(run func(context.Context) (*certificateproviderdata.Provided, error)) *mockCertificateProviderStore_GetAny_Call { + _c.Call.Return(run) + return _c +} + +// newMockCertificateProviderStore creates a new instance of mockCertificateProviderStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockCertificateProviderStore(t interface { + mock.TestingT + Cleanup(func()) +}) *mockCertificateProviderStore { + mock := &mockCertificateProviderStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/donor/mock_NotifyClient_test.go b/internal/donor/mock_NotifyClient_test.go index f9e427c7f3..8edca8cc1e 100644 --- a/internal/donor/mock_NotifyClient_test.go +++ b/internal/donor/mock_NotifyClient_test.go @@ -5,8 +5,10 @@ package donor import ( context "context" - notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" mock "github.com/stretchr/testify/mock" + + notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" ) // mockNotifyClient is an autogenerated mock type for the NotifyClient type @@ -22,17 +24,17 @@ func (_m *mockNotifyClient) EXPECT() *mockNotifyClient_Expecter { return &mockNotifyClient_Expecter{mock: &_m.Mock} } -// SendActorEmail provides a mock function with given fields: _a0, to, lpaUID, email -func (_m *mockNotifyClient) SendActorEmail(_a0 context.Context, to string, lpaUID string, email notify.Email) error { - ret := _m.Called(_a0, to, lpaUID, email) +// SendActorEmail provides a mock function with given fields: _a0, lang, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(_a0 context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email) error { + ret := _m.Called(_a0, lang, to, lpaUID, email) if len(ret) == 0 { panic("no return value specified for SendActorEmail") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.Email) error); ok { - r0 = rf(_a0, to, lpaUID, email) + if rf, ok := ret.Get(0).(func(context.Context, localize.Lang, string, string, notify.Email) error); ok { + r0 = rf(_a0, lang, to, lpaUID, email) } else { r0 = ret.Error(0) } @@ -47,16 +49,17 @@ type mockNotifyClient_SendActorEmail_Call struct { // SendActorEmail is a helper method to define mock.On call // - _a0 context.Context +// - lang localize.Lang // - to string // - lpaUID string // - email notify.Email -func (_e *mockNotifyClient_Expecter) SendActorEmail(_a0 interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { - return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", _a0, to, lpaUID, email)} +func (_e *mockNotifyClient_Expecter) SendActorEmail(_a0 interface{}, lang interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { + return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", _a0, lang, to, lpaUID, email)} } -func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(_a0 context.Context, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(_a0 context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.Email)) + run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.Email)) }) return _c } @@ -66,22 +69,22 @@ func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyCli return _c } -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { _c.Call.Return(run) return _c } -// SendActorSMS provides a mock function with given fields: _a0, to, lpaUID, sms -func (_m *mockNotifyClient) SendActorSMS(_a0 context.Context, to string, lpaUID string, sms notify.SMS) error { - ret := _m.Called(_a0, to, lpaUID, sms) +// SendActorSMS provides a mock function with given fields: _a0, lang, to, lpaUID, sms +func (_m *mockNotifyClient) SendActorSMS(_a0 context.Context, lang localize.Lang, to string, lpaUID string, sms notify.SMS) error { + ret := _m.Called(_a0, lang, to, lpaUID, sms) if len(ret) == 0 { panic("no return value specified for SendActorSMS") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.SMS) error); ok { - r0 = rf(_a0, to, lpaUID, sms) + if rf, ok := ret.Get(0).(func(context.Context, localize.Lang, string, string, notify.SMS) error); ok { + r0 = rf(_a0, lang, to, lpaUID, sms) } else { r0 = ret.Error(0) } @@ -96,16 +99,17 @@ type mockNotifyClient_SendActorSMS_Call struct { // SendActorSMS is a helper method to define mock.On call // - _a0 context.Context +// - lang localize.Lang // - to string // - lpaUID string // - sms notify.SMS -func (_e *mockNotifyClient_Expecter) SendActorSMS(_a0 interface{}, to interface{}, lpaUID interface{}, sms interface{}) *mockNotifyClient_SendActorSMS_Call { - return &mockNotifyClient_SendActorSMS_Call{Call: _e.mock.On("SendActorSMS", _a0, to, lpaUID, sms)} +func (_e *mockNotifyClient_Expecter) SendActorSMS(_a0 interface{}, lang interface{}, to interface{}, lpaUID interface{}, sms interface{}) *mockNotifyClient_SendActorSMS_Call { + return &mockNotifyClient_SendActorSMS_Call{Call: _e.mock.On("SendActorSMS", _a0, lang, to, lpaUID, sms)} } -func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(_a0 context.Context, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(_a0 context.Context, lang localize.Lang, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.SMS)) + run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.SMS)) }) return _c } @@ -115,7 +119,7 @@ func (_c *mockNotifyClient_SendActorSMS_Call) Return(_a0 error) *mockNotifyClien return _c } -func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/witness_code_sender.go b/internal/donor/witness_code_sender.go index ea8c6e7475..5e4e9ef09a 100644 --- a/internal/donor/witness_code_sender.go +++ b/internal/donor/witness_code_sender.go @@ -5,6 +5,7 @@ import ( "errors" "time" + "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -23,9 +24,13 @@ type DonorStore interface { Put(context.Context, *donordata.Provided) error } +type CertificateProviderStore interface { + GetAny(context.Context) (*certificateproviderdata.Provided, error) +} + type NotifyClient interface { - SendActorEmail(context context.Context, to, lpaUID string, email notify.Email) error - SendActorSMS(context context.Context, to, lpaUID string, sms notify.SMS) error + SendActorEmail(context context.Context, lang localize.Lang, to, lpaUID string, email notify.Email) error + SendActorSMS(context context.Context, lang localize.Lang, to, lpaUID string, sms notify.SMS) error } type Localizer interface { @@ -43,20 +48,22 @@ type Localizer interface { } type WitnessCodeSender struct { - donorStore DonorStore - notifyClient NotifyClient - localizer Localizer - randomCode func(int) string - now func() time.Time + donorStore DonorStore + certificateProviderStore CertificateProviderStore + notifyClient NotifyClient + localizer Localizer + randomCode func(int) string + now func() time.Time } -func NewWitnessCodeSender(donorStore DonorStore, notifyClient NotifyClient, localizer Localizer) *WitnessCodeSender { +func NewWitnessCodeSender(donorStore DonorStore, certificateProviderStore CertificateProviderStore, notifyClient NotifyClient, localizer Localizer) *WitnessCodeSender { return &WitnessCodeSender{ - donorStore: donorStore, - notifyClient: notifyClient, - localizer: localizer, - randomCode: random.Code, - now: time.Now, + donorStore: donorStore, + certificateProviderStore: certificateProviderStore, + notifyClient: notifyClient, + localizer: localizer, + randomCode: random.Code, + now: time.Now, } } @@ -76,7 +83,12 @@ func (s *WitnessCodeSender) SendToCertificateProvider(ctx context.Context, donor return err } - return s.notifyClient.SendActorSMS(ctx, donor.CertificateProvider.Mobile, donor.LpaUID, notify.WitnessCodeSMS{ + contactLanguage := localize.En + if certificateProvider, _ := s.certificateProviderStore.GetAny(ctx); certificateProvider != nil { + contactLanguage = certificateProvider.ContactLanguagePreference + } + + return s.notifyClient.SendActorSMS(ctx, contactLanguage, donor.CertificateProvider.Mobile, donor.LpaUID, notify.WitnessCodeSMS{ WitnessCode: code, DonorFullName: s.localizer.Possessive(donor.Donor.FullName()), LpaType: localize.LowerFirst(s.localizer.T(donor.Type.String())), @@ -99,7 +111,7 @@ func (s *WitnessCodeSender) SendToIndependentWitness(ctx context.Context, donor return err } - return s.notifyClient.SendActorSMS(ctx, donor.IndependentWitness.Mobile, donor.LpaUID, notify.WitnessCodeSMS{ + return s.notifyClient.SendActorSMS(ctx, localize.En, donor.IndependentWitness.Mobile, donor.LpaUID, notify.WitnessCodeSMS{ WitnessCode: code, DonorFullName: s.localizer.Possessive(donor.Donor.FullName()), LpaType: localize.LowerFirst(s.localizer.T(donor.Type.String())), diff --git a/internal/donor/witness_code_sender_test.go b/internal/donor/witness_code_sender_test.go index 5edf22c5d8..a44af1983e 100644 --- a/internal/donor/witness_code_sender_test.go +++ b/internal/donor/witness_code_sender_test.go @@ -5,7 +5,10 @@ import ( "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/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/stretchr/testify/assert" @@ -37,7 +40,7 @@ func TestWitnessCodeSenderSendToCertificateProvider(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(ctx, "0777", "lpa-uid", notify.WitnessCodeSMS{ + SendActorSMS(ctx, localize.En, "0777", "lpa-uid", notify.WitnessCodeSMS{ WitnessCode: tc.expectedWitnessCode, DonorFullName: "Joe Jones’", LpaType: "property and affairs", @@ -55,6 +58,11 @@ func TestWitnessCodeSenderSendToCertificateProvider(t *testing.T) { }). Return(nil) + certificateProviderStore := newMockCertificateProviderStore(t) + certificateProviderStore.EXPECT(). + GetAny(ctx). + Return(nil, dynamo.NotFoundError{}) + localizer := newMockLocalizer(t) localizer.EXPECT(). T("property-and-affairs"). @@ -64,11 +72,12 @@ func TestWitnessCodeSenderSendToCertificateProvider(t *testing.T) { Return("Joe Jones’") sender := &WitnessCodeSender{ - donorStore: donorStore, - notifyClient: notifyClient, - localizer: localizer, - randomCode: func(int) string { return tc.randomCode }, - now: func() time.Time { return now }, + donorStore: donorStore, + certificateProviderStore: certificateProviderStore, + notifyClient: notifyClient, + localizer: localizer, + randomCode: func(int) string { return tc.randomCode }, + now: func() time.Time { return now }, } err := sender.SendToCertificateProvider(ctx, &donordata.Provided{ LpaUID: "lpa-uid", @@ -82,6 +91,61 @@ func TestWitnessCodeSenderSendToCertificateProvider(t *testing.T) { } } +func TestWitnessCodeSenderSendToCertificateProviderWhenContactLanguagePreference(t *testing.T) { + now := time.Now() + ctx := context.Background() + + notifyClient := newMockNotifyClient(t) + notifyClient.EXPECT(). + SendActorSMS(ctx, localize.Cy, "0777", "lpa-uid", notify.WitnessCodeSMS{ + WitnessCode: "1234", + DonorFullName: "Joe Jones’", + LpaType: "property and affairs", + }). + Return(nil) + + donorStore := newMockDonorStore(t) + donorStore.EXPECT(). + Put(ctx, &donordata.Provided{ + LpaUID: "lpa-uid", + Donor: donordata.Donor{FirstNames: "Joe", LastName: "Jones"}, + CertificateProvider: donordata.CertificateProvider{Mobile: "0777"}, + CertificateProviderCodes: donordata.WitnessCodes{{Code: "1234", Created: now}}, + Type: lpadata.LpaTypePropertyAndAffairs, + }). + Return(nil) + + certificateProviderStore := newMockCertificateProviderStore(t) + certificateProviderStore.EXPECT(). + GetAny(ctx). + Return(&certificateproviderdata.Provided{ContactLanguagePreference: localize.Cy}, nil) + + localizer := newMockLocalizer(t) + localizer.EXPECT(). + T("property-and-affairs"). + Return("property and affairs") + localizer.EXPECT(). + Possessive("Joe Jones"). + Return("Joe Jones’") + + sender := &WitnessCodeSender{ + donorStore: donorStore, + certificateProviderStore: certificateProviderStore, + notifyClient: notifyClient, + localizer: localizer, + randomCode: func(int) string { return "1234" }, + now: func() time.Time { return now }, + } + err := sender.SendToCertificateProvider(ctx, &donordata.Provided{ + LpaUID: "lpa-uid", + Donor: donordata.Donor{FirstNames: "Joe", LastName: "Jones"}, + CertificateProvider: donordata.CertificateProvider{Mobile: "0777"}, + Type: lpadata.LpaTypePropertyAndAffairs, + }) + + assert.Nil(t, err) +} + func TestWitnessCodeSenderSendToCertificateProviderWhenTooRecentlySent(t *testing.T) { now := time.Now() ctx := context.Background() @@ -97,7 +161,7 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenTooRecentlySent(t *testin func TestWitnessCodeSenderSendToCertificateProviderWhenNotifyClientErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) donorStore := newMockDonorStore(t) @@ -105,6 +169,11 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenNotifyClientErrors(t *tes Put(mock.Anything, mock.Anything). Return(nil) + certificateProviderStore := newMockCertificateProviderStore(t) + certificateProviderStore.EXPECT(). + GetAny(ctx). + Return(nil, dynamo.NotFoundError{}) + localizer := newMockLocalizer(t) localizer.EXPECT(). T("property-and-affairs"). @@ -114,11 +183,12 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenNotifyClientErrors(t *tes Return("Joe Jones’") sender := &WitnessCodeSender{ - donorStore: donorStore, - notifyClient: notifyClient, - localizer: localizer, - randomCode: func(int) string { return "1234" }, - now: time.Now, + donorStore: donorStore, + certificateProviderStore: certificateProviderStore, + notifyClient: notifyClient, + localizer: localizer, + randomCode: func(int) string { return "1234" }, + now: time.Now, } err := sender.SendToCertificateProvider(context.Background(), &donordata.Provided{ CertificateProvider: donordata.CertificateProvider{Mobile: "0777"}, @@ -155,7 +225,7 @@ func TestWitnessCodeSenderSendToIndependentWitness(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(ctx, "0777", "lpa-uid", notify.WitnessCodeSMS{ + SendActorSMS(ctx, localize.En, "0777", "lpa-uid", notify.WitnessCodeSMS{ WitnessCode: "1234", DonorFullName: "Joe Jones’", LpaType: "property and affairs", @@ -213,7 +283,7 @@ func TestWitnessCodeSenderSendToIndependentWitnessWhenTooRecentlySent(t *testing func TestWitnessCodeSenderSendToIndependentWitnessWhenNotifyClientErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) donorStore := newMockDonorStore(t) diff --git a/internal/notify/client.go b/internal/notify/client.go index bbd9aa1294..285bad9d4c 100644 --- a/internal/notify/client.go +++ b/internal/notify/client.go @@ -138,18 +138,15 @@ type emailWrapper struct { Reference string `json:"reference"` } -func (c *Client) SendEmail(ctx context.Context, to string, email Email) error { - tracer := otel.GetTracerProvider().Tracer("mlpab") - ctx, span := tracer.Start(ctx, "Email", - trace.WithSpanKind(trace.SpanKindInternal)) - span.SetAttributes( - attribute.KeyValue{Key: "template_id", Value: attribute.StringValue(email.emailID(c.isProduction))}, - attribute.KeyValue{Key: "to", Value: attribute.StringValue(to)}) +func (c *Client) SendEmail(ctx context.Context, lang localize.Lang, to string, email Email) error { + templateID := email.emailID(c.isProduction, lang) + + ctx, span := newSpan(ctx, "Email", templateID, to) defer span.End() req, err := c.newRequest(ctx, http.MethodPost, "/v2/notifications/email", emailWrapper{ EmailAddress: to, - TemplateID: email.emailID(c.isProduction), + TemplateID: templateID, Personalisation: email, }) if err != nil { @@ -166,24 +163,21 @@ func (c *Client) SendEmail(ctx context.Context, to string, email Email) error { return nil } -func (c *Client) SendActorEmail(ctx context.Context, to, lpaUID string, email Email) error { - tracer := otel.GetTracerProvider().Tracer("mlpab") - ctx, span := tracer.Start(ctx, "Email", - trace.WithSpanKind(trace.SpanKindInternal)) - span.SetAttributes( - attribute.KeyValue{Key: "template_id", Value: attribute.StringValue(email.emailID(c.isProduction))}, - attribute.KeyValue{Key: "to", Value: attribute.StringValue(to)}) +func (c *Client) SendActorEmail(ctx context.Context, lang localize.Lang, to, lpaUID string, email Email) error { + templateID := email.emailID(c.isProduction, lang) + + ctx, span := newSpan(ctx, "Email", templateID, to) defer span.End() - if ok, err := c.recentlySent(ctx, c.makeReference(lpaUID, to, email)); err != nil || ok { + if ok, err := c.recentlySent(ctx, c.makeReference(lpaUID, to, templateID)); err != nil || ok { return err } req, err := c.newRequest(ctx, http.MethodPost, "/v2/notifications/email", emailWrapper{ EmailAddress: to, - TemplateID: email.emailID(c.isProduction), + TemplateID: templateID, Personalisation: email, - Reference: c.makeReference(lpaUID, to, email), + Reference: c.makeReference(lpaUID, to, templateID), }) if err != nil { return err @@ -214,18 +208,15 @@ type smsWrapper struct { Personalisation any `json:"personalisation,omitempty"` } -func (c *Client) SendActorSMS(ctx context.Context, to, lpaUID string, sms SMS) error { - tracer := otel.GetTracerProvider().Tracer("mlpab") - ctx, span := tracer.Start(ctx, "SMS", - trace.WithSpanKind(trace.SpanKindInternal)) - span.SetAttributes( - attribute.KeyValue{Key: "template_id", Value: attribute.StringValue(sms.smsID(c.isProduction))}, - attribute.KeyValue{Key: "to", Value: attribute.StringValue(to)}) +func (c *Client) SendActorSMS(ctx context.Context, lang localize.Lang, to, lpaUID string, sms SMS) error { + templateID := sms.smsID(c.isProduction, lang) + + ctx, span := newSpan(ctx, "SMS", templateID, to) defer span.End() req, err := c.newRequest(ctx, http.MethodPost, "/v2/notifications/sms", smsWrapper{ PhoneNumber: to, - TemplateID: sms.smsID(c.isProduction), + TemplateID: templateID, Personalisation: sms, }) if err != nil { @@ -317,13 +308,23 @@ func (c *Client) do(req *http.Request) (response, error) { return r, nil } -func (c *Client) makeReference(lpaUID, to string, email Email) string { +func (c *Client) makeReference(lpaUID, to, templateID string) string { hash := sha256.New() hash.Write([]byte(lpaUID)) hash.Write([]byte{'|'}) hash.Write([]byte(to)) hash.Write([]byte{'|'}) - hash.Write([]byte(email.emailID(c.isProduction))) + hash.Write([]byte(templateID)) return base64.RawStdEncoding.EncodeToString(hash.Sum(nil)) } + +func newSpan(ctx context.Context, label, templateID, to string) (context.Context, trace.Span) { + tracer := otel.GetTracerProvider().Tracer("mlpab") + ctx, span := tracer.Start(ctx, label, + trace.WithSpanKind(trace.SpanKindInternal)) + span.SetAttributes( + attribute.KeyValue{Key: "template_id", Value: attribute.StringValue(templateID)}, + attribute.KeyValue{Key: "to", Value: attribute.StringValue(to)}) + return ctx, span +} diff --git a/internal/notify/client_test.go b/internal/notify/client_test.go index 844cb6cfc9..008cd8a3ca 100644 --- a/internal/notify/client_test.go +++ b/internal/notify/client_test.go @@ -116,7 +116,7 @@ type testEmail struct { A string } -func (e testEmail) emailID(bool) string { return "template-id" } +func (e testEmail) emailID(bool, localize.Lang) string { return "template-id" } func TestSendEmail(t *testing.T) { assert := assert.New(t) @@ -146,7 +146,7 @@ func TestSendEmail(t *testing.T) { client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, nil, nil) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - err := client.SendEmail(ctx, "me@example.com", testEmail{A: "value"}) + err := client.SendEmail(ctx, localize.En, "me@example.com", testEmail{A: "value"}) assert.Nil(err) } @@ -169,7 +169,7 @@ func TestSendEmailWhenError(t *testing.T) { client, _ := New(logger, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, nil, nil) - err := client.SendEmail(ctx, "me@example.com", testEmail{}) + err := client.SendEmail(ctx, localize.En, "me@example.com", testEmail{}) assert.Equal(`error sending message: This happened: Plus this`, err.Error()) } @@ -228,7 +228,7 @@ func TestSendActorEmail(t *testing.T) { client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, eventClient, nil) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - err := client.SendActorEmail(ctx, "me@example.com", "lpa-uid", testEmail{A: "value"}) + err := client.SendActorEmail(ctx, localize.En, "me@example.com", "lpa-uid", testEmail{A: "value"}) assert.Nil(err) }) } @@ -256,7 +256,7 @@ func TestSendActorEmailWhenToSimulated(t *testing.T) { client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, nil, nil) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - err := client.SendActorEmail(ctx, email, "lpa-uid", testEmail{A: "value"}) + err := client.SendActorEmail(ctx, localize.En, email, "lpa-uid", testEmail{A: "value"}) assert.Nil(err) } } @@ -292,7 +292,7 @@ func TestSendActorEmailWhenAlreadyRecentlyCreated(t *testing.T) { client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, nil, nil) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - err := client.SendActorEmail(ctx, "me@example.com", "lpa-uid", testEmail{A: "value"}) + err := client.SendActorEmail(ctx, localize.En, "me@example.com", "lpa-uid", testEmail{A: "value"}) assert.Nil(err) }) } @@ -306,7 +306,7 @@ func TestSendActorEmailWhenReferenceExistsError(t *testing.T) { client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, nil, nil) - err := client.SendActorEmail(context.Background(), "me@example.com", "lpa-uid", testEmail{A: "value"}) + err := client.SendActorEmail(context.Background(), localize.En, "me@example.com", "lpa-uid", testEmail{A: "value"}) assert.Equal(t, expectedError, err) } @@ -331,7 +331,7 @@ func TestSendActorEmailWhenError(t *testing.T) { client, _ := New(logger, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, nil, nil) - err := client.SendActorEmail(context.Background(), "me@example.com", "lpa-uid", testEmail{}) + err := client.SendActorEmail(context.Background(), localize.En, "me@example.com", "lpa-uid", testEmail{}) assert.Equal(t, "error sending message: This happened: Plus this", err.Error()) } @@ -358,7 +358,7 @@ func TestSendActorEmailWhenEventError(t *testing.T) { client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, eventClient, nil) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - err := client.SendActorEmail(context.Background(), "me@example.com", "lpa-uid", testEmail{A: "value"}) + err := client.SendActorEmail(context.Background(), localize.En, "me@example.com", "lpa-uid", testEmail{A: "value"}) assert.Equal(t, expectedError, err) } @@ -506,7 +506,7 @@ type testSMS struct { A string } -func (e testSMS) smsID(bool) string { return "template-id" } +func (e testSMS) smsID(bool, localize.Lang) string { return "template-id" } func TestSendActorSMS(t *testing.T) { assert := assert.New(t) @@ -536,7 +536,7 @@ func TestSendActorSMS(t *testing.T) { client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, eventClient, nil) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - err := client.SendActorSMS(ctx, "+447535111111", "lpa-uid", testSMS{A: "value"}) + err := client.SendActorSMS(ctx, localize.En, "+447535111111", "lpa-uid", testSMS{A: "value"}) assert.Nil(err) } @@ -552,7 +552,7 @@ func TestSendActorSMSWhenToSimulated(t *testing.T) { client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, nil, nil) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - err := client.SendActorSMS(context.Background(), phone, "lpa-uid", testSMS{A: "value"}) + err := client.SendActorSMS(context.Background(), localize.En, phone, "lpa-uid", testSMS{A: "value"}) assert.Nil(t, err) } } @@ -567,7 +567,7 @@ func TestSendActorSMSWhenError(t *testing.T) { client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, nil, nil) - err := client.SendActorSMS(context.Background(), "+447535111111", "lpa-uid", testSMS{}) + err := client.SendActorSMS(context.Background(), localize.En, "+447535111111", "lpa-uid", testSMS{}) assert.Equal(t, "error sending message: This happened: Plus this", err.Error()) } @@ -585,7 +585,7 @@ func TestSendActorSMSWhenEventError(t *testing.T) { client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, eventClient, nil) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - err := client.SendActorSMS(context.Background(), "+447535111111", "lpa-uid", testSMS{A: "value"}) + err := client.SendActorSMS(context.Background(), localize.En, "+447535111111", "lpa-uid", testSMS{A: "value"}) assert.Equal(t, expectedError, err) } diff --git a/internal/notify/email.go b/internal/notify/email.go index 1418357406..aedec15e56 100644 --- a/internal/notify/email.go +++ b/internal/notify/email.go @@ -1,7 +1,9 @@ package notify +import "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" + type Email interface { - emailID(bool) string + emailID(bool, localize.Lang) string } type InitialOriginalAttorneyEmail struct { @@ -15,7 +17,7 @@ type InitialOriginalAttorneyEmail struct { AttorneyOptOutURL string } -func (e InitialOriginalAttorneyEmail) emailID(isProduction bool) string { +func (e InitialOriginalAttorneyEmail) emailID(isProduction bool, _ localize.Lang) string { if isProduction { return "080071dc-0434-4b13-adb7-c4e5612c4b47" } @@ -34,7 +36,7 @@ type InitialReplacementAttorneyEmail struct { AttorneyOptOutURL string } -func (e InitialReplacementAttorneyEmail) emailID(isProduction bool) string { +func (e InitialReplacementAttorneyEmail) emailID(isProduction bool, _ localize.Lang) string { if isProduction { return "8d335239-7002-4825-8393-cc00ad246648" } @@ -50,11 +52,19 @@ type CertificateProviderCertificateProvidedEmail struct { DonorFirstNamesPossessive string } -func (e CertificateProviderCertificateProvidedEmail) emailID(isProduction bool) string { +func (e CertificateProviderCertificateProvidedEmail) emailID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "3a52508e-b8f1-4192-b9f4-e912964db3e7" + } + return "64d7d56b-966b-464f-8084-1ac5d91c3d58" } + if lang.IsCy() { + return "ef87ab25-1d4a-4f2d-aaa6-8ef3200c6643" + } + return "76f4370f-1a78-4488-9029-b00fbc292386" } @@ -70,7 +80,7 @@ type CertificateProviderInviteEmail struct { CertificateProviderOptOutURL string } -func (e CertificateProviderInviteEmail) emailID(isProduction bool) string { +func (e CertificateProviderInviteEmail) emailID(isProduction bool, _ localize.Lang) string { if isProduction { return "08a8d89d-e5b7-4bb9-94d2-25139543e962" } @@ -87,11 +97,19 @@ type CertificateProviderProvideCertificatePromptEmail struct { ShareCode string } -func (e CertificateProviderProvideCertificatePromptEmail) emailID(isProduction bool) string { +func (e CertificateProviderProvideCertificatePromptEmail) emailID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "73704800-f241-4b17-8e37-09ee2804a570" + } + return "eac04624-f058-411a-be48-854a77022ac8" } + if lang.IsCy() { + return "675b29ff-63ec-4257-923d-8fcd0db057f7" + } + return "3ad5a806-6789-4687-8731-49ff7357372f" } @@ -103,7 +121,7 @@ type OrganisationMemberInviteEmail struct { JoinAnOrganisationURL string } -func (e OrganisationMemberInviteEmail) emailID(isProduction bool) string { +func (e OrganisationMemberInviteEmail) emailID(isProduction bool, _ localize.Lang) string { if isProduction { return "8433502f-7cbd-42de-a075-7f9343531167" } @@ -120,11 +138,19 @@ type DonorAccessEmail struct { ShareCode string } -func (e DonorAccessEmail) emailID(isProduction bool) string { +func (e DonorAccessEmail) emailID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "cd0f3029-6d6e-4c00-9098-e20394982dc6" + } + return "4e7337cd-34aa-41ba-81e3-3c866e3daf4b" } + if lang.IsCy() { + return "12c7981d-9db2-4b5c-8922-0d437cf997e1" + } + return "0d762056-570b-4fca-9871-1f6a69f9da47" } @@ -137,11 +163,19 @@ type CertificateProviderOptedOutPreWitnessingEmail struct { DonorStartPageURL string } -func (e CertificateProviderOptedOutPreWitnessingEmail) emailID(isProduction bool) string { +func (e CertificateProviderOptedOutPreWitnessingEmail) emailID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "28a72a2e-7dd7-4131-9ac1-616e8f453175" + } + return "1e85965d-4288-42ea-bdd5-f4a29020cf73" } + if lang.IsCy() { + return "3ad13ea7-aed6-4814-90b1-186ac3b78a14" + } + return "06691e59-899a-4b06-8337-68e4c93d5e29" } @@ -155,15 +189,23 @@ type CertificateProviderOptedOutPostWitnessingEmail struct { DonorStartPageURL string } -func (e CertificateProviderOptedOutPostWitnessingEmail) emailID(isProduction bool) string { +func (e CertificateProviderOptedOutPostWitnessingEmail) emailID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "fb22a2fa-b3eb-42b1-9884-fb9398308bc4" + } + return "e284f26e-600a-44f8-b76a-95b93339a054" } + if lang.IsCy() { + return "ce8f18dd-4edf-4289-b98d-a016283217fc" + } + return "654332f4-4e53-4fa1-91d0-f480b577b3d9" } -type CertificateProviderFailedIDCheckEmail struct { +type CertificateProviderFailedIdentityCheckEmail struct { Greeting string DonorFullName string CertificateProviderFullName string @@ -171,11 +213,19 @@ type CertificateProviderFailedIDCheckEmail struct { DonorStartPageURL string } -func (e CertificateProviderFailedIDCheckEmail) emailID(isProduction bool) string { +func (e CertificateProviderFailedIdentityCheckEmail) emailID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "c29f3c42-0cbf-42d0-9c5c-3ceea2095b07" + } + return "4020a281-8b64-45ec-85c6-19a89c08bcdb" } + if lang.IsCy() { + return "de242ce4-ff15-4467-a207-dd2d8f7e2ae5" + } + return "26d337be-eef3-405f-96ed-cb2ed76002b3" } @@ -189,11 +239,19 @@ type PaymentConfirmationEmail struct { AmountPaidWithCurrency string } -func (e PaymentConfirmationEmail) emailID(isProduction bool) string { +func (e PaymentConfirmationEmail) emailID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "b1d0a9d7-0886-4d5d-acc0-08fe69e492ad" + } + return "d0946a7d-d7fe-47cb-9b41-464f13727bf3" } + if lang.IsCy() { + return "662548fd-4382-42f3-88eb-7426bd868a23" + } + return "ff757818-f066-4605-8751-af481afe8a2b" } @@ -206,13 +264,13 @@ type AttorneyOptedOutEmail struct { DonorStartPageURL string } -func (e AttorneyOptedOutEmail) emailID(isProduction bool) string { +func (e AttorneyOptedOutEmail) emailID(isProduction bool, _ localize.Lang) string { return "TODO" } type DonorIdentityCheckExpiredEmail struct{} -func (e DonorIdentityCheckExpiredEmail) emailID(isProduction bool) string { +func (e DonorIdentityCheckExpiredEmail) emailID(isProduction bool, _ localize.Lang) string { return "TODO" } @@ -223,11 +281,19 @@ type VouchingShareCodeEmail struct { LpaType string } -func (s VouchingShareCodeEmail) emailID(isProduction bool) string { +func (s VouchingShareCodeEmail) emailID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "93ee9148-b962-4398-ab94-d2625e39fbb1" + } + return "38e26a3f-d87d-4b0c-8985-8fb5bed79466" } + if lang.IsCy() { + return "a5d9bc34-a7f4-44c4-8473-376845c5b0b9" + } + return "881e25c4-4898-4525-bca3-722f51c5d6ee" } @@ -240,7 +306,7 @@ type VoucherInviteEmail struct { VoucherStartPageURL string } -func (s VoucherInviteEmail) emailID(isProduction bool) string { +func (s VoucherInviteEmail) emailID(isProduction bool, _ localize.Lang) string { if isProduction { return "36ad56ad-823b-4852-88a7-8acc4dfd1749" } @@ -254,11 +320,19 @@ type VouchingFailedAttemptEmail struct { DonorStartPageURL string } -func (e VouchingFailedAttemptEmail) emailID(isProduction bool) string { +func (e VouchingFailedAttemptEmail) emailID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "db45c036-1379-45d1-a521-919217f50e45" + } + return "f21ee857-8c3e-43ee-adf2-2d9f1ff1a1a8" } + if lang.IsCy() { + return "6f647fa8-587b-4f49-be75-d85a44f167b2" + } + return "584412e6-f235-4227-aff9-6cb56ba48e31" } @@ -268,11 +342,19 @@ type VoucherHasConfirmedDonorIdentityEmail struct { DonorStartPageURL string } -func (e VoucherHasConfirmedDonorIdentityEmail) emailID(isProduction bool) string { +func (e VoucherHasConfirmedDonorIdentityEmail) emailID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "d1c1bb6f-e9eb-44d6-802b-49590fb0d0fa" + } + return "67cd151e-6e7b-4fba-9457-f0252e75dfe2" } + if lang.IsCy() { + return "d81b27c2-07e3-47c3-baa6-a8114673c32d" + } + return "86e6d479-6bef-428c-a09d-02a325b97972" } @@ -282,10 +364,18 @@ type VoucherHasConfirmedDonorIdentityOnSignedLpaEmail struct { DonorStartPageURL string } -func (e VoucherHasConfirmedDonorIdentityOnSignedLpaEmail) emailID(isProduction bool) string { +func (e VoucherHasConfirmedDonorIdentityOnSignedLpaEmail) emailID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "3305cfe2-5622-4292-9838-78d6c152db23" + } + return "8df993ff-e4d9-43f2-b714-39053510c664" } + if lang.IsCy() { + return "3884d77c-09c2-4396-b6df-cd32e76a4bb0" + } + return "efa0ef78-9e65-4edf-88c8-70d3da7a4b0e" } diff --git a/internal/notify/mock_Email_test.go b/internal/notify/mock_Email_test.go index 02e24379dc..12b19b7aab 100644 --- a/internal/notify/mock_Email_test.go +++ b/internal/notify/mock_Email_test.go @@ -2,7 +2,10 @@ package notify -import mock "github.com/stretchr/testify/mock" +import ( + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" + mock "github.com/stretchr/testify/mock" +) // mockEmail is an autogenerated mock type for the Email type type mockEmail struct { @@ -17,17 +20,17 @@ func (_m *mockEmail) EXPECT() *mockEmail_Expecter { return &mockEmail_Expecter{mock: &_m.Mock} } -// emailID provides a mock function with given fields: _a0 -func (_m *mockEmail) emailID(_a0 bool) string { - ret := _m.Called(_a0) +// emailID provides a mock function with given fields: _a0, _a1 +func (_m *mockEmail) emailID(_a0 bool, _a1 localize.Lang) string { + ret := _m.Called(_a0, _a1) if len(ret) == 0 { panic("no return value specified for emailID") } var r0 string - if rf, ok := ret.Get(0).(func(bool) string); ok { - r0 = rf(_a0) + if rf, ok := ret.Get(0).(func(bool, localize.Lang) string); ok { + r0 = rf(_a0, _a1) } else { r0 = ret.Get(0).(string) } @@ -42,13 +45,14 @@ type mockEmail_emailID_Call struct { // emailID is a helper method to define mock.On call // - _a0 bool -func (_e *mockEmail_Expecter) emailID(_a0 interface{}) *mockEmail_emailID_Call { - return &mockEmail_emailID_Call{Call: _e.mock.On("emailID", _a0)} +// - _a1 localize.Lang +func (_e *mockEmail_Expecter) emailID(_a0 interface{}, _a1 interface{}) *mockEmail_emailID_Call { + return &mockEmail_emailID_Call{Call: _e.mock.On("emailID", _a0, _a1)} } -func (_c *mockEmail_emailID_Call) Run(run func(_a0 bool)) *mockEmail_emailID_Call { +func (_c *mockEmail_emailID_Call) Run(run func(_a0 bool, _a1 localize.Lang)) *mockEmail_emailID_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) + run(args[0].(bool), args[1].(localize.Lang)) }) return _c } @@ -58,7 +62,7 @@ func (_c *mockEmail_emailID_Call) Return(_a0 string) *mockEmail_emailID_Call { return _c } -func (_c *mockEmail_emailID_Call) RunAndReturn(run func(bool) string) *mockEmail_emailID_Call { +func (_c *mockEmail_emailID_Call) RunAndReturn(run func(bool, localize.Lang) string) *mockEmail_emailID_Call { _c.Call.Return(run) return _c } diff --git a/internal/notify/mock_SMS_test.go b/internal/notify/mock_SMS_test.go index a11f94db8e..5e0509b235 100644 --- a/internal/notify/mock_SMS_test.go +++ b/internal/notify/mock_SMS_test.go @@ -2,7 +2,10 @@ package notify -import mock "github.com/stretchr/testify/mock" +import ( + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" + mock "github.com/stretchr/testify/mock" +) // mockSMS is an autogenerated mock type for the SMS type type mockSMS struct { @@ -17,17 +20,17 @@ func (_m *mockSMS) EXPECT() *mockSMS_Expecter { return &mockSMS_Expecter{mock: &_m.Mock} } -// smsID provides a mock function with given fields: _a0 -func (_m *mockSMS) smsID(_a0 bool) string { - ret := _m.Called(_a0) +// smsID provides a mock function with given fields: _a0, _a1 +func (_m *mockSMS) smsID(_a0 bool, _a1 localize.Lang) string { + ret := _m.Called(_a0, _a1) if len(ret) == 0 { panic("no return value specified for smsID") } var r0 string - if rf, ok := ret.Get(0).(func(bool) string); ok { - r0 = rf(_a0) + if rf, ok := ret.Get(0).(func(bool, localize.Lang) string); ok { + r0 = rf(_a0, _a1) } else { r0 = ret.Get(0).(string) } @@ -42,13 +45,14 @@ type mockSMS_smsID_Call struct { // smsID is a helper method to define mock.On call // - _a0 bool -func (_e *mockSMS_Expecter) smsID(_a0 interface{}) *mockSMS_smsID_Call { - return &mockSMS_smsID_Call{Call: _e.mock.On("smsID", _a0)} +// - _a1 localize.Lang +func (_e *mockSMS_Expecter) smsID(_a0 interface{}, _a1 interface{}) *mockSMS_smsID_Call { + return &mockSMS_smsID_Call{Call: _e.mock.On("smsID", _a0, _a1)} } -func (_c *mockSMS_smsID_Call) Run(run func(_a0 bool)) *mockSMS_smsID_Call { +func (_c *mockSMS_smsID_Call) Run(run func(_a0 bool, _a1 localize.Lang)) *mockSMS_smsID_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(bool)) + run(args[0].(bool), args[1].(localize.Lang)) }) return _c } @@ -58,7 +62,7 @@ func (_c *mockSMS_smsID_Call) Return(_a0 string) *mockSMS_smsID_Call { return _c } -func (_c *mockSMS_smsID_Call) RunAndReturn(run func(bool) string) *mockSMS_smsID_Call { +func (_c *mockSMS_smsID_Call) RunAndReturn(run func(bool, localize.Lang) string) *mockSMS_smsID_Call { _c.Call.Return(run) return _c } diff --git a/internal/notify/sms.go b/internal/notify/sms.go index f8de146518..4b2b0bdfdc 100644 --- a/internal/notify/sms.go +++ b/internal/notify/sms.go @@ -1,7 +1,9 @@ package notify +import "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" + type SMS interface { - smsID(bool) string + smsID(bool, localize.Lang) string } type CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS struct { @@ -11,11 +13,19 @@ type CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChan DonorFirstNames string } -func (s CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS) smsID(isProduction bool) string { +func (s CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS) smsID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "b894b318-ebf1-4e31-8bc4-d1289a1d0dd7" + } + return "28873afc-f019-48c1-bd25-df88c27813e0" } + if lang.IsCy() { + return "7c1820ef-bc75-4d33-9d3d-edcb49404be1" + } + return "bcdc85a7-32b1-40a6-a61f-a552406e6ecc" } @@ -24,7 +34,7 @@ type CertificateProviderActingDigitallyHasNotConfirmedPersonalDetailsLPADetailsC LpaType string } -func (s CertificateProviderActingDigitallyHasNotConfirmedPersonalDetailsLPADetailsChangedPromptSMS) smsID(isProduction bool) string { +func (s CertificateProviderActingDigitallyHasNotConfirmedPersonalDetailsLPADetailsChangedPromptSMS) smsID(isProduction bool, _ localize.Lang) string { if isProduction { return "796990f2-cf49-48a4-9f04-fc12f4a9702b" } @@ -38,7 +48,7 @@ type CertificateProviderActingOnPaperDetailsChangedSMS struct { DonorFirstNames string } -func (s CertificateProviderActingOnPaperDetailsChangedSMS) smsID(isProduction bool) string { +func (s CertificateProviderActingOnPaperDetailsChangedSMS) smsID(isProduction bool, _ localize.Lang) string { if isProduction { return "b3044df8-b58d-4eb0-bfc2-de6fa778a2c9" } @@ -53,7 +63,7 @@ type CertificateProviderActingOnPaperMeetingPromptSMS struct { CertificateProviderStartPageURL string } -func (s CertificateProviderActingOnPaperMeetingPromptSMS) smsID(isProduction bool) string { +func (s CertificateProviderActingOnPaperMeetingPromptSMS) smsID(isProduction bool, _ localize.Lang) string { if isProduction { return "45589f2d-c45e-420f-9d16-f2c7a3d64bfb" } @@ -67,11 +77,19 @@ type WitnessCodeSMS struct { LpaType string } -func (s WitnessCodeSMS) smsID(isProduction bool) string { +func (s WitnessCodeSMS) smsID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "5ae6190d-0610-45a2-be4f-1cdcab6e579c" + } + return "e39849c0-ecab-4e16-87ec-6b22afb9d535" } + if lang.IsCy() { + return "482ee4ca-5934-42b0-b9eb-57de4aa58f5a" + } + return "dfa15e16-1f23-494a-bffb-a475513df6cc" } @@ -83,11 +101,19 @@ type VouchingShareCodeSMS struct { DonorFirstNamesPossessive string } -func (s VouchingShareCodeSMS) smsID(isProduction bool) string { +func (s VouchingShareCodeSMS) smsID(isProduction bool, lang localize.Lang) string { if isProduction { + if lang.IsCy() { + return "ab573f2e-de40-42ad-a4cf-25ba3be1fe0c" + } + return "4864a99a-40a7-4aef-8c1d-7fdc0a4775b9" } + if lang.IsCy() { + return "ae5554c5-0c9c-4b39-9527-406c05167816" + } + return "84d70372-5c7a-4a88-a836-ee7c7dea203a" } @@ -97,7 +123,7 @@ type VoucherHasConfirmedDonorIdentitySMS struct { DonorStartPageURL string } -func (e VoucherHasConfirmedDonorIdentitySMS) smsID(isProduction bool) string { +func (e VoucherHasConfirmedDonorIdentitySMS) smsID(isProduction bool, _ localize.Lang) string { if isProduction { return "ba3a4ae6-e68c-44e4-9923-f84d83c5f147" } @@ -110,7 +136,7 @@ type VoucherHasConfirmedDonorIdentityOnSignedLpaSMS struct { DonorStartPageURL string } -func (e VoucherHasConfirmedDonorIdentityOnSignedLpaSMS) smsID(isProduction bool) string { +func (e VoucherHasConfirmedDonorIdentityOnSignedLpaSMS) smsID(isProduction bool, _ localize.Lang) string { if isProduction { return "7067aa92-df60-4e80-b2bf-0c64a4256d68" } diff --git a/internal/page/common.go b/internal/page/common.go index 2c0a66a36c..af7a707e6e 100644 --- a/internal/page/common.go +++ b/internal/page/common.go @@ -13,7 +13,6 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" - "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode/sharecodedata" @@ -33,11 +32,6 @@ type ShareCodeStore interface { Put(ctx context.Context, actorType actor.Type, shareCode string, data sharecodedata.Link) error } -type NotifyClient interface { - SendActorEmail(context context.Context, to, lpaUID string, email notify.Email) error - SendActorSMS(context context.Context, to, lpaUID string, sms notify.SMS) error -} - type OneLoginClient interface { AuthCodeURL(state, nonce, locale string, identity bool) (string, error) EndSessionURL(idToken, postLogoutURL string) (string, error) diff --git a/internal/page/mock_NotifyClient_test.go b/internal/page/mock_NotifyClient_test.go deleted file mode 100644 index 39754abbcf..0000000000 --- a/internal/page/mock_NotifyClient_test.go +++ /dev/null @@ -1,135 +0,0 @@ -// Code generated by mockery v2.46.1. DO NOT EDIT. - -package page - -import ( - context "context" - - notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" - mock "github.com/stretchr/testify/mock" -) - -// mockNotifyClient is an autogenerated mock type for the NotifyClient type -type mockNotifyClient struct { - mock.Mock -} - -type mockNotifyClient_Expecter struct { - mock *mock.Mock -} - -func (_m *mockNotifyClient) EXPECT() *mockNotifyClient_Expecter { - return &mockNotifyClient_Expecter{mock: &_m.Mock} -} - -// SendActorEmail provides a mock function with given fields: _a0, to, lpaUID, email -func (_m *mockNotifyClient) SendActorEmail(_a0 context.Context, to string, lpaUID string, email notify.Email) error { - ret := _m.Called(_a0, to, lpaUID, email) - - if len(ret) == 0 { - panic("no return value specified for SendActorEmail") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.Email) error); ok { - r0 = rf(_a0, to, lpaUID, email) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// mockNotifyClient_SendActorEmail_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendActorEmail' -type mockNotifyClient_SendActorEmail_Call struct { - *mock.Call -} - -// SendActorEmail is a helper method to define mock.On call -// - _a0 context.Context -// - to string -// - lpaUID string -// - email notify.Email -func (_e *mockNotifyClient_Expecter) SendActorEmail(_a0 interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { - return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", _a0, to, lpaUID, email)} -} - -func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(_a0 context.Context, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.Email)) - }) - return _c -} - -func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyClient_SendActorEmail_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { - _c.Call.Return(run) - return _c -} - -// SendActorSMS provides a mock function with given fields: _a0, to, lpaUID, sms -func (_m *mockNotifyClient) SendActorSMS(_a0 context.Context, to string, lpaUID string, sms notify.SMS) error { - ret := _m.Called(_a0, to, lpaUID, sms) - - if len(ret) == 0 { - panic("no return value specified for SendActorSMS") - } - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.SMS) error); ok { - r0 = rf(_a0, to, lpaUID, sms) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// mockNotifyClient_SendActorSMS_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendActorSMS' -type mockNotifyClient_SendActorSMS_Call struct { - *mock.Call -} - -// SendActorSMS is a helper method to define mock.On call -// - _a0 context.Context -// - to string -// - lpaUID string -// - sms notify.SMS -func (_e *mockNotifyClient_Expecter) SendActorSMS(_a0 interface{}, to interface{}, lpaUID interface{}, sms interface{}) *mockNotifyClient_SendActorSMS_Call { - return &mockNotifyClient_SendActorSMS_Call{Call: _e.mock.On("SendActorSMS", _a0, to, lpaUID, sms)} -} - -func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(_a0 context.Context, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.SMS)) - }) - return _c -} - -func (_c *mockNotifyClient_SendActorSMS_Call) Return(_a0 error) *mockNotifyClient_SendActorSMS_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { - _c.Call.Return(run) - return _c -} - -// newMockNotifyClient creates a new instance of mockNotifyClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func newMockNotifyClient(t interface { - mock.TestingT - Cleanup(func()) -}) *mockNotifyClient { - mock := &mockNotifyClient{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/scheduled/mock_NotifyClient_test.go b/internal/scheduled/mock_NotifyClient_test.go index e80609c83b..de98b5fdc6 100644 --- a/internal/scheduled/mock_NotifyClient_test.go +++ b/internal/scheduled/mock_NotifyClient_test.go @@ -5,8 +5,10 @@ package scheduled import ( context "context" - notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" mock "github.com/stretchr/testify/mock" + + notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" ) // mockNotifyClient is an autogenerated mock type for the NotifyClient type @@ -22,17 +24,17 @@ func (_m *mockNotifyClient) EXPECT() *mockNotifyClient_Expecter { return &mockNotifyClient_Expecter{mock: &_m.Mock} } -// SendActorEmail provides a mock function with given fields: ctx, to, lpaUID, email -func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, to string, lpaUID string, email notify.Email) error { - ret := _m.Called(ctx, to, lpaUID, email) +// SendActorEmail provides a mock function with given fields: ctx, lang, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email) error { + ret := _m.Called(ctx, lang, to, lpaUID, email) if len(ret) == 0 { panic("no return value specified for SendActorEmail") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.Email) error); ok { - r0 = rf(ctx, to, lpaUID, email) + if rf, ok := ret.Get(0).(func(context.Context, localize.Lang, string, string, notify.Email) error); ok { + r0 = rf(ctx, lang, to, lpaUID, email) } else { r0 = ret.Error(0) } @@ -47,16 +49,17 @@ type mockNotifyClient_SendActorEmail_Call struct { // SendActorEmail is a helper method to define mock.On call // - ctx context.Context +// - lang localize.Lang // - to string // - lpaUID string // - email notify.Email -func (_e *mockNotifyClient_Expecter) SendActorEmail(ctx interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { - return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", ctx, to, lpaUID, email)} +func (_e *mockNotifyClient_Expecter) SendActorEmail(ctx interface{}, lang interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { + return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", ctx, lang, to, lpaUID, email)} } -func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.Email)) + run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.Email)) }) return _c } @@ -66,7 +69,7 @@ func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyCli return _c } -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { _c.Call.Return(run) return _c } diff --git a/internal/scheduled/runner.go b/internal/scheduled/runner.go index 8d9a2a5e97..75c33fd243 100644 --- a/internal/scheduled/runner.go +++ b/internal/scheduled/runner.go @@ -10,6 +10,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" ) @@ -29,7 +30,7 @@ type DonorStore interface { } type NotifyClient interface { - SendActorEmail(ctx context.Context, to, lpaUID string, email notify.Email) error + SendActorEmail(ctx context.Context, lang localize.Lang, to, lpaUID string, email notify.Email) error } type Logger interface { @@ -158,7 +159,7 @@ func (r *Runner) stepCancelDonorIdentity(ctx context.Context, row *Event) error provided.IdentityUserData = identity.UserData{Status: identity.StatusExpired} provided.Tasks.ConfirmYourIdentityAndSign = task.IdentityStateNotStarted - if err := r.notifyClient.SendActorEmail(ctx, provided.CorrespondentEmail(), provided.LpaUID, notify.DonorIdentityCheckExpiredEmail{}); err != nil { + if err := r.notifyClient.SendActorEmail(ctx, provided.Donor.ContactLanguagePreference, provided.CorrespondentEmail(), provided.LpaUID, notify.DonorIdentityCheckExpiredEmail{}); err != nil { return fmt.Errorf("error sending email: %w", err) } diff --git a/internal/scheduled/runner_test.go b/internal/scheduled/runner_test.go index 05cea0f5cd..6430f71b5c 100644 --- a/internal/scheduled/runner_test.go +++ b/internal/scheduled/runner_test.go @@ -10,6 +10,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" "github.com/stretchr/testify/assert" @@ -402,13 +403,13 @@ func TestRunnerStepCancelDonorIdentity(t *testing.T) { One(ctx, lpaKey, donorKey). Return(&donordata.Provided{ LpaUID: "lpa-uid", - Donor: donordata.Donor{Email: "donor@example.com"}, + Donor: donordata.Donor{Email: "donor@example.com", ContactLanguagePreference: localize.Cy}, IdentityUserData: identity.UserData{Status: identity.StatusConfirmed}, }, nil) donorStore.EXPECT(). Put(ctx, &donordata.Provided{ LpaUID: "lpa-uid", - Donor: donordata.Donor{Email: "donor@example.com"}, + Donor: donordata.Donor{Email: "donor@example.com", ContactLanguagePreference: localize.Cy}, IdentityUserData: identity.UserData{Status: identity.StatusExpired}, Tasks: donordata.Tasks{ConfirmYourIdentityAndSign: task.IdentityStateNotStarted}, }). @@ -416,7 +417,7 @@ func TestRunnerStepCancelDonorIdentity(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, "donor@example.com", "lpa-uid", notify.DonorIdentityCheckExpiredEmail{}). + SendActorEmail(ctx, localize.Cy, "donor@example.com", "lpa-uid", notify.DonorIdentityCheckExpiredEmail{}). Return(nil) runner := &Runner{ @@ -499,7 +500,7 @@ func TestRunnerStepCancelDonorIdentityWhenNotifySendErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) runner := &Runner{ @@ -531,7 +532,7 @@ func TestRunnerStepCancelDonorIdentityWhenDonorStorePutErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) runner := &Runner{ diff --git a/internal/sharecode/mock_NotifyClient_test.go b/internal/sharecode/mock_NotifyClient_test.go index 3f0da41482..9913afe468 100644 --- a/internal/sharecode/mock_NotifyClient_test.go +++ b/internal/sharecode/mock_NotifyClient_test.go @@ -5,8 +5,10 @@ package sharecode import ( context "context" - notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" mock "github.com/stretchr/testify/mock" + + notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" ) // mockNotifyClient is an autogenerated mock type for the NotifyClient type @@ -22,17 +24,17 @@ func (_m *mockNotifyClient) EXPECT() *mockNotifyClient_Expecter { return &mockNotifyClient_Expecter{mock: &_m.Mock} } -// SendActorEmail provides a mock function with given fields: _a0, to, lpaUID, email -func (_m *mockNotifyClient) SendActorEmail(_a0 context.Context, to string, lpaUID string, email notify.Email) error { - ret := _m.Called(_a0, to, lpaUID, email) +// SendActorEmail provides a mock function with given fields: _a0, lang, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(_a0 context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email) error { + ret := _m.Called(_a0, lang, to, lpaUID, email) if len(ret) == 0 { panic("no return value specified for SendActorEmail") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.Email) error); ok { - r0 = rf(_a0, to, lpaUID, email) + if rf, ok := ret.Get(0).(func(context.Context, localize.Lang, string, string, notify.Email) error); ok { + r0 = rf(_a0, lang, to, lpaUID, email) } else { r0 = ret.Error(0) } @@ -47,16 +49,17 @@ type mockNotifyClient_SendActorEmail_Call struct { // SendActorEmail is a helper method to define mock.On call // - _a0 context.Context +// - lang localize.Lang // - to string // - lpaUID string // - email notify.Email -func (_e *mockNotifyClient_Expecter) SendActorEmail(_a0 interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { - return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", _a0, to, lpaUID, email)} +func (_e *mockNotifyClient_Expecter) SendActorEmail(_a0 interface{}, lang interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { + return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", _a0, lang, to, lpaUID, email)} } -func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(_a0 context.Context, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(_a0 context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.Email)) + run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.Email)) }) return _c } @@ -66,22 +69,22 @@ func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyCli return _c } -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { _c.Call.Return(run) return _c } -// SendActorSMS provides a mock function with given fields: _a0, to, lpaUID, sms -func (_m *mockNotifyClient) SendActorSMS(_a0 context.Context, to string, lpaUID string, sms notify.SMS) error { - ret := _m.Called(_a0, to, lpaUID, sms) +// SendActorSMS provides a mock function with given fields: _a0, lang, to, lpaUID, sms +func (_m *mockNotifyClient) SendActorSMS(_a0 context.Context, lang localize.Lang, to string, lpaUID string, sms notify.SMS) error { + ret := _m.Called(_a0, lang, to, lpaUID, sms) if len(ret) == 0 { panic("no return value specified for SendActorSMS") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.SMS) error); ok { - r0 = rf(_a0, to, lpaUID, sms) + if rf, ok := ret.Get(0).(func(context.Context, localize.Lang, string, string, notify.SMS) error); ok { + r0 = rf(_a0, lang, to, lpaUID, sms) } else { r0 = ret.Error(0) } @@ -96,16 +99,17 @@ type mockNotifyClient_SendActorSMS_Call struct { // SendActorSMS is a helper method to define mock.On call // - _a0 context.Context +// - lang localize.Lang // - to string // - lpaUID string // - sms notify.SMS -func (_e *mockNotifyClient_Expecter) SendActorSMS(_a0 interface{}, to interface{}, lpaUID interface{}, sms interface{}) *mockNotifyClient_SendActorSMS_Call { - return &mockNotifyClient_SendActorSMS_Call{Call: _e.mock.On("SendActorSMS", _a0, to, lpaUID, sms)} +func (_e *mockNotifyClient_Expecter) SendActorSMS(_a0 interface{}, lang interface{}, to interface{}, lpaUID interface{}, sms interface{}) *mockNotifyClient_SendActorSMS_Call { + return &mockNotifyClient_SendActorSMS_Call{Call: _e.mock.On("SendActorSMS", _a0, lang, to, lpaUID, sms)} } -func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(_a0 context.Context, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(_a0 context.Context, lang localize.Lang, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.SMS)) + run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.SMS)) }) return _c } @@ -115,7 +119,7 @@ func (_c *mockNotifyClient_SendActorSMS_Call) Return(_a0 error) *mockNotifyClien return _c } -func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { _c.Call.Return(run) return _c } diff --git a/internal/sharecode/sender.go b/internal/sharecode/sender.go index 18642950a0..12b0118638 100644 --- a/internal/sharecode/sender.go +++ b/internal/sharecode/sender.go @@ -39,8 +39,8 @@ type ShareCodeStore interface { } type NotifyClient interface { - SendActorEmail(context context.Context, to, lpaUID string, email notify.Email) error - SendActorSMS(context context.Context, to, lpaUID string, sms notify.SMS) error + SendActorEmail(context context.Context, lang localize.Lang, to, lpaUID string, email notify.Email) error + SendActorSMS(context context.Context, lang localize.Lang, to, lpaUID string, sms notify.SMS) error } type EventClient interface { @@ -321,7 +321,7 @@ func (s *Sender) createShareCode(ctx context.Context, lpaKey dynamo.LpaKeyType, } func (s *Sender) sendEmail(ctx context.Context, to string, lpaUID string, email notify.Email) error { - if err := s.notifyClient.SendActorEmail(ctx, to, lpaUID, email); err != nil { + if err := s.notifyClient.SendActorEmail(ctx, localize.En, to, lpaUID, email); err != nil { return fmt.Errorf("email failed: %w", err) } @@ -329,7 +329,7 @@ func (s *Sender) sendEmail(ctx context.Context, to string, lpaUID string, email } func (s *Sender) sendSMS(ctx context.Context, to, lpaUID string, sms notify.SMS) error { - if err := s.notifyClient.SendActorSMS(ctx, to, lpaUID, sms); err != nil { + if err := s.notifyClient.SendActorSMS(ctx, localize.En, to, lpaUID, sms); err != nil { return fmt.Errorf("sms failed: %w", err) } diff --git a/internal/sharecode/sender_test.go b/internal/sharecode/sender_test.go index 431f1bbb80..4a63fedeb0 100644 --- a/internal/sharecode/sender_test.go +++ b/internal/sharecode/sender_test.go @@ -73,7 +73,7 @@ func TestShareCodeSenderSendCertificateProviderInvite(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, "name@example.org", "lpa-uid", notify.CertificateProviderInviteEmail{ + SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.CertificateProviderInviteEmail{ ShareCode: testRandomString, CertificateProviderFullName: "Joanna Jones", DonorFirstNames: "Jan", @@ -166,7 +166,7 @@ func TestShareCodeSenderSendCertificateProviderInviteWithTestCode(t *testing.T) notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, "name@example.org", "lpa-uid", notify.CertificateProviderInviteEmail{ + SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.CertificateProviderInviteEmail{ CertificateProviderFullName: "Joanna Jones", DonorFirstNames: "Jan", DonorFullName: "Jan Smith", @@ -180,7 +180,7 @@ func TestShareCodeSenderSendCertificateProviderInviteWithTestCode(t *testing.T) Once(). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, "name@example.org", "lpa-uid", notify.CertificateProviderInviteEmail{ + SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.CertificateProviderInviteEmail{ CertificateProviderFullName: "Joanna Jones", DonorFirstNames: "Jan", DonorFullName: "Jan Smith", @@ -261,7 +261,7 @@ func TestShareCodeSenderSendCertificateProviderInviteWhenEmailErrors(t *testing. notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) @@ -321,7 +321,7 @@ func TestShareCodeSenderSendCertificateProviderPromptOnline(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, "name@example.org", "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ + SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ ShareCode: testRandomString, CertificateProviderFullName: "Joanna Jones", DonorFullName: "Jan Smith", @@ -454,7 +454,7 @@ func TestShareCodeSenderSendCertificateProviderPromptWithTestCode(t *testing.T) notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, "name@example.org", "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ + SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ CertificateProviderFullName: "Joanna Jones", DonorFullName: "Jan Smith", LpaType: "property and affairs", @@ -464,7 +464,7 @@ func TestShareCodeSenderSendCertificateProviderPromptWithTestCode(t *testing.T) Once(). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, "name@example.org", "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ + SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ CertificateProviderFullName: "Joanna Jones", DonorFullName: "Jan Smith", LpaType: "property and affairs", @@ -564,7 +564,7 @@ func TestShareCodeSenderSendCertificateProviderPromptWhenEmailErrors(t *testing. notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) @@ -690,7 +690,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, "trusted@example.com", "lpa-uid", notify.InitialOriginalAttorneyEmail{ + SendActorEmail(ctx, localize.En, "trusted@example.com", "lpa-uid", notify.InitialOriginalAttorneyEmail{ ShareCode: testRandomString, AttorneyFullName: "Trusty", DonorFirstNames: "Jan", @@ -702,7 +702,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { }). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, "untrusted@example.com", "lpa-uid", notify.InitialReplacementAttorneyEmail{ + SendActorEmail(ctx, localize.En, "untrusted@example.com", "lpa-uid", notify.InitialReplacementAttorneyEmail{ ShareCode: testRandomString, AttorneyFullName: "Untrusty", DonorFirstNames: "Jan", @@ -714,7 +714,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { }). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, "name@example.org", "lpa-uid", notify.InitialOriginalAttorneyEmail{ + SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.InitialOriginalAttorneyEmail{ ShareCode: testRandomString, AttorneyFullName: "Joanna Jones", DonorFirstNames: "Jan", @@ -726,7 +726,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { }). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, "name2@example.org", "lpa-uid", notify.InitialOriginalAttorneyEmail{ + SendActorEmail(ctx, localize.En, "name2@example.org", "lpa-uid", notify.InitialOriginalAttorneyEmail{ ShareCode: testRandomString, AttorneyFullName: "John Jones", DonorFirstNames: "Jan", @@ -738,7 +738,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { }). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, "dave@example.com", "lpa-uid", notify.InitialReplacementAttorneyEmail{ + SendActorEmail(ctx, localize.En, "dave@example.com", "lpa-uid", notify.InitialReplacementAttorneyEmail{ ShareCode: testRandomString, AttorneyFullName: "Dave Davis", DonorFirstNames: "Jan", @@ -965,7 +965,7 @@ func TestShareCodeSenderSendAttorneysWithTestCode(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, "name@example.org", "lpa-uid", notify.InitialOriginalAttorneyEmail{ + SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.InitialOriginalAttorneyEmail{ ShareCode: tc.expectedTestCode, AttorneyFullName: "Joanna Jones", DonorFirstNames: "Jan", @@ -977,7 +977,7 @@ func TestShareCodeSenderSendAttorneysWithTestCode(t *testing.T) { }). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, "name@example.org", "lpa-uid", notify.InitialOriginalAttorneyEmail{ + SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.InitialOriginalAttorneyEmail{ ShareCode: testRandomString, AttorneyFullName: "Joanna Jones", DonorFirstNames: "Jan", @@ -1054,7 +1054,7 @@ func TestShareCodeSenderSendAttorneysWhenEmailErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) eventClient := newMockEventClient(t) @@ -1145,7 +1145,7 @@ func TestSendVoucherAccessCode(t *testing.T) { notifyClient: func() *mockNotifyClient { nc := newMockNotifyClient(t) nc.EXPECT(). - SendActorSMS(ctx, "123", "lpa-uid", notify.VouchingShareCodeSMS{ + SendActorSMS(ctx, localize.En, "123", "lpa-uid", notify.VouchingShareCodeSMS{ ShareCode: testRandomString, DonorFullNamePossessive: "Possessive full name", LpaType: "translated type", @@ -1154,7 +1154,7 @@ func TestSendVoucherAccessCode(t *testing.T) { }). Return(nil) nc.EXPECT(). - SendActorEmail(ctx, "voucher@example.com", "lpa-uid", + SendActorEmail(ctx, localize.En, "voucher@example.com", "lpa-uid", notify.VoucherInviteEmail{ VoucherFullName: "c d", DonorFullName: "a b", @@ -1192,7 +1192,7 @@ func TestSendVoucherAccessCode(t *testing.T) { notifyClient: func() *mockNotifyClient { nc := newMockNotifyClient(t) nc.EXPECT(). - SendActorEmail(ctx, "donor@example.com", "lpa-uid", + SendActorEmail(ctx, localize.En, "donor@example.com", "lpa-uid", notify.VouchingShareCodeEmail{ ShareCode: testRandomString, VoucherFullName: "c d", @@ -1201,7 +1201,7 @@ func TestSendVoucherAccessCode(t *testing.T) { }). Return(nil) nc.EXPECT(). - SendActorEmail(ctx, "voucher@example.com", "lpa-uid", + SendActorEmail(ctx, localize.En, "voucher@example.com", "lpa-uid", notify.VoucherInviteEmail{ VoucherFullName: "c d", DonorFullName: "a b", @@ -1313,7 +1313,7 @@ func TestSendVoucherAccessCodeWhenNotifyClientError(t *testing.T) { notifyClient: func() *mockNotifyClient { nc := newMockNotifyClient(t) nc.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError). Once() return nc @@ -1338,7 +1338,7 @@ func TestSendVoucherAccessCodeWhenNotifyClientError(t *testing.T) { notifyClient: func() *mockNotifyClient { nc := newMockNotifyClient(t) nc.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError). Once() return nc @@ -1357,11 +1357,11 @@ func TestSendVoucherAccessCodeWhenNotifyClientError(t *testing.T) { notifyClient: func() *mockNotifyClient { nc := newMockNotifyClient(t) nc.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil). Once() nc.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError). Once() return nc diff --git a/internal/supporter/supporterpage/donor_access.go b/internal/supporter/supporterpage/donor_access.go index 23ba86096c..3533fc9c9d 100644 --- a/internal/supporter/supporterpage/donor_access.go +++ b/internal/supporter/supporterpage/donor_access.go @@ -102,7 +102,7 @@ func DonorAccess(logger Logger, tmpl template.Template, donorStore DonorStore, s return err } - if err := notifyClient.SendEmail(r.Context(), data.Form.Email, notify.DonorAccessEmail{ + if err := notifyClient.SendEmail(r.Context(), donor.Donor.ContactLanguagePreference, data.Form.Email, notify.DonorAccessEmail{ SupporterFullName: member.FullName(), OrganisationName: organisation.Name, LpaType: localize.LowerFirst(appData.Localizer.T(donor.Type.String())), diff --git a/internal/supporter/supporterpage/donor_access_test.go b/internal/supporter/supporterpage/donor_access_test.go index 326aecc6a8..50c2a57326 100644 --- a/internal/supporter/supporterpage/donor_access_test.go +++ b/internal/supporter/supporterpage/donor_access_test.go @@ -9,8 +9,9 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" - donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -123,12 +124,12 @@ func TestPostDonorAccess(t *testing.T) { Get(r.Context()). Return(&donordata.Provided{ Type: lpadata.LpaTypePropertyAndAffairs, - Donor: donordata.Donor{UID: donorUID, FirstNames: "Barry", LastName: "Boy"}, + Donor: donordata.Donor{UID: donorUID, FirstNames: "Barry", LastName: "Boy", ContactLanguagePreference: localize.En}, }, nil) donorStore.EXPECT(). Put(r.Context(), &donordata.Provided{ Type: lpadata.LpaTypePropertyAndAffairs, - Donor: donordata.Donor{UID: donorUID, FirstNames: "Barry", LastName: "Boy", Email: "email@example.com"}, + Donor: donordata.Donor{UID: donorUID, FirstNames: "Barry", LastName: "Boy", Email: "email@example.com", ContactLanguagePreference: localize.En}, }). Return(nil) @@ -147,7 +148,7 @@ func TestPostDonorAccess(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(r.Context(), "email@example.com", notify.DonorAccessEmail{ + SendEmail(r.Context(), localize.En, "email@example.com", notify.DonorAccessEmail{ SupporterFullName: "John Smith", OrganisationName: "Helpers", LpaType: "translation", @@ -241,7 +242,7 @@ func TestPostDonorAccessWhenNotifyErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(r.Context(), mock.Anything, mock.Anything). + SendEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything). Return(expectedError) localizer := newMockLocalizer(t) diff --git a/internal/supporter/supporterpage/invite_member.go b/internal/supporter/supporterpage/invite_member.go index b2f6d6a2d4..418a760cfd 100644 --- a/internal/supporter/supporterpage/invite_member.go +++ b/internal/supporter/supporterpage/invite_member.go @@ -6,6 +6,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/supporter" @@ -46,7 +47,7 @@ func InviteMember(tmpl template.Template, memberStore MemberStore, notifyClient return err } - if err := notifyClient.SendEmail(r.Context(), data.Form.Email, notify.OrganisationMemberInviteEmail{ + if err := notifyClient.SendEmail(r.Context(), localize.En, data.Form.Email, notify.OrganisationMemberInviteEmail{ OrganisationName: organisation.Name, InviterEmail: appData.LoginSessionEmail, InviteCode: inviteCode, diff --git a/internal/supporter/supporterpage/invite_member_test.go b/internal/supporter/supporterpage/invite_member_test.go index 034dc34842..ddcb03ca1f 100644 --- a/internal/supporter/supporterpage/invite_member_test.go +++ b/internal/supporter/supporterpage/invite_member_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/supporter" @@ -73,7 +74,7 @@ func TestPostInviteMember(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(r.Context(), "email@example.com", notify.OrganisationMemberInviteEmail{ + SendEmail(r.Context(), localize.En, "email@example.com", notify.OrganisationMemberInviteEmail{ OrganisationName: "My organisation", InviterEmail: "supporter@example.com", InviteCode: "abcde", @@ -163,7 +164,7 @@ func TestPostInviteMemberWhenNotifySendErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(r.Context(), mock.Anything, mock.Anything). + SendEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything). Return(expectedError) err := InviteMember(nil, memberStore, notifyClient, func(int) string { return "abcde" }, "http://base")(testAppData, w, r, &supporterdata.Organisation{}, nil) diff --git a/internal/supporter/supporterpage/manage_team_members.go b/internal/supporter/supporterpage/manage_team_members.go index e5653bfefd..f5dcdd5b16 100644 --- a/internal/supporter/supporterpage/manage_team_members.go +++ b/internal/supporter/supporterpage/manage_team_members.go @@ -7,6 +7,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/supporter" @@ -52,7 +53,7 @@ func ManageTeamMembers(tmpl template.Template, memberStore MemberStore, randomSt return err } - if err := notifyClient.SendEmail(r.Context(), data.Form.Email, notify.OrganisationMemberInviteEmail{ + if err := notifyClient.SendEmail(r.Context(), localize.En, data.Form.Email, notify.OrganisationMemberInviteEmail{ OrganisationName: organisation.Name, InviterEmail: appData.LoginSessionEmail, InviteCode: inviteCode, diff --git a/internal/supporter/supporterpage/manage_team_members_test.go b/internal/supporter/supporterpage/manage_team_members_test.go index f0528441b2..af56699dec 100644 --- a/internal/supporter/supporterpage/manage_team_members_test.go +++ b/internal/supporter/supporterpage/manage_team_members_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/supporter" @@ -133,7 +134,7 @@ func TestPostManageTeamMembers(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(r.Context(), "email@example.com", notify.OrganisationMemberInviteEmail{ + SendEmail(r.Context(), localize.En, "email@example.com", notify.OrganisationMemberInviteEmail{ OrganisationName: "My organisation", InviterEmail: "supporter@example.com", InviteCode: "abcde", @@ -239,7 +240,7 @@ func TestPostManageTeamMembersWhenNotifyClientError(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(mock.Anything, mock.Anything, mock.Anything). + SendEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) err := ManageTeamMembers(nil, memberStore, func(int) string { return "abcde" }, notifyClient, "")(testAppData, w, r, &supporterdata.Organisation{}, nil) diff --git a/internal/supporter/supporterpage/mock_NotifyClient_test.go b/internal/supporter/supporterpage/mock_NotifyClient_test.go index 7a44a71119..aa4fc38469 100644 --- a/internal/supporter/supporterpage/mock_NotifyClient_test.go +++ b/internal/supporter/supporterpage/mock_NotifyClient_test.go @@ -5,8 +5,10 @@ package supporterpage import ( context "context" - notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" mock "github.com/stretchr/testify/mock" + + notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" ) // mockNotifyClient is an autogenerated mock type for the NotifyClient type @@ -22,17 +24,17 @@ func (_m *mockNotifyClient) EXPECT() *mockNotifyClient_Expecter { return &mockNotifyClient_Expecter{mock: &_m.Mock} } -// SendEmail provides a mock function with given fields: ctx, to, email -func (_m *mockNotifyClient) SendEmail(ctx context.Context, to string, email notify.Email) error { - ret := _m.Called(ctx, to, email) +// SendEmail provides a mock function with given fields: ctx, lang, to, email +func (_m *mockNotifyClient) SendEmail(ctx context.Context, lang localize.Lang, to string, email notify.Email) error { + ret := _m.Called(ctx, lang, to, email) if len(ret) == 0 { panic("no return value specified for SendEmail") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, notify.Email) error); ok { - r0 = rf(ctx, to, email) + if rf, ok := ret.Get(0).(func(context.Context, localize.Lang, string, notify.Email) error); ok { + r0 = rf(ctx, lang, to, email) } else { r0 = ret.Error(0) } @@ -47,15 +49,16 @@ type mockNotifyClient_SendEmail_Call struct { // SendEmail is a helper method to define mock.On call // - ctx context.Context +// - lang localize.Lang // - to string // - email notify.Email -func (_e *mockNotifyClient_Expecter) SendEmail(ctx interface{}, to interface{}, email interface{}) *mockNotifyClient_SendEmail_Call { - return &mockNotifyClient_SendEmail_Call{Call: _e.mock.On("SendEmail", ctx, to, email)} +func (_e *mockNotifyClient_Expecter) SendEmail(ctx interface{}, lang interface{}, to interface{}, email interface{}) *mockNotifyClient_SendEmail_Call { + return &mockNotifyClient_SendEmail_Call{Call: _e.mock.On("SendEmail", ctx, lang, to, email)} } -func (_c *mockNotifyClient_SendEmail_Call) Run(run func(ctx context.Context, to string, email notify.Email)) *mockNotifyClient_SendEmail_Call { +func (_c *mockNotifyClient_SendEmail_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, email notify.Email)) *mockNotifyClient_SendEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(notify.Email)) + run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(notify.Email)) }) return _c } @@ -65,7 +68,7 @@ func (_c *mockNotifyClient_SendEmail_Call) Return(_a0 error) *mockNotifyClient_S return _c } -func (_c *mockNotifyClient_SendEmail_Call) RunAndReturn(run func(context.Context, string, notify.Email) error) *mockNotifyClient_SendEmail_Call { +func (_c *mockNotifyClient_SendEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, notify.Email) error) *mockNotifyClient_SendEmail_Call { _c.Call.Return(run) return _c } diff --git a/internal/supporter/supporterpage/register.go b/internal/supporter/supporterpage/register.go index 0b84d5e56a..426958035b 100644 --- a/internal/supporter/supporterpage/register.go +++ b/internal/supporter/supporterpage/register.go @@ -12,6 +12,7 @@ import ( "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/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" @@ -87,7 +88,7 @@ type SessionStore interface { } type NotifyClient interface { - SendEmail(ctx context.Context, to string, email notify.Email) error + SendEmail(ctx context.Context, lang localize.Lang, to string, email notify.Email) error } type ShareCodeStore interface { diff --git a/internal/voucher/voucherpage/mock_NotifyClient_test.go b/internal/voucher/voucherpage/mock_NotifyClient_test.go index e975ed46e2..100b8a328f 100644 --- a/internal/voucher/voucherpage/mock_NotifyClient_test.go +++ b/internal/voucher/voucherpage/mock_NotifyClient_test.go @@ -5,7 +5,9 @@ package voucherpage import ( context "context" + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" lpadata "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" + mock "github.com/stretchr/testify/mock" notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" @@ -70,17 +72,17 @@ func (_c *mockNotifyClient_EmailGreeting_Call) RunAndReturn(run func(*lpadata.Lp return _c } -// SendActorEmail provides a mock function with given fields: ctx, to, lpaUID, email -func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, to string, lpaUID string, email notify.Email) error { - ret := _m.Called(ctx, to, lpaUID, email) +// SendActorEmail provides a mock function with given fields: ctx, lang, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email) error { + ret := _m.Called(ctx, lang, to, lpaUID, email) if len(ret) == 0 { panic("no return value specified for SendActorEmail") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.Email) error); ok { - r0 = rf(ctx, to, lpaUID, email) + if rf, ok := ret.Get(0).(func(context.Context, localize.Lang, string, string, notify.Email) error); ok { + r0 = rf(ctx, lang, to, lpaUID, email) } else { r0 = ret.Error(0) } @@ -95,16 +97,17 @@ type mockNotifyClient_SendActorEmail_Call struct { // SendActorEmail is a helper method to define mock.On call // - ctx context.Context +// - lang localize.Lang // - to string // - lpaUID string // - email notify.Email -func (_e *mockNotifyClient_Expecter) SendActorEmail(ctx interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { - return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", ctx, to, lpaUID, email)} +func (_e *mockNotifyClient_Expecter) SendActorEmail(ctx interface{}, lang interface{}, to interface{}, lpaUID interface{}, email interface{}) *mockNotifyClient_SendActorEmail_Call { + return &mockNotifyClient_SendActorEmail_Call{Call: _e.mock.On("SendActorEmail", ctx, lang, to, lpaUID, email)} } -func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.Email)) + run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.Email)) }) return _c } @@ -114,22 +117,22 @@ func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyCli return _c } -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { _c.Call.Return(run) return _c } -// SendActorSMS provides a mock function with given fields: ctx, to, lpaUID, sms -func (_m *mockNotifyClient) SendActorSMS(ctx context.Context, to string, lpaUID string, sms notify.SMS) error { - ret := _m.Called(ctx, to, lpaUID, sms) +// SendActorSMS provides a mock function with given fields: ctx, lang, to, lpaUID, sms +func (_m *mockNotifyClient) SendActorSMS(ctx context.Context, lang localize.Lang, to string, lpaUID string, sms notify.SMS) error { + ret := _m.Called(ctx, lang, to, lpaUID, sms) if len(ret) == 0 { panic("no return value specified for SendActorSMS") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, string, notify.SMS) error); ok { - r0 = rf(ctx, to, lpaUID, sms) + if rf, ok := ret.Get(0).(func(context.Context, localize.Lang, string, string, notify.SMS) error); ok { + r0 = rf(ctx, lang, to, lpaUID, sms) } else { r0 = ret.Error(0) } @@ -144,16 +147,17 @@ type mockNotifyClient_SendActorSMS_Call struct { // SendActorSMS is a helper method to define mock.On call // - ctx context.Context +// - lang localize.Lang // - to string // - lpaUID string // - sms notify.SMS -func (_e *mockNotifyClient_Expecter) SendActorSMS(ctx interface{}, to interface{}, lpaUID interface{}, sms interface{}) *mockNotifyClient_SendActorSMS_Call { - return &mockNotifyClient_SendActorSMS_Call{Call: _e.mock.On("SendActorSMS", ctx, to, lpaUID, sms)} +func (_e *mockNotifyClient_Expecter) SendActorSMS(ctx interface{}, lang interface{}, to interface{}, lpaUID interface{}, sms interface{}) *mockNotifyClient_SendActorSMS_Call { + return &mockNotifyClient_SendActorSMS_Call{Call: _e.mock.On("SendActorSMS", ctx, lang, to, lpaUID, sms)} } -func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(ctx context.Context, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(notify.SMS)) + run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.SMS)) }) return _c } @@ -163,7 +167,7 @@ func (_c *mockNotifyClient_SendActorSMS_Call) Return(_a0 error) *mockNotifyClien return _c } -func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { _c.Call.Return(run) return _c } diff --git a/internal/voucher/voucherpage/register.go b/internal/voucher/voucherpage/register.go index a82589c70f..d43438b362 100644 --- a/internal/voucher/voucherpage/register.go +++ b/internal/voucher/voucherpage/register.go @@ -13,6 +13,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/dashboard/dashboarddata" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" @@ -45,8 +46,8 @@ type DonorStore interface { type NotifyClient interface { EmailGreeting(lpa *lpadata.Lpa) string - SendActorEmail(ctx context.Context, to, lpaUID string, email notify.Email) error - SendActorSMS(ctx context.Context, to, lpaUID string, sms notify.SMS) error + SendActorEmail(ctx context.Context, lang localize.Lang, to, lpaUID string, email notify.Email) error + SendActorSMS(ctx context.Context, lang localize.Lang, to, lpaUID string, sms notify.SMS) error } type Logger interface { diff --git a/internal/voucher/voucherpage/vouch_failer.go b/internal/voucher/voucherpage/vouch_failer.go index 00deb5f719..d518711120 100644 --- a/internal/voucher/voucherpage/vouch_failer.go +++ b/internal/voucher/voucherpage/vouch_failer.go @@ -30,7 +30,7 @@ func makeVouchFailer(donorStore DonorStore, notifyClient NotifyClient, appPublic DonorStartPageURL: appPublicURL + page.PathStart.Format(), } - if err := notifyClient.SendActorEmail(ctx, lpa.Donor.Email, lpa.LpaUID, email); err != nil { + if err := notifyClient.SendActorEmail(ctx, lpa.Donor.ContactLanguagePreference, lpa.Donor.Email, lpa.LpaUID, email); err != nil { return err } diff --git a/internal/voucher/voucherpage/vouch_failer_test.go b/internal/voucher/voucherpage/vouch_failer_test.go index b2845b9798..95af8f892e 100644 --- a/internal/voucher/voucherpage/vouch_failer_test.go +++ b/internal/voucher/voucherpage/vouch_failer_test.go @@ -6,6 +6,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/voucher/voucherdata" @@ -18,7 +19,7 @@ var ctx = context.WithValue(context.Background(), (*string)(nil), "test") func TestVouchFailer(t *testing.T) { lpa := &lpadata.Lpa{ LpaUID: "lpa-uid", - Donor: lpadata.Donor{Email: "john@example.com"}, + Donor: lpadata.Donor{Email: "john@example.com", ContactLanguagePreference: localize.Cy}, } provided := &voucherdata.Provided{ FirstNames: "Vivian", @@ -45,7 +46,7 @@ func TestVouchFailer(t *testing.T) { EmailGreeting(lpa). Return("greeting") notifyClient.EXPECT(). - SendActorEmail(ctx, "john@example.com", "lpa-uid", notify.VouchingFailedAttemptEmail{ + SendActorEmail(ctx, localize.Cy, "john@example.com", "lpa-uid", notify.VouchingFailedAttemptEmail{ Greeting: "greeting", VoucherFullName: "Vivian Vaughn", DonorStartPageURL: "app:///start", @@ -77,7 +78,7 @@ func TestVouchFailerWheNotifyClientErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("greeting") notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) err := makeVouchFailer(donorStore, notifyClient, "app://")(ctx, &voucherdata.Provided{}, &lpadata.Lpa{}) @@ -98,7 +99,7 @@ func TestVouchFailerWhenDonorStorePutErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("greeting") notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) err := makeVouchFailer(donorStore, notifyClient, "app://")(ctx, &voucherdata.Provided{}, &lpadata.Lpa{}) diff --git a/internal/voucher/voucherpage/your_declaration.go b/internal/voucher/voucherpage/your_declaration.go index 1ad9d38353..998749df7a 100644 --- a/internal/voucher/voucherpage/your_declaration.go +++ b/internal/voucher/voucherpage/your_declaration.go @@ -28,28 +28,28 @@ func YourDeclaration(tmpl template.Template, lpaStoreResolvingService LpaStoreRe sendNotification := func(ctx context.Context, lpa *lpadata.Lpa, provided *voucherdata.Provided) error { if lpa.Donor.Mobile != "" { if !lpa.SignedForDonor() { - return notifyClient.SendActorSMS(ctx, lpa.Donor.Mobile, lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentitySMS{ + return notifyClient.SendActorSMS(ctx, lpa.Donor.ContactLanguagePreference, lpa.Donor.Mobile, lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentitySMS{ VoucherFullName: provided.FullName(), DonorFullName: lpa.Donor.FullName(), DonorStartPageURL: appPublicURL + page.PathStart.Format(), }) } - return notifyClient.SendActorSMS(ctx, lpa.Donor.Mobile, lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentityOnSignedLpaSMS{ + return notifyClient.SendActorSMS(ctx, lpa.Donor.ContactLanguagePreference, lpa.Donor.Mobile, lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentityOnSignedLpaSMS{ VoucherFullName: provided.FullName(), DonorStartPageURL: appPublicURL + page.PathStart.Format(), }) } if !lpa.SignedForDonor() { - return notifyClient.SendActorEmail(ctx, lpa.Donor.Email, lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentityEmail{ + return notifyClient.SendActorEmail(ctx, lpa.Donor.ContactLanguagePreference, lpa.Donor.Email, lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentityEmail{ VoucherFullName: provided.FullName(), DonorFullName: lpa.Donor.FullName(), DonorStartPageURL: appPublicURL + page.PathStart.Format(), }) } - return notifyClient.SendActorEmail(ctx, lpa.Donor.Email, lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentityOnSignedLpaEmail{ + return notifyClient.SendActorEmail(ctx, lpa.Donor.ContactLanguagePreference, lpa.Donor.Email, lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentityOnSignedLpaEmail{ VoucherFullName: provided.FullName(), DonorFullName: lpa.Donor.FullName(), DonorStartPageURL: appPublicURL + page.PathStart.Format(), diff --git a/internal/voucher/voucherpage/your_declaration_test.go b/internal/voucher/voucherpage/your_declaration_test.go index 4b6a18eeb8..a22a392489 100644 --- a/internal/voucher/voucherpage/your_declaration_test.go +++ b/internal/voucher/voucherpage/your_declaration_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -114,11 +115,11 @@ func TestPostYourDeclaration(t *testing.T) { "email": { lpa: &lpadata.Lpa{ LpaUID: "lpa-uid", - Donor: lpadata.Donor{FirstNames: "John", LastName: "Smith", Email: "blah@example.com"}, + Donor: lpadata.Donor{FirstNames: "John", LastName: "Smith", Email: "blah@example.com", ContactLanguagePreference: localize.En}, }, setupNotify: func(m *mockNotifyClient) { m.EXPECT(). - SendActorEmail(r.Context(), "blah@example.com", "lpa-uid", notify.VoucherHasConfirmedDonorIdentityEmail{ + SendActorEmail(r.Context(), localize.En, "blah@example.com", "lpa-uid", notify.VoucherHasConfirmedDonorIdentityEmail{ DonorFullName: "John Smith", DonorStartPageURL: "app:///start", VoucherFullName: "Vivian Voucher", @@ -129,13 +130,13 @@ func TestPostYourDeclaration(t *testing.T) { "email when signed": { lpa: &lpadata.Lpa{ LpaUID: "lpa-uid", - Donor: lpadata.Donor{FirstNames: "John", LastName: "Smith", Email: "blah@example.com"}, + Donor: lpadata.Donor{FirstNames: "John", LastName: "Smith", Email: "blah@example.com", ContactLanguagePreference: localize.Cy}, SignedAt: time.Now(), WitnessedByCertificateProviderAt: time.Now(), }, setupNotify: func(m *mockNotifyClient) { m.EXPECT(). - SendActorEmail(r.Context(), "blah@example.com", "lpa-uid", notify.VoucherHasConfirmedDonorIdentityOnSignedLpaEmail{ + SendActorEmail(r.Context(), localize.Cy, "blah@example.com", "lpa-uid", notify.VoucherHasConfirmedDonorIdentityOnSignedLpaEmail{ DonorFullName: "John Smith", DonorStartPageURL: "app:///start", VoucherFullName: "Vivian Voucher", @@ -146,11 +147,11 @@ func TestPostYourDeclaration(t *testing.T) { "mobile": { lpa: &lpadata.Lpa{ LpaUID: "lpa-uid", - Donor: lpadata.Donor{FirstNames: "John", LastName: "Smith", Email: "blah@example.com", Mobile: "0777"}, + Donor: lpadata.Donor{FirstNames: "John", LastName: "Smith", Email: "blah@example.com", Mobile: "0777", ContactLanguagePreference: localize.Cy}, }, setupNotify: func(m *mockNotifyClient) { m.EXPECT(). - SendActorSMS(r.Context(), "0777", "lpa-uid", notify.VoucherHasConfirmedDonorIdentitySMS{ + SendActorSMS(r.Context(), localize.Cy, "0777", "lpa-uid", notify.VoucherHasConfirmedDonorIdentitySMS{ DonorFullName: "John Smith", DonorStartPageURL: "app:///start", VoucherFullName: "Vivian Voucher", @@ -161,13 +162,13 @@ func TestPostYourDeclaration(t *testing.T) { "mobile when signed": { lpa: &lpadata.Lpa{ LpaUID: "lpa-uid", - Donor: lpadata.Donor{FirstNames: "John", LastName: "Smith", Email: "blah@example.com", Mobile: "0777"}, + Donor: lpadata.Donor{FirstNames: "John", LastName: "Smith", Email: "blah@example.com", Mobile: "0777", ContactLanguagePreference: localize.En}, SignedAt: time.Now(), WitnessedByCertificateProviderAt: time.Now(), }, setupNotify: func(m *mockNotifyClient) { m.EXPECT(). - SendActorSMS(r.Context(), "0777", "lpa-uid", notify.VoucherHasConfirmedDonorIdentityOnSignedLpaSMS{ + SendActorSMS(r.Context(), localize.En, "0777", "lpa-uid", notify.VoucherHasConfirmedDonorIdentityOnSignedLpaSMS{ DonorStartPageURL: "app:///start", VoucherFullName: "Vivian Voucher", }). @@ -255,7 +256,7 @@ func TestPostYourDeclarationWhenNotifyClientErrors(t *testing.T) { }, setupNotify: func(m *mockNotifyClient) { m.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) }, }, @@ -267,7 +268,7 @@ func TestPostYourDeclarationWhenNotifyClientErrors(t *testing.T) { }, setupNotify: func(m *mockNotifyClient) { m.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) }, }, @@ -278,7 +279,7 @@ func TestPostYourDeclarationWhenNotifyClientErrors(t *testing.T) { }, setupNotify: func(m *mockNotifyClient) { m.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) }, }, @@ -290,7 +291,7 @@ func TestPostYourDeclarationWhenNotifyClientErrors(t *testing.T) { }, setupNotify: func(m *mockNotifyClient) { m.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) }, }, @@ -329,7 +330,7 @@ func TestPostYourDeclarationWhenStoreErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) voucherStore := newMockVoucherStore(t)