diff --git a/cmd/event-received/factory.go b/cmd/event-received/factory.go index 800edd3ea3..61a4ef6bf8 100644 --- a/cmd/event-received/factory.go +++ b/cmd/event-received/factory.go @@ -11,6 +11,7 @@ import ( v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" "github.com/ministryofjustice/opg-modernising-lpa/internal/app" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/lambda" @@ -40,7 +41,7 @@ type SecretsClient interface { } type ShareCodeSender interface { - SendCertificateProviderInvite(context.Context, appcontext.Data, sharecode.CertificateProviderInvite) error + SendCertificateProviderInvite(context.Context, appcontext.Data, sharecode.CertificateProviderInvite, notify.ToEmail) error SendCertificateProviderPrompt(context.Context, appcontext.Data, *donordata.Provided) error SendAttorneys(context.Context, appcontext.Data, *lpadata.Lpa) error } @@ -166,7 +167,7 @@ func (f *Factory) ShareCodeSender(ctx context.Context) (ShareCodeSender, error) return nil, err } - f.shareCodeSender = sharecode.NewSender(sharecode.NewStore(f.dynamoClient), notifyClient, f.appPublicURL, random.String, event.NewClient(f.cfg, f.eventBusName)) + f.shareCodeSender = sharecode.NewSender(sharecode.NewStore(f.dynamoClient), notifyClient, f.appPublicURL, random.String, event.NewClient(f.cfg, f.eventBusName), certificateprovider.NewStore(f.dynamoClient)) } return f.shareCodeSender, nil diff --git a/cmd/event-received/main.go b/cmd/event-received/main.go index 294be97bbb..80c39476e3 100644 --- a/cmd/event-received/main.go +++ b/cmd/event-received/main.go @@ -16,6 +16,7 @@ import ( "github.com/aws/aws-lambda-go/lambda" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" + dynamodbtypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" "github.com/aws/aws-sdk-go-v2/service/s3/types" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/document" @@ -77,18 +78,26 @@ type uidEvent struct { } type dynamodbClient interface { - AnyByPK(ctx context.Context, pk dynamo.PK, v interface{}) error - AllByLpaUIDAndPartialSK(ctx context.Context, uid string, partialSK dynamo.SK, v interface{}) error - Create(ctx context.Context, v interface{}) error - CreateOnly(ctx context.Context, v interface{}) error - DeleteOne(ctx context.Context, pk dynamo.PK, sk dynamo.SK) error + AllByKeys(ctx context.Context, keys []dynamo.Keys) ([]map[string]dynamodbtypes.AttributeValue, error) + AllByLpaUIDAndPartialSK(ctx context.Context, uid string, partialSK dynamo.SK, v any) error + AllByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v any) error + AllBySK(ctx context.Context, sk dynamo.SK, v any) error + AllKeysByPK(ctx context.Context, pk dynamo.PK) ([]dynamo.Keys, error) + AnyByPK(ctx context.Context, pk dynamo.PK, v any) error + BatchPut(ctx context.Context, items []any) error + Create(ctx context.Context, v any) error + CreateOnly(ctx context.Context, v any) error DeleteKeys(ctx context.Context, keys []dynamo.Keys) error + DeleteOne(ctx context.Context, pk dynamo.PK, sk dynamo.SK) error + LatestForActor(ctx context.Context, sk dynamo.SK, v any) error Move(ctx context.Context, oldKeys dynamo.Keys, value any) error - One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error - OneByUID(ctx context.Context, uid string, v interface{}) error - OneByPK(ctx context.Context, pk dynamo.PK, v interface{}) error - OneBySK(ctx context.Context, sk dynamo.SK, v interface{}) error - Put(ctx context.Context, v interface{}) error + One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v any) error + OneByPK(ctx context.Context, pk dynamo.PK, v any) error + OneByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v any) error + OneBySK(ctx context.Context, sk dynamo.SK, v any) error + OneByUID(ctx context.Context, uid string, v any) error + Put(ctx context.Context, v any) error + Update(ctx context.Context, pk dynamo.PK, sk dynamo.SK, values map[string]dynamodbtypes.AttributeValue, expression string) error WriteTransaction(ctx context.Context, transaction *dynamo.Transaction) error } diff --git a/cmd/event-received/mock_ShareCodeSender_test.go b/cmd/event-received/mock_ShareCodeSender_test.go index 4d3fc1fe12..585259a1bb 100644 --- a/cmd/event-received/mock_ShareCodeSender_test.go +++ b/cmd/event-received/mock_ShareCodeSender_test.go @@ -13,6 +13,8 @@ import ( mock "github.com/stretchr/testify/mock" + notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) @@ -77,17 +79,17 @@ func (_c *mockShareCodeSender_SendAttorneys_Call) RunAndReturn(run func(context. return _c } -// SendCertificateProviderInvite provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockShareCodeSender) SendCertificateProviderInvite(_a0 context.Context, _a1 appcontext.Data, _a2 sharecode.CertificateProviderInvite) error { - ret := _m.Called(_a0, _a1, _a2) +// SendCertificateProviderInvite provides a mock function with given fields: _a0, _a1, _a2, _a3 +func (_m *mockShareCodeSender) SendCertificateProviderInvite(_a0 context.Context, _a1 appcontext.Data, _a2 sharecode.CertificateProviderInvite, _a3 notify.ToEmail) error { + ret := _m.Called(_a0, _a1, _a2, _a3) if len(ret) == 0 { panic("no return value specified for SendCertificateProviderInvite") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, appcontext.Data, sharecode.CertificateProviderInvite) error); ok { - r0 = rf(_a0, _a1, _a2) + if rf, ok := ret.Get(0).(func(context.Context, appcontext.Data, sharecode.CertificateProviderInvite, notify.ToEmail) error); ok { + r0 = rf(_a0, _a1, _a2, _a3) } else { r0 = ret.Error(0) } @@ -104,13 +106,14 @@ type mockShareCodeSender_SendCertificateProviderInvite_Call struct { // - _a0 context.Context // - _a1 appcontext.Data // - _a2 sharecode.CertificateProviderInvite -func (_e *mockShareCodeSender_Expecter) SendCertificateProviderInvite(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockShareCodeSender_SendCertificateProviderInvite_Call { - return &mockShareCodeSender_SendCertificateProviderInvite_Call{Call: _e.mock.On("SendCertificateProviderInvite", _a0, _a1, _a2)} +// - _a3 notify.ToEmail +func (_e *mockShareCodeSender_Expecter) SendCertificateProviderInvite(_a0 interface{}, _a1 interface{}, _a2 interface{}, _a3 interface{}) *mockShareCodeSender_SendCertificateProviderInvite_Call { + return &mockShareCodeSender_SendCertificateProviderInvite_Call{Call: _e.mock.On("SendCertificateProviderInvite", _a0, _a1, _a2, _a3)} } -func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) Run(run func(_a0 context.Context, _a1 appcontext.Data, _a2 sharecode.CertificateProviderInvite)) *mockShareCodeSender_SendCertificateProviderInvite_Call { +func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) Run(run func(_a0 context.Context, _a1 appcontext.Data, _a2 sharecode.CertificateProviderInvite, _a3 notify.ToEmail)) *mockShareCodeSender_SendCertificateProviderInvite_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(appcontext.Data), args[2].(sharecode.CertificateProviderInvite)) + run(args[0].(context.Context), args[1].(appcontext.Data), args[2].(sharecode.CertificateProviderInvite), args[3].(notify.ToEmail)) }) return _c } @@ -120,7 +123,7 @@ func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) Return(_a0 err return _c } -func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) RunAndReturn(run func(context.Context, appcontext.Data, sharecode.CertificateProviderInvite) error) *mockShareCodeSender_SendCertificateProviderInvite_Call { +func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) RunAndReturn(run func(context.Context, appcontext.Data, sharecode.CertificateProviderInvite, notify.ToEmail) error) *mockShareCodeSender_SendCertificateProviderInvite_Call { _c.Call.Return(run) return _c } diff --git a/cmd/event-received/mock_dynamodbClient_test.go b/cmd/event-received/mock_dynamodbClient_test.go index ca9820e532..f67d81c789 100644 --- a/cmd/event-received/mock_dynamodbClient_test.go +++ b/cmd/event-received/mock_dynamodbClient_test.go @@ -7,6 +7,8 @@ import ( dynamo "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" mock "github.com/stretchr/testify/mock" + + types "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" ) // mockDynamodbClient is an autogenerated mock type for the dynamodbClient type @@ -22,8 +24,67 @@ func (_m *mockDynamodbClient) EXPECT() *mockDynamodbClient_Expecter { return &mockDynamodbClient_Expecter{mock: &_m.Mock} } +// AllByKeys provides a mock function with given fields: ctx, keys +func (_m *mockDynamodbClient) AllByKeys(ctx context.Context, keys []dynamo.Keys) ([]map[string]types.AttributeValue, error) { + ret := _m.Called(ctx, keys) + + if len(ret) == 0 { + panic("no return value specified for AllByKeys") + } + + var r0 []map[string]types.AttributeValue + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) ([]map[string]types.AttributeValue, error)); ok { + return rf(ctx, keys) + } + if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) []map[string]types.AttributeValue); ok { + r0 = rf(ctx, keys) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]map[string]types.AttributeValue) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []dynamo.Keys) error); ok { + r1 = rf(ctx, keys) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockDynamodbClient_AllByKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllByKeys' +type mockDynamodbClient_AllByKeys_Call struct { + *mock.Call +} + +// AllByKeys is a helper method to define mock.On call +// - ctx context.Context +// - keys []dynamo.Keys +func (_e *mockDynamodbClient_Expecter) AllByKeys(ctx interface{}, keys interface{}) *mockDynamodbClient_AllByKeys_Call { + return &mockDynamodbClient_AllByKeys_Call{Call: _e.mock.On("AllByKeys", ctx, keys)} +} + +func (_c *mockDynamodbClient_AllByKeys_Call) Run(run func(ctx context.Context, keys []dynamo.Keys)) *mockDynamodbClient_AllByKeys_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]dynamo.Keys)) + }) + return _c +} + +func (_c *mockDynamodbClient_AllByKeys_Call) Return(_a0 []map[string]types.AttributeValue, _a1 error) *mockDynamodbClient_AllByKeys_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockDynamodbClient_AllByKeys_Call) RunAndReturn(run func(context.Context, []dynamo.Keys) ([]map[string]types.AttributeValue, error)) *mockDynamodbClient_AllByKeys_Call { + _c.Call.Return(run) + return _c +} + // AllByLpaUIDAndPartialSK provides a mock function with given fields: ctx, uid, partialSK, v -func (_m *mockDynamodbClient) AllByLpaUIDAndPartialSK(ctx context.Context, uid string, partialSK dynamo.SK, v interface{}) error { +func (_m *mockDynamodbClient) AllByLpaUIDAndPartialSK(ctx context.Context, uid string, partialSK dynamo.SK, v any) error { ret := _m.Called(ctx, uid, partialSK, v) if len(ret) == 0 { @@ -31,7 +92,7 @@ func (_m *mockDynamodbClient) AllByLpaUIDAndPartialSK(ctx context.Context, uid s } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, dynamo.SK, interface{}) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, dynamo.SK, any) error); ok { r0 = rf(ctx, uid, partialSK, v) } else { r0 = ret.Error(0) @@ -49,14 +110,14 @@ type mockDynamodbClient_AllByLpaUIDAndPartialSK_Call struct { // - ctx context.Context // - uid string // - partialSK dynamo.SK -// - v interface{} +// - v any func (_e *mockDynamodbClient_Expecter) AllByLpaUIDAndPartialSK(ctx interface{}, uid interface{}, partialSK interface{}, v interface{}) *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call { return &mockDynamodbClient_AllByLpaUIDAndPartialSK_Call{Call: _e.mock.On("AllByLpaUIDAndPartialSK", ctx, uid, partialSK, v)} } -func (_c *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call) Run(run func(ctx context.Context, uid string, partialSK dynamo.SK, v interface{})) *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call { +func (_c *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call) Run(run func(ctx context.Context, uid string, partialSK dynamo.SK, v any)) *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(dynamo.SK), args[3].(interface{})) + run(args[0].(context.Context), args[1].(string), args[2].(dynamo.SK), args[3].(any)) }) return _c } @@ -66,13 +127,169 @@ func (_c *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call) Return(_a0 error) *mo return _c } -func (_c *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call) RunAndReturn(run func(context.Context, string, dynamo.SK, interface{}) error) *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call { +func (_c *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call) RunAndReturn(run func(context.Context, string, dynamo.SK, any) error) *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call { + _c.Call.Return(run) + return _c +} + +// AllByPartialSK provides a mock function with given fields: ctx, pk, partialSK, v +func (_m *mockDynamodbClient) AllByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v any) error { + ret := _m.Called(ctx, pk, partialSK, v) + + if len(ret) == 0 { + panic("no return value specified for AllByPartialSK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, any) error); ok { + r0 = rf(ctx, pk, partialSK, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamodbClient_AllByPartialSK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllByPartialSK' +type mockDynamodbClient_AllByPartialSK_Call struct { + *mock.Call +} + +// AllByPartialSK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - partialSK dynamo.SK +// - v any +func (_e *mockDynamodbClient_Expecter) AllByPartialSK(ctx interface{}, pk interface{}, partialSK interface{}, v interface{}) *mockDynamodbClient_AllByPartialSK_Call { + return &mockDynamodbClient_AllByPartialSK_Call{Call: _e.mock.On("AllByPartialSK", ctx, pk, partialSK, v)} +} + +func (_c *mockDynamodbClient_AllByPartialSK_Call) Run(run func(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v any)) *mockDynamodbClient_AllByPartialSK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(any)) + }) + return _c +} + +func (_c *mockDynamodbClient_AllByPartialSK_Call) Return(_a0 error) *mockDynamodbClient_AllByPartialSK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamodbClient_AllByPartialSK_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, any) error) *mockDynamodbClient_AllByPartialSK_Call { + _c.Call.Return(run) + return _c +} + +// AllBySK provides a mock function with given fields: ctx, sk, v +func (_m *mockDynamodbClient) AllBySK(ctx context.Context, sk dynamo.SK, v any) error { + ret := _m.Called(ctx, sk, v) + + if len(ret) == 0 { + panic("no return value specified for AllBySK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.SK, any) error); ok { + r0 = rf(ctx, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamodbClient_AllBySK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllBySK' +type mockDynamodbClient_AllBySK_Call struct { + *mock.Call +} + +// AllBySK is a helper method to define mock.On call +// - ctx context.Context +// - sk dynamo.SK +// - v any +func (_e *mockDynamodbClient_Expecter) AllBySK(ctx interface{}, sk interface{}, v interface{}) *mockDynamodbClient_AllBySK_Call { + return &mockDynamodbClient_AllBySK_Call{Call: _e.mock.On("AllBySK", ctx, sk, v)} +} + +func (_c *mockDynamodbClient_AllBySK_Call) Run(run func(ctx context.Context, sk dynamo.SK, v any)) *mockDynamodbClient_AllBySK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(any)) + }) + return _c +} + +func (_c *mockDynamodbClient_AllBySK_Call) Return(_a0 error) *mockDynamodbClient_AllBySK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamodbClient_AllBySK_Call) RunAndReturn(run func(context.Context, dynamo.SK, any) error) *mockDynamodbClient_AllBySK_Call { + _c.Call.Return(run) + return _c +} + +// AllKeysByPK provides a mock function with given fields: ctx, pk +func (_m *mockDynamodbClient) AllKeysByPK(ctx context.Context, pk dynamo.PK) ([]dynamo.Keys, error) { + ret := _m.Called(ctx, pk) + + if len(ret) == 0 { + panic("no return value specified for AllKeysByPK") + } + + var r0 []dynamo.Keys + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK) ([]dynamo.Keys, error)); ok { + return rf(ctx, pk) + } + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK) []dynamo.Keys); ok { + r0 = rf(ctx, pk) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]dynamo.Keys) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, dynamo.PK) error); ok { + r1 = rf(ctx, pk) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockDynamodbClient_AllKeysByPK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllKeysByPK' +type mockDynamodbClient_AllKeysByPK_Call struct { + *mock.Call +} + +// AllKeysByPK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +func (_e *mockDynamodbClient_Expecter) AllKeysByPK(ctx interface{}, pk interface{}) *mockDynamodbClient_AllKeysByPK_Call { + return &mockDynamodbClient_AllKeysByPK_Call{Call: _e.mock.On("AllKeysByPK", ctx, pk)} +} + +func (_c *mockDynamodbClient_AllKeysByPK_Call) Run(run func(ctx context.Context, pk dynamo.PK)) *mockDynamodbClient_AllKeysByPK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK)) + }) + return _c +} + +func (_c *mockDynamodbClient_AllKeysByPK_Call) Return(_a0 []dynamo.Keys, _a1 error) *mockDynamodbClient_AllKeysByPK_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockDynamodbClient_AllKeysByPK_Call) RunAndReturn(run func(context.Context, dynamo.PK) ([]dynamo.Keys, error)) *mockDynamodbClient_AllKeysByPK_Call { _c.Call.Return(run) return _c } // AnyByPK provides a mock function with given fields: ctx, pk, v -func (_m *mockDynamodbClient) AnyByPK(ctx context.Context, pk dynamo.PK, v interface{}) error { +func (_m *mockDynamodbClient) AnyByPK(ctx context.Context, pk dynamo.PK, v any) error { ret := _m.Called(ctx, pk, v) if len(ret) == 0 { @@ -80,7 +297,7 @@ func (_m *mockDynamodbClient) AnyByPK(ctx context.Context, pk dynamo.PK, v inter } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, interface{}) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, any) error); ok { r0 = rf(ctx, pk, v) } else { r0 = ret.Error(0) @@ -97,14 +314,14 @@ type mockDynamodbClient_AnyByPK_Call struct { // AnyByPK is a helper method to define mock.On call // - ctx context.Context // - pk dynamo.PK -// - v interface{} +// - v any func (_e *mockDynamodbClient_Expecter) AnyByPK(ctx interface{}, pk interface{}, v interface{}) *mockDynamodbClient_AnyByPK_Call { return &mockDynamodbClient_AnyByPK_Call{Call: _e.mock.On("AnyByPK", ctx, pk, v)} } -func (_c *mockDynamodbClient_AnyByPK_Call) Run(run func(ctx context.Context, pk dynamo.PK, v interface{})) *mockDynamodbClient_AnyByPK_Call { +func (_c *mockDynamodbClient_AnyByPK_Call) Run(run func(ctx context.Context, pk dynamo.PK, v any)) *mockDynamodbClient_AnyByPK_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(interface{})) + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(any)) }) return _c } @@ -114,13 +331,60 @@ func (_c *mockDynamodbClient_AnyByPK_Call) Return(_a0 error) *mockDynamodbClient return _c } -func (_c *mockDynamodbClient_AnyByPK_Call) RunAndReturn(run func(context.Context, dynamo.PK, interface{}) error) *mockDynamodbClient_AnyByPK_Call { +func (_c *mockDynamodbClient_AnyByPK_Call) RunAndReturn(run func(context.Context, dynamo.PK, any) error) *mockDynamodbClient_AnyByPK_Call { + _c.Call.Return(run) + return _c +} + +// BatchPut provides a mock function with given fields: ctx, items +func (_m *mockDynamodbClient) BatchPut(ctx context.Context, items []any) error { + ret := _m.Called(ctx, items) + + if len(ret) == 0 { + panic("no return value specified for BatchPut") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []any) error); ok { + r0 = rf(ctx, items) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamodbClient_BatchPut_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BatchPut' +type mockDynamodbClient_BatchPut_Call struct { + *mock.Call +} + +// BatchPut is a helper method to define mock.On call +// - ctx context.Context +// - items []any +func (_e *mockDynamodbClient_Expecter) BatchPut(ctx interface{}, items interface{}) *mockDynamodbClient_BatchPut_Call { + return &mockDynamodbClient_BatchPut_Call{Call: _e.mock.On("BatchPut", ctx, items)} +} + +func (_c *mockDynamodbClient_BatchPut_Call) Run(run func(ctx context.Context, items []any)) *mockDynamodbClient_BatchPut_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]any)) + }) + return _c +} + +func (_c *mockDynamodbClient_BatchPut_Call) Return(_a0 error) *mockDynamodbClient_BatchPut_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamodbClient_BatchPut_Call) RunAndReturn(run func(context.Context, []any) error) *mockDynamodbClient_BatchPut_Call { _c.Call.Return(run) return _c } // Create provides a mock function with given fields: ctx, v -func (_m *mockDynamodbClient) Create(ctx context.Context, v interface{}) error { +func (_m *mockDynamodbClient) Create(ctx context.Context, v any) error { ret := _m.Called(ctx, v) if len(ret) == 0 { @@ -128,7 +392,7 @@ func (_m *mockDynamodbClient) Create(ctx context.Context, v interface{}) error { } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, interface{}) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, any) error); ok { r0 = rf(ctx, v) } else { r0 = ret.Error(0) @@ -144,14 +408,14 @@ type mockDynamodbClient_Create_Call struct { // Create is a helper method to define mock.On call // - ctx context.Context -// - v interface{} +// - v any func (_e *mockDynamodbClient_Expecter) Create(ctx interface{}, v interface{}) *mockDynamodbClient_Create_Call { return &mockDynamodbClient_Create_Call{Call: _e.mock.On("Create", ctx, v)} } -func (_c *mockDynamodbClient_Create_Call) Run(run func(ctx context.Context, v interface{})) *mockDynamodbClient_Create_Call { +func (_c *mockDynamodbClient_Create_Call) Run(run func(ctx context.Context, v any)) *mockDynamodbClient_Create_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(interface{})) + run(args[0].(context.Context), args[1].(any)) }) return _c } @@ -161,13 +425,13 @@ func (_c *mockDynamodbClient_Create_Call) Return(_a0 error) *mockDynamodbClient_ return _c } -func (_c *mockDynamodbClient_Create_Call) RunAndReturn(run func(context.Context, interface{}) error) *mockDynamodbClient_Create_Call { +func (_c *mockDynamodbClient_Create_Call) RunAndReturn(run func(context.Context, any) error) *mockDynamodbClient_Create_Call { _c.Call.Return(run) return _c } // CreateOnly provides a mock function with given fields: ctx, v -func (_m *mockDynamodbClient) CreateOnly(ctx context.Context, v interface{}) error { +func (_m *mockDynamodbClient) CreateOnly(ctx context.Context, v any) error { ret := _m.Called(ctx, v) if len(ret) == 0 { @@ -175,7 +439,7 @@ func (_m *mockDynamodbClient) CreateOnly(ctx context.Context, v interface{}) err } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, interface{}) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, any) error); ok { r0 = rf(ctx, v) } else { r0 = ret.Error(0) @@ -191,14 +455,14 @@ type mockDynamodbClient_CreateOnly_Call struct { // CreateOnly is a helper method to define mock.On call // - ctx context.Context -// - v interface{} +// - v any func (_e *mockDynamodbClient_Expecter) CreateOnly(ctx interface{}, v interface{}) *mockDynamodbClient_CreateOnly_Call { return &mockDynamodbClient_CreateOnly_Call{Call: _e.mock.On("CreateOnly", ctx, v)} } -func (_c *mockDynamodbClient_CreateOnly_Call) Run(run func(ctx context.Context, v interface{})) *mockDynamodbClient_CreateOnly_Call { +func (_c *mockDynamodbClient_CreateOnly_Call) Run(run func(ctx context.Context, v any)) *mockDynamodbClient_CreateOnly_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(interface{})) + run(args[0].(context.Context), args[1].(any)) }) return _c } @@ -208,7 +472,7 @@ func (_c *mockDynamodbClient_CreateOnly_Call) Return(_a0 error) *mockDynamodbCli return _c } -func (_c *mockDynamodbClient_CreateOnly_Call) RunAndReturn(run func(context.Context, interface{}) error) *mockDynamodbClient_CreateOnly_Call { +func (_c *mockDynamodbClient_CreateOnly_Call) RunAndReturn(run func(context.Context, any) error) *mockDynamodbClient_CreateOnly_Call { _c.Call.Return(run) return _c } @@ -308,6 +572,54 @@ func (_c *mockDynamodbClient_DeleteOne_Call) RunAndReturn(run func(context.Conte return _c } +// LatestForActor provides a mock function with given fields: ctx, sk, v +func (_m *mockDynamodbClient) LatestForActor(ctx context.Context, sk dynamo.SK, v any) error { + ret := _m.Called(ctx, sk, v) + + if len(ret) == 0 { + panic("no return value specified for LatestForActor") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.SK, any) error); ok { + r0 = rf(ctx, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamodbClient_LatestForActor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LatestForActor' +type mockDynamodbClient_LatestForActor_Call struct { + *mock.Call +} + +// LatestForActor is a helper method to define mock.On call +// - ctx context.Context +// - sk dynamo.SK +// - v any +func (_e *mockDynamodbClient_Expecter) LatestForActor(ctx interface{}, sk interface{}, v interface{}) *mockDynamodbClient_LatestForActor_Call { + return &mockDynamodbClient_LatestForActor_Call{Call: _e.mock.On("LatestForActor", ctx, sk, v)} +} + +func (_c *mockDynamodbClient_LatestForActor_Call) Run(run func(ctx context.Context, sk dynamo.SK, v any)) *mockDynamodbClient_LatestForActor_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(any)) + }) + return _c +} + +func (_c *mockDynamodbClient_LatestForActor_Call) Return(_a0 error) *mockDynamodbClient_LatestForActor_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamodbClient_LatestForActor_Call) RunAndReturn(run func(context.Context, dynamo.SK, any) error) *mockDynamodbClient_LatestForActor_Call { + _c.Call.Return(run) + return _c +} + // Move provides a mock function with given fields: ctx, oldKeys, value func (_m *mockDynamodbClient) Move(ctx context.Context, oldKeys dynamo.Keys, value any) error { ret := _m.Called(ctx, oldKeys, value) @@ -357,7 +669,7 @@ func (_c *mockDynamodbClient_Move_Call) RunAndReturn(run func(context.Context, d } // One provides a mock function with given fields: ctx, pk, sk, v -func (_m *mockDynamodbClient) One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error { +func (_m *mockDynamodbClient) One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v any) error { ret := _m.Called(ctx, pk, sk, v) if len(ret) == 0 { @@ -365,7 +677,7 @@ func (_m *mockDynamodbClient) One(ctx context.Context, pk dynamo.PK, sk dynamo.S } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, interface{}) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, any) error); ok { r0 = rf(ctx, pk, sk, v) } else { r0 = ret.Error(0) @@ -383,14 +695,14 @@ type mockDynamodbClient_One_Call struct { // - ctx context.Context // - pk dynamo.PK // - sk dynamo.SK -// - v interface{} +// - v any func (_e *mockDynamodbClient_Expecter) One(ctx interface{}, pk interface{}, sk interface{}, v interface{}) *mockDynamodbClient_One_Call { return &mockDynamodbClient_One_Call{Call: _e.mock.On("One", ctx, pk, sk, v)} } -func (_c *mockDynamodbClient_One_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{})) *mockDynamodbClient_One_Call { +func (_c *mockDynamodbClient_One_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v any)) *mockDynamodbClient_One_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(interface{})) + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(any)) }) return _c } @@ -400,13 +712,13 @@ func (_c *mockDynamodbClient_One_Call) Return(_a0 error) *mockDynamodbClient_One return _c } -func (_c *mockDynamodbClient_One_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, interface{}) error) *mockDynamodbClient_One_Call { +func (_c *mockDynamodbClient_One_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, any) error) *mockDynamodbClient_One_Call { _c.Call.Return(run) return _c } // OneByPK provides a mock function with given fields: ctx, pk, v -func (_m *mockDynamodbClient) OneByPK(ctx context.Context, pk dynamo.PK, v interface{}) error { +func (_m *mockDynamodbClient) OneByPK(ctx context.Context, pk dynamo.PK, v any) error { ret := _m.Called(ctx, pk, v) if len(ret) == 0 { @@ -414,7 +726,7 @@ func (_m *mockDynamodbClient) OneByPK(ctx context.Context, pk dynamo.PK, v inter } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, interface{}) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, any) error); ok { r0 = rf(ctx, pk, v) } else { r0 = ret.Error(0) @@ -431,14 +743,14 @@ type mockDynamodbClient_OneByPK_Call struct { // OneByPK is a helper method to define mock.On call // - ctx context.Context // - pk dynamo.PK -// - v interface{} +// - v any func (_e *mockDynamodbClient_Expecter) OneByPK(ctx interface{}, pk interface{}, v interface{}) *mockDynamodbClient_OneByPK_Call { return &mockDynamodbClient_OneByPK_Call{Call: _e.mock.On("OneByPK", ctx, pk, v)} } -func (_c *mockDynamodbClient_OneByPK_Call) Run(run func(ctx context.Context, pk dynamo.PK, v interface{})) *mockDynamodbClient_OneByPK_Call { +func (_c *mockDynamodbClient_OneByPK_Call) Run(run func(ctx context.Context, pk dynamo.PK, v any)) *mockDynamodbClient_OneByPK_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(interface{})) + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(any)) }) return _c } @@ -448,13 +760,62 @@ func (_c *mockDynamodbClient_OneByPK_Call) Return(_a0 error) *mockDynamodbClient return _c } -func (_c *mockDynamodbClient_OneByPK_Call) RunAndReturn(run func(context.Context, dynamo.PK, interface{}) error) *mockDynamodbClient_OneByPK_Call { +func (_c *mockDynamodbClient_OneByPK_Call) RunAndReturn(run func(context.Context, dynamo.PK, any) error) *mockDynamodbClient_OneByPK_Call { + _c.Call.Return(run) + return _c +} + +// OneByPartialSK provides a mock function with given fields: ctx, pk, partialSK, v +func (_m *mockDynamodbClient) OneByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v any) error { + ret := _m.Called(ctx, pk, partialSK, v) + + if len(ret) == 0 { + panic("no return value specified for OneByPartialSK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, any) error); ok { + r0 = rf(ctx, pk, partialSK, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamodbClient_OneByPartialSK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneByPartialSK' +type mockDynamodbClient_OneByPartialSK_Call struct { + *mock.Call +} + +// OneByPartialSK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - partialSK dynamo.SK +// - v any +func (_e *mockDynamodbClient_Expecter) OneByPartialSK(ctx interface{}, pk interface{}, partialSK interface{}, v interface{}) *mockDynamodbClient_OneByPartialSK_Call { + return &mockDynamodbClient_OneByPartialSK_Call{Call: _e.mock.On("OneByPartialSK", ctx, pk, partialSK, v)} +} + +func (_c *mockDynamodbClient_OneByPartialSK_Call) Run(run func(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v any)) *mockDynamodbClient_OneByPartialSK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(any)) + }) + return _c +} + +func (_c *mockDynamodbClient_OneByPartialSK_Call) Return(_a0 error) *mockDynamodbClient_OneByPartialSK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamodbClient_OneByPartialSK_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, any) error) *mockDynamodbClient_OneByPartialSK_Call { _c.Call.Return(run) return _c } // OneBySK provides a mock function with given fields: ctx, sk, v -func (_m *mockDynamodbClient) OneBySK(ctx context.Context, sk dynamo.SK, v interface{}) error { +func (_m *mockDynamodbClient) OneBySK(ctx context.Context, sk dynamo.SK, v any) error { ret := _m.Called(ctx, sk, v) if len(ret) == 0 { @@ -462,7 +823,7 @@ func (_m *mockDynamodbClient) OneBySK(ctx context.Context, sk dynamo.SK, v inter } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, dynamo.SK, interface{}) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, dynamo.SK, any) error); ok { r0 = rf(ctx, sk, v) } else { r0 = ret.Error(0) @@ -479,14 +840,14 @@ type mockDynamodbClient_OneBySK_Call struct { // OneBySK is a helper method to define mock.On call // - ctx context.Context // - sk dynamo.SK -// - v interface{} +// - v any func (_e *mockDynamodbClient_Expecter) OneBySK(ctx interface{}, sk interface{}, v interface{}) *mockDynamodbClient_OneBySK_Call { return &mockDynamodbClient_OneBySK_Call{Call: _e.mock.On("OneBySK", ctx, sk, v)} } -func (_c *mockDynamodbClient_OneBySK_Call) Run(run func(ctx context.Context, sk dynamo.SK, v interface{})) *mockDynamodbClient_OneBySK_Call { +func (_c *mockDynamodbClient_OneBySK_Call) Run(run func(ctx context.Context, sk dynamo.SK, v any)) *mockDynamodbClient_OneBySK_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(interface{})) + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(any)) }) return _c } @@ -496,13 +857,13 @@ func (_c *mockDynamodbClient_OneBySK_Call) Return(_a0 error) *mockDynamodbClient return _c } -func (_c *mockDynamodbClient_OneBySK_Call) RunAndReturn(run func(context.Context, dynamo.SK, interface{}) error) *mockDynamodbClient_OneBySK_Call { +func (_c *mockDynamodbClient_OneBySK_Call) RunAndReturn(run func(context.Context, dynamo.SK, any) error) *mockDynamodbClient_OneBySK_Call { _c.Call.Return(run) return _c } // OneByUID provides a mock function with given fields: ctx, uid, v -func (_m *mockDynamodbClient) OneByUID(ctx context.Context, uid string, v interface{}) error { +func (_m *mockDynamodbClient) OneByUID(ctx context.Context, uid string, v any) error { ret := _m.Called(ctx, uid, v) if len(ret) == 0 { @@ -510,7 +871,7 @@ func (_m *mockDynamodbClient) OneByUID(ctx context.Context, uid string, v interf } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, interface{}) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, any) error); ok { r0 = rf(ctx, uid, v) } else { r0 = ret.Error(0) @@ -527,14 +888,14 @@ type mockDynamodbClient_OneByUID_Call struct { // OneByUID is a helper method to define mock.On call // - ctx context.Context // - uid string -// - v interface{} +// - v any func (_e *mockDynamodbClient_Expecter) OneByUID(ctx interface{}, uid interface{}, v interface{}) *mockDynamodbClient_OneByUID_Call { return &mockDynamodbClient_OneByUID_Call{Call: _e.mock.On("OneByUID", ctx, uid, v)} } -func (_c *mockDynamodbClient_OneByUID_Call) Run(run func(ctx context.Context, uid string, v interface{})) *mockDynamodbClient_OneByUID_Call { +func (_c *mockDynamodbClient_OneByUID_Call) Run(run func(ctx context.Context, uid string, v any)) *mockDynamodbClient_OneByUID_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(interface{})) + run(args[0].(context.Context), args[1].(string), args[2].(any)) }) return _c } @@ -544,13 +905,13 @@ func (_c *mockDynamodbClient_OneByUID_Call) Return(_a0 error) *mockDynamodbClien return _c } -func (_c *mockDynamodbClient_OneByUID_Call) RunAndReturn(run func(context.Context, string, interface{}) error) *mockDynamodbClient_OneByUID_Call { +func (_c *mockDynamodbClient_OneByUID_Call) RunAndReturn(run func(context.Context, string, any) error) *mockDynamodbClient_OneByUID_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: ctx, v -func (_m *mockDynamodbClient) Put(ctx context.Context, v interface{}) error { +func (_m *mockDynamodbClient) Put(ctx context.Context, v any) error { ret := _m.Called(ctx, v) if len(ret) == 0 { @@ -558,7 +919,7 @@ func (_m *mockDynamodbClient) Put(ctx context.Context, v interface{}) error { } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, interface{}) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, any) error); ok { r0 = rf(ctx, v) } else { r0 = ret.Error(0) @@ -574,14 +935,14 @@ type mockDynamodbClient_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - v interface{} +// - v any func (_e *mockDynamodbClient_Expecter) Put(ctx interface{}, v interface{}) *mockDynamodbClient_Put_Call { return &mockDynamodbClient_Put_Call{Call: _e.mock.On("Put", ctx, v)} } -func (_c *mockDynamodbClient_Put_Call) Run(run func(ctx context.Context, v interface{})) *mockDynamodbClient_Put_Call { +func (_c *mockDynamodbClient_Put_Call) Run(run func(ctx context.Context, v any)) *mockDynamodbClient_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(interface{})) + run(args[0].(context.Context), args[1].(any)) }) return _c } @@ -591,7 +952,57 @@ func (_c *mockDynamodbClient_Put_Call) Return(_a0 error) *mockDynamodbClient_Put return _c } -func (_c *mockDynamodbClient_Put_Call) RunAndReturn(run func(context.Context, interface{}) error) *mockDynamodbClient_Put_Call { +func (_c *mockDynamodbClient_Put_Call) RunAndReturn(run func(context.Context, any) error) *mockDynamodbClient_Put_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, pk, sk, values, expression +func (_m *mockDynamodbClient) Update(ctx context.Context, pk dynamo.PK, sk dynamo.SK, values map[string]types.AttributeValue, expression string) error { + ret := _m.Called(ctx, pk, sk, values, expression) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, map[string]types.AttributeValue, string) error); ok { + r0 = rf(ctx, pk, sk, values, expression) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamodbClient_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type mockDynamodbClient_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - sk dynamo.SK +// - values map[string]types.AttributeValue +// - expression string +func (_e *mockDynamodbClient_Expecter) Update(ctx interface{}, pk interface{}, sk interface{}, values interface{}, expression interface{}) *mockDynamodbClient_Update_Call { + return &mockDynamodbClient_Update_Call{Call: _e.mock.On("Update", ctx, pk, sk, values, expression)} +} + +func (_c *mockDynamodbClient_Update_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, values map[string]types.AttributeValue, expression string)) *mockDynamodbClient_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(map[string]types.AttributeValue), args[4].(string)) + }) + return _c +} + +func (_c *mockDynamodbClient_Update_Call) Return(_a0 error) *mockDynamodbClient_Update_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamodbClient_Update_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, map[string]types.AttributeValue, string) error) *mockDynamodbClient_Update_Call { _c.Call.Return(run) return _c } diff --git a/cmd/event-received/sirius_event_handler.go b/cmd/event-received/sirius_event_handler.go index 844216612b..10b4963ba5 100644 --- a/cmd/event-received/sirius_event_handler.go +++ b/cmd/event-received/sirius_event_handler.go @@ -8,9 +8,12 @@ import ( "github.com/aws/aws-lambda-go/events" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + "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/event" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" + "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -208,6 +211,9 @@ func handleDonorSubmissionCompleted(ctx context.Context, client dynamodbClient, return err } + // There is no certificate provider record yet, so assume English + to := notify.ToLpaCertificateProvider(&certificateproviderdata.Provided{ContactLanguagePreference: localize.En}, lpa) + if err := shareCodeSender.SendCertificateProviderInvite(ctx, appData, sharecode.CertificateProviderInvite{ LpaKey: lpa.LpaKey, LpaOwnerKey: lpa.LpaOwnerKey, @@ -217,8 +223,7 @@ func handleDonorSubmissionCompleted(ctx context.Context, client dynamodbClient, DonorFullName: lpa.Donor.FullName(), CertificateProviderUID: lpa.CertificateProvider.UID, CertificateProviderFullName: lpa.CertificateProvider.FullName(), - CertificateProviderEmail: lpa.CertificateProvider.Email, - }); err != nil { + }, to); err != nil { return fmt.Errorf("failed to send share code to certificate provider: %w", err) } diff --git a/cmd/event-received/sirius_event_handler_test.go b/cmd/event-received/sirius_event_handler_test.go index 4cf39bd3f8..c4c49407d4 100644 --- a/cmd/event-received/sirius_event_handler_test.go +++ b/cmd/event-received/sirius_event_handler_test.go @@ -11,10 +11,13 @@ import ( "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + "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/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" "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -744,8 +747,7 @@ func TestHandleDonorSubmissionCompleted(t *testing.T) { DonorFullName: "Dave Smith", CertificateProviderUID: uid, CertificateProviderFullName: "John Smith", - CertificateProviderEmail: "john@example.com", - }). + }, notify.ToLpaCertificateProvider(&certificateproviderdata.Provided{ContactLanguagePreference: localize.En}, lpa)). Return(nil) client := newMockDynamodbClient(t) @@ -801,7 +803,7 @@ func TestHandleDonorSubmissionCompletedWhenWriteTransactionError(t *testing.T) { shareCodeSender := newMockShareCodeSender(t) shareCodeSender.EXPECT(). - SendCertificateProviderInvite(mock.Anything, mock.Anything, mock.Anything). + SendCertificateProviderInvite(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) client := newMockDynamodbClient(t) @@ -847,7 +849,7 @@ func TestHandleDonorSubmissionCompletedWhenShareCodeSenderError(t *testing.T) { shareCodeSender := newMockShareCodeSender(t) shareCodeSender.EXPECT(). - SendCertificateProviderInvite(ctx, mock.Anything, mock.Anything). + SendCertificateProviderInvite(ctx, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) err := handleDonorSubmissionCompleted(ctx, nil, donorSubmissionCompletedEvent, shareCodeSender, appData, lpaStoreClient, testUuidStringFn, testNowFn) diff --git a/internal/app/app.go b/internal/app/app.go index 25acfe8c77..f2788c65f1 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -115,7 +115,7 @@ func App( scheduledStore := scheduled.NewStore(lpaDynamoClient) progressTracker := task.ProgressTracker{Localizer: localizer} - shareCodeSender := sharecode.NewSender(shareCodeStore, notifyClient, appPublicURL, random.String, eventClient) + shareCodeSender := sharecode.NewSender(shareCodeStore, notifyClient, appPublicURL, random.String, eventClient, certificateProviderStore) 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 4eb36fde59..dba961df38 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.Donor.ContactLanguagePreference, lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { + if err := notifyClient.SendActorEmail(r.Context(), notify.ToLpaDonor(lpa), 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 d52f4eb9e4..8496a258d5 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.Donor.ContactLanguagePreference, lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { + if err := notifyClient.SendActorEmail(ctx, notify.ToLpaDonor(lpa), 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 54116dc43b..bb0e55acea 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 @@ -204,7 +204,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) { EmailGreeting(lpa). Return("Dear donor") notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "a@example.com", "lpa-uid", notify.AttorneyOptedOutEmail{ + SendActorEmail(ctx, notify.ToLpaDonor(lpa), "lpa-uid", notify.AttorneyOptedOutEmail{ Greeting: "Dear donor", AttorneyFullName: tc.attorneyFullName, DonorFullName: "a b c", @@ -359,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, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) return client @@ -397,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, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) return client @@ -445,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, mock.Anything). + SendActorEmail(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 50ca7c4cb4..e34db95ffe 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 @@ -85,25 +85,27 @@ func TestGetConfirmDontWantToBeAttorneyWhenTemplateErrors(t *testing.T) { func TestPostConfirmDontWantToBeAttorney(t *testing.T) { r, _ := http.NewRequestWithContext(appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) w := httptest.NewRecorder() + uid := actoruid.New() + lpa := &lpadata.Lpa{ + LpaUID: "lpa-uid", + SignedAt: time.Now(), + Donor: lpadata.Donor{ + FirstNames: "a b", LastName: "c", Email: "a@example.com", + ContactLanguagePreference: localize.En, + }, + Attorneys: lpadata.Attorneys{ + Attorneys: []lpadata.Attorney{ + {FirstNames: "d e", LastName: "f", UID: uid}, + }, + }, + Type: lpadata.LpaTypePersonalWelfare, + } lpaStoreResolvingService := newMockLpaStoreResolvingService(t) lpaStoreResolvingService.EXPECT(). Get(r.Context()). - Return(&lpadata.Lpa{ - LpaUID: "lpa-uid", - SignedAt: time.Now(), - Donor: lpadata.Donor{ - FirstNames: "a b", LastName: "c", Email: "a@example.com", - ContactLanguagePreference: localize.En, - }, - Attorneys: lpadata.Attorneys{ - Attorneys: []lpadata.Attorney{ - {FirstNames: "d e", LastName: "f", UID: uid}, - }, - }, - Type: lpadata.LpaTypePersonalWelfare, - }, nil) + Return(lpa, nil) certificateProviderStore := newMockAttorneyStore(t) certificateProviderStore.EXPECT(). @@ -122,7 +124,7 @@ func TestPostConfirmDontWantToBeAttorney(t *testing.T) { EmailGreeting(mock.Anything). Return("Dear donor") notifyClient.EXPECT(). - SendActorEmail(r.Context(), localize.En, "a@example.com", "lpa-uid", notify.AttorneyOptedOutEmail{ + SendActorEmail(r.Context(), notify.ToLpaDonor(lpa), "lpa-uid", notify.AttorneyOptedOutEmail{ Greeting: "Dear donor", AttorneyFullName: "d e f", DonorFullName: "a b c", @@ -186,7 +188,7 @@ func TestPostConfirmDontWantToBeAttorneyErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) return client @@ -206,7 +208,7 @@ func TestPostConfirmDontWantToBeAttorneyErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) return client @@ -234,7 +236,7 @@ func TestPostConfirmDontWantToBeAttorneyErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(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 b433f9071a..0f5d9c6889 100644 --- a/internal/attorney/attorneypage/mock_NotifyClient_test.go +++ b/internal/attorney/attorneypage/mock_NotifyClient_test.go @@ -5,9 +5,7 @@ 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" @@ -72,17 +70,17 @@ func (_c *mockNotifyClient_EmailGreeting_Call) RunAndReturn(run func(*lpadata.Lp return _c } -// 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) +// SendActorEmail provides a mock function with given fields: ctx, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email) error { + ret := _m.Called(ctx, 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, localize.Lang, string, string, notify.Email) error); ok { - r0 = rf(ctx, lang, to, lpaUID, email) + if rf, ok := ret.Get(0).(func(context.Context, notify.ToEmail, string, notify.Email) error); ok { + r0 = rf(ctx, to, lpaUID, email) } else { r0 = ret.Error(0) } @@ -97,17 +95,16 @@ type mockNotifyClient_SendActorEmail_Call struct { // SendActorEmail is a helper method to define mock.On call // - ctx context.Context -// - lang localize.Lang -// - to string +// - to notify.ToEmail // - lpaUID string // - email notify.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 (_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 (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.Email)) + run(args[0].(context.Context), args[1].(notify.ToEmail), args[2].(string), args[3].(notify.Email)) }) return _c } @@ -117,7 +114,7 @@ func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyCli return _c } -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, notify.ToEmail, 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 3d99526992..d71377b72a 100644 --- a/internal/attorney/attorneypage/register.go +++ b/internal/attorney/attorneypage/register.go @@ -15,7 +15,6 @@ 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" @@ -88,7 +87,7 @@ type LpaStoreClient interface { type NotifyClient interface { EmailGreeting(lpa *lpadata.Lpa) string - SendActorEmail(ctx context.Context, lang localize.Lang, to, lpaUID string, email notify.Email) error + SendActorEmail(ctx context.Context, to notify.ToEmail, 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 bf4a786416..045a267b61 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 @@ -75,7 +75,7 @@ func ConfirmDontWantToBeCertificateProvider(tmpl template.Template, lpaStoreClie return err } - if err := notifyClient.SendActorEmail(r.Context(), lpa.Donor.ContactLanguagePreference, lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { + if err := notifyClient.SendActorEmail(r.Context(), notify.ToLpaDonor(lpa), 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 500b8a3238..f85855821a 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.Donor.ContactLanguagePreference, lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { + if err := notifyClient.SendActorEmail(ctx, notify.ToLpaDonor(lpa), 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 b7469a7c54..f2295b4a54 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 @@ -26,7 +26,7 @@ func TestGetConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/", nil) - lpa := lpadata.Lpa{LpaUID: "lpa-uid"} + lpa := &lpadata.Lpa{LpaUID: "lpa-uid"} sessionStore := newMockSessionStore(t) sessionStore.EXPECT(). @@ -36,13 +36,13 @@ func TestGetConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { lpaStoreResolvingService := newMockLpaStoreResolvingService(t) lpaStoreResolvingService.EXPECT(). Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"})). - Return(&lpa, nil) + Return(lpa, nil) template := newMockTemplate(t) template.EXPECT(). Execute(w, &confirmDontWantToBeCertificateProviderDataLoggedOut{ App: testAppData, - Lpa: &lpa, + Lpa: lpa, }). Return(nil) @@ -138,13 +138,13 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"}) testcases := map[string]struct { - lpa lpadata.Lpa + lpa *lpadata.Lpa lpaStoreClient func() *mockLpaStoreClient donorStore func() *mockDonorStore email notify.Email }{ "witnessed and signed": { - lpa: lpadata.Lpa{ + lpa: &lpadata.Lpa{ LpaUID: "lpa-uid", SignedAt: time.Now(), WitnessedByCertificateProviderAt: time.Now(), @@ -177,7 +177,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { }, }, "cannot-register": { - lpa: lpadata.Lpa{ + lpa: &lpadata.Lpa{ LpaUID: "lpa-uid", SignedAt: time.Now(), WitnessedByCertificateProviderAt: time.Now(), @@ -201,7 +201,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { }, }, "not witnessed and signed": { - lpa: lpadata.Lpa{ + lpa: &lpadata.Lpa{ LpaUID: "lpa-uid", Donor: lpadata.Donor{ FirstNames: "a b", LastName: "c", Email: "a@example.com", @@ -279,14 +279,14 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { lpaStoreResolvingService := newMockLpaStoreResolvingService(t) lpaStoreResolvingService.EXPECT(). Get(ctx). - Return(&tc.lpa, nil) + Return(tc.lpa, nil) notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - EmailGreeting(&tc.lpa). + EmailGreeting(tc.lpa). Return("Dear donor") notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "a@example.com", "lpa-uid", tc.email). + SendActorEmail(ctx, notify.ToLpaDonor(tc.lpa), "lpa-uid", tc.email). Return(nil) localizer := newMockLocalizer(t) @@ -533,7 +533,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOutErrors(t *testing.T) EmailGreeting(mock.Anything). Return("") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) return client @@ -580,7 +580,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOutErrors(t *testing.T) EmailGreeting(mock.Anything). Return("") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(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 b31a75dcfd..bd9bd13fbc 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 @@ -200,7 +200,7 @@ func TestPostConfirmDontWantToBeCertificateProvider(t *testing.T) { EmailGreeting(mock.Anything). Return("Dear donor") notifyClient.EXPECT(). - SendActorEmail(r.Context(), localize.En, "a@example.com", "lpa-uid", tc.email). + SendActorEmail(r.Context(), notify.ToLpaDonor(tc.lpa), "lpa-uid", tc.email). Return(nil) err := ConfirmDontWantToBeCertificateProvider(nil, tc.lpaStoreClient(), tc.donorStore(), certificateProviderStore, notifyClient, "example.com")(testAppData, w, r, nil, tc.lpa) @@ -391,7 +391,7 @@ func TestPostConfirmDontWantToBeCertificateProviderErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("Dear donor") client.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(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 ca6e301911..4f75e4dabe 100644 --- a/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback.go +++ b/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback.go @@ -89,7 +89,7 @@ func IdentityWithOneLoginCallback(oneLoginClient OneLoginClient, sessionStore Se } if lpa.SignedForDonor() { - if err := notifyClient.SendActorEmail(r.Context(), lpa.Donor.ContactLanguagePreference, lpa.CorrespondentEmail(), lpa.LpaUID, notify.CertificateProviderFailedIdentityCheckEmail{ + if err := notifyClient.SendActorEmail(r.Context(), notify.ToLpaDonor(lpa), 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 d77f8d374c..096aae87b3 100644 --- a/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback_test.go +++ b/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback_test.go @@ -184,6 +184,15 @@ func TestGetIdentityWithOneLoginCallbackWhenIdentityCheckFailed(t *testing.T) { Tasks: certificateproviderdata.Tasks{ConfirmYourIdentity: task.IdentityStateCompleted}, } + lpa := &lpadata.Lpa{ + LpaUID: "lpa-uid", + CertificateProvider: lpadata.CertificateProvider{FirstNames: "a", LastName: "b"}, + Donor: lpadata.Donor{Email: "a@example.com", FirstNames: "c", LastName: "d", ContactLanguagePreference: localize.En}, + Type: lpadata.LpaTypePersonalWelfare, + SignedAt: time.Now(), + WitnessedByCertificateProviderAt: time.Now(), + } + certificateProviderStore := newMockCertificateProviderStore(t) certificateProviderStore.EXPECT(). Put(r.Context(), updatedCertificateProvider). @@ -217,7 +226,7 @@ func TestGetIdentityWithOneLoginCallbackWhenIdentityCheckFailed(t *testing.T) { EmailGreeting(mock.Anything). Return("Dear donor") notifyClient.EXPECT(). - SendActorEmail(r.Context(), localize.En, "a@example.com", "lpa-uid", notify.CertificateProviderFailedIdentityCheckEmail{ + SendActorEmail(r.Context(), notify.ToLpaDonor(lpa), "lpa-uid", notify.CertificateProviderFailedIdentityCheckEmail{ Greeting: "Dear donor", DonorFullName: "c d", CertificateProviderFullName: "a b", @@ -237,14 +246,7 @@ func TestGetIdentityWithOneLoginCallbackWhenIdentityCheckFailed(t *testing.T) { }). Return(nil) - err := IdentityWithOneLoginCallback(oneLoginClient, sessionStore, certificateProviderStore, notifyClient, nil, eventClient, "www.example.com")(testAppData, w, r, &certificateproviderdata.Provided{LpaID: "lpa-id"}, &lpadata.Lpa{ - LpaUID: "lpa-uid", - CertificateProvider: lpadata.CertificateProvider{FirstNames: "a", LastName: "b"}, - Donor: lpadata.Donor{Email: "a@example.com", FirstNames: "c", LastName: "d", ContactLanguagePreference: localize.En}, - Type: lpadata.LpaTypePersonalWelfare, - SignedAt: time.Now(), - WitnessedByCertificateProviderAt: time.Now(), - }) + err := IdentityWithOneLoginCallback(oneLoginClient, sessionStore, certificateProviderStore, notifyClient, nil, eventClient, "www.example.com")(testAppData, w, r, &certificateproviderdata.Provided{LpaID: "lpa-id"}, lpa) resp := w.Result() assert.Nil(t, err) @@ -292,7 +294,7 @@ func TestGetIdentityWithOneLoginCallbackWhenSendingEmailError(t *testing.T) { EmailGreeting(mock.Anything). Return("") notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(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 b80dcf23d9..253604d809 100644 --- a/internal/certificateprovider/certificateproviderpage/mock_NotifyClient_test.go +++ b/internal/certificateprovider/certificateproviderpage/mock_NotifyClient_test.go @@ -5,9 +5,7 @@ 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" @@ -72,17 +70,17 @@ func (_c *mockNotifyClient_EmailGreeting_Call) RunAndReturn(run func(*lpadata.Lp return _c } -// 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) +// SendActorEmail provides a mock function with given fields: ctx, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email) error { + ret := _m.Called(ctx, 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, localize.Lang, string, string, notify.Email) error); ok { - r0 = rf(ctx, lang, to, lpaUID, email) + if rf, ok := ret.Get(0).(func(context.Context, notify.ToEmail, string, notify.Email) error); ok { + r0 = rf(ctx, to, lpaUID, email) } else { r0 = ret.Error(0) } @@ -97,17 +95,16 @@ type mockNotifyClient_SendActorEmail_Call struct { // SendActorEmail is a helper method to define mock.On call // - ctx context.Context -// - lang localize.Lang -// - to string +// - to notify.ToEmail // - lpaUID string // - email notify.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 (_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 (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.Email)) + run(args[0].(context.Context), args[1].(notify.ToEmail), args[2].(string), args[3].(notify.Email)) }) return _c } @@ -117,7 +114,7 @@ func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyCli return _c } -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, notify.ToEmail, 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 2d3db6dcb8..aa429cd0b6 100644 --- a/internal/certificateprovider/certificateproviderpage/provide_certificate.go +++ b/internal/certificateprovider/certificateproviderpage/provide_certificate.go @@ -71,7 +71,7 @@ func ProvideCertificate( certificateProvider.SignedAt = lpa.CertificateProvider.SignedAt } - if err := notifyClient.SendActorEmail(r.Context(), certificateProvider.ContactLanguagePreference, certificateProvider.Email, lpa.LpaUID, notify.CertificateProviderCertificateProvidedEmail{ + if err := notifyClient.SendActorEmail(r.Context(), notify.ToLpaCertificateProvider(certificateProvider, lpa), 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 7d3189ceb3..4abd09cce2 100644 --- a/internal/certificateprovider/certificateproviderpage/provide_certificate_test.go +++ b/internal/certificateprovider/certificateproviderpage/provide_certificate_test.go @@ -130,7 +130,7 @@ func TestPostProvideCertificate(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(r.Context(), localize.En, "a@example.com", "lpa-uid", notify.CertificateProviderCertificateProvidedEmail{ + SendActorEmail(r.Context(), notify.ToLpaCertificateProvider(certificateProvider, lpa), "lpa-uid", notify.CertificateProviderCertificateProvidedEmail{ DonorFullNamePossessive: "the possessive full name", DonorFirstNamesPossessive: "the possessive first names", LpaType: "the translated term", @@ -217,7 +217,7 @@ func TestPostProvideCertificateWhenSignedInLpaStore(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(r.Context(), localize.En, "a@example.com", "lpa-uid", notify.CertificateProviderCertificateProvidedEmail{ + SendActorEmail(r.Context(), notify.ToLpaCertificateProvider(certificateProvider, lpa), "lpa-uid", notify.CertificateProviderCertificateProvidedEmail{ DonorFullNamePossessive: "the possessive full name", DonorFirstNamesPossessive: "the possessive first names", LpaType: "the translated term", @@ -312,7 +312,7 @@ func TestPostProvideCertificateOnStoreError(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything). Return(nil) shareCodeSender := newMockShareCodeSender(t) @@ -389,7 +389,7 @@ func TestPostProvideCertificateOnNotifyClientError(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything). Return(expectedError) testAppData.Localizer = localizer @@ -446,7 +446,7 @@ func TestPostProvideCertificateWhenShareCodeSenderErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(r.Context(), 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 9feea8581f..5c7e97880f 100644 --- a/internal/certificateprovider/certificateproviderpage/register.go +++ b/internal/certificateprovider/certificateproviderpage/register.go @@ -18,7 +18,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/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" @@ -78,7 +77,7 @@ type SessionStore interface { type NotifyClient interface { EmailGreeting(lpa *lpadata.Lpa) string - SendActorEmail(ctx context.Context, lang localize.Lang, to, lpaUID string, email notify.Email) error + SendActorEmail(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email) error } type ShareCodeSender interface { diff --git a/internal/donor/donorpage/are_you_sure_you_no_longer_need_voucher.go b/internal/donor/donorpage/are_you_sure_you_no_longer_need_voucher.go index c1f093be5c..dfdb62c99e 100644 --- a/internal/donor/donorpage/are_you_sure_you_no_longer_need_voucher.go +++ b/internal/donor/donorpage/are_you_sure_you_no_longer_need_voucher.go @@ -10,7 +10,6 @@ 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/form" - "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -39,7 +38,7 @@ func AreYouSureYouNoLongerNeedVoucher(tmpl template.Template, donorStore DonorSt provided.WantVoucher = form.YesNoUnknown nextPage := handleDoNext(doNext, provided).Format(provided.LpaID) - if err := notifyClient.SendActorEmail(r.Context(), localize.En, provided.Voucher.Email, provided.LpaUID, notify.VoucherInformedTheyAreNoLongerNeededToVouchEmail{ + if err := notifyClient.SendActorEmail(r.Context(), notify.ToVoucher(provided.Voucher), provided.LpaUID, notify.VoucherInformedTheyAreNoLongerNeededToVouchEmail{ VoucherFullName: provided.Voucher.FullName(), DonorFullName: provided.Donor.FullName(), }); err != nil { diff --git a/internal/donor/donorpage/are_you_sure_you_no_longer_need_voucher_test.go b/internal/donor/donorpage/are_you_sure_you_no_longer_need_voucher_test.go index 0dcaa88702..a6c17baccc 100644 --- a/internal/donor/donorpage/are_you_sure_you_no_longer_need_voucher_test.go +++ b/internal/donor/donorpage/are_you_sure_you_no_longer_need_voucher_test.go @@ -10,7 +10,6 @@ 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/identity" - "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -111,7 +110,7 @@ func TestPostAreYouSureYouNoLongerNeedVoucher(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(r.Context(), localize.En, "voucher@example.com", "lpa-uid", notify.VoucherInformedTheyAreNoLongerNeededToVouchEmail{ + SendActorEmail(r.Context(), notify.ToVoucher(tc.provided.Voucher), "lpa-uid", notify.VoucherInformedTheyAreNoLongerNeededToVouchEmail{ DonorFullName: "d e", VoucherFullName: "a b", }). @@ -144,7 +143,7 @@ func TestPostAreYouSureYouNoLongerNeedVoucherWhenNotifyErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) err := AreYouSureYouNoLongerNeedVoucher(nil, nil, notifyClient)(testAppData, w, r, &donordata.Provided{}) @@ -162,7 +161,7 @@ func TestPostAreYouSureYouNoLongerNeedVoucherWhenStoreErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) err := AreYouSureYouNoLongerNeedVoucher(nil, donorStore, notifyClient)(testAppData, w, r, &donordata.Provided{}) diff --git a/internal/donor/donorpage/check_your_lpa.go b/internal/donor/donorpage/check_your_lpa.go index 08985e5849..c02d161c73 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, localize.En, provided.CertificateProvider.Mobile, provided.LpaUID, sms) + return n.notifyClient.SendActorSMS(ctx, notify.ToCertificateProvider(provided.CertificateProvider), provided.LpaUID, sms) } func (n *checkYourLpaNotifier) sendOnlineNotification(ctx context.Context, appData appcontext.Data, donor *donordata.Provided, wasCompleted bool) error { @@ -75,8 +75,7 @@ func (n *checkYourLpaNotifier) sendOnlineNotification(ctx context.Context, appDa DonorFullName: donor.Donor.FullName(), CertificateProviderUID: donor.CertificateProvider.UID, CertificateProviderFullName: donor.CertificateProvider.FullName(), - CertificateProviderEmail: donor.CertificateProvider.Email, - }) + }, notify.ToCertificateProvider(donor.CertificateProvider)) } certificateProvider, err := n.certificateProviderStore.GetAny(ctx) @@ -99,7 +98,7 @@ func (n *checkYourLpaNotifier) sendOnlineNotification(ctx context.Context, appDa } } - return n.notifyClient.SendActorSMS(ctx, certificateProvider.ContactLanguagePreference, donor.CertificateProvider.Mobile, donor.LpaUID, sms) + return n.notifyClient.SendActorSMS(ctx, notify.ToProvidedCertificateProvider(certificateProvider, donor.CertificateProvider), 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 146db87b4e..7d99412749 100644 --- a/internal/donor/donorpage/check_your_lpa_test.go +++ b/internal/donor/donorpage/check_your_lpa_test.go @@ -145,8 +145,7 @@ func TestPostCheckYourLpaDigitalCertificateProviderOnFirstCheck(t *testing.T) { SendCertificateProviderInvite(r.Context(), testAppData, sharecode.CertificateProviderInvite{ CertificateProviderUID: provided.CertificateProvider.UID, CertificateProviderFullName: provided.CertificateProvider.FullName(), - CertificateProviderEmail: provided.CertificateProvider.Email, - }). + }, notify.ToCertificateProvider(provided.CertificateProvider)). Return(nil) donorStore := newMockDonorStore(t) @@ -226,9 +225,14 @@ func TestPostCheckYourLpaDigitalCertificateProviderOnSubsequentChecks(t *testing CertificateProvider: donordata.CertificateProvider{CarryOutBy: lpadata.ChannelOnline, Mobile: "07700900000"}, } + certificateProvider := &certificateproviderdata.Provided{ + ContactLanguagePreference: localize.Cy, + Tasks: certificateproviderdata.Tasks{ConfirmYourDetails: tc.certificateProviderDetailsTaskState}, + } + notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(r.Context(), localize.Cy, "07700900000", "lpa-uid", tc.expectedSms). + SendActorSMS(r.Context(), notify.ToProvidedCertificateProvider(certificateProvider, provided.CertificateProvider), "lpa-uid", tc.expectedSms). Return(nil) donorStore := newMockDonorStore(t) @@ -239,10 +243,7 @@ func TestPostCheckYourLpaDigitalCertificateProviderOnSubsequentChecks(t *testing certificateProviderStore := newMockCertificateProviderStore(t) certificateProviderStore.EXPECT(). GetAny(r.Context()). - Return(&certificateproviderdata.Provided{ - ContactLanguagePreference: localize.Cy, - Tasks: certificateproviderdata.Tasks{ConfirmYourDetails: tc.certificateProviderDetailsTaskState}, - }, nil) + Return(certificateProvider, nil) err := CheckYourLpa(nil, donorStore, nil, notifyClient, certificateProviderStore, testNowFn, "http://example.org")(testAppData, w, r, provided) resp := w.Result() @@ -327,7 +328,7 @@ func TestPostCheckYourLpaPaperCertificateProviderOnFirstCheck(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(r.Context(), localize.En, "07700900000", "lpa-uid", notify.CertificateProviderActingOnPaperMeetingPromptSMS{ + SendActorSMS(r.Context(), notify.ToCertificateProvider(provided.CertificateProvider), "lpa-uid", notify.CertificateProviderActingOnPaperMeetingPromptSMS{ DonorFullName: "Teneil Throssell", LpaType: "property and affairs", DonorFirstNames: "Teneil", @@ -372,7 +373,7 @@ func TestPostCheckYourLpaPaperCertificateProviderOnSubsequentCheck(t *testing.T) notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(r.Context(), localize.En, "07700900000", "lpa-uid", notify.CertificateProviderActingOnPaperDetailsChangedSMS{ + SendActorSMS(r.Context(), notify.ToCertificateProvider(provided.CertificateProvider), "lpa-uid", notify.CertificateProviderActingOnPaperDetailsChangedSMS{ DonorFullName: "Teneil Throssell", DonorFirstNames: "Teneil", LpaUID: "lpa-uid", @@ -409,7 +410,7 @@ func TestPostCheckYourLpaWhenStoreErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(r.Context(), mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(r.Context(), mock.Anything, mock.Anything, mock.Anything). Return(nil) donorStore := newMockDonorStore(t) @@ -441,7 +442,7 @@ func TestPostCheckYourLpaWhenShareCodeSenderErrors(t *testing.T) { shareCodeSender := newMockShareCodeSender(t) shareCodeSender.EXPECT(). - SendCertificateProviderInvite(r.Context(), testAppData, mock.Anything). + SendCertificateProviderInvite(r.Context(), testAppData, mock.Anything, mock.Anything). Return(expectedError) err := CheckYourLpa(nil, nil, shareCodeSender, nil, nil, testNowFn, "http://example.org")(testAppData, w, r, donor) @@ -469,7 +470,7 @@ func TestPostCheckYourLpaWhenNotifyClientErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(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 49a24a06a5..e84426bd6b 100644 --- a/internal/donor/donorpage/mock_NotifyClient_test.go +++ b/internal/donor/donorpage/mock_NotifyClient_test.go @@ -5,10 +5,8 @@ package donorpage import ( context "context" - localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" - mock "github.com/stretchr/testify/mock" - 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 @@ -24,17 +22,17 @@ func (_m *mockNotifyClient) EXPECT() *mockNotifyClient_Expecter { return &mockNotifyClient_Expecter{mock: &_m.Mock} } -// 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) +// SendActorEmail provides a mock function with given fields: ctx, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email) error { + ret := _m.Called(ctx, 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, localize.Lang, string, string, notify.Email) error); ok { - r0 = rf(ctx, lang, to, lpaUID, email) + if rf, ok := ret.Get(0).(func(context.Context, notify.ToEmail, string, notify.Email) error); ok { + r0 = rf(ctx, to, lpaUID, email) } else { r0 = ret.Error(0) } @@ -49,17 +47,16 @@ type mockNotifyClient_SendActorEmail_Call struct { // SendActorEmail is a helper method to define mock.On call // - ctx context.Context -// - lang localize.Lang -// - to string +// - to notify.ToEmail // - lpaUID string // - email notify.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 (_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 (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.Email)) + run(args[0].(context.Context), args[1].(notify.ToEmail), args[2].(string), args[3].(notify.Email)) }) return _c } @@ -69,22 +66,22 @@ func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyCli return _c } -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, notify.ToEmail, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { _c.Call.Return(run) return _c } -// 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) +// SendActorSMS provides a mock function with given fields: ctx, to, lpaUID, sms +func (_m *mockNotifyClient) SendActorSMS(ctx context.Context, to notify.ToMobile, lpaUID string, sms notify.SMS) error { + ret := _m.Called(ctx, 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, localize.Lang, string, string, notify.SMS) error); ok { - r0 = rf(ctx, lang, to, lpaUID, sms) + if rf, ok := ret.Get(0).(func(context.Context, notify.ToMobile, string, notify.SMS) error); ok { + r0 = rf(ctx, to, lpaUID, sms) } else { r0 = ret.Error(0) } @@ -99,17 +96,16 @@ type mockNotifyClient_SendActorSMS_Call struct { // SendActorSMS is a helper method to define mock.On call // - ctx context.Context -// - lang localize.Lang -// - to string +// - to notify.ToMobile // - lpaUID string // - sms notify.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 (_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 (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(ctx context.Context, to notify.ToMobile, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.SMS)) + run(args[0].(context.Context), args[1].(notify.ToMobile), args[2].(string), args[3].(notify.SMS)) }) return _c } @@ -119,22 +115,22 @@ func (_c *mockNotifyClient_SendActorSMS_Call) Return(_a0 error) *mockNotifyClien return _c } -func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, notify.ToMobile, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { _c.Call.Return(run) return _c } -// 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) +// SendEmail provides a mock function with given fields: ctx, to, email +func (_m *mockNotifyClient) SendEmail(ctx context.Context, to notify.ToEmail, 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, localize.Lang, string, notify.Email) error); ok { - r0 = rf(ctx, lang, to, email) + if rf, ok := ret.Get(0).(func(context.Context, notify.ToEmail, notify.Email) error); ok { + r0 = rf(ctx, to, email) } else { r0 = ret.Error(0) } @@ -149,16 +145,15 @@ type mockNotifyClient_SendEmail_Call struct { // SendEmail is a helper method to define mock.On call // - ctx context.Context -// - lang localize.Lang -// - to string +// - to notify.ToEmail // - email notify.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 (_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, lang localize.Lang, to string, email notify.Email)) *mockNotifyClient_SendEmail_Call { +func (_c *mockNotifyClient_SendEmail_Call) Run(run func(ctx context.Context, to notify.ToEmail, email notify.Email)) *mockNotifyClient_SendEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(notify.Email)) + run(args[0].(context.Context), args[1].(notify.ToEmail), args[2].(notify.Email)) }) return _c } @@ -168,7 +163,7 @@ func (_c *mockNotifyClient_SendEmail_Call) Return(_a0 error) *mockNotifyClient_S return _c } -func (_c *mockNotifyClient_SendEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, notify.Email) error) *mockNotifyClient_SendEmail_Call { +func (_c *mockNotifyClient_SendEmail_Call) RunAndReturn(run func(context.Context, notify.ToEmail, notify.Email) error) *mockNotifyClient_SendEmail_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/mock_ShareCodeSender_test.go b/internal/donor/donorpage/mock_ShareCodeSender_test.go index 9acb2dec1c..1f489ea6c6 100644 --- a/internal/donor/donorpage/mock_ShareCodeSender_test.go +++ b/internal/donor/donorpage/mock_ShareCodeSender_test.go @@ -11,6 +11,8 @@ import ( mock "github.com/stretchr/testify/mock" + notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) @@ -27,17 +29,17 @@ func (_m *mockShareCodeSender) EXPECT() *mockShareCodeSender_Expecter { return &mockShareCodeSender_Expecter{mock: &_m.Mock} } -// SendCertificateProviderInvite provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockShareCodeSender) SendCertificateProviderInvite(_a0 context.Context, _a1 appcontext.Data, _a2 sharecode.CertificateProviderInvite) error { - ret := _m.Called(_a0, _a1, _a2) +// SendCertificateProviderInvite provides a mock function with given fields: ctx, appData, invite, to +func (_m *mockShareCodeSender) SendCertificateProviderInvite(ctx context.Context, appData appcontext.Data, invite sharecode.CertificateProviderInvite, to notify.ToEmail) error { + ret := _m.Called(ctx, appData, invite, to) if len(ret) == 0 { panic("no return value specified for SendCertificateProviderInvite") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, appcontext.Data, sharecode.CertificateProviderInvite) error); ok { - r0 = rf(_a0, _a1, _a2) + if rf, ok := ret.Get(0).(func(context.Context, appcontext.Data, sharecode.CertificateProviderInvite, notify.ToEmail) error); ok { + r0 = rf(ctx, appData, invite, to) } else { r0 = ret.Error(0) } @@ -51,16 +53,17 @@ type mockShareCodeSender_SendCertificateProviderInvite_Call struct { } // SendCertificateProviderInvite is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 appcontext.Data -// - _a2 sharecode.CertificateProviderInvite -func (_e *mockShareCodeSender_Expecter) SendCertificateProviderInvite(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockShareCodeSender_SendCertificateProviderInvite_Call { - return &mockShareCodeSender_SendCertificateProviderInvite_Call{Call: _e.mock.On("SendCertificateProviderInvite", _a0, _a1, _a2)} +// - ctx context.Context +// - appData appcontext.Data +// - invite sharecode.CertificateProviderInvite +// - to notify.ToEmail +func (_e *mockShareCodeSender_Expecter) SendCertificateProviderInvite(ctx interface{}, appData interface{}, invite interface{}, to interface{}) *mockShareCodeSender_SendCertificateProviderInvite_Call { + return &mockShareCodeSender_SendCertificateProviderInvite_Call{Call: _e.mock.On("SendCertificateProviderInvite", ctx, appData, invite, to)} } -func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) Run(run func(_a0 context.Context, _a1 appcontext.Data, _a2 sharecode.CertificateProviderInvite)) *mockShareCodeSender_SendCertificateProviderInvite_Call { +func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) Run(run func(ctx context.Context, appData appcontext.Data, invite sharecode.CertificateProviderInvite, to notify.ToEmail)) *mockShareCodeSender_SendCertificateProviderInvite_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(appcontext.Data), args[2].(sharecode.CertificateProviderInvite)) + run(args[0].(context.Context), args[1].(appcontext.Data), args[2].(sharecode.CertificateProviderInvite), args[3].(notify.ToEmail)) }) return _c } @@ -70,14 +73,14 @@ func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) Return(_a0 err return _c } -func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) RunAndReturn(run func(context.Context, appcontext.Data, sharecode.CertificateProviderInvite) error) *mockShareCodeSender_SendCertificateProviderInvite_Call { +func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) RunAndReturn(run func(context.Context, appcontext.Data, sharecode.CertificateProviderInvite, notify.ToEmail) error) *mockShareCodeSender_SendCertificateProviderInvite_Call { _c.Call.Return(run) return _c } -// SendCertificateProviderPrompt provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context, _a1 appcontext.Data, _a2 *donordata.Provided) error { - ret := _m.Called(_a0, _a1, _a2) +// SendCertificateProviderPrompt provides a mock function with given fields: ctx, appData, provided +func (_m *mockShareCodeSender) SendCertificateProviderPrompt(ctx context.Context, appData appcontext.Data, provided *donordata.Provided) error { + ret := _m.Called(ctx, appData, provided) if len(ret) == 0 { panic("no return value specified for SendCertificateProviderPrompt") @@ -85,7 +88,7 @@ func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context var r0 error if rf, ok := ret.Get(0).(func(context.Context, appcontext.Data, *donordata.Provided) error); ok { - r0 = rf(_a0, _a1, _a2) + r0 = rf(ctx, appData, provided) } else { r0 = ret.Error(0) } @@ -99,14 +102,14 @@ type mockShareCodeSender_SendCertificateProviderPrompt_Call struct { } // SendCertificateProviderPrompt is a helper method to define mock.On call -// - _a0 context.Context -// - _a1 appcontext.Data -// - _a2 *donordata.Provided -func (_e *mockShareCodeSender_Expecter) SendCertificateProviderPrompt(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockShareCodeSender_SendCertificateProviderPrompt_Call { - return &mockShareCodeSender_SendCertificateProviderPrompt_Call{Call: _e.mock.On("SendCertificateProviderPrompt", _a0, _a1, _a2)} +// - ctx context.Context +// - appData appcontext.Data +// - provided *donordata.Provided +func (_e *mockShareCodeSender_Expecter) SendCertificateProviderPrompt(ctx interface{}, appData interface{}, provided interface{}) *mockShareCodeSender_SendCertificateProviderPrompt_Call { + return &mockShareCodeSender_SendCertificateProviderPrompt_Call{Call: _e.mock.On("SendCertificateProviderPrompt", ctx, appData, provided)} } -func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) Run(run func(_a0 context.Context, _a1 appcontext.Data, _a2 *donordata.Provided)) *mockShareCodeSender_SendCertificateProviderPrompt_Call { +func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) Run(run func(ctx context.Context, appData appcontext.Data, provided *donordata.Provided)) *mockShareCodeSender_SendCertificateProviderPrompt_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(appcontext.Data), args[2].(*donordata.Provided)) }) diff --git a/internal/donor/donorpage/payment_confirmation.go b/internal/donor/donorpage/payment_confirmation.go index ed6f486aaf..8922f3dfc3 100644 --- a/internal/donor/donorpage/payment_confirmation.go +++ b/internal/donor/donorpage/payment_confirmation.go @@ -12,7 +12,6 @@ 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" ) @@ -50,7 +49,7 @@ func PaymentConfirmation(logger Logger, payClient PayClient, donorStore DonorSto } } - if err := notifyClient.SendEmail(r.Context(), localize.En, payment.Email, notify.PaymentConfirmationEmail{ + if err := notifyClient.SendEmail(r.Context(), notify.ToPayee(payment), 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 ffbe62dfb4..1a2e461b64 100644 --- a/internal/donor/donorpage/payment_confirmation_test.go +++ b/internal/donor/donorpage/payment_confirmation_test.go @@ -734,7 +734,7 @@ func TestGetPaymentConfirmationWhenNotifyClientError(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendEmail(mock.Anything, mock.Anything, mock.Anything). Return(expectedError) localizer := newMockLocalizer(t). @@ -985,7 +985,7 @@ func (m *mockLocalizer) withEmailLocalizations() *mockLocalizer { func (m *mockNotifyClient) withEmailPersonalizations(ctx context.Context, amount string) *mockNotifyClient { m.EXPECT(). - SendEmail(ctx, localize.En, "a@example.com", notify.PaymentConfirmationEmail{ + SendEmail(ctx, notify.ToCustomEmail(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 6ef856584d..a036c83d81 100644 --- a/internal/donor/donorpage/register.go +++ b/internal/donor/donorpage/register.go @@ -18,7 +18,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/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" @@ -85,8 +84,8 @@ type AddressClient interface { } type ShareCodeSender interface { - SendCertificateProviderInvite(context.Context, appcontext.Data, sharecode.CertificateProviderInvite) error - SendCertificateProviderPrompt(context.Context, appcontext.Data, *donordata.Provided) error + SendCertificateProviderInvite(ctx context.Context, appData appcontext.Data, invite sharecode.CertificateProviderInvite, to notify.ToEmail) error + SendCertificateProviderPrompt(ctx context.Context, appData appcontext.Data, provided *donordata.Provided) error SendVoucherAccessCode(ctx context.Context, donor *donordata.Provided, appData appcontext.Data) error } @@ -98,9 +97,9 @@ type OneLoginClient interface { } type NotifyClient interface { - 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 - SendActorEmail(ctx context.Context, lang localize.Lang, to, lpaUID string, email notify.Email) error + SendActorSMS(ctx context.Context, to notify.ToMobile, lpaUID string, sms notify.SMS) error + SendEmail(ctx context.Context, to notify.ToEmail, email notify.Email) error + SendActorEmail(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email) error } type SessionStore interface { diff --git a/internal/donor/mock_NotifyClient_test.go b/internal/donor/mock_NotifyClient_test.go index 03c1ac2507..776ea3fbac 100644 --- a/internal/donor/mock_NotifyClient_test.go +++ b/internal/donor/mock_NotifyClient_test.go @@ -5,10 +5,8 @@ package donor import ( context "context" - localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" - mock "github.com/stretchr/testify/mock" - 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 @@ -24,67 +22,17 @@ func (_m *mockNotifyClient) EXPECT() *mockNotifyClient_Expecter { return &mockNotifyClient_Expecter{mock: &_m.Mock} } -// 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, localize.Lang, string, string, notify.Email) error); ok { - r0 = rf(_a0, lang, 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 -// - lang localize.Lang -// - to string -// - lpaUID string -// - email notify.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, 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].(localize.Lang), args[2].(string), args[3].(string), args[4].(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, 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, 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) +// SendActorSMS provides a mock function with given fields: _a0, to, lpaUID, sms +func (_m *mockNotifyClient) SendActorSMS(_a0 context.Context, to notify.ToMobile, 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, localize.Lang, string, string, notify.SMS) error); ok { - r0 = rf(_a0, lang, to, lpaUID, sms) + if rf, ok := ret.Get(0).(func(context.Context, notify.ToMobile, string, notify.SMS) error); ok { + r0 = rf(_a0, to, lpaUID, sms) } else { r0 = ret.Error(0) } @@ -99,17 +47,16 @@ type mockNotifyClient_SendActorSMS_Call struct { // SendActorSMS is a helper method to define mock.On call // - _a0 context.Context -// - lang localize.Lang -// - to string +// - to notify.ToMobile // - lpaUID string // - sms notify.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 (_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, lang localize.Lang, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(_a0 context.Context, to notify.ToMobile, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.SMS)) + run(args[0].(context.Context), args[1].(notify.ToMobile), args[2].(string), args[3].(notify.SMS)) }) return _c } @@ -119,7 +66,7 @@ func (_c *mockNotifyClient_SendActorSMS_Call) Return(_a0 error) *mockNotifyClien return _c } -func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, notify.ToMobile, 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 5e4e9ef09a..d924a48db6 100644 --- a/internal/donor/witness_code_sender.go +++ b/internal/donor/witness_code_sender.go @@ -29,8 +29,7 @@ type CertificateProviderStore interface { } type NotifyClient interface { - 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 + SendActorSMS(context context.Context, to notify.ToMobile, lpaUID string, sms notify.SMS) error } type Localizer interface { @@ -83,12 +82,12 @@ func (s *WitnessCodeSender) SendToCertificateProvider(ctx context.Context, donor return err } - contactLanguage := localize.En + to := notify.ToCertificateProvider(donor.CertificateProvider) if certificateProvider, _ := s.certificateProviderStore.GetAny(ctx); certificateProvider != nil { - contactLanguage = certificateProvider.ContactLanguagePreference + to = notify.ToProvidedCertificateProvider(certificateProvider, donor.CertificateProvider) } - return s.notifyClient.SendActorSMS(ctx, contactLanguage, donor.CertificateProvider.Mobile, donor.LpaUID, notify.WitnessCodeSMS{ + return s.notifyClient.SendActorSMS(ctx, to, donor.LpaUID, notify.WitnessCodeSMS{ WitnessCode: code, DonorFullName: s.localizer.Possessive(donor.Donor.FullName()), LpaType: localize.LowerFirst(s.localizer.T(donor.Type.String())), @@ -111,7 +110,7 @@ func (s *WitnessCodeSender) SendToIndependentWitness(ctx context.Context, donor return err } - return s.notifyClient.SendActorSMS(ctx, localize.En, donor.IndependentWitness.Mobile, donor.LpaUID, notify.WitnessCodeSMS{ + return s.notifyClient.SendActorSMS(ctx, notify.ToIndependentWitness(donor.IndependentWitness), 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 a44af1983e..5dc8aa0622 100644 --- a/internal/donor/witness_code_sender_test.go +++ b/internal/donor/witness_code_sender_test.go @@ -40,7 +40,7 @@ func TestWitnessCodeSenderSendToCertificateProvider(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(ctx, localize.En, "0777", "lpa-uid", notify.WitnessCodeSMS{ + SendActorSMS(ctx, notify.ToCertificateProvider(donordata.CertificateProvider{Mobile: "0777"}), "lpa-uid", notify.WitnessCodeSMS{ WitnessCode: tc.expectedWitnessCode, DonorFullName: "Joe Jones’", LpaType: "property and affairs", @@ -95,9 +95,18 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenContactLanguagePreference now := time.Now() ctx := context.Background() + certificateProvider := &certificateproviderdata.Provided{ContactLanguagePreference: localize.Cy} + provided := &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, + } + notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(ctx, localize.Cy, "0777", "lpa-uid", notify.WitnessCodeSMS{ + SendActorSMS(ctx, notify.ToProvidedCertificateProvider(certificateProvider, provided.CertificateProvider), "lpa-uid", notify.WitnessCodeSMS{ WitnessCode: "1234", DonorFullName: "Joe Jones’", LpaType: "property and affairs", @@ -106,19 +115,13 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenContactLanguagePreference 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, - }). + Put(ctx, provided). Return(nil) certificateProviderStore := newMockCertificateProviderStore(t) certificateProviderStore.EXPECT(). GetAny(ctx). - Return(&certificateproviderdata.Provided{ContactLanguagePreference: localize.Cy}, nil) + Return(certificateProvider, nil) localizer := newMockLocalizer(t) localizer.EXPECT(). @@ -161,7 +164,7 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenTooRecentlySent(t *testin func TestWitnessCodeSenderSendToCertificateProviderWhenNotifyClientErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) donorStore := newMockDonorStore(t) @@ -225,7 +228,7 @@ func TestWitnessCodeSenderSendToIndependentWitness(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(ctx, localize.En, "0777", "lpa-uid", notify.WitnessCodeSMS{ + SendActorSMS(ctx, notify.ToIndependentWitness(donordata.IndependentWitness{Mobile: "0777"}), "lpa-uid", notify.WitnessCodeSMS{ WitnessCode: "1234", DonorFullName: "Joe Jones’", LpaType: "property and affairs", @@ -283,7 +286,7 @@ func TestWitnessCodeSenderSendToIndependentWitnessWhenTooRecentlySent(t *testing func TestWitnessCodeSenderSendToIndependentWitnessWhenNotifyClientErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) donorStore := newMockDonorStore(t) diff --git a/internal/lpastore/client.go b/internal/lpastore/client.go index fc07a1d2a8..2b6f17aa54 100644 --- a/internal/lpastore/client.go +++ b/internal/lpastore/client.go @@ -15,7 +15,8 @@ import ( const ( issuer = "opg.poas.makeregister" statusActive = "active" - statusReplacement = "replacement" + statusInactive = "inactive" + statusRemoved = "removed" appointmentTypeOriginal = "original" appointmentTypeReplacement = "replacement" ) diff --git a/internal/lpastore/client_test.go b/internal/lpastore/client_test.go index 8904b3f981..2ff34278e1 100644 --- a/internal/lpastore/client_test.go +++ b/internal/lpastore/client_test.go @@ -122,7 +122,7 @@ func TestClientServiceContract(t *testing.T) { "country": matchers.String("GB"), }), "channel": matchers.Regex("online", "online|paper"), - "status": matchers.Regex("active", "active|inactive|removed|replacement"), + "status": matchers.Regex("active", "active|inactive|removed"), "appointmentType": matchers.Regex("original", "original|replacement"), }, 1), "trustCorporations": matchers.EachLike(map[string]any{ @@ -138,7 +138,7 @@ func TestClientServiceContract(t *testing.T) { "country": matchers.String("GB"), }), "channel": matchers.Regex("paper", "online|paper"), - "status": matchers.Regex("active", "active|replacement"), + "status": matchers.Regex("active", "active|inactive|removed"), "appointmentType": matchers.Regex("original", "original|replacement"), }, 1), "certificateProvider": matchers.Like(map[string]any{ @@ -287,7 +287,7 @@ func TestClientServiceContract(t *testing.T) { "postcode": matchers.String("A1 1FF"), "country": matchers.String("GB"), }), - "status": matchers.Regex("active", "active|replacement"), + "status": matchers.Regex("active", "active|inactive|removed"), "appointmentType": matchers.Regex("original", "original|replacement"), "channel": matchers.Regex("online", "online|post"), }, 1), diff --git a/internal/lpastore/lpa.go b/internal/lpastore/lpa.go index d230d49beb..429c371059 100644 --- a/internal/lpastore/lpa.go +++ b/internal/lpastore/lpa.go @@ -217,7 +217,7 @@ func (c *Client) SendLpa(ctx context.Context, donor *donordata.Provided) error { DateOfBirth: attorney.DateOfBirth, Email: attorney.Email, Address: attorney.Address, - Status: statusReplacement, + Status: statusInactive, AppointmentType: appointmentTypeReplacement, Channel: attorney.Channel(), }) @@ -230,7 +230,7 @@ func (c *Client) SendLpa(ctx context.Context, donor *donordata.Provided) error { CompanyNumber: trustCorporation.CompanyNumber, Email: trustCorporation.Email, Address: trustCorporation.Address, - Status: statusReplacement, + Status: statusInactive, AppointmentType: appointmentTypeReplacement, Channel: trustCorporation.Channel(), }) @@ -404,11 +404,12 @@ func lpaResponseToLpa(l lpaResponse) *lpadata.Lpa { SignedAt: a.SignedAt, ContactLanguagePreference: a.ContactLanguagePreference, Channel: a.Channel, + Removed: a.Status == statusRemoved, } - if a.Status == "replacement" { + if a.AppointmentType == appointmentTypeReplacement { data.ReplacementAttorneys.Attorneys = append(data.ReplacementAttorneys.Attorneys, at) - } else if a.Status == "active" { + } else { data.Attorneys.Attorneys = append(data.Attorneys.Attorneys, at) } } @@ -424,11 +425,12 @@ func lpaResponseToLpa(l lpaResponse) *lpadata.Lpa { Signatories: t.Signatories, ContactLanguagePreference: t.ContactLanguagePreference, Channel: t.Channel, + Removed: t.Status == statusRemoved, } - if t.Status == "replacement" { + if t.AppointmentType == appointmentTypeReplacement { data.ReplacementAttorneys.TrustCorporation = tc - } else if t.Status == "active" { + } else { data.Attorneys.TrustCorporation = tc } } diff --git a/internal/lpastore/lpa_test.go b/internal/lpastore/lpa_test.go index c1baaf7c2a..ebbd8c14ed 100644 --- a/internal/lpastore/lpa_test.go +++ b/internal/lpastore/lpa_test.go @@ -284,12 +284,12 @@ func TestClientSendLpa(t *testing.T) { "attorneys":[ {"uid":"` + attorneyUID.String() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"appointmentType":"original","status":"active","channel":"online"}, {"uid":"` + attorney2UID.String() + `","firstNames":"Alice","lastName":"Attorney","dateOfBirth":"1998-01-02","address":{"line1":"aa-line-1","line2":"aa-line-2","line3":"aa-line-3","town":"aa-town","postcode":"A1 1AF","country":"GB"},"appointmentType":"original","status":"active","channel":"paper"}, -{"uid":"` + replacementAttorneyUID.String() + `","firstNames":"Richard","lastName":"Attorney","dateOfBirth":"1999-11-12","email":"richard@example.com","address":{"line1":"r-line-1","line2":"r-line-2","line3":"r-line-3","town":"r-town","postcode":"R1 1FF","country":"GB"},"appointmentType":"replacement","status":"replacement","channel":"online"}, -{"uid":"` + replacementAttorney2UID.String() + `","firstNames":"Rachel","lastName":"Attorney","dateOfBirth":"1998-11-12","email":"rachel@example.com","address":{"line1":"rr-line-1","line2":"rr-line-2","line3":"rr-line-3","town":"rr-town","postcode":"R1 1RF","country":"GB"},"appointmentType":"replacement","status":"replacement","channel":"online"} +{"uid":"` + replacementAttorneyUID.String() + `","firstNames":"Richard","lastName":"Attorney","dateOfBirth":"1999-11-12","email":"richard@example.com","address":{"line1":"r-line-1","line2":"r-line-2","line3":"r-line-3","town":"r-town","postcode":"R1 1FF","country":"GB"},"appointmentType":"replacement","status":"inactive","channel":"online"}, +{"uid":"` + replacementAttorney2UID.String() + `","firstNames":"Rachel","lastName":"Attorney","dateOfBirth":"1998-11-12","email":"rachel@example.com","address":{"line1":"rr-line-1","line2":"rr-line-2","line3":"rr-line-3","town":"rr-town","postcode":"R1 1RF","country":"GB"},"appointmentType":"replacement","status":"inactive","channel":"online"} ], "trustCorporations":[ {"uid":"` + trustCorporationUID.String() + `","name":"Trusty","companyNumber":"55555","email":"trusty@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"appointmentType":"original","status":"active","channel":"online"}, -{"uid":"` + replacementTrustCorporationUID.String() + `","name":"UnTrusty","companyNumber":"65555","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"appointmentType":"replacement","status":"replacement","channel":"paper"} +{"uid":"` + replacementTrustCorporationUID.String() + `","name":"UnTrusty","companyNumber":"65555","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"appointmentType":"replacement","status":"inactive","channel":"paper"} ], "certificateProvider":{"uid":"` + certificateProviderUID.String() + `","firstNames":"Carol","lastName":"Cert","email":"carol@example.com","phone":"0700009000","address":{"line1":"c-line-1","line2":"c-line-2","line3":"c-line-3","town":"c-town","postcode":"C1 1FF","country":"GB"},"channel":"online"}, "peopleToNotify":[{"uid":"` + personToNotifyUID.String() + `","firstNames":"Peter","lastName":"Notify","address":{"line1":"p-line-1","line2":"p-line-2","line3":"p-line-3","town":"p-town","postcode":"P1 1FF","country":"GB"}}], @@ -481,7 +481,7 @@ func TestClientLpa(t *testing.T) { "channel":"online", "lpaType":"property-and-affairs", "donor":{"uid":"` + donorUID.String() + `","firstNames":"John Johnson","lastName":"Smith","dateOfBirth":"2000-01-02","email":"john@example.com","address":{"line1":"line-1","line2":"","line3":"","town":"town","postcode":"","country":"GB"},"otherNamesKnownBy":"JJ"}, -"attorneys":[{"uid":"` + attorneyUID.String() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"","line3":"","town":"a-town","postcode":"","country":"GB"},"status":"active"}], +"attorneys":[{"uid":"` + attorneyUID.String() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"","line3":"","town":"a-town","postcode":"","country":"GB"},"status":"active","appointmentType":"original"}], "certificateProvider":{"uid":"` + certificateProviderUID.String() + `","firstNames":"Carol","lastName":"Cert","address":{"line1":"c-line-1","line2":"","line3":"","town":"c-town","postcode":"","country":"GB"},"channel":"paper"}, "restrictionsAndConditions":"", "whenTheLpaCanBeUsed":"when-capacity-lost", @@ -539,7 +539,7 @@ func TestClientLpa(t *testing.T) { "channel":"online", "lpaType":"property-and-affairs", "donor":{"uid":"` + donorUID.String() + `","firstNames":"John Johnson","lastName":"Smith","dateOfBirth":"2000-01-02","email":"john@example.com","address":{"line1":"line-1","line2":"","line3":"","town":"town","postcode":"","country":"GB"},"otherNamesKnownBy":"JJ"}, -"attorneys":[{"uid":"` + attorneyUID.String() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"","line3":"","town":"a-town","postcode":"","country":"GB"},"status":"active"}], +"attorneys":[{"uid":"` + attorneyUID.String() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"","line3":"","town":"a-town","postcode":"","country":"GB"},"status":"active","appointmentType":"original"}], "certificateProvider":{"uid":"` + certificateProviderUID.String() + `","firstNames":"Carol","lastName":"Cert","address":{"line1":"c-line-1","line2":"","line3":"","town":"c-town","postcode":"","country":"GB"},"channel":"paper"}, "restrictionsAndConditions":"", "whenTheLpaCanBeUsed":"", @@ -736,14 +736,14 @@ func TestClientLpa(t *testing.T) { "channel":"online", "donor":{"uid":"` + donorUID.String() + `","firstNames":"John Johnson","lastName":"Smith","dateOfBirth":"2000-01-02","email":"john@example.com","address":{"line1":"line-1","line2":"line-2","line3":"line-3","town":"town","postcode":"F1 1FF","country":"GB"},"otherNamesKnownBy":"JJ","identityCheck":{"checkedAt":"2002-01-02T12:13:14.0000000015Z","type":"one-login"}}, "attorneys":[ -{"uid":"` + attorneyUID.String() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active"}, -{"uid":"` + attorney2UID.String() + `","firstNames":"Alice","lastName":"Attorney","dateOfBirth":"1998-01-02","email":"alice@example.com","address":{"line1":"aa-line-1","line2":"aa-line-2","line3":"aa-line-3","town":"aa-town","postcode":"A1 1AF","country":"GB"},"status":"active"}, -{"uid":"` + replacementAttorneyUID.String() + `","firstNames":"Richard","lastName":"Attorney","dateOfBirth":"1999-11-12","email":"richard@example.com","address":{"line1":"r-line-1","line2":"r-line-2","line3":"r-line-3","town":"r-town","postcode":"R1 1FF","country":"GB"},"status":"replacement"}, -{"uid":"` + replacementAttorney2UID.String() + `","firstNames":"Rachel","lastName":"Attorney","dateOfBirth":"1998-11-12","email":"rachel@example.com","address":{"line1":"rr-line-1","line2":"rr-line-2","line3":"rr-line-3","town":"rr-town","postcode":"R1 1RF","country":"GB"},"status":"replacement"} +{"uid":"` + attorneyUID.String() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active","appointmentType":"original"}, +{"uid":"` + attorney2UID.String() + `","firstNames":"Alice","lastName":"Attorney","dateOfBirth":"1998-01-02","email":"alice@example.com","address":{"line1":"aa-line-1","line2":"aa-line-2","line3":"aa-line-3","town":"aa-town","postcode":"A1 1AF","country":"GB"},"status":"active","appointmentType":"original"}, +{"uid":"` + replacementAttorneyUID.String() + `","firstNames":"Richard","lastName":"Attorney","dateOfBirth":"1999-11-12","email":"richard@example.com","address":{"line1":"r-line-1","line2":"r-line-2","line3":"r-line-3","town":"r-town","postcode":"R1 1FF","country":"GB"},"status":"replacement","appointmentType":"replacement"}, +{"uid":"` + replacementAttorney2UID.String() + `","firstNames":"Rachel","lastName":"Attorney","dateOfBirth":"1998-11-12","email":"rachel@example.com","address":{"line1":"rr-line-1","line2":"rr-line-2","line3":"rr-line-3","town":"rr-town","postcode":"R1 1RF","country":"GB"},"status":"replacement","appointmentType":"replacement"} ], "trustCorporations":[ -{"uid":"` + trustCorporationUID.String() + `","name":"Trusty","companyNumber":"55555","email":"trusty@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active","channel":"online"}, -{"uid":"` + replacementTrustCorporationUID.String() + `","name":"UnTrusty","companyNumber":"65555","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"replacement","channel":"paper"} +{"uid":"` + trustCorporationUID.String() + `","name":"Trusty","companyNumber":"55555","email":"trusty@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active","channel":"online","appointmentType":"original"}, +{"uid":"` + replacementTrustCorporationUID.String() + `","name":"UnTrusty","companyNumber":"65555","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"replacement","channel":"paper","appointmentType":"replacement"} ], "certificateProvider":{"uid":"` + certificateProviderUID.String() + `","firstNames":"Carol","lastName":"Cert","email":"carol@example.com","phone":"0700009000","address":{"line1":"c-line-1","line2":"c-line-2","line3":"c-line-3","town":"c-town","postcode":"C1 1FF","country":"GB"},"channel":"online","identityCheck":{"checkedAt":"2002-01-01T13:14:15.000000016Z","type":"one-login"}}, "peopleToNotify":[{"uid":"` + personToNotifyUID.String() + `","firstNames":"Peter","lastName":"Notify","address":{"line1":"p-line-1","line2":"p-line-2","line3":"p-line-3","town":"p-town","postcode":"P1 1FF","country":"GB"}}], @@ -941,7 +941,7 @@ func TestClientLpas(t *testing.T) { "lpaType":"property-and-affairs", "channel":"online", "donor":{"uid":"` + donorUID.String() + `","firstNames":"John Johnson","lastName":"Smith","dateOfBirth":"2000-01-02","email":"john@example.com","address":{"line1":"line-1","line2":"","line3":"","town":"town","postcode":"","country":"GB"},"otherNamesKnownBy":"JJ"}, -"attorneys":[{"uid":"` + attorneyUID.String() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"","line3":"","town":"a-town","postcode":"","country":"GB"},"status":"active"}], +"attorneys":[{"uid":"` + attorneyUID.String() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"","line3":"","town":"a-town","postcode":"","country":"GB"},"status":"active","appointmentType":"original"}], "certificateProvider":{"uid":"` + certificateProviderUID.String() + `","firstNames":"Carol","lastName":"Cert","address":{"line1":"c-line-1","line2":"","line3":"","town":"c-town","postcode":"","country":"GB"},"channel":"paper"}, "restrictionsAndConditions":"", "whenTheLpaCanBeUsed":"when-capacity-lost", @@ -1013,6 +1013,7 @@ func TestClientLpas(t *testing.T) { Postcode: "A1 1AF", Country: "GB", }, + Removed: true, }}, }, AttorneyDecisions: lpadata.AttorneyDecisions{ @@ -1032,6 +1033,7 @@ func TestClientLpas(t *testing.T) { Postcode: "A1 1FF", Country: "GB", }, + Removed: true, }, Attorneys: []lpadata.Attorney{{ UID: replacementAttorneyUID, @@ -1110,14 +1112,14 @@ func TestClientLpas(t *testing.T) { "channel":"online", "donor":{"uid":"` + donorUID.String() + `","firstNames":"John Johnson","lastName":"Smith","dateOfBirth":"2000-01-02","email":"john@example.com","address":{"line1":"line-1","line2":"line-2","line3":"line-3","town":"town","postcode":"F1 1FF","country":"GB"},"otherNamesKnownBy":"JJ"}, "attorneys":[ -{"uid":"` + attorneyUID.String() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active"}, -{"uid":"` + attorney2UID.String() + `","firstNames":"Alice","lastName":"Attorney","dateOfBirth":"1998-01-02","email":"alice@example.com","address":{"line1":"aa-line-1","line2":"aa-line-2","line3":"aa-line-3","town":"aa-town","postcode":"A1 1AF","country":"GB"},"status":"active"}, -{"uid":"` + replacementAttorneyUID.String() + `","firstNames":"Richard","lastName":"Attorney","dateOfBirth":"1999-11-12","email":"richard@example.com","address":{"line1":"r-line-1","line2":"r-line-2","line3":"r-line-3","town":"r-town","postcode":"R1 1FF","country":"GB"},"status":"replacement"}, -{"uid":"` + replacementAttorney2UID.String() + `","firstNames":"Rachel","lastName":"Attorney","dateOfBirth":"1998-11-12","email":"rachel@example.com","address":{"line1":"rr-line-1","line2":"rr-line-2","line3":"rr-line-3","town":"rr-town","postcode":"R1 1RF","country":"GB"},"status":"replacement"} +{"uid":"` + attorneyUID.String() + `","firstNames":"Adam","lastName":"Attorney","dateOfBirth":"1999-01-02","email":"adam@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active","appointmentType":"original"}, +{"uid":"` + attorney2UID.String() + `","firstNames":"Alice","lastName":"Attorney","dateOfBirth":"1998-01-02","email":"alice@example.com","address":{"line1":"aa-line-1","line2":"aa-line-2","line3":"aa-line-3","town":"aa-town","postcode":"A1 1AF","country":"GB"},"status":"removed","appointmentType":"original"}, +{"uid":"` + replacementAttorneyUID.String() + `","firstNames":"Richard","lastName":"Attorney","dateOfBirth":"1999-11-12","email":"richard@example.com","address":{"line1":"r-line-1","line2":"r-line-2","line3":"r-line-3","town":"r-town","postcode":"R1 1FF","country":"GB"},"status":"replacement","appointmentType":"replacement"}, +{"uid":"` + replacementAttorney2UID.String() + `","firstNames":"Rachel","lastName":"Attorney","dateOfBirth":"1998-11-12","email":"rachel@example.com","address":{"line1":"rr-line-1","line2":"rr-line-2","line3":"rr-line-3","town":"rr-town","postcode":"R1 1RF","country":"GB"},"status":"replacement","appointmentType":"replacement"} ], "trustCorporations":[ -{"uid":"` + trustCorporationUID.String() + `","name":"Trusty","companyNumber":"55555","email":"trusty@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active"}, -{"uid":"` + replacementTrustCorporationUID.String() + `","name":"UnTrusty","companyNumber":"65555","email":"untrusty@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"replacement"} +{"uid":"` + trustCorporationUID.String() + `","name":"Trusty","companyNumber":"55555","email":"trusty@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"active","appointmentType":"original"}, +{"uid":"` + replacementTrustCorporationUID.String() + `","name":"UnTrusty","companyNumber":"65555","email":"untrusty@example.com","address":{"line1":"a-line-1","line2":"a-line-2","line3":"a-line-3","town":"a-town","postcode":"A1 1FF","country":"GB"},"status":"removed","appointmentType":"replacement"} ], "certificateProvider":{"uid":"` + certificateProviderUID.String() + `","firstNames":"Carol","lastName":"Cert","email":"carol@example.com","phone":"0700009000","address":{"line1":"c-line-1","line2":"c-line-2","line3":"c-line-3","town":"c-town","postcode":"C1 1FF","country":"GB"},"channel":"online"}, "peopleToNotify":[{"uid":"` + personToNotifyUID.String() + `","firstNames":"Peter","lastName":"Notify","address":{"line1":"p-line-1","line2":"p-line-2","line3":"p-line-3","town":"p-town","postcode":"P1 1FF","country":"GB"}}], diff --git a/internal/lpastore/lpadata/attorney.go b/internal/lpastore/lpadata/attorney.go index 69459e8638..3fc279c27d 100644 --- a/internal/lpastore/lpadata/attorney.go +++ b/internal/lpastore/lpadata/attorney.go @@ -20,6 +20,7 @@ type Attorney struct { SignedAt time.Time ContactLanguagePreference localize.Lang Channel Channel + Removed bool } func (a Attorney) FullName() string { diff --git a/internal/lpastore/lpadata/correspondent.go b/internal/lpastore/lpadata/correspondent.go index cb7d034951..d2b5f9dccd 100644 --- a/internal/lpastore/lpadata/correspondent.go +++ b/internal/lpastore/lpadata/correspondent.go @@ -4,6 +4,7 @@ type Correspondent struct { FirstNames string LastName string Email string + Phone string } func (c Correspondent) FullName() string { diff --git a/internal/lpastore/lpadata/lpa_type.go b/internal/lpastore/lpadata/lpa_type.go index eccc963b2e..8c03d1c0af 100644 --- a/internal/lpastore/lpadata/lpa_type.go +++ b/internal/lpastore/lpadata/lpa_type.go @@ -7,14 +7,3 @@ const ( LpaTypePersonalWelfare LpaType = iota + 1 // personal-welfare LpaTypePropertyAndAffairs // property-and-affairs ) - -// TODO: move this somewhere else -func (e LpaType) WhatLPACoversTransKey() string { - switch e { - case LpaTypePropertyAndAffairs: - return "whatPropertyAndAffairsCovers" - case LpaTypePersonalWelfare: - return "whatPersonalWelfareCovers" - } - return "" -} diff --git a/internal/lpastore/lpadata/lpa_type_test.go b/internal/lpastore/lpadata/lpa_type_test.go index 880a8016c4..46d2656653 100644 --- a/internal/lpastore/lpadata/lpa_type_test.go +++ b/internal/lpastore/lpadata/lpa_type_test.go @@ -37,18 +37,3 @@ func TestLpaType(t *testing.T) { assert.False(t, LpaTypePersonalWelfare.IsPropertyAndAffairs()) }) } - -func TestLpaTypeWhatLPACoversTransKey(t *testing.T) { - testCases := map[LpaType]string{ - LpaTypePropertyAndAffairs: "whatPropertyAndAffairsCovers", - LpaTypePersonalWelfare: "whatPersonalWelfareCovers", - LpaType(99): "", - LpaType(0): "", - } - - for lpaType, translationKey := range testCases { - t.Run(lpaType.String(), func(t *testing.T) { - assert.Equal(t, translationKey, lpaType.WhatLPACoversTransKey()) - }) - } -} diff --git a/internal/lpastore/lpadata/trust_corporation.go b/internal/lpastore/lpadata/trust_corporation.go index 355ca3aaa9..af451e20ed 100644 --- a/internal/lpastore/lpadata/trust_corporation.go +++ b/internal/lpastore/lpadata/trust_corporation.go @@ -16,4 +16,5 @@ type TrustCorporation struct { Signatories []TrustCorporationSignatory ContactLanguagePreference localize.Lang Channel Channel + Removed bool } diff --git a/internal/lpastore/resolving_service.go b/internal/lpastore/resolving_service.go index 2aba02c8c2..817011f5f8 100644 --- a/internal/lpastore/resolving_service.go +++ b/internal/lpastore/resolving_service.go @@ -102,6 +102,7 @@ func (s *ResolvingService) merge(lpa *lpadata.Lpa, donor *donordata.Provided) *l FirstNames: donor.Correspondent.FirstNames, LastName: donor.Correspondent.LastName, Email: donor.Correspondent.Email, + Phone: donor.Correspondent.Phone, } if donor.Voucher.Allowed { lpa.Voucher = lpadata.Voucher{ diff --git a/internal/notify/client.go b/internal/notify/client.go index 821eabbd51..66e469a23b 100644 --- a/internal/notify/client.go +++ b/internal/notify/client.go @@ -138,14 +138,19 @@ type emailWrapper struct { Reference string `json:"reference"` } -func (c *Client) SendEmail(ctx context.Context, lang localize.Lang, to string, email Email) error { +func (c *Client) SendEmail(ctx context.Context, to ToEmail, email Email) error { + if to.ignore() { + return nil + } + + address, lang := to.toEmail() templateID := email.emailID(c.isProduction, lang) - ctx, span := newSpan(ctx, "Email", templateID, to) + ctx, span := newSpan(ctx, "Email", templateID, address) defer span.End() req, err := c.newRequest(ctx, http.MethodPost, "/v2/notifications/email", emailWrapper{ - EmailAddress: to, + EmailAddress: address, TemplateID: templateID, Personalisation: email, }) @@ -155,7 +160,7 @@ func (c *Client) SendEmail(ctx context.Context, lang localize.Lang, to string, e resp, err := c.do(req) if err != nil { - c.logger.ErrorContext(ctx, "email send failed", slog.String("to", to)) + c.logger.ErrorContext(ctx, "email send failed", slog.String("to", address)) return err } span.SetAttributes(attribute.KeyValue{Key: "notify_id", Value: attribute.StringValue(resp.ID)}) @@ -163,21 +168,27 @@ func (c *Client) SendEmail(ctx context.Context, lang localize.Lang, to string, e return nil } -func (c *Client) SendActorEmail(ctx context.Context, lang localize.Lang, to, lpaUID string, email Email) error { +func (c *Client) SendActorEmail(ctx context.Context, to ToEmail, lpaUID string, email Email) error { + if to.ignore() { + return nil + } + + address, lang := to.toEmail() + templateID := email.emailID(c.isProduction, lang) - ctx, span := newSpan(ctx, "Email", templateID, to) + ctx, span := newSpan(ctx, "Email", templateID, address) defer span.End() - if ok, err := c.recentlySent(ctx, c.makeReference(lpaUID, to, templateID)); err != nil || ok { + if ok, err := c.recentlySent(ctx, c.makeReference(lpaUID, address, templateID)); err != nil || ok { return err } req, err := c.newRequest(ctx, http.MethodPost, "/v2/notifications/email", emailWrapper{ - EmailAddress: to, + EmailAddress: address, TemplateID: templateID, Personalisation: email, - Reference: c.makeReference(lpaUID, to, templateID), + Reference: c.makeReference(lpaUID, address, templateID), }) if err != nil { return err @@ -185,12 +196,12 @@ func (c *Client) SendActorEmail(ctx context.Context, lang localize.Lang, to, lpa resp, err := c.do(req) if err != nil { - c.logger.ErrorContext(ctx, "email send failed", slog.String("to", to)) + c.logger.ErrorContext(ctx, "email send failed", slog.String("to", address)) return err } span.SetAttributes(attribute.KeyValue{Key: "notify_id", Value: attribute.StringValue(resp.ID)}) - if !slices.Contains(simulatedEmails, to) { + if !slices.Contains(simulatedEmails, address) { if err := c.eventClient.SendNotificationSent(ctx, event.NotificationSent{ UID: lpaUID, NotificationID: resp.ID, @@ -208,14 +219,20 @@ type smsWrapper struct { Personalisation any `json:"personalisation,omitempty"` } -func (c *Client) SendActorSMS(ctx context.Context, lang localize.Lang, to, lpaUID string, sms SMS) error { +func (c *Client) SendActorSMS(ctx context.Context, to ToMobile, lpaUID string, sms SMS) error { + if to.ignore() { + return nil + } + + number, lang := to.toMobile() + templateID := sms.smsID(c.isProduction, lang) - ctx, span := newSpan(ctx, "SMS", templateID, to) + ctx, span := newSpan(ctx, "SMS", templateID, number) defer span.End() req, err := c.newRequest(ctx, http.MethodPost, "/v2/notifications/sms", smsWrapper{ - PhoneNumber: to, + PhoneNumber: number, TemplateID: templateID, Personalisation: sms, }) @@ -229,7 +246,7 @@ func (c *Client) SendActorSMS(ctx context.Context, lang localize.Lang, to, lpaUI } span.SetAttributes(attribute.KeyValue{Key: "notification_id", Value: attribute.StringValue(resp.ID)}) - if !slices.Contains(simulatedPhones, to) { + if !slices.Contains(simulatedPhones, number) { if err := c.eventClient.SendNotificationSent(ctx, event.NotificationSent{ UID: lpaUID, NotificationID: resp.ID, diff --git a/internal/notify/client_test.go b/internal/notify/client_test.go index 008cd8a3ca..7a2aa2c262 100644 --- a/internal/notify/client_test.go +++ b/internal/notify/client_test.go @@ -146,7 +146,17 @@ 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, localize.En, "me@example.com", testEmail{A: "value"}) + err := client.SendEmail(ctx, to{lang: localize.En, email: "me@example.com"}, testEmail{A: "value"}) + assert.Nil(err) +} + +func TestSendEmailWhenIgnored(t *testing.T) { + assert := assert.New(t) + ctx := context.Background() + + client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", nil, nil, nil) + + err := client.SendEmail(ctx, to{ignored: true}, testEmail{A: "value"}) assert.Nil(err) } @@ -169,7 +179,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, localize.En, "me@example.com", testEmail{}) + err := client.SendEmail(ctx, to{lang: localize.En, email: "me@example.com"}, testEmail{}) assert.Equal(`error sending message: This happened: Plus this`, err.Error()) } @@ -228,12 +238,22 @@ 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, localize.En, "me@example.com", "lpa-uid", testEmail{A: "value"}) + err := client.SendActorEmail(ctx, to{lang: localize.En, email: "me@example.com"}, "lpa-uid", testEmail{A: "value"}) assert.Nil(err) }) } } +func TestSendActorEmailWhenIgnored(t *testing.T) { + assert := assert.New(t) + ctx := context.Background() + + client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", nil, nil, nil) + + err := client.SendActorEmail(ctx, to{ignored: true}, "lpa-uid", testEmail{A: "value"}) + assert.Nil(err) +} + func TestSendActorEmailWhenToSimulated(t *testing.T) { assert := assert.New(t) ctx := context.Background() @@ -256,7 +276,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, localize.En, email, "lpa-uid", testEmail{A: "value"}) + err := client.SendActorEmail(ctx, to{lang: localize.En, email: email}, "lpa-uid", testEmail{A: "value"}) assert.Nil(err) } } @@ -292,7 +312,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, localize.En, "me@example.com", "lpa-uid", testEmail{A: "value"}) + err := client.SendActorEmail(ctx, to{lang: localize.En, email: "me@example.com"}, "lpa-uid", testEmail{A: "value"}) assert.Nil(err) }) } @@ -306,7 +326,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(), localize.En, "me@example.com", "lpa-uid", testEmail{A: "value"}) + err := client.SendActorEmail(context.Background(), to{lang: localize.En, email: "me@example.com"}, "lpa-uid", testEmail{A: "value"}) assert.Equal(t, expectedError, err) } @@ -331,7 +351,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(), localize.En, "me@example.com", "lpa-uid", testEmail{}) + err := client.SendActorEmail(context.Background(), to{lang: localize.En, email: "me@example.com"}, "lpa-uid", testEmail{}) assert.Equal(t, "error sending message: This happened: Plus this", err.Error()) } @@ -358,7 +378,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(), localize.En, "me@example.com", "lpa-uid", testEmail{A: "value"}) + err := client.SendActorEmail(context.Background(), to{lang: localize.En, email: "me@example.com"}, "lpa-uid", testEmail{A: "value"}) assert.Equal(t, expectedError, err) } @@ -536,7 +556,17 @@ 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, localize.En, "+447535111111", "lpa-uid", testSMS{A: "value"}) + err := client.SendActorSMS(ctx, to{lang: localize.En, mobile: "+447535111111"}, "lpa-uid", testSMS{A: "value"}) + assert.Nil(err) +} + +func TestSendActorSMSWhenIgnored(t *testing.T) { + assert := assert.New(t) + ctx := context.Background() + + client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", nil, nil, nil) + + err := client.SendActorSMS(ctx, to{ignored: true}, "lpa-uid", testSMS{A: "value"}) assert.Nil(err) } @@ -552,7 +582,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(), localize.En, phone, "lpa-uid", testSMS{A: "value"}) + err := client.SendActorSMS(context.Background(), to{lang: localize.En, mobile: phone}, "lpa-uid", testSMS{A: "value"}) assert.Nil(t, err) } } @@ -567,7 +597,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(), localize.En, "+447535111111", "lpa-uid", testSMS{}) + err := client.SendActorSMS(context.Background(), to{lang: localize.En, mobile: "+447535111111"}, "lpa-uid", testSMS{}) assert.Equal(t, "error sending message: This happened: Plus this", err.Error()) } @@ -585,7 +615,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(), localize.En, "+447535111111", "lpa-uid", testSMS{A: "value"}) + err := client.SendActorSMS(context.Background(), to{lang: localize.En, mobile: "+447535111111"}, "lpa-uid", testSMS{A: "value"}) assert.Equal(t, expectedError, err) } diff --git a/internal/notify/mock_ToEmail_test.go b/internal/notify/mock_ToEmail_test.go new file mode 100644 index 0000000000..7218121720 --- /dev/null +++ b/internal/notify/mock_ToEmail_test.go @@ -0,0 +1,135 @@ +// Code generated by mockery. DO NOT EDIT. + +package notify + +import ( + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" + mock "github.com/stretchr/testify/mock" +) + +// mockToEmail is an autogenerated mock type for the ToEmail type +type mockToEmail struct { + mock.Mock +} + +type mockToEmail_Expecter struct { + mock *mock.Mock +} + +func (_m *mockToEmail) EXPECT() *mockToEmail_Expecter { + return &mockToEmail_Expecter{mock: &_m.Mock} +} + +// ignore provides a mock function with given fields: +func (_m *mockToEmail) ignore() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ignore") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// mockToEmail_ignore_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ignore' +type mockToEmail_ignore_Call struct { + *mock.Call +} + +// ignore is a helper method to define mock.On call +func (_e *mockToEmail_Expecter) ignore() *mockToEmail_ignore_Call { + return &mockToEmail_ignore_Call{Call: _e.mock.On("ignore")} +} + +func (_c *mockToEmail_ignore_Call) Run(run func()) *mockToEmail_ignore_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *mockToEmail_ignore_Call) Return(_a0 bool) *mockToEmail_ignore_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockToEmail_ignore_Call) RunAndReturn(run func() bool) *mockToEmail_ignore_Call { + _c.Call.Return(run) + return _c +} + +// toEmail provides a mock function with given fields: +func (_m *mockToEmail) toEmail() (string, localize.Lang) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for toEmail") + } + + var r0 string + var r1 localize.Lang + if rf, ok := ret.Get(0).(func() (string, localize.Lang)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() localize.Lang); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(localize.Lang) + } + + return r0, r1 +} + +// mockToEmail_toEmail_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'toEmail' +type mockToEmail_toEmail_Call struct { + *mock.Call +} + +// toEmail is a helper method to define mock.On call +func (_e *mockToEmail_Expecter) toEmail() *mockToEmail_toEmail_Call { + return &mockToEmail_toEmail_Call{Call: _e.mock.On("toEmail")} +} + +func (_c *mockToEmail_toEmail_Call) Run(run func()) *mockToEmail_toEmail_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *mockToEmail_toEmail_Call) Return(_a0 string, _a1 localize.Lang) *mockToEmail_toEmail_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockToEmail_toEmail_Call) RunAndReturn(run func() (string, localize.Lang)) *mockToEmail_toEmail_Call { + _c.Call.Return(run) + return _c +} + +// newMockToEmail creates a new instance of mockToEmail. 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 newMockToEmail(t interface { + mock.TestingT + Cleanup(func()) +}) *mockToEmail { + mock := &mockToEmail{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/notify/mock_ToMobile_test.go b/internal/notify/mock_ToMobile_test.go new file mode 100644 index 0000000000..cc85b47ebc --- /dev/null +++ b/internal/notify/mock_ToMobile_test.go @@ -0,0 +1,135 @@ +// Code generated by mockery. DO NOT EDIT. + +package notify + +import ( + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" + mock "github.com/stretchr/testify/mock" +) + +// mockToMobile is an autogenerated mock type for the ToMobile type +type mockToMobile struct { + mock.Mock +} + +type mockToMobile_Expecter struct { + mock *mock.Mock +} + +func (_m *mockToMobile) EXPECT() *mockToMobile_Expecter { + return &mockToMobile_Expecter{mock: &_m.Mock} +} + +// ignore provides a mock function with given fields: +func (_m *mockToMobile) ignore() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ignore") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// mockToMobile_ignore_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ignore' +type mockToMobile_ignore_Call struct { + *mock.Call +} + +// ignore is a helper method to define mock.On call +func (_e *mockToMobile_Expecter) ignore() *mockToMobile_ignore_Call { + return &mockToMobile_ignore_Call{Call: _e.mock.On("ignore")} +} + +func (_c *mockToMobile_ignore_Call) Run(run func()) *mockToMobile_ignore_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *mockToMobile_ignore_Call) Return(_a0 bool) *mockToMobile_ignore_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockToMobile_ignore_Call) RunAndReturn(run func() bool) *mockToMobile_ignore_Call { + _c.Call.Return(run) + return _c +} + +// toMobile provides a mock function with given fields: +func (_m *mockToMobile) toMobile() (string, localize.Lang) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for toMobile") + } + + var r0 string + var r1 localize.Lang + if rf, ok := ret.Get(0).(func() (string, localize.Lang)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() localize.Lang); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(localize.Lang) + } + + return r0, r1 +} + +// mockToMobile_toMobile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'toMobile' +type mockToMobile_toMobile_Call struct { + *mock.Call +} + +// toMobile is a helper method to define mock.On call +func (_e *mockToMobile_Expecter) toMobile() *mockToMobile_toMobile_Call { + return &mockToMobile_toMobile_Call{Call: _e.mock.On("toMobile")} +} + +func (_c *mockToMobile_toMobile_Call) Run(run func()) *mockToMobile_toMobile_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *mockToMobile_toMobile_Call) Return(_a0 string, _a1 localize.Lang) *mockToMobile_toMobile_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockToMobile_toMobile_Call) RunAndReturn(run func() (string, localize.Lang)) *mockToMobile_toMobile_Call { + _c.Call.Return(run) + return _c +} + +// newMockToMobile creates a new instance of mockToMobile. 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 newMockToMobile(t interface { + mock.TestingT + Cleanup(func()) +}) *mockToMobile { + mock := &mockToMobile{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/notify/mock_To_test.go b/internal/notify/mock_To_test.go new file mode 100644 index 0000000000..8bf376a321 --- /dev/null +++ b/internal/notify/mock_To_test.go @@ -0,0 +1,190 @@ +// Code generated by mockery. DO NOT EDIT. + +package notify + +import ( + localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" + mock "github.com/stretchr/testify/mock" +) + +// mockTo is an autogenerated mock type for the To type +type mockTo struct { + mock.Mock +} + +type mockTo_Expecter struct { + mock *mock.Mock +} + +func (_m *mockTo) EXPECT() *mockTo_Expecter { + return &mockTo_Expecter{mock: &_m.Mock} +} + +// ignore provides a mock function with given fields: +func (_m *mockTo) ignore() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ignore") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// mockTo_ignore_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ignore' +type mockTo_ignore_Call struct { + *mock.Call +} + +// ignore is a helper method to define mock.On call +func (_e *mockTo_Expecter) ignore() *mockTo_ignore_Call { + return &mockTo_ignore_Call{Call: _e.mock.On("ignore")} +} + +func (_c *mockTo_ignore_Call) Run(run func()) *mockTo_ignore_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *mockTo_ignore_Call) Return(_a0 bool) *mockTo_ignore_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockTo_ignore_Call) RunAndReturn(run func() bool) *mockTo_ignore_Call { + _c.Call.Return(run) + return _c +} + +// toEmail provides a mock function with given fields: +func (_m *mockTo) toEmail() (string, localize.Lang) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for toEmail") + } + + var r0 string + var r1 localize.Lang + if rf, ok := ret.Get(0).(func() (string, localize.Lang)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() localize.Lang); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(localize.Lang) + } + + return r0, r1 +} + +// mockTo_toEmail_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'toEmail' +type mockTo_toEmail_Call struct { + *mock.Call +} + +// toEmail is a helper method to define mock.On call +func (_e *mockTo_Expecter) toEmail() *mockTo_toEmail_Call { + return &mockTo_toEmail_Call{Call: _e.mock.On("toEmail")} +} + +func (_c *mockTo_toEmail_Call) Run(run func()) *mockTo_toEmail_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *mockTo_toEmail_Call) Return(_a0 string, _a1 localize.Lang) *mockTo_toEmail_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockTo_toEmail_Call) RunAndReturn(run func() (string, localize.Lang)) *mockTo_toEmail_Call { + _c.Call.Return(run) + return _c +} + +// toMobile provides a mock function with given fields: +func (_m *mockTo) toMobile() (string, localize.Lang) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for toMobile") + } + + var r0 string + var r1 localize.Lang + if rf, ok := ret.Get(0).(func() (string, localize.Lang)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + if rf, ok := ret.Get(1).(func() localize.Lang); ok { + r1 = rf() + } else { + r1 = ret.Get(1).(localize.Lang) + } + + return r0, r1 +} + +// mockTo_toMobile_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'toMobile' +type mockTo_toMobile_Call struct { + *mock.Call +} + +// toMobile is a helper method to define mock.On call +func (_e *mockTo_Expecter) toMobile() *mockTo_toMobile_Call { + return &mockTo_toMobile_Call{Call: _e.mock.On("toMobile")} +} + +func (_c *mockTo_toMobile_Call) Run(run func()) *mockTo_toMobile_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *mockTo_toMobile_Call) Return(_a0 string, _a1 localize.Lang) *mockTo_toMobile_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockTo_toMobile_Call) RunAndReturn(run func() (string, localize.Lang)) *mockTo_toMobile_Call { + _c.Call.Return(run) + return _c +} + +// newMockTo creates a new instance of mockTo. 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 newMockTo(t interface { + mock.TestingT + Cleanup(func()) +}) *mockTo { + mock := &mockTo{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/notify/to.go b/internal/notify/to.go new file mode 100644 index 0000000000..304b506dae --- /dev/null +++ b/internal/notify/to.go @@ -0,0 +1,142 @@ +package notify + +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/localize" + "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" +) + +type To interface { + ToEmail + ToMobile +} + +type ToEmail interface { + toEmail() (string, localize.Lang) + ignore() bool +} + +type ToMobile interface { + toMobile() (string, localize.Lang) + ignore() bool +} + +type to struct { + email string + mobile string + lang localize.Lang + ignored bool +} + +func (t to) toEmail() (string, localize.Lang) { return t.email, t.lang } +func (t to) toMobile() (string, localize.Lang) { return t.mobile, t.lang } +func (t to) ignore() bool { return t.ignored } + +func ToDonor(donor *donordata.Provided) To { + to := to{ + mobile: donor.Donor.Mobile, + email: donor.Donor.Email, + lang: donor.Donor.ContactLanguagePreference, + } + + if donor.Correspondent.Email != "" { + to.email = donor.Correspondent.Email + } + if donor.Correspondent.Phone != "" { + to.mobile = donor.Correspondent.Phone + } + + return to +} + +func ToLpaDonor(lpa *lpadata.Lpa) To { + to := to{ + mobile: lpa.Donor.Mobile, + email: lpa.Donor.Email, + lang: lpa.Donor.ContactLanguagePreference, + } + + if lpa.Correspondent.Email != "" { + to.email = lpa.Correspondent.Email + } + if lpa.Correspondent.Phone != "" { + to.mobile = lpa.Correspondent.Phone + } + + return to +} + +// ToCertificateProvider should only be used for the initial communication with +// the certificate provider, after that it may be possible to use the data they +// have entered so only use this as a fallback. +func ToCertificateProvider(certificateProvider donordata.CertificateProvider) To { + return to{ + mobile: certificateProvider.Mobile, + email: certificateProvider.Email, + lang: localize.En, + } +} + +func ToProvidedCertificateProvider(provided *certificateproviderdata.Provided, certificateProvider donordata.CertificateProvider) To { + return to{ + mobile: certificateProvider.Mobile, + email: provided.Email, + lang: provided.ContactLanguagePreference, + } +} + +func ToLpaCertificateProvider(provided *certificateproviderdata.Provided, lpa *lpadata.Lpa) To { + return to{ + mobile: lpa.CertificateProvider.Phone, + email: lpa.CertificateProvider.Email, + lang: provided.ContactLanguagePreference, + } +} + +func ToLpaAttorney(attorney lpadata.Attorney) To { + return to{ + mobile: attorney.Mobile, + email: attorney.Email, + lang: attorney.ContactLanguagePreference, + ignored: attorney.Removed, + } +} + +func ToLpaTrustCorporation(trustCorporation lpadata.TrustCorporation) To { + return to{ + mobile: trustCorporation.Mobile, + email: trustCorporation.Email, + lang: trustCorporation.ContactLanguagePreference, + ignored: trustCorporation.Removed, + } +} + +func ToIndependentWitness(independentWitness donordata.IndependentWitness) ToMobile { + return to{ + mobile: independentWitness.Mobile, + lang: localize.En, + } +} + +func ToVoucher(voucher donordata.Voucher) ToEmail { + return to{ + email: voucher.Email, + lang: localize.En, + } +} + +func ToPayee(resp pay.GetPaymentResponse) ToEmail { + return to{ + email: resp.Email, + lang: localize.En, + } +} + +func ToCustomEmail(lang localize.Lang, email string) ToEmail { + return to{ + lang: lang, + email: email, + } +} diff --git a/internal/notify/to_test.go b/internal/notify/to_test.go new file mode 100644 index 0000000000..ed7d51e513 --- /dev/null +++ b/internal/notify/to_test.go @@ -0,0 +1,221 @@ +package notify + +import ( + "testing" + + "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/localize" + "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" + "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" + "github.com/stretchr/testify/assert" +) + +func TestToDonor(t *testing.T) { + to := ToDonor(&donordata.Provided{ + Donor: donordata.Donor{Mobile: "0777", Email: "a@b.c", ContactLanguagePreference: localize.Cy}, + }) + + email, lang := to.toEmail() + assert.Equal(t, "a@b.c", email) + assert.Equal(t, localize.Cy, lang) + + mobile, lang := to.toMobile() + assert.Equal(t, "0777", mobile) + assert.Equal(t, localize.Cy, lang) + + assert.False(t, to.ignore()) +} + +func TestToDonorWhenCorrespondent(t *testing.T) { + to := ToDonor(&donordata.Provided{ + Donor: donordata.Donor{Mobile: "0777", Email: "a@b.c", ContactLanguagePreference: localize.Cy}, + Correspondent: donordata.Correspondent{Phone: "0779", Email: "d@e.f"}, + }) + + email, lang := to.toEmail() + assert.Equal(t, "d@e.f", email) + assert.Equal(t, localize.Cy, lang) + + mobile, lang := to.toMobile() + assert.Equal(t, "0779", mobile) + assert.Equal(t, localize.Cy, lang) + + assert.False(t, to.ignore()) +} + +func TestToLpaDonor(t *testing.T) { + to := ToLpaDonor(&lpadata.Lpa{ + Donor: lpadata.Donor{Mobile: "0777", Email: "a@b.c", ContactLanguagePreference: localize.Cy}, + }) + + email, lang := to.toEmail() + assert.Equal(t, "a@b.c", email) + assert.Equal(t, localize.Cy, lang) + + mobile, lang := to.toMobile() + assert.Equal(t, "0777", mobile) + assert.Equal(t, localize.Cy, lang) + + assert.False(t, to.ignore()) +} + +func TestToLpaDonorWhenCorrespondent(t *testing.T) { + to := ToLpaDonor(&lpadata.Lpa{ + Donor: lpadata.Donor{Mobile: "0777", Email: "a@b.c", ContactLanguagePreference: localize.Cy}, + Correspondent: lpadata.Correspondent{Phone: "0779", Email: "d@e.f"}, + }) + + email, lang := to.toEmail() + assert.Equal(t, "d@e.f", email) + assert.Equal(t, localize.Cy, lang) + + mobile, lang := to.toMobile() + assert.Equal(t, "0779", mobile) + assert.Equal(t, localize.Cy, lang) + + assert.False(t, to.ignore()) +} + +func TestToCertificateProvider(t *testing.T) { + to := ToCertificateProvider(donordata.CertificateProvider{ + Mobile: "0777", + Email: "a@b.c", + }) + + email, lang := to.toEmail() + assert.Equal(t, "a@b.c", email) + assert.Equal(t, localize.En, lang) + + mobile, lang := to.toMobile() + assert.Equal(t, "0777", mobile) + assert.Equal(t, localize.En, lang) + + assert.False(t, to.ignore()) +} + +func TestToProvidedCertificateProvider(t *testing.T) { + to := ToProvidedCertificateProvider(&certificateproviderdata.Provided{ + Email: "d@e.f", + ContactLanguagePreference: localize.Cy, + }, donordata.CertificateProvider{ + Mobile: "0777", + Email: "a@b.c", + }) + + email, lang := to.toEmail() + assert.Equal(t, "d@e.f", email) + assert.Equal(t, localize.Cy, lang) + + mobile, lang := to.toMobile() + assert.Equal(t, "0777", mobile) + assert.Equal(t, localize.Cy, lang) + + assert.False(t, to.ignore()) +} + +func TestToLpaCertificateProvider(t *testing.T) { + to := ToLpaCertificateProvider(&certificateproviderdata.Provided{ + Email: "d@e.f", + ContactLanguagePreference: localize.Cy, + }, &lpadata.Lpa{ + CertificateProvider: lpadata.CertificateProvider{ + Phone: "0777", + Email: "a@b.c", + }, + }) + + email, lang := to.toEmail() + assert.Equal(t, "a@b.c", email) + assert.Equal(t, localize.Cy, lang) + + mobile, lang := to.toMobile() + assert.Equal(t, "0777", mobile) + assert.Equal(t, localize.Cy, lang) + + assert.False(t, to.ignore()) +} + +func TestToLpaAttorney(t *testing.T) { + to := ToLpaAttorney(lpadata.Attorney{ + Mobile: "0777", + Email: "a@b.c", + ContactLanguagePreference: localize.Cy, + Removed: true, + }) + + email, lang := to.toEmail() + assert.Equal(t, "a@b.c", email) + assert.Equal(t, localize.Cy, lang) + + mobile, lang := to.toMobile() + assert.Equal(t, "0777", mobile) + assert.Equal(t, localize.Cy, lang) + + assert.True(t, to.ignore()) +} + +func TestToLpaTrustCorporation(t *testing.T) { + to := ToLpaTrustCorporation(lpadata.TrustCorporation{ + Mobile: "0777", + Email: "a@b.c", + ContactLanguagePreference: localize.Cy, + Removed: true, + }) + + email, lang := to.toEmail() + assert.Equal(t, "a@b.c", email) + assert.Equal(t, localize.Cy, lang) + + mobile, lang := to.toMobile() + assert.Equal(t, "0777", mobile) + assert.Equal(t, localize.Cy, lang) + + assert.True(t, to.ignore()) +} + +func TestToIndependentWitness(t *testing.T) { + to := ToIndependentWitness(donordata.IndependentWitness{ + Mobile: "0777", + }) + + mobile, lang := to.toMobile() + assert.Equal(t, "0777", mobile) + assert.Equal(t, localize.En, lang) + + assert.False(t, to.ignore()) +} + +func TestToVoucher(t *testing.T) { + to := ToVoucher(donordata.Voucher{ + Email: "a@b.c", + }) + + email, lang := to.toEmail() + assert.Equal(t, "a@b.c", email) + assert.Equal(t, localize.En, lang) + + assert.False(t, to.ignore()) +} + +func TestToPayee(t *testing.T) { + to := ToPayee(pay.GetPaymentResponse{ + Email: "a@b.c", + }) + + email, lang := to.toEmail() + assert.Equal(t, "a@b.c", email) + assert.Equal(t, localize.En, lang) + + assert.False(t, to.ignore()) +} + +func TestToCustomEmail(t *testing.T) { + to := ToCustomEmail(localize.Cy, "a@b.c") + + email, lang := to.toEmail() + assert.Equal(t, "a@b.c", email) + assert.Equal(t, localize.Cy, lang) + + assert.False(t, to.ignore()) +} diff --git a/internal/page/fixtures/attorney.go b/internal/page/fixtures/attorney.go index 7f50bec03c..c0bb2eb4c6 100644 --- a/internal/page/fixtures/attorney.go +++ b/internal/page/fixtures/attorney.go @@ -22,6 +22,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/random" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" + "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode/sharecodedata" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" "github.com/ministryofjustice/opg-modernising-lpa/internal/uid" @@ -47,7 +48,7 @@ type AttorneyStore interface { func Attorney( tmpl template.Template, sessionStore *sesh.Store, - shareCodeSender ShareCodeSender, + shareCodeSender *sharecode.Sender, donorStore DonorStore, certificateProviderStore CertificateProviderStore, attorneyStore AttorneyStore, diff --git a/internal/page/fixtures/certificate_provider.go b/internal/page/fixtures/certificate_provider.go index b8fed1e0a0..5f81a8c6fa 100644 --- a/internal/page/fixtures/certificate_provider.go +++ b/internal/page/fixtures/certificate_provider.go @@ -16,6 +16,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "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" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/random" @@ -29,7 +30,7 @@ import ( func CertificateProvider( tmpl template.Template, sessionStore *sesh.Store, - shareCodeSender ShareCodeSender, + shareCodeSender *sharecode.Sender, donorStore DonorStore, certificateProviderStore CertificateProviderStore, eventClient *event.Client, @@ -229,8 +230,7 @@ func CertificateProvider( DonorFullName: donorDetails.Donor.FullName(), CertificateProviderUID: donorDetails.CertificateProvider.UID, CertificateProviderFullName: donorDetails.CertificateProvider.FullName(), - CertificateProviderEmail: donorDetails.CertificateProvider.Email, - }) + }, notify.ToCertificateProvider(donorDetails.CertificateProvider)) switch redirect { case "": diff --git a/internal/page/fixtures/fixtures.go b/internal/page/fixtures/fixtures.go index dcd47d36d4..4095bf3ba7 100644 --- a/internal/page/fixtures/fixtures.go +++ b/internal/page/fixtures/fixtures.go @@ -19,19 +19,12 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/random" - "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode/sharecodedata" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/ministryofjustice/opg-modernising-lpa/internal/voucher" "github.com/ministryofjustice/opg-modernising-lpa/internal/voucher/voucherdata" ) -type ShareCodeSender interface { - SendCertificateProviderInvite(context context.Context, appData appcontext.Data, invite sharecode.CertificateProviderInvite) error - SendAttorneys(context context.Context, appData appcontext.Data, donorProvided *lpadata.Lpa) error - UseTestCode(shareCode string) -} - const ( testEmail = "simulate-delivered@notifications.service.gov.uk" testMobile = "07700900000" diff --git a/internal/scheduled/mock_NotifyClient_test.go b/internal/scheduled/mock_NotifyClient_test.go index cd3e664f7b..f0e7bfe7f8 100644 --- a/internal/scheduled/mock_NotifyClient_test.go +++ b/internal/scheduled/mock_NotifyClient_test.go @@ -5,10 +5,8 @@ package scheduled import ( context "context" - localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" - mock "github.com/stretchr/testify/mock" - 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 @@ -24,17 +22,17 @@ func (_m *mockNotifyClient) EXPECT() *mockNotifyClient_Expecter { return &mockNotifyClient_Expecter{mock: &_m.Mock} } -// 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) +// SendActorEmail provides a mock function with given fields: ctx, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email) error { + ret := _m.Called(ctx, 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, localize.Lang, string, string, notify.Email) error); ok { - r0 = rf(ctx, lang, to, lpaUID, email) + if rf, ok := ret.Get(0).(func(context.Context, notify.ToEmail, string, notify.Email) error); ok { + r0 = rf(ctx, to, lpaUID, email) } else { r0 = ret.Error(0) } @@ -49,17 +47,16 @@ type mockNotifyClient_SendActorEmail_Call struct { // SendActorEmail is a helper method to define mock.On call // - ctx context.Context -// - lang localize.Lang -// - to string +// - to notify.ToEmail // - lpaUID string // - email notify.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 (_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 (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.Email)) + run(args[0].(context.Context), args[1].(notify.ToEmail), args[2].(string), args[3].(notify.Email)) }) return _c } @@ -69,7 +66,7 @@ func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyCli return _c } -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, notify.ToEmail, 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 1b6fa4bc8c..748a756173 100644 --- a/internal/scheduled/runner.go +++ b/internal/scheduled/runner.go @@ -13,7 +13,6 @@ 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/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -34,7 +33,7 @@ type DonorStore interface { } type NotifyClient interface { - SendActorEmail(ctx context.Context, lang localize.Lang, to, lpaUID string, email notify.Email) error + SendActorEmail(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email) error } type Logger interface { @@ -211,7 +210,7 @@ func (r *Runner) stepCancelDonorIdentity(ctx context.Context, row *Event) error provided.IdentityUserData = identity.UserData{Status: identity.StatusExpired} provided.Tasks.ConfirmYourIdentity = task.IdentityStateNotStarted - if err := r.notifyClient.SendActorEmail(ctx, provided.Donor.ContactLanguagePreference, provided.CorrespondentEmail(), provided.LpaUID, notify.DonorIdentityCheckExpiredEmail{}); err != nil { + if err := r.notifyClient.SendActorEmail(ctx, notify.ToDonor(provided), 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 b0d79167a5..017fb629c7 100644 --- a/internal/scheduled/runner_test.go +++ b/internal/scheduled/runner_test.go @@ -458,14 +458,16 @@ func TestRunnerCancelDonorIdentity(t *testing.T) { TargetLpaOwnerKey: donorKey, } + provided := &donordata.Provided{ + LpaUID: "lpa-uid", + Donor: donordata.Donor{Email: "donor@example.com", ContactLanguagePreference: localize.Cy}, + IdentityUserData: identity.UserData{Status: identity.StatusConfirmed}, + } + donorStore := newMockDonorStore(t) donorStore.EXPECT(). One(ctx, lpaKey, donorKey). - Return(&donordata.Provided{ - LpaUID: "lpa-uid", - Donor: donordata.Donor{Email: "donor@example.com", ContactLanguagePreference: localize.Cy}, - IdentityUserData: identity.UserData{Status: identity.StatusConfirmed}, - }, nil) + Return(provided, nil) donorStore.EXPECT(). Put(ctx, &donordata.Provided{ LpaUID: "lpa-uid", @@ -476,7 +478,7 @@ func TestRunnerCancelDonorIdentity(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.Cy, "donor@example.com", "lpa-uid", notify.DonorIdentityCheckExpiredEmail{}). + SendActorEmail(ctx, notify.ToDonor(provided), "lpa-uid", notify.DonorIdentityCheckExpiredEmail{}). Return(nil) runner := &Runner{ @@ -559,7 +561,7 @@ func TestRunnerCancelDonorIdentityWhenNotifySendErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) runner := &Runner{ @@ -591,7 +593,7 @@ func TestRunnerCancelDonorIdentityWhenDonorStorePutErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) runner := &Runner{ diff --git a/internal/sharecode/mock_CertificateProviderStore_test.go b/internal/sharecode/mock_CertificateProviderStore_test.go new file mode 100644 index 0000000000..70bbe7d707 --- /dev/null +++ b/internal/sharecode/mock_CertificateProviderStore_test.go @@ -0,0 +1,96 @@ +// Code generated by mockery. DO NOT EDIT. + +package sharecode + +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: ctx +func (_m *mockCertificateProviderStore) GetAny(ctx context.Context) (*certificateproviderdata.Provided, error) { + ret := _m.Called(ctx) + + 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(ctx) + } + if rf, ok := ret.Get(0).(func(context.Context) *certificateproviderdata.Provided); ok { + r0 = rf(ctx) + } 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(ctx) + } 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 +// - ctx context.Context +func (_e *mockCertificateProviderStore_Expecter) GetAny(ctx interface{}) *mockCertificateProviderStore_GetAny_Call { + return &mockCertificateProviderStore_GetAny_Call{Call: _e.mock.On("GetAny", ctx)} +} + +func (_c *mockCertificateProviderStore_GetAny_Call) Run(run func(ctx 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/sharecode/mock_NotifyClient_test.go b/internal/sharecode/mock_NotifyClient_test.go index 4739928e3f..9dcd3bf6cd 100644 --- a/internal/sharecode/mock_NotifyClient_test.go +++ b/internal/sharecode/mock_NotifyClient_test.go @@ -5,10 +5,8 @@ package sharecode import ( context "context" - localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" - mock "github.com/stretchr/testify/mock" - 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 @@ -24,17 +22,17 @@ func (_m *mockNotifyClient) EXPECT() *mockNotifyClient_Expecter { return &mockNotifyClient_Expecter{mock: &_m.Mock} } -// 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) +// SendActorEmail provides a mock function with given fields: _a0, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(_a0 context.Context, to notify.ToEmail, 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, localize.Lang, string, string, notify.Email) error); ok { - r0 = rf(_a0, lang, to, lpaUID, email) + if rf, ok := ret.Get(0).(func(context.Context, notify.ToEmail, string, notify.Email) error); ok { + r0 = rf(_a0, to, lpaUID, email) } else { r0 = ret.Error(0) } @@ -49,17 +47,16 @@ type mockNotifyClient_SendActorEmail_Call struct { // SendActorEmail is a helper method to define mock.On call // - _a0 context.Context -// - lang localize.Lang -// - to string +// - to notify.ToEmail // - lpaUID string // - email notify.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 (_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, lang localize.Lang, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(_a0 context.Context, to notify.ToEmail, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.Email)) + run(args[0].(context.Context), args[1].(notify.ToEmail), args[2].(string), args[3].(notify.Email)) }) return _c } @@ -69,22 +66,22 @@ func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyCli return _c } -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, notify.ToEmail, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { _c.Call.Return(run) return _c } -// 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) +// SendActorSMS provides a mock function with given fields: _a0, to, lpaUID, sms +func (_m *mockNotifyClient) SendActorSMS(_a0 context.Context, to notify.ToMobile, 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, localize.Lang, string, string, notify.SMS) error); ok { - r0 = rf(_a0, lang, to, lpaUID, sms) + if rf, ok := ret.Get(0).(func(context.Context, notify.ToMobile, string, notify.SMS) error); ok { + r0 = rf(_a0, to, lpaUID, sms) } else { r0 = ret.Error(0) } @@ -99,17 +96,16 @@ type mockNotifyClient_SendActorSMS_Call struct { // SendActorSMS is a helper method to define mock.On call // - _a0 context.Context -// - lang localize.Lang -// - to string +// - to notify.ToMobile // - lpaUID string // - sms notify.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 (_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, lang localize.Lang, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(_a0 context.Context, to notify.ToMobile, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.SMS)) + run(args[0].(context.Context), args[1].(notify.ToMobile), args[2].(string), args[3].(notify.SMS)) }) return _c } @@ -119,7 +115,7 @@ func (_c *mockNotifyClient_SendActorSMS_Call) Return(_a0 error) *mockNotifyClien return _c } -func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, notify.ToMobile, 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 6664674365..76f412c4b1 100644 --- a/internal/sharecode/sender.go +++ b/internal/sharecode/sender.go @@ -8,6 +8,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + "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/dynamo" @@ -39,8 +40,8 @@ type ShareCodeStore interface { } type NotifyClient interface { - 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 + SendActorEmail(context context.Context, to notify.ToEmail, lpaUID string, email notify.Email) error + SendActorSMS(context context.Context, to notify.ToMobile, lpaUID string, sms notify.SMS) error } type EventClient interface { @@ -49,22 +50,28 @@ type EventClient interface { SendPaperFormRequested(ctx context.Context, paperFormRequestedEvent event.PaperFormRequested) error } +type CertificateProviderStore interface { + GetAny(ctx context.Context) (*certificateproviderdata.Provided, error) +} + type Sender struct { - testCode string - shareCodeStore ShareCodeStore - notifyClient NotifyClient - appPublicURL string - randomString func(int) string - eventClient EventClient + testCode string + shareCodeStore ShareCodeStore + certificateProviderStore CertificateProviderStore + notifyClient NotifyClient + appPublicURL string + randomString func(int) string + eventClient EventClient } -func NewSender(shareCodeStore ShareCodeStore, notifyClient NotifyClient, appPublicURL string, randomString func(int) string, eventClient EventClient) *Sender { +func NewSender(shareCodeStore ShareCodeStore, notifyClient NotifyClient, appPublicURL string, randomString func(int) string, eventClient EventClient, certificateProviderStore CertificateProviderStore) *Sender { return &Sender{ - shareCodeStore: shareCodeStore, - notifyClient: notifyClient, - appPublicURL: appPublicURL, - randomString: randomString, - eventClient: eventClient, + shareCodeStore: shareCodeStore, + notifyClient: notifyClient, + appPublicURL: appPublicURL, + randomString: randomString, + eventClient: eventClient, + certificateProviderStore: certificateProviderStore, } } @@ -81,23 +88,27 @@ type CertificateProviderInvite struct { DonorFullName string CertificateProviderUID actoruid.UID CertificateProviderFullName string - CertificateProviderEmail string } -func (s *Sender) SendCertificateProviderInvite(ctx context.Context, appData appcontext.Data, invite CertificateProviderInvite) error { +func (s *Sender) SendCertificateProviderInvite(ctx context.Context, appData appcontext.Data, invite CertificateProviderInvite, to notify.ToEmail) error { shareCode, err := s.createShareCode(ctx, invite.LpaKey, invite.LpaOwnerKey, invite.CertificateProviderUID, actor.TypeCertificateProvider) if err != nil { return err } - return s.sendEmail(ctx, invite.CertificateProviderEmail, invite.LpaUID, notify.CertificateProviderInviteEmail{ + whatLpaCovers := "whatPropertyAndAffairsCovers" + if invite.Type.IsPersonalWelfare() { + whatLpaCovers = "whatPersonalWelfareCovers" + } + + return s.sendEmail(ctx, to, invite.LpaUID, notify.CertificateProviderInviteEmail{ CertificateProviderFullName: invite.CertificateProviderFullName, DonorFullName: invite.DonorFullName, LpaType: localize.LowerFirst(appData.Localizer.T(invite.Type.String())), CertificateProviderStartURL: fmt.Sprintf("%s%s", s.appPublicURL, page.PathCertificateProviderStart), DonorFirstNames: invite.DonorFirstNames, DonorFirstNamesPossessive: appData.Localizer.Possessive(invite.DonorFirstNames), - WhatLpaCovers: appData.Localizer.T(invite.Type.WhatLPACoversTransKey()), + WhatLpaCovers: appData.Localizer.T(whatLpaCovers), ShareCode: shareCode, CertificateProviderOptOutURL: fmt.Sprintf("%s%s", s.appPublicURL, page.PathCertificateProviderEnterReferenceNumberOptOut), }) @@ -113,7 +124,12 @@ func (s *Sender) SendCertificateProviderPrompt(ctx context.Context, appData appc return s.sendPaperForm(ctx, donor.LpaUID, actor.TypeCertificateProvider, donor.CertificateProvider.UID, shareCode) } - return s.sendEmail(ctx, donor.CertificateProvider.Email, donor.LpaUID, notify.CertificateProviderProvideCertificatePromptEmail{ + to := notify.ToCertificateProvider(donor.CertificateProvider) + if certificateProvider, err := s.certificateProviderStore.GetAny(ctx); err == nil { + to = notify.ToProvidedCertificateProvider(certificateProvider, donor.CertificateProvider) + } + + return s.sendEmail(ctx, to, donor.LpaUID, notify.CertificateProviderProvideCertificatePromptEmail{ CertificateProviderFullName: donor.CertificateProvider.FullName(), DonorFullName: donor.Donor.FullName(), LpaType: localize.LowerFirst(appData.Localizer.T(donor.Type.String())), @@ -145,39 +161,39 @@ func (s *Sender) SendAttorneys(ctx context.Context, appData appcontext.Data, don return nil } -func (s *Sender) SendVoucherAccessCode(ctx context.Context, donor *donordata.Provided, appData appcontext.Data) error { - shareCode, err := s.createShareCode(ctx, donor.PK, donor.SK, donor.Voucher.UID, actor.TypeVoucher) +func (s *Sender) SendVoucherAccessCode(ctx context.Context, provided *donordata.Provided, appData appcontext.Data) error { + shareCode, err := s.createShareCode(ctx, provided.PK, provided.SK, provided.Voucher.UID, actor.TypeVoucher) if err != nil { return err } - if donor.Donor.Mobile != "" { - if err := s.sendSMS(ctx, donor.Donor.Mobile, donor.LpaUID, notify.VouchingShareCodeSMS{ + if provided.Donor.Mobile != "" { + if err := s.sendSMS(ctx, notify.ToDonor(provided), provided.LpaUID, notify.VouchingShareCodeSMS{ ShareCode: shareCode, - DonorFullNamePossessive: appData.Localizer.Possessive(donor.Donor.FullName()), - LpaType: appData.Localizer.T(donor.Type.String()), - VoucherFullName: donor.Voucher.FullName(), - DonorFirstNamesPossessive: appData.Localizer.Possessive(donor.Donor.FirstNames), + DonorFullNamePossessive: appData.Localizer.Possessive(provided.Donor.FullName()), + LpaType: appData.Localizer.T(provided.Type.String()), + VoucherFullName: provided.Voucher.FullName(), + DonorFirstNamesPossessive: appData.Localizer.Possessive(provided.Donor.FirstNames), }); err != nil { return err } } else { - if err := s.sendEmail(ctx, donor.Donor.Email, donor.LpaUID, notify.VouchingShareCodeEmail{ + if err := s.sendEmail(ctx, notify.ToDonor(provided), provided.LpaUID, notify.VouchingShareCodeEmail{ ShareCode: shareCode, - VoucherFullName: donor.Voucher.FullName(), - DonorFullName: donor.Donor.FullName(), - LpaType: appData.Localizer.T(donor.Type.String()), + VoucherFullName: provided.Voucher.FullName(), + DonorFullName: provided.Donor.FullName(), + LpaType: appData.Localizer.T(provided.Type.String()), }); err != nil { return err } } - return s.sendEmail(ctx, donor.Voucher.Email, donor.LpaUID, notify.VoucherInviteEmail{ - VoucherFullName: donor.Voucher.FullName(), - DonorFullName: donor.Donor.FullName(), - DonorFirstNamesPossessive: appData.Localizer.Possessive(donor.Donor.FirstNames), - DonorFirstNames: donor.Donor.FirstNames, - LpaType: appData.Localizer.T(donor.Type.String()), + return s.sendEmail(ctx, notify.ToVoucher(provided.Voucher), provided.LpaUID, notify.VoucherInviteEmail{ + VoucherFullName: provided.Voucher.FullName(), + DonorFullName: provided.Donor.FullName(), + DonorFirstNamesPossessive: appData.Localizer.Possessive(provided.Donor.FirstNames), + DonorFirstNames: provided.Donor.FirstNames, + LpaType: appData.Localizer.T(provided.Type.String()), VoucherStartPageURL: s.appPublicURL + page.PathVoucherStart.Format(), }) } @@ -196,7 +212,7 @@ func (s *Sender) sendOriginalAttorney(ctx context.Context, appData appcontext.Da return s.sendPaperForm(ctx, lpa.LpaUID, actor.TypeAttorney, attorney.UID, shareCode) } - return s.sendEmail(ctx, attorney.Email, lpa.LpaUID, + return s.sendEmail(ctx, notify.ToLpaAttorney(attorney), lpa.LpaUID, notify.InitialOriginalAttorneyEmail{ AttorneyFullName: attorney.FullName(), DonorFirstNames: lpa.Donor.FirstNames, @@ -223,7 +239,7 @@ func (s *Sender) sendReplacementAttorney(ctx context.Context, appData appcontext return s.sendPaperForm(ctx, lpa.LpaUID, actor.TypeReplacementAttorney, attorney.UID, shareCode) } - return s.sendEmail(ctx, attorney.Email, lpa.LpaUID, + return s.sendEmail(ctx, notify.ToLpaAttorney(attorney), lpa.LpaUID, notify.InitialReplacementAttorneyEmail{ AttorneyFullName: attorney.FullName(), DonorFirstNames: lpa.Donor.FirstNames, @@ -254,7 +270,7 @@ func (s *Sender) sendTrustCorporation(ctx context.Context, appData appcontext.Da return s.sendPaperForm(ctx, lpa.LpaUID, actor.TypeTrustCorporation, trustCorporation.UID, shareCode) } - return s.sendEmail(ctx, trustCorporation.Email, lpa.LpaUID, + return s.sendEmail(ctx, notify.ToLpaTrustCorporation(trustCorporation), lpa.LpaUID, notify.InitialOriginalAttorneyEmail{ AttorneyFullName: trustCorporation.Name, DonorFirstNames: lpa.Donor.FirstNames, @@ -285,7 +301,7 @@ func (s *Sender) sendReplacementTrustCorporation(ctx context.Context, appData ap return s.sendPaperForm(ctx, lpa.LpaUID, actor.TypeReplacementTrustCorporation, trustCorporation.UID, shareCode) } - return s.sendEmail(ctx, trustCorporation.Email, lpa.LpaUID, + return s.sendEmail(ctx, notify.ToLpaTrustCorporation(trustCorporation), lpa.LpaUID, notify.InitialReplacementAttorneyEmail{ AttorneyFullName: trustCorporation.Name, DonorFirstNames: lpa.Donor.FirstNames, @@ -320,16 +336,16 @@ func (s *Sender) createShareCode(ctx context.Context, lpaKey dynamo.LpaKeyType, return shareCode, nil } -func (s *Sender) sendEmail(ctx context.Context, to string, lpaUID string, email notify.Email) error { - if err := s.notifyClient.SendActorEmail(ctx, localize.En, to, lpaUID, email); err != nil { +func (s *Sender) sendEmail(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email) error { + if err := s.notifyClient.SendActorEmail(ctx, to, lpaUID, email); err != nil { return fmt.Errorf("email failed: %w", err) } return nil } -func (s *Sender) sendSMS(ctx context.Context, to, lpaUID string, sms notify.SMS) error { - if err := s.notifyClient.SendActorSMS(ctx, localize.En, to, lpaUID, sms); err != nil { +func (s *Sender) sendSMS(ctx context.Context, to notify.ToMobile, lpaUID string, sms notify.SMS) error { + if err := s.notifyClient.SendActorSMS(ctx, 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 a599fd94ea..ab60fc4148 100644 --- a/internal/sharecode/sender_test.go +++ b/internal/sharecode/sender_test.go @@ -9,6 +9,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + certificateproviderdata "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/event" @@ -47,13 +48,15 @@ func TestShareCodeSenderSendCertificateProviderInvite(t *testing.T) { LpaUID: "lpa-uid", } + to := notify.ToCertificateProvider(donor.CertificateProvider) + localizer := newMockLocalizer(t) localizer.EXPECT(). T(donor.Type.String()). Return("Property and affairs"). Once() localizer.EXPECT(). - T(donor.Type.WhatLPACoversTransKey()). + T("whatPropertyAndAffairsCovers"). Return("houses and stuff"). Once() localizer.EXPECT(). @@ -73,7 +76,7 @@ func TestShareCodeSenderSendCertificateProviderInvite(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.CertificateProviderInviteEmail{ + SendActorEmail(ctx, to, "lpa-uid", notify.CertificateProviderInviteEmail{ ShareCode: testRandomString, CertificateProviderFullName: "Joanna Jones", DonorFirstNames: "Jan", @@ -86,7 +89,7 @@ func TestShareCodeSenderSendCertificateProviderInvite(t *testing.T) { }). Return(nil) - sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil, nil) err := sender.SendCertificateProviderInvite(ctx, TestAppData, CertificateProviderInvite{ LpaKey: dynamo.LpaKey("lpa"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")), @@ -96,8 +99,7 @@ func TestShareCodeSenderSendCertificateProviderInvite(t *testing.T) { DonorFullName: donor.Donor.FullName(), CertificateProviderUID: donor.CertificateProvider.UID, CertificateProviderFullName: donor.CertificateProvider.FullName(), - CertificateProviderEmail: donor.CertificateProvider.Email, - }) + }, to) assert.Nil(t, err) } @@ -127,7 +129,7 @@ func TestShareCodeSenderSendCertificateProviderInviteWithTestCode(t *testing.T) FirstNames: "Jan", LastName: "Smith", }, - Type: lpadata.LpaTypePropertyAndAffairs, + Type: lpadata.LpaTypePersonalWelfare, LpaUID: "lpa-uid", } @@ -136,16 +138,17 @@ func TestShareCodeSenderSendCertificateProviderInviteWithTestCode(t *testing.T) localizer := newMockLocalizer(t) localizer.EXPECT(). T(donor.Type.String()). - Return("Property and affairs"). + Return("Personal welfare"). Twice() localizer.EXPECT(). Possessive("Jan"). Return("Jan’s") localizer.EXPECT(). - T(donor.Type.WhatLPACoversTransKey()). - Return("houses and stuff") + T("whatPersonalWelfareCovers"). + Return("health and stuff") TestAppData.Localizer = localizer + to := notify.ToCertificateProvider(donor.CertificateProvider) ctx := context.Background() shareCodeStore := newMockShareCodeStore(t) @@ -166,35 +169,35 @@ func TestShareCodeSenderSendCertificateProviderInviteWithTestCode(t *testing.T) notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.CertificateProviderInviteEmail{ + SendActorEmail(ctx, to, "lpa-uid", notify.CertificateProviderInviteEmail{ CertificateProviderFullName: "Joanna Jones", DonorFirstNames: "Jan", DonorFullName: "Jan Smith", - LpaType: "property and affairs", + LpaType: "personal welfare", CertificateProviderStartURL: fmt.Sprintf("http://app%s", page.PathCertificateProviderStart), ShareCode: tc.expectedTestCode, DonorFirstNamesPossessive: "Jan’s", - WhatLpaCovers: "houses and stuff", + WhatLpaCovers: "health and stuff", CertificateProviderOptOutURL: fmt.Sprintf("http://app%s", page.PathCertificateProviderEnterReferenceNumberOptOut), }). Once(). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.CertificateProviderInviteEmail{ + SendActorEmail(ctx, to, "lpa-uid", notify.CertificateProviderInviteEmail{ CertificateProviderFullName: "Joanna Jones", DonorFirstNames: "Jan", DonorFullName: "Jan Smith", - LpaType: "property and affairs", + LpaType: "personal welfare", CertificateProviderStartURL: fmt.Sprintf("http://app%s", page.PathCertificateProviderStart), ShareCode: testRandomString, DonorFirstNamesPossessive: "Jan’s", - WhatLpaCovers: "houses and stuff", + WhatLpaCovers: "health and stuff", CertificateProviderOptOutURL: fmt.Sprintf("http://app%s", page.PathCertificateProviderEnterReferenceNumberOptOut), }). Once(). Return(nil) - sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil, nil) if tc.useTestCode { sender.UseTestCode("abcdef123456") @@ -209,8 +212,7 @@ func TestShareCodeSenderSendCertificateProviderInviteWithTestCode(t *testing.T) DonorFullName: donor.Donor.FullName(), CertificateProviderUID: donor.CertificateProvider.UID, CertificateProviderFullName: donor.CertificateProvider.FullName(), - CertificateProviderEmail: donor.CertificateProvider.Email, - }) + }, to) assert.Nil(t, err) err = sender.SendCertificateProviderInvite(ctx, TestAppData, CertificateProviderInvite{ @@ -222,8 +224,7 @@ func TestShareCodeSenderSendCertificateProviderInviteWithTestCode(t *testing.T) DonorFullName: donor.Donor.FullName(), CertificateProviderUID: donor.CertificateProvider.UID, CertificateProviderFullName: donor.CertificateProvider.FullName(), - CertificateProviderEmail: donor.CertificateProvider.Email, - }) + }, to) assert.Nil(t, err) }) } @@ -245,6 +246,8 @@ func TestShareCodeSenderSendCertificateProviderInviteWhenEmailErrors(t *testing. Type: lpadata.LpaTypePropertyAndAffairs, } + to := notify.ToCertificateProvider(donor.CertificateProvider) + localizer := newMockLocalizer(t) localizer.EXPECT(). T(mock.Anything). @@ -261,10 +264,10 @@ func TestShareCodeSenderSendCertificateProviderInviteWhenEmailErrors(t *testing. notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil, nil) err := sender.SendCertificateProviderInvite(ctx, TestAppData, CertificateProviderInvite{ LpaUID: donor.LpaUID, Type: donor.Type, @@ -272,8 +275,7 @@ func TestShareCodeSenderSendCertificateProviderInviteWhenEmailErrors(t *testing. DonorFullName: donor.Donor.FullName(), CertificateProviderUID: donor.CertificateProvider.UID, CertificateProviderFullName: donor.CertificateProvider.FullName(), - CertificateProviderEmail: donor.CertificateProvider.Email, - }) + }, to) assert.Equal(t, expectedError, errors.Unwrap(err)) } @@ -286,8 +288,8 @@ func TestShareCodeSenderSendCertificateProviderInviteWhenShareCodeStoreErrors(t Put(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) - err := sender.SendCertificateProviderInvite(ctx, TestAppData, CertificateProviderInvite{}) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil, nil) + err := sender.SendCertificateProviderInvite(ctx, TestAppData, CertificateProviderInvite{}, notify.ToCustomEmail(localize.En, "")) assert.Equal(t, expectedError, errors.Unwrap(err)) } @@ -321,7 +323,69 @@ func TestShareCodeSenderSendCertificateProviderPromptOnline(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ + SendActorEmail(ctx, notify.ToCertificateProvider(donor.CertificateProvider), "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ + ShareCode: testRandomString, + CertificateProviderFullName: "Joanna Jones", + DonorFullName: "Jan Smith", + LpaType: "property and affairs", + CertificateProviderStartURL: fmt.Sprintf("http://app%s", page.PathCertificateProviderStart), + }). + Return(nil) + + shareCodeStore := newMockShareCodeStore(t) + shareCodeStore.EXPECT(). + Put(ctx, actor.TypeCertificateProvider, testRandomString, sharecodedata.Link{ + LpaKey: dynamo.LpaKey("lpa"), + LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")), + }). + Return(nil) + + certificateProviderStore := newMockCertificateProviderStore(t) + certificateProviderStore.EXPECT(). + GetAny(ctx). + Return(nil, expectedError) + + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil, certificateProviderStore) + err := sender.SendCertificateProviderPrompt(ctx, TestAppData, donor) + + assert.Nil(t, err) +} + +func TestShareCodeSenderSendCertificateProviderPromptOnlineWhenStarted(t *testing.T) { + donor := &donordata.Provided{ + CertificateProvider: donordata.CertificateProvider{ + FirstNames: "Joanna", + LastName: "Jones", + Email: "name@example.org", + CarryOutBy: lpadata.ChannelOnline, + }, + Donor: donordata.Donor{ + FirstNames: "Jan", + LastName: "Smith", + }, + Type: lpadata.LpaTypePropertyAndAffairs, + LpaUID: "lpa-uid", + PK: dynamo.LpaKey("lpa"), + SK: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")), + } + + certificateProvider := &certificateproviderdata.Provided{ + Email: "correct@example.com", + ContactLanguagePreference: localize.Cy, + } + + localizer := newMockLocalizer(t) + localizer.EXPECT(). + T(donor.Type.String()). + Return("Property and affairs"). + Once() + TestAppData.Localizer = localizer + + ctx := context.Background() + + notifyClient := newMockNotifyClient(t) + notifyClient.EXPECT(). + SendActorEmail(ctx, notify.ToProvidedCertificateProvider(certificateProvider, donor.CertificateProvider), "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ ShareCode: testRandomString, CertificateProviderFullName: "Joanna Jones", DonorFullName: "Jan Smith", @@ -338,7 +402,12 @@ func TestShareCodeSenderSendCertificateProviderPromptOnline(t *testing.T) { }). Return(nil) - sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + certificateProviderStore := newMockCertificateProviderStore(t) + certificateProviderStore.EXPECT(). + GetAny(ctx). + Return(certificateProvider, nil) + + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil, certificateProviderStore) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, donor) assert.Nil(t, err) @@ -386,7 +455,7 @@ func TestShareCodeSenderSendCertificateProviderPromptPaper(t *testing.T) { }). Return(nil) - sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient, nil) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, donor) assert.Nil(t, err) @@ -454,7 +523,7 @@ func TestShareCodeSenderSendCertificateProviderPromptWithTestCode(t *testing.T) notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ + SendActorEmail(ctx, notify.ToCertificateProvider(donor.CertificateProvider), "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ CertificateProviderFullName: "Joanna Jones", DonorFullName: "Jan Smith", LpaType: "property and affairs", @@ -464,7 +533,7 @@ func TestShareCodeSenderSendCertificateProviderPromptWithTestCode(t *testing.T) Once(). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ + SendActorEmail(ctx, notify.ToCertificateProvider(donor.CertificateProvider), "lpa-uid", notify.CertificateProviderProvideCertificatePromptEmail{ CertificateProviderFullName: "Joanna Jones", DonorFullName: "Jan Smith", LpaType: "property and affairs", @@ -474,7 +543,12 @@ func TestShareCodeSenderSendCertificateProviderPromptWithTestCode(t *testing.T) Once(). Return(nil) - sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + certificateProviderStore := newMockCertificateProviderStore(t) + certificateProviderStore.EXPECT(). + GetAny(ctx). + Return(nil, expectedError) + + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil, certificateProviderStore) if tc.useTestCode { sender.UseTestCode("abcdef123456") @@ -503,7 +577,7 @@ func TestShareCodeSenderSendCertificateProviderPromptPaperWhenShareCodeStoreErro Put(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil, nil) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, donor) assert.ErrorIs(t, err, expectedError) @@ -528,7 +602,7 @@ func TestShareCodeSenderSendCertificateProviderPromptPaperWhenEventClientError(t SendPaperFormRequested(mock.Anything, mock.Anything). Return(expectedError) - sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient, nil) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, donor) assert.Equal(t, expectedError, err) @@ -564,10 +638,15 @@ func TestShareCodeSenderSendCertificateProviderPromptWhenEmailErrors(t *testing. notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + certificateProviderStore := newMockCertificateProviderStore(t) + certificateProviderStore.EXPECT(). + GetAny(ctx). + Return(nil, expectedError) + + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil, certificateProviderStore) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, donor) assert.Equal(t, expectedError, errors.Unwrap(err)) @@ -581,7 +660,7 @@ func TestShareCodeSenderSendCertificateProviderPromptWhenShareCodeStoreErrors(t Put(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil, nil) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, &donordata.Provided{}) assert.Equal(t, expectedError, errors.Unwrap(err)) @@ -596,7 +675,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { replacement1UID := actoruid.New() replacement2UID := actoruid.New() - donor := &lpadata.Lpa{ + lpa := &lpadata.Lpa{ Attorneys: lpadata.Attorneys{ TrustCorporation: lpadata.TrustCorporation{ UID: trustCorporationUID, @@ -655,7 +734,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { localizer := newMockLocalizer(t) localizer.EXPECT(). - T(donor.Type.String()). + T(lpa.Type.String()). Return("property and affairs") localizer.EXPECT(). Possessive("Jan"). @@ -690,7 +769,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "trusted@example.com", "lpa-uid", notify.InitialOriginalAttorneyEmail{ + SendActorEmail(ctx, notify.ToLpaTrustCorporation(lpa.Attorneys.TrustCorporation), "lpa-uid", notify.InitialOriginalAttorneyEmail{ ShareCode: testRandomString, AttorneyFullName: "Trusty", DonorFirstNames: "Jan", @@ -702,7 +781,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { }). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "untrusted@example.com", "lpa-uid", notify.InitialReplacementAttorneyEmail{ + SendActorEmail(ctx, notify.ToLpaTrustCorporation(lpa.ReplacementAttorneys.TrustCorporation), "lpa-uid", notify.InitialReplacementAttorneyEmail{ ShareCode: testRandomString, AttorneyFullName: "Untrusty", DonorFirstNames: "Jan", @@ -714,7 +793,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { }). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.InitialOriginalAttorneyEmail{ + SendActorEmail(ctx, notify.ToLpaAttorney(lpa.Attorneys.Attorneys[0]), "lpa-uid", notify.InitialOriginalAttorneyEmail{ ShareCode: testRandomString, AttorneyFullName: "Joanna Jones", DonorFirstNames: "Jan", @@ -726,7 +805,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { }). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "name2@example.org", "lpa-uid", notify.InitialOriginalAttorneyEmail{ + SendActorEmail(ctx, notify.ToLpaAttorney(lpa.Attorneys.Attorneys[1]), "lpa-uid", notify.InitialOriginalAttorneyEmail{ ShareCode: testRandomString, AttorneyFullName: "John Jones", DonorFirstNames: "Jan", @@ -738,7 +817,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { }). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "dave@example.com", "lpa-uid", notify.InitialReplacementAttorneyEmail{ + SendActorEmail(ctx, notify.ToLpaAttorney(lpa.ReplacementAttorneys.Attorneys[0]), "lpa-uid", notify.InitialReplacementAttorneyEmail{ ShareCode: testRandomString, AttorneyFullName: "Dave Davis", DonorFirstNames: "Jan", @@ -769,49 +848,49 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { Return(nil) eventClient.EXPECT(). SendAttorneyStarted(ctx, event.AttorneyStarted{ - LpaUID: donor.LpaUID, + LpaUID: lpa.LpaUID, ActorUID: attorney1UID, }). Return(nil) eventClient.EXPECT(). SendAttorneyStarted(ctx, event.AttorneyStarted{ - LpaUID: donor.LpaUID, + LpaUID: lpa.LpaUID, ActorUID: attorney2UID, }). Return(nil) eventClient.EXPECT(). SendAttorneyStarted(ctx, event.AttorneyStarted{ - LpaUID: donor.LpaUID, + LpaUID: lpa.LpaUID, ActorUID: attorney3UID, }). Return(nil) eventClient.EXPECT(). SendAttorneyStarted(ctx, event.AttorneyStarted{ - LpaUID: donor.LpaUID, + LpaUID: lpa.LpaUID, ActorUID: trustCorporationUID, }). Return(nil) eventClient.EXPECT(). SendAttorneyStarted(ctx, event.AttorneyStarted{ - LpaUID: donor.LpaUID, + LpaUID: lpa.LpaUID, ActorUID: replacementTrustCorporationUID, }). Return(nil) eventClient.EXPECT(). SendAttorneyStarted(ctx, event.AttorneyStarted{ - LpaUID: donor.LpaUID, + LpaUID: lpa.LpaUID, ActorUID: replacement1UID, }). Return(nil) eventClient.EXPECT(). SendAttorneyStarted(ctx, event.AttorneyStarted{ - LpaUID: donor.LpaUID, + LpaUID: lpa.LpaUID, ActorUID: replacement2UID, }). Return(nil) - sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, eventClient) - err := sender.SendAttorneys(ctx, TestAppData, donor) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, eventClient, nil) + err := sender.SendAttorneys(ctx, TestAppData, lpa) assert.Nil(t, err) } @@ -893,7 +972,7 @@ func TestShareCodeSenderSendAttorneysTrustCorporationsNoEmail(t *testing.T) { }). Return(nil) - sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient, nil) err := sender.SendAttorneys(ctx, TestAppData, donor) assert.Nil(t, err) @@ -916,7 +995,7 @@ func TestShareCodeSenderSendAttorneysWithTestCode(t *testing.T) { }, } - donor := &lpadata.Lpa{ + lpa := &lpadata.Lpa{ Attorneys: lpadata.Attorneys{Attorneys: []lpadata.Attorney{ { FirstNames: "Joanna", @@ -937,7 +1016,7 @@ func TestShareCodeSenderSendAttorneysWithTestCode(t *testing.T) { localizer := newMockLocalizer(t) localizer.EXPECT(). - T(donor.Type.String()). + T(lpa.Type.String()). Return("property and affairs") localizer.EXPECT(). Possessive("Jan"). @@ -965,7 +1044,7 @@ func TestShareCodeSenderSendAttorneysWithTestCode(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.InitialOriginalAttorneyEmail{ + SendActorEmail(ctx, notify.ToLpaAttorney(lpa.Attorneys.Attorneys[0]), "lpa-uid", notify.InitialOriginalAttorneyEmail{ ShareCode: tc.expectedTestCode, AttorneyFullName: "Joanna Jones", DonorFirstNames: "Jan", @@ -977,7 +1056,7 @@ func TestShareCodeSenderSendAttorneysWithTestCode(t *testing.T) { }). Return(nil) notifyClient.EXPECT(). - SendActorEmail(ctx, localize.En, "name@example.org", "lpa-uid", notify.InitialOriginalAttorneyEmail{ + SendActorEmail(ctx, notify.ToLpaAttorney(lpa.Attorneys.Attorneys[0]), "lpa-uid", notify.InitialOriginalAttorneyEmail{ ShareCode: testRandomString, AttorneyFullName: "Joanna Jones", DonorFirstNames: "Jan", @@ -992,27 +1071,27 @@ func TestShareCodeSenderSendAttorneysWithTestCode(t *testing.T) { eventClient := newMockEventClient(t) eventClient.EXPECT(). SendAttorneyStarted(ctx, event.AttorneyStarted{ - LpaUID: donor.LpaUID, + LpaUID: lpa.LpaUID, ActorUID: uid, }). Return(nil) eventClient.EXPECT(). SendAttorneyStarted(ctx, event.AttorneyStarted{ - LpaUID: donor.LpaUID, + LpaUID: lpa.LpaUID, ActorUID: uid, }). Return(nil) - sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, eventClient) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, eventClient, nil) if tc.useTestCode { sender.UseTestCode("abcdef123456") } - err := sender.SendAttorneys(ctx, TestAppData, donor) + err := sender.SendAttorneys(ctx, TestAppData, lpa) assert.Nil(t, err) - err = sender.SendAttorneys(ctx, TestAppData, donor) + err = sender.SendAttorneys(ctx, TestAppData, lpa) assert.Nil(t, err) }) } @@ -1054,7 +1133,7 @@ func TestShareCodeSenderSendAttorneysWhenEmailErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) eventClient := newMockEventClient(t) @@ -1062,7 +1141,7 @@ func TestShareCodeSenderSendAttorneysWhenEmailErrors(t *testing.T) { SendAttorneyStarted(mock.Anything, mock.Anything). Return(nil) - sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, eventClient) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, eventClient, nil) err := sender.SendAttorneys(ctx, TestAppData, donor) assert.Equal(t, expectedError, errors.Unwrap(err)) @@ -1076,7 +1155,7 @@ func TestShareCodeSenderSendAttorneysWhenShareCodeStoreErrors(t *testing.T) { Put(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil, nil) err := sender.SendAttorneys(ctx, TestAppData, &lpadata.Lpa{ Attorneys: lpadata.Attorneys{Attorneys: []lpadata.Attorney{{Email: "hey@example.com"}}}, }) @@ -1124,7 +1203,7 @@ func TestShareCodeSenderSendAttorneysWhenEventClientErrors(t *testing.T) { SendAttorneyStarted(mock.Anything, mock.Anything). Return(expectedError) - sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient, nil) err := sender.SendAttorneys(ctx, TestAppData, lpa) assert.Equal(t, expectedError, err) @@ -1137,15 +1216,15 @@ func TestSendVoucherAccessCode(t *testing.T) { uid := actoruid.New() testcases := map[string]struct { - notifyClient func() *mockNotifyClient + notifyClient func(*donordata.Provided) *mockNotifyClient localizer func() *mockLocalizer donor donordata.Donor }{ "sms": { - notifyClient: func() *mockNotifyClient { + notifyClient: func(provided *donordata.Provided) *mockNotifyClient { nc := newMockNotifyClient(t) nc.EXPECT(). - SendActorSMS(ctx, localize.En, "123", "lpa-uid", notify.VouchingShareCodeSMS{ + SendActorSMS(ctx, notify.ToDonor(provided), "lpa-uid", notify.VouchingShareCodeSMS{ ShareCode: testRandomString, DonorFullNamePossessive: "Possessive full name", LpaType: "translated type", @@ -1154,7 +1233,7 @@ func TestSendVoucherAccessCode(t *testing.T) { }). Return(nil) nc.EXPECT(). - SendActorEmail(ctx, localize.En, "voucher@example.com", "lpa-uid", + SendActorEmail(ctx, notify.ToVoucher(provided.Voucher), "lpa-uid", notify.VoucherInviteEmail{ VoucherFullName: "c d", DonorFullName: "a b", @@ -1189,10 +1268,10 @@ func TestSendVoucherAccessCode(t *testing.T) { }, }, "email": { - notifyClient: func() *mockNotifyClient { + notifyClient: func(provided *donordata.Provided) *mockNotifyClient { nc := newMockNotifyClient(t) nc.EXPECT(). - SendActorEmail(ctx, localize.En, "donor@example.com", "lpa-uid", + SendActorEmail(ctx, notify.ToDonor(provided), "lpa-uid", notify.VouchingShareCodeEmail{ ShareCode: testRandomString, VoucherFullName: "c d", @@ -1201,7 +1280,7 @@ func TestSendVoucherAccessCode(t *testing.T) { }). Return(nil) nc.EXPECT(). - SendActorEmail(ctx, localize.En, "voucher@example.com", "lpa-uid", + SendActorEmail(ctx, notify.ToVoucher(provided.Voucher), "lpa-uid", notify.VoucherInviteEmail{ VoucherFullName: "c d", DonorFullName: "a b", @@ -1236,20 +1315,7 @@ func TestSendVoucherAccessCode(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - shareCodeStore := newMockShareCodeStore(t) - shareCodeStore.EXPECT(). - Put(ctx, actor.TypeVoucher, testRandomString, sharecodedata.Link{ - LpaKey: dynamo.LpaKey("lpa"), - LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")), - ActorUID: uid, - }). - Return(nil) - - sender := NewSender(shareCodeStore, tc.notifyClient(), "http://app", testRandomStringFn, nil) - - TestAppData.Localizer = tc.localizer() - - err := sender.SendVoucherAccessCode(ctx, &donordata.Provided{ + provided := &donordata.Provided{ PK: dynamo.LpaKey("lpa"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")), LpaUID: "lpa-uid", @@ -1261,8 +1327,21 @@ func TestSendVoucherAccessCode(t *testing.T) { LastName: "d", Email: "voucher@example.com", }, - }, TestAppData) + } + + shareCodeStore := newMockShareCodeStore(t) + shareCodeStore.EXPECT(). + Put(ctx, actor.TypeVoucher, testRandomString, sharecodedata.Link{ + LpaKey: dynamo.LpaKey("lpa"), + LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")), + ActorUID: uid, + }). + Return(nil) + + sender := NewSender(shareCodeStore, tc.notifyClient(provided), "http://app", testRandomStringFn, nil, nil) + TestAppData.Localizer = tc.localizer() + err := sender.SendVoucherAccessCode(ctx, provided, TestAppData) assert.Nil(t, err) }) } @@ -1277,7 +1356,7 @@ func TestSendVoucherAccessCodeWhenShareCodeStoreError(t *testing.T) { Put(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil, nil) err := sender.SendVoucherAccessCode(ctx, &donordata.Provided{ PK: dynamo.LpaKey("lpa"), @@ -1313,7 +1392,7 @@ func TestSendVoucherAccessCodeWhenNotifyClientError(t *testing.T) { notifyClient: func() *mockNotifyClient { nc := newMockNotifyClient(t) nc.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError). Once() return nc @@ -1338,7 +1417,7 @@ func TestSendVoucherAccessCodeWhenNotifyClientError(t *testing.T) { notifyClient: func() *mockNotifyClient { nc := newMockNotifyClient(t) nc.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError). Once() return nc @@ -1357,11 +1436,11 @@ func TestSendVoucherAccessCodeWhenNotifyClientError(t *testing.T) { notifyClient: func() *mockNotifyClient { nc := newMockNotifyClient(t) nc.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil). Once() nc.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError). Once() return nc @@ -1394,7 +1473,7 @@ func TestSendVoucherAccessCodeWhenNotifyClientError(t *testing.T) { TestAppData.Localizer = tc.localizer() - sender := NewSender(shareCodeStore, tc.notifyClient(), "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, tc.notifyClient(), "http://app", testRandomStringFn, nil, nil) err := sender.SendVoucherAccessCode(ctx, &donordata.Provided{ PK: dynamo.LpaKey("lpa"), diff --git a/internal/supporter/supporterpage/donor_access.go b/internal/supporter/supporterpage/donor_access.go index 3533fc9c9d..698350b2ac 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(), donor.Donor.ContactLanguagePreference, data.Form.Email, notify.DonorAccessEmail{ + if err := notifyClient.SendEmail(r.Context(), notify.ToDonor(donor), 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 50c2a57326..519e708988 100644 --- a/internal/supporter/supporterpage/donor_access_test.go +++ b/internal/supporter/supporterpage/donor_access_test.go @@ -119,6 +119,11 @@ func TestPostDonorAccess(t *testing.T) { donorUID := actoruid.New() + updatedDonor := &donordata.Provided{ + Type: lpadata.LpaTypePropertyAndAffairs, + Donor: donordata.Donor{UID: donorUID, FirstNames: "Barry", LastName: "Boy", Email: "email@example.com", ContactLanguagePreference: localize.En}, + } + donorStore := newMockDonorStore(t) donorStore.EXPECT(). Get(r.Context()). @@ -127,10 +132,7 @@ func TestPostDonorAccess(t *testing.T) { 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", ContactLanguagePreference: localize.En}, - }). + Put(r.Context(), updatedDonor). Return(nil) shareCodeStore := newMockShareCodeStore(t) @@ -148,7 +150,7 @@ func TestPostDonorAccess(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(r.Context(), localize.En, "email@example.com", notify.DonorAccessEmail{ + SendEmail(r.Context(), notify.ToDonor(updatedDonor), notify.DonorAccessEmail{ SupporterFullName: "John Smith", OrganisationName: "Helpers", LpaType: "translation", @@ -242,7 +244,7 @@ func TestPostDonorAccessWhenNotifyErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything). + SendEmail(r.Context(), 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 418a760cfd..d7b2b410ef 100644 --- a/internal/supporter/supporterpage/invite_member.go +++ b/internal/supporter/supporterpage/invite_member.go @@ -47,7 +47,7 @@ func InviteMember(tmpl template.Template, memberStore MemberStore, notifyClient return err } - if err := notifyClient.SendEmail(r.Context(), localize.En, data.Form.Email, notify.OrganisationMemberInviteEmail{ + if err := notifyClient.SendEmail(r.Context(), notify.ToCustomEmail(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 ddcb03ca1f..c1aeda714a 100644 --- a/internal/supporter/supporterpage/invite_member_test.go +++ b/internal/supporter/supporterpage/invite_member_test.go @@ -74,7 +74,7 @@ func TestPostInviteMember(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(r.Context(), localize.En, "email@example.com", notify.OrganisationMemberInviteEmail{ + SendEmail(r.Context(), notify.ToCustomEmail(localize.En, "email@example.com"), notify.OrganisationMemberInviteEmail{ OrganisationName: "My organisation", InviterEmail: "supporter@example.com", InviteCode: "abcde", @@ -164,7 +164,7 @@ func TestPostInviteMemberWhenNotifySendErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(r.Context(), mock.Anything, mock.Anything, mock.Anything). + SendEmail(r.Context(), 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 f5dcdd5b16..c63ae58d04 100644 --- a/internal/supporter/supporterpage/manage_team_members.go +++ b/internal/supporter/supporterpage/manage_team_members.go @@ -53,7 +53,7 @@ func ManageTeamMembers(tmpl template.Template, memberStore MemberStore, randomSt return err } - if err := notifyClient.SendEmail(r.Context(), localize.En, data.Form.Email, notify.OrganisationMemberInviteEmail{ + if err := notifyClient.SendEmail(r.Context(), notify.ToCustomEmail(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 af56699dec..b44222ad68 100644 --- a/internal/supporter/supporterpage/manage_team_members_test.go +++ b/internal/supporter/supporterpage/manage_team_members_test.go @@ -134,7 +134,7 @@ func TestPostManageTeamMembers(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(r.Context(), localize.En, "email@example.com", notify.OrganisationMemberInviteEmail{ + SendEmail(r.Context(), notify.ToCustomEmail(localize.En, "email@example.com"), notify.OrganisationMemberInviteEmail{ OrganisationName: "My organisation", InviterEmail: "supporter@example.com", InviteCode: "abcde", @@ -240,7 +240,7 @@ func TestPostManageTeamMembersWhenNotifyClientError(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendEmail(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 aa6987daed..ee4999553d 100644 --- a/internal/supporter/supporterpage/mock_NotifyClient_test.go +++ b/internal/supporter/supporterpage/mock_NotifyClient_test.go @@ -5,10 +5,8 @@ package supporterpage import ( context "context" - localize "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" - mock "github.com/stretchr/testify/mock" - 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 @@ -24,17 +22,17 @@ func (_m *mockNotifyClient) EXPECT() *mockNotifyClient_Expecter { return &mockNotifyClient_Expecter{mock: &_m.Mock} } -// 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) +// SendEmail provides a mock function with given fields: ctx, to, email +func (_m *mockNotifyClient) SendEmail(ctx context.Context, to notify.ToEmail, 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, localize.Lang, string, notify.Email) error); ok { - r0 = rf(ctx, lang, to, email) + if rf, ok := ret.Get(0).(func(context.Context, notify.ToEmail, notify.Email) error); ok { + r0 = rf(ctx, to, email) } else { r0 = ret.Error(0) } @@ -49,16 +47,15 @@ type mockNotifyClient_SendEmail_Call struct { // SendEmail is a helper method to define mock.On call // - ctx context.Context -// - lang localize.Lang -// - to string +// - to notify.ToEmail // - email notify.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 (_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, lang localize.Lang, to string, email notify.Email)) *mockNotifyClient_SendEmail_Call { +func (_c *mockNotifyClient_SendEmail_Call) Run(run func(ctx context.Context, to notify.ToEmail, email notify.Email)) *mockNotifyClient_SendEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(notify.Email)) + run(args[0].(context.Context), args[1].(notify.ToEmail), args[2].(notify.Email)) }) return _c } @@ -68,7 +65,7 @@ func (_c *mockNotifyClient_SendEmail_Call) Return(_a0 error) *mockNotifyClient_S return _c } -func (_c *mockNotifyClient_SendEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, notify.Email) error) *mockNotifyClient_SendEmail_Call { +func (_c *mockNotifyClient_SendEmail_Call) RunAndReturn(run func(context.Context, notify.ToEmail, 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 d0654e9ab5..7b8aae49b3 100644 --- a/internal/supporter/supporterpage/register.go +++ b/internal/supporter/supporterpage/register.go @@ -12,7 +12,6 @@ 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" @@ -88,7 +87,7 @@ type SessionStore interface { } type NotifyClient interface { - SendEmail(ctx context.Context, lang localize.Lang, to string, email notify.Email) error + SendEmail(ctx context.Context, to notify.ToEmail, 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 92aceb6ada..6a1ecc25e0 100644 --- a/internal/voucher/voucherpage/mock_NotifyClient_test.go +++ b/internal/voucher/voucherpage/mock_NotifyClient_test.go @@ -5,9 +5,7 @@ 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" @@ -72,17 +70,17 @@ func (_c *mockNotifyClient_EmailGreeting_Call) RunAndReturn(run func(*lpadata.Lp return _c } -// 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) +// SendActorEmail provides a mock function with given fields: ctx, to, lpaUID, email +func (_m *mockNotifyClient) SendActorEmail(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email) error { + ret := _m.Called(ctx, 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, localize.Lang, string, string, notify.Email) error); ok { - r0 = rf(ctx, lang, to, lpaUID, email) + if rf, ok := ret.Get(0).(func(context.Context, notify.ToEmail, string, notify.Email) error); ok { + r0 = rf(ctx, to, lpaUID, email) } else { r0 = ret.Error(0) } @@ -97,17 +95,16 @@ type mockNotifyClient_SendActorEmail_Call struct { // SendActorEmail is a helper method to define mock.On call // - ctx context.Context -// - lang localize.Lang -// - to string +// - to notify.ToEmail // - lpaUID string // - email notify.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 (_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 (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) Run(run func(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email)) *mockNotifyClient_SendActorEmail_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.Email)) + run(args[0].(context.Context), args[1].(notify.ToEmail), args[2].(string), args[3].(notify.Email)) }) return _c } @@ -117,22 +114,22 @@ func (_c *mockNotifyClient_SendActorEmail_Call) Return(_a0 error) *mockNotifyCli return _c } -func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { +func (_c *mockNotifyClient_SendActorEmail_Call) RunAndReturn(run func(context.Context, notify.ToEmail, string, notify.Email) error) *mockNotifyClient_SendActorEmail_Call { _c.Call.Return(run) return _c } -// 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) +// SendActorSMS provides a mock function with given fields: ctx, to, lpaUID, sms +func (_m *mockNotifyClient) SendActorSMS(ctx context.Context, to notify.ToMobile, lpaUID string, sms notify.SMS) error { + ret := _m.Called(ctx, 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, localize.Lang, string, string, notify.SMS) error); ok { - r0 = rf(ctx, lang, to, lpaUID, sms) + if rf, ok := ret.Get(0).(func(context.Context, notify.ToMobile, string, notify.SMS) error); ok { + r0 = rf(ctx, to, lpaUID, sms) } else { r0 = ret.Error(0) } @@ -147,17 +144,16 @@ type mockNotifyClient_SendActorSMS_Call struct { // SendActorSMS is a helper method to define mock.On call // - ctx context.Context -// - lang localize.Lang -// - to string +// - to notify.ToMobile // - lpaUID string // - sms notify.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 (_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 (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(ctx context.Context, lang localize.Lang, to string, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) Run(run func(ctx context.Context, to notify.ToMobile, lpaUID string, sms notify.SMS)) *mockNotifyClient_SendActorSMS_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(localize.Lang), args[2].(string), args[3].(string), args[4].(notify.SMS)) + run(args[0].(context.Context), args[1].(notify.ToMobile), args[2].(string), args[3].(notify.SMS)) }) return _c } @@ -167,7 +163,7 @@ func (_c *mockNotifyClient_SendActorSMS_Call) Return(_a0 error) *mockNotifyClien return _c } -func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, localize.Lang, string, string, notify.SMS) error) *mockNotifyClient_SendActorSMS_Call { +func (_c *mockNotifyClient_SendActorSMS_Call) RunAndReturn(run func(context.Context, notify.ToMobile, 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 be1c398a3e..3bf4bf0437 100644 --- a/internal/voucher/voucherpage/register.go +++ b/internal/voucher/voucherpage/register.go @@ -14,7 +14,6 @@ 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/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" @@ -48,8 +47,8 @@ type DonorStore interface { type NotifyClient interface { EmailGreeting(lpa *lpadata.Lpa) string - 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 + SendActorEmail(ctx context.Context, to notify.ToEmail, lpaUID string, email notify.Email) error + SendActorSMS(ctx context.Context, to notify.ToMobile, 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 76805da3d1..5853477e72 100644 --- a/internal/voucher/voucherpage/vouch_failer.go +++ b/internal/voucher/voucherpage/vouch_failer.go @@ -25,7 +25,7 @@ func makeVouchFailer(donorStore DonorStore, notifyClient NotifyClient, appPublic DonorStartPageURL: appPublicURL + page.PathStart.Format(), } - if err := notifyClient.SendActorEmail(ctx, lpa.Donor.ContactLanguagePreference, lpa.CorrespondentEmail(), lpa.LpaUID, email); err != nil { + if err := notifyClient.SendActorEmail(ctx, notify.ToLpaDonor(lpa), lpa.LpaUID, email); err != nil { return fmt.Errorf("could not send email: %w", err) } diff --git a/internal/voucher/voucherpage/vouch_failer_test.go b/internal/voucher/voucherpage/vouch_failer_test.go index 9568a2e6bf..4be69866e0 100644 --- a/internal/voucher/voucherpage/vouch_failer_test.go +++ b/internal/voucher/voucherpage/vouch_failer_test.go @@ -46,7 +46,7 @@ func TestVouchFailer(t *testing.T) { EmailGreeting(lpa). Return("greeting") notifyClient.EXPECT(). - SendActorEmail(ctx, localize.Cy, "john@example.com", "lpa-uid", notify.VouchingFailedAttemptEmail{ + SendActorEmail(ctx, notify.ToLpaDonor(lpa), "lpa-uid", notify.VouchingFailedAttemptEmail{ Greeting: "greeting", VoucherFullName: "Vivian Vaughn", DonorStartPageURL: "app:///start", @@ -78,7 +78,7 @@ func TestVouchFailerWheNotifyClientErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("greeting") notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) err := makeVouchFailer(donorStore, notifyClient, "app://")(ctx, &voucherdata.Provided{}, &lpadata.Lpa{}) @@ -99,7 +99,7 @@ func TestVouchFailerWhenDonorStorePutErrors(t *testing.T) { EmailGreeting(mock.Anything). Return("greeting") notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(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 2bb17179a6..208655f7e9 100644 --- a/internal/voucher/voucherpage/your_declaration.go +++ b/internal/voucher/voucherpage/your_declaration.go @@ -29,28 +29,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.ContactLanguagePreference, lpa.Donor.Mobile, lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentitySMS{ + return notifyClient.SendActorSMS(ctx, notify.ToLpaDonor(lpa), lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentitySMS{ VoucherFullName: provided.FullName(), DonorFullName: lpa.Donor.FullName(), DonorStartPageURL: appPublicURL + page.PathStart.Format(), }) } - return notifyClient.SendActorSMS(ctx, lpa.Donor.ContactLanguagePreference, lpa.Donor.Mobile, lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentityOnSignedLpaSMS{ + return notifyClient.SendActorSMS(ctx, notify.ToLpaDonor(lpa), lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentityOnSignedLpaSMS{ VoucherFullName: provided.FullName(), DonorStartPageURL: appPublicURL + page.PathStart.Format(), }) } if !lpa.SignedForDonor() { - return notifyClient.SendActorEmail(ctx, lpa.Donor.ContactLanguagePreference, lpa.Donor.Email, lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentityEmail{ + return notifyClient.SendActorEmail(ctx, notify.ToLpaDonor(lpa), lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentityEmail{ VoucherFullName: provided.FullName(), DonorFullName: lpa.Donor.FullName(), DonorStartPageURL: appPublicURL + page.PathStart.Format(), }) } - return notifyClient.SendActorEmail(ctx, lpa.Donor.ContactLanguagePreference, lpa.Donor.Email, lpa.LpaUID, notify.VoucherHasConfirmedDonorIdentityOnSignedLpaEmail{ + return notifyClient.SendActorEmail(ctx, notify.ToLpaDonor(lpa), 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 69e33333df..e70dd4cd76 100644 --- a/internal/voucher/voucherpage/your_declaration_test.go +++ b/internal/voucher/voucherpage/your_declaration_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - 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/identity" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" @@ -112,16 +112,16 @@ func TestPostYourDeclaration(t *testing.T) { testcases := map[string]struct { lpa *lpadata.Lpa - setupNotify func(*mockNotifyClient) + setupNotify func(*lpadata.Lpa, *mockNotifyClient) }{ "email": { lpa: &lpadata.Lpa{ LpaUID: "lpa-uid", Donor: lpadata.Donor{FirstNames: "John", LastName: "Smith", Email: "blah@example.com", ContactLanguagePreference: localize.En}, }, - setupNotify: func(m *mockNotifyClient) { + setupNotify: func(lpa *lpadata.Lpa, m *mockNotifyClient) { m.EXPECT(). - SendActorEmail(r.Context(), localize.En, "blah@example.com", "lpa-uid", notify.VoucherHasConfirmedDonorIdentityEmail{ + SendActorEmail(r.Context(), notify.ToLpaDonor(lpa), "lpa-uid", notify.VoucherHasConfirmedDonorIdentityEmail{ DonorFullName: "John Smith", DonorStartPageURL: "app:///start", VoucherFullName: "Vivian Voucher", @@ -136,9 +136,9 @@ func TestPostYourDeclaration(t *testing.T) { SignedAt: time.Now(), WitnessedByCertificateProviderAt: time.Now(), }, - setupNotify: func(m *mockNotifyClient) { + setupNotify: func(lpa *lpadata.Lpa, m *mockNotifyClient) { m.EXPECT(). - SendActorEmail(r.Context(), localize.Cy, "blah@example.com", "lpa-uid", notify.VoucherHasConfirmedDonorIdentityOnSignedLpaEmail{ + SendActorEmail(r.Context(), notify.ToLpaDonor(lpa), "lpa-uid", notify.VoucherHasConfirmedDonorIdentityOnSignedLpaEmail{ DonorFullName: "John Smith", DonorStartPageURL: "app:///start", VoucherFullName: "Vivian Voucher", @@ -151,9 +151,9 @@ func TestPostYourDeclaration(t *testing.T) { LpaUID: "lpa-uid", Donor: lpadata.Donor{FirstNames: "John", LastName: "Smith", Email: "blah@example.com", Mobile: "0777", ContactLanguagePreference: localize.Cy}, }, - setupNotify: func(m *mockNotifyClient) { + setupNotify: func(lpa *lpadata.Lpa, m *mockNotifyClient) { m.EXPECT(). - SendActorSMS(r.Context(), localize.Cy, "0777", "lpa-uid", notify.VoucherHasConfirmedDonorIdentitySMS{ + SendActorSMS(r.Context(), notify.ToLpaDonor(lpa), "lpa-uid", notify.VoucherHasConfirmedDonorIdentitySMS{ DonorFullName: "John Smith", DonorStartPageURL: "app:///start", VoucherFullName: "Vivian Voucher", @@ -168,9 +168,9 @@ func TestPostYourDeclaration(t *testing.T) { SignedAt: time.Now(), WitnessedByCertificateProviderAt: time.Now(), }, - setupNotify: func(m *mockNotifyClient) { + setupNotify: func(lpa *lpadata.Lpa, m *mockNotifyClient) { m.EXPECT(). - SendActorSMS(r.Context(), localize.En, "0777", "lpa-uid", notify.VoucherHasConfirmedDonorIdentityOnSignedLpaSMS{ + SendActorSMS(r.Context(), notify.ToLpaDonor(lpa), "lpa-uid", notify.VoucherHasConfirmedDonorIdentityOnSignedLpaSMS{ DonorStartPageURL: "app:///start", VoucherFullName: "Vivian Voucher", }). @@ -212,7 +212,7 @@ func TestPostYourDeclaration(t *testing.T) { Return(nil) notifyClient := newMockNotifyClient(t) - tc.setupNotify(notifyClient) + tc.setupNotify(tc.lpa, notifyClient) err := YourDeclaration(nil, lpaStoreResolvingService, voucherStore, donorStore, notifyClient, testNowFn, "app://")(testAppData, w, r, &voucherdata.Provided{LpaID: "lpa-id", FirstNames: "Vivian", LastName: "Voucher"}) resp := w.Result() @@ -272,7 +272,7 @@ func TestPostYourDeclarationWhenNotifyClientErrors(t *testing.T) { }, setupNotify: func(m *mockNotifyClient) { m.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) }, }, @@ -284,7 +284,7 @@ func TestPostYourDeclarationWhenNotifyClientErrors(t *testing.T) { }, setupNotify: func(m *mockNotifyClient) { m.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) }, }, @@ -295,7 +295,7 @@ func TestPostYourDeclarationWhenNotifyClientErrors(t *testing.T) { }, setupNotify: func(m *mockNotifyClient) { m.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) }, }, @@ -307,7 +307,7 @@ func TestPostYourDeclarationWhenNotifyClientErrors(t *testing.T) { }, setupNotify: func(m *mockNotifyClient) { m.EXPECT(). - SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorSMS(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) }, }, @@ -388,7 +388,7 @@ func TestPostYourDeclarationWhenStoreErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient.EXPECT(). - SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + SendActorEmail(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(nil) donorStore := newMockDonorStore(t)