From dd72f7849088d5bce34bc904163aa3b6551a96d5 Mon Sep 17 00:00:00 2001 From: Joshua Hawxwell Date: Thu, 8 Aug 2024 15:19:30 +0100 Subject: [PATCH] Move WitnessCodeSender from page to donor package --- internal/app/app.go | 2 +- .../donor/donorpage/change_mobile_number.go | 26 +- .../donorpage/change_mobile_number_test.go | 8 +- .../donorpage/mock_WitnessCodeSender_test.go | 44 +- internal/donor/donorpage/register.go | 4 +- .../donor/donorpage/resend_witness_code.go | 9 +- .../donorpage/resend_witness_code_test.go | 8 +- .../donorpage/witnessing_your_signature.go | 4 +- .../witnessing_your_signature_test.go | 12 +- internal/donor/mock_DonorStore_test.go | 142 +++++ internal/donor/mock_Localizer_test.go | 534 ++++++++++++++++++ internal/donor/mock_NotifyClient_test.go | 135 +++++ .../witness_code_sender.go} | 43 +- .../witness_code_sender_test.go} | 22 +- internal/page/fixtures/donor.go | 3 +- 15 files changed, 917 insertions(+), 79 deletions(-) create mode 100644 internal/donor/mock_DonorStore_test.go create mode 100644 internal/donor/mock_Localizer_test.go create mode 100644 internal/donor/mock_NotifyClient_test.go rename internal/{page/witness_code.go => donor/witness_code_sender.go} (59%) rename internal/{page/witness_code_test.go => donor/witness_code_sender_test.go} (98%) diff --git a/internal/app/app.go b/internal/app/app.go index 37abbee584..e1b44fa712 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -107,7 +107,7 @@ func App( progressTracker := task.ProgressTracker{Localizer: localizer} shareCodeSender := sharecode.NewSender(shareCodeStore, notifyClient, appPublicURL, random.String, eventClient) - witnessCodeSender := page.NewWitnessCodeSender(donorStore, notifyClient) + witnessCodeSender := donor.NewWitnessCodeSender(donorStore, notifyClient, localizer) lpaStoreResolvingService := lpastore.NewResolvingService(donorStore, lpaStoreClient) diff --git a/internal/donor/donorpage/change_mobile_number.go b/internal/donor/donorpage/change_mobile_number.go index 9741d3c9b2..cb80d3e7cc 100644 --- a/internal/donor/donorpage/change_mobile_number.go +++ b/internal/donor/donorpage/change_mobile_number.go @@ -23,7 +23,7 @@ type changeMobileNumberData struct { } func ChangeMobileNumber(tmpl template.Template, witnessCodeSender WitnessCodeSender, actorType actor.Type) Handler { - var send func(context.Context, *donordata.Provided, page.Localizer) error + var send func(context.Context, *donordata.Provided) error var redirect donor.Path switch actorType { case actor.TypeIndependentWitness: @@ -36,16 +36,16 @@ func ChangeMobileNumber(tmpl template.Template, witnessCodeSender WitnessCodeSen panic("ChangeMobileNumber only supports IndependentWitness or CertificateProvider actors") } - return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, provided *donordata.Provided) error { data := &changeMobileNumberData{ App: appData, Form: &changeMobileNumberForm{}, ActorType: actorType, - FirstNames: donor.CertificateProvider.FirstNames, + FirstNames: provided.CertificateProvider.FirstNames, } if actorType == actor.TypeIndependentWitness { - data.FirstNames = donor.IndependentWitness.FirstNames + data.FirstNames = provided.IndependentWitness.FirstNames } if r.Method == http.MethodPost { @@ -54,23 +54,23 @@ func ChangeMobileNumber(tmpl template.Template, witnessCodeSender WitnessCodeSen if data.Errors.None() { if actorType == actor.TypeIndependentWitness { - donor.IndependentWitness.HasNonUKMobile = data.Form.HasNonUKMobile + provided.IndependentWitness.HasNonUKMobile = data.Form.HasNonUKMobile if data.Form.HasNonUKMobile { - donor.IndependentWitness.Mobile = data.Form.NonUKMobile + provided.IndependentWitness.Mobile = data.Form.NonUKMobile } else { - donor.IndependentWitness.Mobile = data.Form.Mobile + provided.IndependentWitness.Mobile = data.Form.Mobile } } else { - donor.CertificateProvider.HasNonUKMobile = data.Form.HasNonUKMobile + provided.CertificateProvider.HasNonUKMobile = data.Form.HasNonUKMobile if data.Form.HasNonUKMobile { - donor.CertificateProvider.Mobile = data.Form.NonUKMobile + provided.CertificateProvider.Mobile = data.Form.NonUKMobile } else { - donor.CertificateProvider.Mobile = data.Form.Mobile + provided.CertificateProvider.Mobile = data.Form.Mobile } } - if err := send(r.Context(), donor, appData.Localizer); err != nil { - if errors.Is(err, page.ErrTooManyWitnessCodeRequests) { + if err := send(r.Context(), provided); err != nil { + if errors.Is(err, donor.ErrTooManyWitnessCodeRequests) { data.Errors.Add("request", validation.CustomError{Label: "pleaseWaitOneMinute"}) return tmpl(w, data) } @@ -78,7 +78,7 @@ func ChangeMobileNumber(tmpl template.Template, witnessCodeSender WitnessCodeSen return err } - return redirect.Redirect(w, r, appData, donor) + return redirect.Redirect(w, r, appData, provided) } } diff --git a/internal/donor/donorpage/change_mobile_number_test.go b/internal/donor/donorpage/change_mobile_number_test.go index 15b3517de3..5ecdbce243 100644 --- a/internal/donor/donorpage/change_mobile_number_test.go +++ b/internal/donor/donorpage/change_mobile_number_test.go @@ -210,7 +210,7 @@ func TestPostChangeMobileNumber(t *testing.T) { witnessCodeSender := newMockWitnessCodeSender(t) witnessCodeSender. - On(tc.send, r.Context(), tc.donor, testAppData.Localizer). + On(tc.send, r.Context(), tc.donor). Return(nil) err := ChangeMobileNumber(nil, witnessCodeSender, tc.actorType)(testAppData, w, r, &donordata.Provided{ @@ -237,7 +237,7 @@ func TestPostChangeMobileNumberWhenSendErrors(t *testing.T) { witnessCodeSender := newMockWitnessCodeSender(t) witnessCodeSender.EXPECT(). - SendToCertificateProvider(mock.Anything, mock.Anything, mock.Anything). + SendToCertificateProvider(mock.Anything, mock.Anything). Return(expectedError) err := ChangeMobileNumber(nil, witnessCodeSender, actor.TypeCertificateProvider)(testAppData, w, r, &donordata.Provided{LpaID: "lpa-id"}) @@ -255,8 +255,8 @@ func TestPostChangeMobileNumberWhenSendErrorsWithTooManyRequests(t *testing.T) { witnessCodeSender := newMockWitnessCodeSender(t) witnessCodeSender.EXPECT(). - SendToCertificateProvider(mock.Anything, mock.Anything, mock.Anything). - Return(page.ErrTooManyWitnessCodeRequests) + SendToCertificateProvider(mock.Anything, mock.Anything). + Return(donor.ErrTooManyWitnessCodeRequests) template := newMockTemplate(t) template.EXPECT(). diff --git a/internal/donor/donorpage/mock_WitnessCodeSender_test.go b/internal/donor/donorpage/mock_WitnessCodeSender_test.go index edcb8e8a74..5b27385aac 100644 --- a/internal/donor/donorpage/mock_WitnessCodeSender_test.go +++ b/internal/donor/donorpage/mock_WitnessCodeSender_test.go @@ -7,8 +7,6 @@ import ( donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" mock "github.com/stretchr/testify/mock" - - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) // mockWitnessCodeSender is an autogenerated mock type for the WitnessCodeSender type @@ -24,17 +22,17 @@ func (_m *mockWitnessCodeSender) EXPECT() *mockWitnessCodeSender_Expecter { return &mockWitnessCodeSender_Expecter{mock: &_m.Mock} } -// SendToCertificateProvider provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockWitnessCodeSender) SendToCertificateProvider(_a0 context.Context, _a1 *donordata.Provided, _a2 page.Localizer) error { - ret := _m.Called(_a0, _a1, _a2) +// SendToCertificateProvider provides a mock function with given fields: _a0, _a1 +func (_m *mockWitnessCodeSender) SendToCertificateProvider(_a0 context.Context, _a1 *donordata.Provided) error { + ret := _m.Called(_a0, _a1) if len(ret) == 0 { panic("no return value specified for SendToCertificateProvider") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *donordata.Provided, page.Localizer) error); ok { - r0 = rf(_a0, _a1, _a2) + if rf, ok := ret.Get(0).(func(context.Context, *donordata.Provided) error); ok { + r0 = rf(_a0, _a1) } else { r0 = ret.Error(0) } @@ -50,14 +48,13 @@ type mockWitnessCodeSender_SendToCertificateProvider_Call struct { // SendToCertificateProvider is a helper method to define mock.On call // - _a0 context.Context // - _a1 *donordata.Provided -// - _a2 page.Localizer -func (_e *mockWitnessCodeSender_Expecter) SendToCertificateProvider(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockWitnessCodeSender_SendToCertificateProvider_Call { - return &mockWitnessCodeSender_SendToCertificateProvider_Call{Call: _e.mock.On("SendToCertificateProvider", _a0, _a1, _a2)} +func (_e *mockWitnessCodeSender_Expecter) SendToCertificateProvider(_a0 interface{}, _a1 interface{}) *mockWitnessCodeSender_SendToCertificateProvider_Call { + return &mockWitnessCodeSender_SendToCertificateProvider_Call{Call: _e.mock.On("SendToCertificateProvider", _a0, _a1)} } -func (_c *mockWitnessCodeSender_SendToCertificateProvider_Call) Run(run func(_a0 context.Context, _a1 *donordata.Provided, _a2 page.Localizer)) *mockWitnessCodeSender_SendToCertificateProvider_Call { +func (_c *mockWitnessCodeSender_SendToCertificateProvider_Call) Run(run func(_a0 context.Context, _a1 *donordata.Provided)) *mockWitnessCodeSender_SendToCertificateProvider_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*donordata.Provided), args[2].(page.Localizer)) + run(args[0].(context.Context), args[1].(*donordata.Provided)) }) return _c } @@ -67,22 +64,22 @@ func (_c *mockWitnessCodeSender_SendToCertificateProvider_Call) Return(_a0 error return _c } -func (_c *mockWitnessCodeSender_SendToCertificateProvider_Call) RunAndReturn(run func(context.Context, *donordata.Provided, page.Localizer) error) *mockWitnessCodeSender_SendToCertificateProvider_Call { +func (_c *mockWitnessCodeSender_SendToCertificateProvider_Call) RunAndReturn(run func(context.Context, *donordata.Provided) error) *mockWitnessCodeSender_SendToCertificateProvider_Call { _c.Call.Return(run) return _c } -// SendToIndependentWitness provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockWitnessCodeSender) SendToIndependentWitness(_a0 context.Context, _a1 *donordata.Provided, _a2 page.Localizer) error { - ret := _m.Called(_a0, _a1, _a2) +// SendToIndependentWitness provides a mock function with given fields: _a0, _a1 +func (_m *mockWitnessCodeSender) SendToIndependentWitness(_a0 context.Context, _a1 *donordata.Provided) error { + ret := _m.Called(_a0, _a1) if len(ret) == 0 { panic("no return value specified for SendToIndependentWitness") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *donordata.Provided, page.Localizer) error); ok { - r0 = rf(_a0, _a1, _a2) + if rf, ok := ret.Get(0).(func(context.Context, *donordata.Provided) error); ok { + r0 = rf(_a0, _a1) } else { r0 = ret.Error(0) } @@ -98,14 +95,13 @@ type mockWitnessCodeSender_SendToIndependentWitness_Call struct { // SendToIndependentWitness is a helper method to define mock.On call // - _a0 context.Context // - _a1 *donordata.Provided -// - _a2 page.Localizer -func (_e *mockWitnessCodeSender_Expecter) SendToIndependentWitness(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockWitnessCodeSender_SendToIndependentWitness_Call { - return &mockWitnessCodeSender_SendToIndependentWitness_Call{Call: _e.mock.On("SendToIndependentWitness", _a0, _a1, _a2)} +func (_e *mockWitnessCodeSender_Expecter) SendToIndependentWitness(_a0 interface{}, _a1 interface{}) *mockWitnessCodeSender_SendToIndependentWitness_Call { + return &mockWitnessCodeSender_SendToIndependentWitness_Call{Call: _e.mock.On("SendToIndependentWitness", _a0, _a1)} } -func (_c *mockWitnessCodeSender_SendToIndependentWitness_Call) Run(run func(_a0 context.Context, _a1 *donordata.Provided, _a2 page.Localizer)) *mockWitnessCodeSender_SendToIndependentWitness_Call { +func (_c *mockWitnessCodeSender_SendToIndependentWitness_Call) Run(run func(_a0 context.Context, _a1 *donordata.Provided)) *mockWitnessCodeSender_SendToIndependentWitness_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*donordata.Provided), args[2].(page.Localizer)) + run(args[0].(context.Context), args[1].(*donordata.Provided)) }) return _c } @@ -115,7 +111,7 @@ func (_c *mockWitnessCodeSender_SendToIndependentWitness_Call) Return(_a0 error) return _c } -func (_c *mockWitnessCodeSender_SendToIndependentWitness_Call) RunAndReturn(run func(context.Context, *donordata.Provided, page.Localizer) error) *mockWitnessCodeSender_SendToIndependentWitness_Call { +func (_c *mockWitnessCodeSender_SendToIndependentWitness_Call) RunAndReturn(run func(context.Context, *donordata.Provided) error) *mockWitnessCodeSender_SendToIndependentWitness_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/register.go b/internal/donor/donorpage/register.go index 45cc21c23a..369f0666eb 100644 --- a/internal/donor/donorpage/register.go +++ b/internal/donor/donorpage/register.go @@ -108,8 +108,8 @@ type SessionStore interface { } type WitnessCodeSender interface { - SendToCertificateProvider(context.Context, *donordata.Provided, page.Localizer) error - SendToIndependentWitness(context.Context, *donordata.Provided, page.Localizer) error + SendToCertificateProvider(context.Context, *donordata.Provided) error + SendToIndependentWitness(context.Context, *donordata.Provided) error } type UidClient interface { diff --git a/internal/donor/donorpage/resend_witness_code.go b/internal/donor/donorpage/resend_witness_code.go index ba2d1e2a48..edd194222e 100644 --- a/internal/donor/donorpage/resend_witness_code.go +++ b/internal/donor/donorpage/resend_witness_code.go @@ -9,7 +9,6 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -27,14 +26,14 @@ func ResendWitnessCode(tmpl template.Template, witnessCodeSender WitnessCodeSend redirect = donor.PathWitnessingAsIndependentWitness } - return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, provided *donordata.Provided) error { data := &resendWitnessCodeData{ App: appData, } if r.Method == http.MethodPost { - if err := send(r.Context(), donor, appData.Localizer); err != nil { - if errors.Is(err, page.ErrTooManyWitnessCodeRequests) { + if err := send(r.Context(), provided); err != nil { + if errors.Is(err, donor.ErrTooManyWitnessCodeRequests) { data.Errors.Add("request", validation.CustomError{Label: "pleaseWaitOneMinute"}) return tmpl(w, data) } @@ -42,7 +41,7 @@ func ResendWitnessCode(tmpl template.Template, witnessCodeSender WitnessCodeSend return err } - return redirect.Redirect(w, r, appData, donor) + return redirect.Redirect(w, r, appData, provided) } return tmpl(w, data) diff --git a/internal/donor/donorpage/resend_witness_code_test.go b/internal/donor/donorpage/resend_witness_code_test.go index d77771d724..bc4ebc5bc8 100644 --- a/internal/donor/donorpage/resend_witness_code_test.go +++ b/internal/donor/donorpage/resend_witness_code_test.go @@ -83,7 +83,7 @@ func TestPostResendWitnessCode(t *testing.T) { witnessCodeSender := newMockWitnessCodeSender(t) witnessCodeSender. - On(tc.method, r.Context(), donor, testAppData.Localizer). + On(tc.method, r.Context(), donor). Return(nil) err := ResendWitnessCode(nil, witnessCodeSender, actorType)(testAppData, w, r, donor) @@ -105,7 +105,7 @@ func TestPostResendWitnessCodeWhenSendErrors(t *testing.T) { witnessCodeSender := newMockWitnessCodeSender(t) witnessCodeSender.EXPECT(). - SendToCertificateProvider(r.Context(), donor, mock.Anything). + SendToCertificateProvider(r.Context(), donor). Return(expectedError) err := ResendWitnessCode(nil, witnessCodeSender, actor.TypeCertificateProvider)(testAppData, w, r, donor) @@ -142,8 +142,8 @@ func TestPostResendWitnessCodeWhenTooRecentlySent(t *testing.T) { witnessCodeSender := newMockWitnessCodeSender(t) witnessCodeSender. - On(tc.send, r.Context(), tc.donor, testAppData.Localizer). - Return(page.ErrTooManyWitnessCodeRequests) + On(tc.send, r.Context(), tc.donor). + Return(donor.ErrTooManyWitnessCodeRequests) template := newMockTemplate(t) template.EXPECT(). diff --git a/internal/donor/donorpage/witnessing_your_signature.go b/internal/donor/donorpage/witnessing_your_signature.go index 2fc59e0161..bca9bdd7fc 100644 --- a/internal/donor/donorpage/witnessing_your_signature.go +++ b/internal/donor/donorpage/witnessing_your_signature.go @@ -19,7 +19,7 @@ type witnessingYourSignatureData struct { func WitnessingYourSignature(tmpl template.Template, witnessCodeSender WitnessCodeSender, donorStore DonorStore) Handler { return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, provided *donordata.Provided) error { if r.Method == http.MethodPost { - if err := witnessCodeSender.SendToCertificateProvider(r.Context(), provided, appData.Localizer); err != nil { + if err := witnessCodeSender.SendToCertificateProvider(r.Context(), provided); err != nil { return err } @@ -31,7 +31,7 @@ func WitnessingYourSignature(tmpl template.Template, witnessCodeSender WitnessCo return err } - if err := witnessCodeSender.SendToIndependentWitness(r.Context(), lpa, appData.Localizer); err != nil { + if err := witnessCodeSender.SendToIndependentWitness(r.Context(), lpa); err != nil { return err } diff --git a/internal/donor/donorpage/witnessing_your_signature_test.go b/internal/donor/donorpage/witnessing_your_signature_test.go index aad3ab7813..77e29a6d5d 100644 --- a/internal/donor/donorpage/witnessing_your_signature_test.go +++ b/internal/donor/donorpage/witnessing_your_signature_test.go @@ -60,7 +60,7 @@ func TestPostWitnessingYourSignature(t *testing.T) { witnessCodeSender := newMockWitnessCodeSender(t) witnessCodeSender.EXPECT(). - SendToCertificateProvider(r.Context(), provided, mock.Anything). + SendToCertificateProvider(r.Context(), provided). Return(nil) err := WitnessingYourSignature(nil, witnessCodeSender, nil)(testAppData, w, r, provided) @@ -84,7 +84,7 @@ func TestPostWitnessingYourSignatureCannotSign(t *testing.T) { witnessCodeSender := newMockWitnessCodeSender(t) witnessCodeSender.EXPECT(). - SendToCertificateProvider(r.Context(), provided, mock.Anything). + SendToCertificateProvider(r.Context(), provided). Return(nil) witnessCodeSender.EXPECT(). SendToIndependentWitness(r.Context(), &donordata.Provided{ @@ -92,7 +92,7 @@ func TestPostWitnessingYourSignatureCannotSign(t *testing.T) { Donor: donordata.Donor{CanSign: form.No}, DonorIdentityUserData: identity.UserData{Status: identity.StatusConfirmed}, CertificateProvider: donordata.CertificateProvider{Mobile: "07535111111"}, - }, mock.Anything). + }). Return(nil) donorStore := newMockDonorStore(t) @@ -123,7 +123,7 @@ func TestPostWitnessingYourSignatureWhenWitnessCodeSenderErrors(t *testing.T) { "SendToCertificateProvider": { setupWitnessCodeSender: func(witnessCodeSender *mockWitnessCodeSender) { witnessCodeSender.EXPECT(). - SendToCertificateProvider(mock.Anything, mock.Anything, mock.Anything). + SendToCertificateProvider(mock.Anything, mock.Anything). Return(expectedError) }, setupDonorStore: func(donorStore *mockDonorStore) {}, @@ -131,10 +131,10 @@ func TestPostWitnessingYourSignatureWhenWitnessCodeSenderErrors(t *testing.T) { "SendToIndependentWitness": { setupWitnessCodeSender: func(witnessCodeSender *mockWitnessCodeSender) { witnessCodeSender.EXPECT(). - SendToCertificateProvider(mock.Anything, mock.Anything, mock.Anything). + SendToCertificateProvider(mock.Anything, mock.Anything). Return(nil) witnessCodeSender.EXPECT(). - SendToIndependentWitness(mock.Anything, mock.Anything, mock.Anything). + SendToIndependentWitness(mock.Anything, mock.Anything). Return(expectedError) }, setupDonorStore: func(donorStore *mockDonorStore) { diff --git a/internal/donor/mock_DonorStore_test.go b/internal/donor/mock_DonorStore_test.go new file mode 100644 index 0000000000..8d175917bb --- /dev/null +++ b/internal/donor/mock_DonorStore_test.go @@ -0,0 +1,142 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package donor + +import ( + context "context" + + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" + mock "github.com/stretchr/testify/mock" +) + +// mockDonorStore is an autogenerated mock type for the DonorStore type +type mockDonorStore struct { + mock.Mock +} + +type mockDonorStore_Expecter struct { + mock *mock.Mock +} + +func (_m *mockDonorStore) EXPECT() *mockDonorStore_Expecter { + return &mockDonorStore_Expecter{mock: &_m.Mock} +} + +// Create provides a mock function with given fields: _a0 +func (_m *mockDonorStore) Create(_a0 context.Context) (*donordata.Provided, error) { + ret := _m.Called(_a0) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 *donordata.Provided + var r1 error + if rf, ok := ret.Get(0).(func(context.Context) (*donordata.Provided, error)); ok { + return rf(_a0) + } + if rf, ok := ret.Get(0).(func(context.Context) *donordata.Provided); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*donordata.Provided) + } + } + + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockDonorStore_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type mockDonorStore_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - _a0 context.Context +func (_e *mockDonorStore_Expecter) Create(_a0 interface{}) *mockDonorStore_Create_Call { + return &mockDonorStore_Create_Call{Call: _e.mock.On("Create", _a0)} +} + +func (_c *mockDonorStore_Create_Call) Run(run func(_a0 context.Context)) *mockDonorStore_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context)) + }) + return _c +} + +func (_c *mockDonorStore_Create_Call) Return(_a0 *donordata.Provided, _a1 error) *mockDonorStore_Create_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockDonorStore_Create_Call) RunAndReturn(run func(context.Context) (*donordata.Provided, error)) *mockDonorStore_Create_Call { + _c.Call.Return(run) + return _c +} + +// Put provides a mock function with given fields: _a0, _a1 +func (_m *mockDonorStore) Put(_a0 context.Context, _a1 *donordata.Provided) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for Put") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *donordata.Provided) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDonorStore_Put_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Put' +type mockDonorStore_Put_Call struct { + *mock.Call +} + +// Put is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 *donordata.Provided +func (_e *mockDonorStore_Expecter) Put(_a0 interface{}, _a1 interface{}) *mockDonorStore_Put_Call { + return &mockDonorStore_Put_Call{Call: _e.mock.On("Put", _a0, _a1)} +} + +func (_c *mockDonorStore_Put_Call) Run(run func(_a0 context.Context, _a1 *donordata.Provided)) *mockDonorStore_Put_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*donordata.Provided)) + }) + return _c +} + +func (_c *mockDonorStore_Put_Call) Return(_a0 error) *mockDonorStore_Put_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDonorStore_Put_Call) RunAndReturn(run func(context.Context, *donordata.Provided) error) *mockDonorStore_Put_Call { + _c.Call.Return(run) + return _c +} + +// newMockDonorStore creates a new instance of mockDonorStore. 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 newMockDonorStore(t interface { + mock.TestingT + Cleanup(func()) +}) *mockDonorStore { + mock := &mockDonorStore{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/donor/mock_Localizer_test.go b/internal/donor/mock_Localizer_test.go new file mode 100644 index 0000000000..2c25deba9c --- /dev/null +++ b/internal/donor/mock_Localizer_test.go @@ -0,0 +1,534 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package donor + +import ( + date "github.com/ministryofjustice/opg-modernising-lpa/internal/date" + mock "github.com/stretchr/testify/mock" + + time "time" +) + +// mockLocalizer is an autogenerated mock type for the Localizer type +type mockLocalizer struct { + mock.Mock +} + +type mockLocalizer_Expecter struct { + mock *mock.Mock +} + +func (_m *mockLocalizer) EXPECT() *mockLocalizer_Expecter { + return &mockLocalizer_Expecter{mock: &_m.Mock} +} + +// Concat provides a mock function with given fields: list, joiner +func (_m *mockLocalizer) Concat(list []string, joiner string) string { + ret := _m.Called(list, joiner) + + if len(ret) == 0 { + panic("no return value specified for Concat") + } + + var r0 string + if rf, ok := ret.Get(0).(func([]string, string) string); ok { + r0 = rf(list, joiner) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_Concat_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Concat' +type mockLocalizer_Concat_Call struct { + *mock.Call +} + +// Concat is a helper method to define mock.On call +// - list []string +// - joiner string +func (_e *mockLocalizer_Expecter) Concat(list interface{}, joiner interface{}) *mockLocalizer_Concat_Call { + return &mockLocalizer_Concat_Call{Call: _e.mock.On("Concat", list, joiner)} +} + +func (_c *mockLocalizer_Concat_Call) Run(run func(list []string, joiner string)) *mockLocalizer_Concat_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]string), args[1].(string)) + }) + return _c +} + +func (_c *mockLocalizer_Concat_Call) Return(_a0 string) *mockLocalizer_Concat_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_Concat_Call) RunAndReturn(run func([]string, string) string) *mockLocalizer_Concat_Call { + _c.Call.Return(run) + return _c +} + +// Count provides a mock function with given fields: messageID, count +func (_m *mockLocalizer) Count(messageID string, count int) string { + ret := _m.Called(messageID, count) + + if len(ret) == 0 { + panic("no return value specified for Count") + } + + var r0 string + if rf, ok := ret.Get(0).(func(string, int) string); ok { + r0 = rf(messageID, count) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_Count_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Count' +type mockLocalizer_Count_Call struct { + *mock.Call +} + +// Count is a helper method to define mock.On call +// - messageID string +// - count int +func (_e *mockLocalizer_Expecter) Count(messageID interface{}, count interface{}) *mockLocalizer_Count_Call { + return &mockLocalizer_Count_Call{Call: _e.mock.On("Count", messageID, count)} +} + +func (_c *mockLocalizer_Count_Call) Run(run func(messageID string, count int)) *mockLocalizer_Count_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(int)) + }) + return _c +} + +func (_c *mockLocalizer_Count_Call) Return(_a0 string) *mockLocalizer_Count_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_Count_Call) RunAndReturn(run func(string, int) string) *mockLocalizer_Count_Call { + _c.Call.Return(run) + return _c +} + +// Format provides a mock function with given fields: messageID, data +func (_m *mockLocalizer) Format(messageID string, data map[string]interface{}) string { + ret := _m.Called(messageID, data) + + if len(ret) == 0 { + panic("no return value specified for Format") + } + + var r0 string + if rf, ok := ret.Get(0).(func(string, map[string]interface{}) string); ok { + r0 = rf(messageID, data) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_Format_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Format' +type mockLocalizer_Format_Call struct { + *mock.Call +} + +// Format is a helper method to define mock.On call +// - messageID string +// - data map[string]interface{} +func (_e *mockLocalizer_Expecter) Format(messageID interface{}, data interface{}) *mockLocalizer_Format_Call { + return &mockLocalizer_Format_Call{Call: _e.mock.On("Format", messageID, data)} +} + +func (_c *mockLocalizer_Format_Call) Run(run func(messageID string, data map[string]interface{})) *mockLocalizer_Format_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(map[string]interface{})) + }) + return _c +} + +func (_c *mockLocalizer_Format_Call) Return(_a0 string) *mockLocalizer_Format_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_Format_Call) RunAndReturn(run func(string, map[string]interface{}) string) *mockLocalizer_Format_Call { + _c.Call.Return(run) + return _c +} + +// FormatCount provides a mock function with given fields: messageID, count, data +func (_m *mockLocalizer) FormatCount(messageID string, count int, data map[string]interface{}) string { + ret := _m.Called(messageID, count, data) + + if len(ret) == 0 { + panic("no return value specified for FormatCount") + } + + var r0 string + if rf, ok := ret.Get(0).(func(string, int, map[string]interface{}) string); ok { + r0 = rf(messageID, count, data) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_FormatCount_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FormatCount' +type mockLocalizer_FormatCount_Call struct { + *mock.Call +} + +// FormatCount is a helper method to define mock.On call +// - messageID string +// - count int +// - data map[string]interface{} +func (_e *mockLocalizer_Expecter) FormatCount(messageID interface{}, count interface{}, data interface{}) *mockLocalizer_FormatCount_Call { + return &mockLocalizer_FormatCount_Call{Call: _e.mock.On("FormatCount", messageID, count, data)} +} + +func (_c *mockLocalizer_FormatCount_Call) Run(run func(messageID string, count int, data map[string]interface{})) *mockLocalizer_FormatCount_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string), args[1].(int), args[2].(map[string]interface{})) + }) + return _c +} + +func (_c *mockLocalizer_FormatCount_Call) Return(_a0 string) *mockLocalizer_FormatCount_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_FormatCount_Call) RunAndReturn(run func(string, int, map[string]interface{}) string) *mockLocalizer_FormatCount_Call { + _c.Call.Return(run) + return _c +} + +// FormatDate provides a mock function with given fields: t +func (_m *mockLocalizer) FormatDate(t date.TimeOrDate) string { + ret := _m.Called(t) + + if len(ret) == 0 { + panic("no return value specified for FormatDate") + } + + var r0 string + if rf, ok := ret.Get(0).(func(date.TimeOrDate) string); ok { + r0 = rf(t) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_FormatDate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FormatDate' +type mockLocalizer_FormatDate_Call struct { + *mock.Call +} + +// FormatDate is a helper method to define mock.On call +// - t date.TimeOrDate +func (_e *mockLocalizer_Expecter) FormatDate(t interface{}) *mockLocalizer_FormatDate_Call { + return &mockLocalizer_FormatDate_Call{Call: _e.mock.On("FormatDate", t)} +} + +func (_c *mockLocalizer_FormatDate_Call) Run(run func(t date.TimeOrDate)) *mockLocalizer_FormatDate_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(date.TimeOrDate)) + }) + return _c +} + +func (_c *mockLocalizer_FormatDate_Call) Return(_a0 string) *mockLocalizer_FormatDate_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_FormatDate_Call) RunAndReturn(run func(date.TimeOrDate) string) *mockLocalizer_FormatDate_Call { + _c.Call.Return(run) + return _c +} + +// FormatDateTime provides a mock function with given fields: t +func (_m *mockLocalizer) FormatDateTime(t time.Time) string { + ret := _m.Called(t) + + if len(ret) == 0 { + panic("no return value specified for FormatDateTime") + } + + var r0 string + if rf, ok := ret.Get(0).(func(time.Time) string); ok { + r0 = rf(t) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_FormatDateTime_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FormatDateTime' +type mockLocalizer_FormatDateTime_Call struct { + *mock.Call +} + +// FormatDateTime is a helper method to define mock.On call +// - t time.Time +func (_e *mockLocalizer_Expecter) FormatDateTime(t interface{}) *mockLocalizer_FormatDateTime_Call { + return &mockLocalizer_FormatDateTime_Call{Call: _e.mock.On("FormatDateTime", t)} +} + +func (_c *mockLocalizer_FormatDateTime_Call) Run(run func(t time.Time)) *mockLocalizer_FormatDateTime_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(time.Time)) + }) + return _c +} + +func (_c *mockLocalizer_FormatDateTime_Call) Return(_a0 string) *mockLocalizer_FormatDateTime_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_FormatDateTime_Call) RunAndReturn(run func(time.Time) string) *mockLocalizer_FormatDateTime_Call { + _c.Call.Return(run) + return _c +} + +// FormatTime provides a mock function with given fields: t +func (_m *mockLocalizer) FormatTime(t time.Time) string { + ret := _m.Called(t) + + if len(ret) == 0 { + panic("no return value specified for FormatTime") + } + + var r0 string + if rf, ok := ret.Get(0).(func(time.Time) string); ok { + r0 = rf(t) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_FormatTime_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'FormatTime' +type mockLocalizer_FormatTime_Call struct { + *mock.Call +} + +// FormatTime is a helper method to define mock.On call +// - t time.Time +func (_e *mockLocalizer_Expecter) FormatTime(t interface{}) *mockLocalizer_FormatTime_Call { + return &mockLocalizer_FormatTime_Call{Call: _e.mock.On("FormatTime", t)} +} + +func (_c *mockLocalizer_FormatTime_Call) Run(run func(t time.Time)) *mockLocalizer_FormatTime_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(time.Time)) + }) + return _c +} + +func (_c *mockLocalizer_FormatTime_Call) Return(_a0 string) *mockLocalizer_FormatTime_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_FormatTime_Call) RunAndReturn(run func(time.Time) string) *mockLocalizer_FormatTime_Call { + _c.Call.Return(run) + return _c +} + +// Possessive provides a mock function with given fields: s +func (_m *mockLocalizer) Possessive(s string) string { + ret := _m.Called(s) + + if len(ret) == 0 { + panic("no return value specified for Possessive") + } + + var r0 string + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(s) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_Possessive_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Possessive' +type mockLocalizer_Possessive_Call struct { + *mock.Call +} + +// Possessive is a helper method to define mock.On call +// - s string +func (_e *mockLocalizer_Expecter) Possessive(s interface{}) *mockLocalizer_Possessive_Call { + return &mockLocalizer_Possessive_Call{Call: _e.mock.On("Possessive", s)} +} + +func (_c *mockLocalizer_Possessive_Call) Run(run func(s string)) *mockLocalizer_Possessive_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *mockLocalizer_Possessive_Call) Return(_a0 string) *mockLocalizer_Possessive_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_Possessive_Call) RunAndReturn(run func(string) string) *mockLocalizer_Possessive_Call { + _c.Call.Return(run) + return _c +} + +// SetShowTranslationKeys provides a mock function with given fields: s +func (_m *mockLocalizer) SetShowTranslationKeys(s bool) { + _m.Called(s) +} + +// mockLocalizer_SetShowTranslationKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetShowTranslationKeys' +type mockLocalizer_SetShowTranslationKeys_Call struct { + *mock.Call +} + +// SetShowTranslationKeys is a helper method to define mock.On call +// - s bool +func (_e *mockLocalizer_Expecter) SetShowTranslationKeys(s interface{}) *mockLocalizer_SetShowTranslationKeys_Call { + return &mockLocalizer_SetShowTranslationKeys_Call{Call: _e.mock.On("SetShowTranslationKeys", s)} +} + +func (_c *mockLocalizer_SetShowTranslationKeys_Call) Run(run func(s bool)) *mockLocalizer_SetShowTranslationKeys_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(bool)) + }) + return _c +} + +func (_c *mockLocalizer_SetShowTranslationKeys_Call) Return() *mockLocalizer_SetShowTranslationKeys_Call { + _c.Call.Return() + return _c +} + +func (_c *mockLocalizer_SetShowTranslationKeys_Call) RunAndReturn(run func(bool)) *mockLocalizer_SetShowTranslationKeys_Call { + _c.Call.Return(run) + return _c +} + +// ShowTranslationKeys provides a mock function with given fields: +func (_m *mockLocalizer) ShowTranslationKeys() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ShowTranslationKeys") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// mockLocalizer_ShowTranslationKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ShowTranslationKeys' +type mockLocalizer_ShowTranslationKeys_Call struct { + *mock.Call +} + +// ShowTranslationKeys is a helper method to define mock.On call +func (_e *mockLocalizer_Expecter) ShowTranslationKeys() *mockLocalizer_ShowTranslationKeys_Call { + return &mockLocalizer_ShowTranslationKeys_Call{Call: _e.mock.On("ShowTranslationKeys")} +} + +func (_c *mockLocalizer_ShowTranslationKeys_Call) Run(run func()) *mockLocalizer_ShowTranslationKeys_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *mockLocalizer_ShowTranslationKeys_Call) Return(_a0 bool) *mockLocalizer_ShowTranslationKeys_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_ShowTranslationKeys_Call) RunAndReturn(run func() bool) *mockLocalizer_ShowTranslationKeys_Call { + _c.Call.Return(run) + return _c +} + +// T provides a mock function with given fields: messageID +func (_m *mockLocalizer) T(messageID string) string { + ret := _m.Called(messageID) + + if len(ret) == 0 { + panic("no return value specified for T") + } + + var r0 string + if rf, ok := ret.Get(0).(func(string) string); ok { + r0 = rf(messageID) + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// mockLocalizer_T_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'T' +type mockLocalizer_T_Call struct { + *mock.Call +} + +// T is a helper method to define mock.On call +// - messageID string +func (_e *mockLocalizer_Expecter) T(messageID interface{}) *mockLocalizer_T_Call { + return &mockLocalizer_T_Call{Call: _e.mock.On("T", messageID)} +} + +func (_c *mockLocalizer_T_Call) Run(run func(messageID string)) *mockLocalizer_T_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(string)) + }) + return _c +} + +func (_c *mockLocalizer_T_Call) Return(_a0 string) *mockLocalizer_T_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockLocalizer_T_Call) RunAndReturn(run func(string) string) *mockLocalizer_T_Call { + _c.Call.Return(run) + return _c +} + +// newMockLocalizer creates a new instance of mockLocalizer. 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 newMockLocalizer(t interface { + mock.TestingT + Cleanup(func()) +}) *mockLocalizer { + mock := &mockLocalizer{} + 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 new file mode 100644 index 0000000000..42d9362050 --- /dev/null +++ b/internal/donor/mock_NotifyClient_test.go @@ -0,0 +1,135 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package donor + +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/page/witness_code.go b/internal/donor/witness_code_sender.go similarity index 59% rename from internal/page/witness_code.go rename to internal/donor/witness_code_sender.go index 06639b6cf4..ea8c6e7475 100644 --- a/internal/page/witness_code.go +++ b/internal/donor/witness_code_sender.go @@ -1,10 +1,11 @@ -package page +package donor import ( "context" "errors" "time" + "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" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" @@ -17,23 +18,49 @@ var ( ErrTooManyWitnessCodeRequests = errors.New("too many witness code requests") ) +type DonorStore interface { + Create(context.Context) (*donordata.Provided, error) + Put(context.Context, *donordata.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 +} + +type Localizer interface { + Concat(list []string, joiner string) string + Count(messageID string, count int) string + Format(messageID string, data map[string]interface{}) string + FormatCount(messageID string, count int, data map[string]any) string + FormatDate(t date.TimeOrDate) string + FormatTime(t time.Time) string + FormatDateTime(t time.Time) string + Possessive(s string) string + SetShowTranslationKeys(s bool) + ShowTranslationKeys() bool + T(messageID string) string +} + type WitnessCodeSender struct { donorStore DonorStore notifyClient NotifyClient + localizer Localizer randomCode func(int) string now func() time.Time } -func NewWitnessCodeSender(donorStore DonorStore, notifyClient NotifyClient) *WitnessCodeSender { +func NewWitnessCodeSender(donorStore DonorStore, notifyClient NotifyClient, localizer Localizer) *WitnessCodeSender { return &WitnessCodeSender{ donorStore: donorStore, notifyClient: notifyClient, + localizer: localizer, randomCode: random.Code, now: time.Now, } } -func (s *WitnessCodeSender) SendToCertificateProvider(ctx context.Context, donor *donordata.Provided, localizer Localizer) error { +func (s *WitnessCodeSender) SendToCertificateProvider(ctx context.Context, donor *donordata.Provided) error { if !donor.CertificateProviderCodes.CanRequest(s.now()) { return ErrTooManyWitnessCodeRequests } @@ -51,12 +78,12 @@ func (s *WitnessCodeSender) SendToCertificateProvider(ctx context.Context, donor return s.notifyClient.SendActorSMS(ctx, donor.CertificateProvider.Mobile, donor.LpaUID, notify.WitnessCodeSMS{ WitnessCode: code, - DonorFullName: localizer.Possessive(donor.Donor.FullName()), - LpaType: localize.LowerFirst(localizer.T(donor.Type.String())), + DonorFullName: s.localizer.Possessive(donor.Donor.FullName()), + LpaType: localize.LowerFirst(s.localizer.T(donor.Type.String())), }) } -func (s *WitnessCodeSender) SendToIndependentWitness(ctx context.Context, donor *donordata.Provided, localizer Localizer) error { +func (s *WitnessCodeSender) SendToIndependentWitness(ctx context.Context, donor *donordata.Provided) error { if !donor.IndependentWitnessCodes.CanRequest(s.now()) { return ErrTooManyWitnessCodeRequests } @@ -74,7 +101,7 @@ func (s *WitnessCodeSender) SendToIndependentWitness(ctx context.Context, donor return s.notifyClient.SendActorSMS(ctx, donor.IndependentWitness.Mobile, donor.LpaUID, notify.WitnessCodeSMS{ WitnessCode: code, - DonorFullName: localizer.Possessive(donor.Donor.FullName()), - LpaType: localize.LowerFirst(localizer.T(donor.Type.String())), + DonorFullName: s.localizer.Possessive(donor.Donor.FullName()), + LpaType: localize.LowerFirst(s.localizer.T(donor.Type.String())), }) } diff --git a/internal/page/witness_code_test.go b/internal/donor/witness_code_sender_test.go similarity index 98% rename from internal/page/witness_code_test.go rename to internal/donor/witness_code_sender_test.go index 2e8e2ea88e..5edf22c5d8 100644 --- a/internal/page/witness_code_test.go +++ b/internal/donor/witness_code_sender_test.go @@ -1,4 +1,4 @@ -package page +package donor import ( "context" @@ -66,6 +66,7 @@ func TestWitnessCodeSenderSendToCertificateProvider(t *testing.T) { sender := &WitnessCodeSender{ donorStore: donorStore, notifyClient: notifyClient, + localizer: localizer, randomCode: func(int) string { return tc.randomCode }, now: func() time.Time { return now }, } @@ -74,7 +75,7 @@ func TestWitnessCodeSenderSendToCertificateProvider(t *testing.T) { Donor: donordata.Donor{FirstNames: "Joe", LastName: "Jones"}, CertificateProvider: donordata.CertificateProvider{Mobile: "0777"}, Type: lpadata.LpaTypePropertyAndAffairs, - }, localizer) + }) assert.Nil(t, err) }) @@ -88,7 +89,7 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenTooRecentlySent(t *testin sender := &WitnessCodeSender{now: func() time.Time { return now }} err := sender.SendToCertificateProvider(ctx, &donordata.Provided{ CertificateProviderCodes: donordata.WitnessCodes{{Created: now.Add(-time.Minute)}}, - }, nil) + }) assert.Equal(t, ErrTooManyWitnessCodeRequests, err) } @@ -115,6 +116,7 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenNotifyClientErrors(t *tes sender := &WitnessCodeSender{ donorStore: donorStore, notifyClient: notifyClient, + localizer: localizer, randomCode: func(int) string { return "1234" }, now: time.Now, } @@ -122,7 +124,7 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenNotifyClientErrors(t *tes CertificateProvider: donordata.CertificateProvider{Mobile: "0777"}, Donor: donordata.Donor{FirstNames: "Joe", LastName: "Jones"}, Type: lpadata.LpaTypePropertyAndAffairs, - }, localizer) + }) assert.Equal(t, expectedError, err) } @@ -142,7 +144,7 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenDonorStoreErrors(t *testi CertificateProvider: donordata.CertificateProvider{Mobile: "0777"}, Donor: donordata.Donor{FirstNames: "Joe", LastName: "Jones"}, Type: lpadata.LpaTypePropertyAndAffairs, - }, nil) + }) assert.Equal(t, expectedError, err) } @@ -182,6 +184,7 @@ func TestWitnessCodeSenderSendToIndependentWitness(t *testing.T) { sender := &WitnessCodeSender{ donorStore: donorStore, notifyClient: notifyClient, + localizer: localizer, randomCode: func(int) string { return "1234" }, now: func() time.Time { return now }, } @@ -190,7 +193,7 @@ func TestWitnessCodeSenderSendToIndependentWitness(t *testing.T) { Donor: donordata.Donor{FirstNames: "Joe", LastName: "Jones"}, IndependentWitness: donordata.IndependentWitness{Mobile: "0777"}, Type: lpadata.LpaTypePropertyAndAffairs, - }, localizer) + }) assert.Nil(t, err) } @@ -202,7 +205,7 @@ func TestWitnessCodeSenderSendToIndependentWitnessWhenTooRecentlySent(t *testing sender := &WitnessCodeSender{now: func() time.Time { return now }} err := sender.SendToIndependentWitness(ctx, &donordata.Provided{ IndependentWitnessCodes: donordata.WitnessCodes{{Created: now.Add(-time.Minute)}}, - }, nil) + }) assert.Equal(t, ErrTooManyWitnessCodeRequests, err) } @@ -229,6 +232,7 @@ func TestWitnessCodeSenderSendToIndependentWitnessWhenNotifyClientErrors(t *test sender := &WitnessCodeSender{ donorStore: donorStore, notifyClient: notifyClient, + localizer: localizer, randomCode: func(int) string { return "1234" }, now: time.Now, } @@ -236,7 +240,7 @@ func TestWitnessCodeSenderSendToIndependentWitnessWhenNotifyClientErrors(t *test IndependentWitness: donordata.IndependentWitness{Mobile: "0777"}, Donor: donordata.Donor{FirstNames: "Joe", LastName: "Jones"}, Type: lpadata.LpaTypePropertyAndAffairs, - }, localizer) + }) assert.Equal(t, expectedError, err) } @@ -256,7 +260,7 @@ func TestWitnessCodeSenderSendToIndependentWitnessWhenDonorStoreErrors(t *testin IndependentWitness: donordata.IndependentWitness{Mobile: "0777"}, Donor: donordata.Donor{FirstNames: "Joe", LastName: "Jones"}, Type: lpadata.LpaTypePropertyAndAffairs, - }, nil) + }) assert.Equal(t, expectedError, err) } diff --git a/internal/page/fixtures/donor.go b/internal/page/fixtures/donor.go index a10d0c9503..16d666de31 100644 --- a/internal/page/fixtures/donor.go +++ b/internal/page/fixtures/donor.go @@ -14,6 +14,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/document" + "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/form" @@ -164,7 +165,7 @@ func Donor( data.Redirect = "/lpa/" + donorDetails.LpaID + data.Redirect } - page.UseTestWitnessCode = true + donor.UseTestWitnessCode = true http.Redirect(w, r, data.Redirect, http.StatusFound) return nil