diff --git a/.mockery.yaml b/.mockery.yaml index 21c3b78575..6564fb7926 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -12,6 +12,7 @@ packages: github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneypage: github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata: github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderpage: + github.com/ministryofjustice/opg-modernising-lpa/internal/document: github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata: github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donorpage: github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo: @@ -28,5 +29,6 @@ packages: github.com/ministryofjustice/opg-modernising-lpa/internal/search: github.com/ministryofjustice/opg-modernising-lpa/internal/secrets: github.com/ministryofjustice/opg-modernising-lpa/internal/sesh: + github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode: github.com/ministryofjustice/opg-modernising-lpa/internal/uid: github.com/ministryofjustice/opg-modernising-lpa/internal/validation: diff --git a/cmd/event-received/factory.go b/cmd/event-received/factory.go index 3ba5f17014..f4d2e89351 100644 --- a/cmd/event-received/factory.go +++ b/cmd/event-received/factory.go @@ -21,6 +21,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/random" "github.com/ministryofjustice/opg-modernising-lpa/internal/search" "github.com/ministryofjustice/opg-modernising-lpa/internal/secrets" + "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" "github.com/ministryofjustice/opg-modernising-lpa/internal/uid" ) @@ -142,7 +143,7 @@ func (f *Factory) ShareCodeSender(ctx context.Context) (ShareCodeSender, error) return nil, err } - f.shareCodeSender = page.NewShareCodeSender(app.NewShareCodeStore(f.dynamoClient), notifyClient, f.appPublicURL, random.String, event.NewClient(f.cfg, f.eventBusName)) + f.shareCodeSender = page.NewShareCodeSender(sharecode.NewStore(f.dynamoClient), notifyClient, f.appPublicURL, random.String, event.NewClient(f.cfg, f.eventBusName)) } return f.shareCodeSender, nil diff --git a/cmd/event-received/main.go b/cmd/event-received/main.go index 2b546a6656..e24b0aa550 100644 --- a/cmd/event-received/main.go +++ b/cmd/event-received/main.go @@ -17,8 +17,8 @@ import ( "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/app" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + "github.com/ministryofjustice/opg-modernising-lpa/internal/document" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/random" @@ -117,7 +117,7 @@ func handler(ctx context.Context, event Event) error { if event.isS3Event() { s3Client := s3.NewClient(cfg, evidenceBucketName) - documentStore := app.NewDocumentStore(dynamoClient, nil, nil, nil, nil) + documentStore := document.NewStore(dynamoClient, nil, nil) if err := handleObjectTagsAdded(ctx, dynamoClient, event.S3Event, s3Client, documentStore); err != nil { return fmt.Errorf("ObjectTagging:Put: %w", err) diff --git a/internal/app/app.go b/internal/app/app.go index 5fce02034d..e9b0cbaa02 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -17,6 +17,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneypage" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderpage" + "github.com/ministryofjustice/opg-modernising-lpa/internal/document" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donorpage" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" @@ -33,6 +34,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/random" "github.com/ministryofjustice/opg-modernising-lpa/internal/search" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" + "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) type ErrorHandler func(http.ResponseWriter, *http.Request, error) @@ -92,12 +94,12 @@ func App( lpaStoreClient *lpastore.Client, searchClient *search.Client, ) http.Handler { - documentStore := NewDocumentStore(lpaDynamoClient, s3Client, eventClient, random.UuidString, time.Now) + documentStore := document.NewStore(lpaDynamoClient, s3Client, eventClient) donorStore := donordata.NewStore(lpaDynamoClient, eventClient, logger, searchClient) - certificateProviderStore := certificateproviderdata.NewStore(lpaDynamoClient, time.Now) - attorneyStore := attorneydata.NewStore(lpaDynamoClient, time.Now) - shareCodeStore := &shareCodeStore{dynamoClient: lpaDynamoClient, now: time.Now} + certificateProviderStore := certificateproviderdata.NewStore(lpaDynamoClient) + attorneyStore := attorneydata.NewStore(lpaDynamoClient) + shareCodeStore := sharecode.NewStore(lpaDynamoClient) dashboardStore := &dashboardStore{dynamoClient: lpaDynamoClient, lpaStoreResolvingService: lpastore.NewResolvingService(donorStore, lpaStoreClient)} evidenceReceivedStore := &evidenceReceivedStore{dynamoClient: lpaDynamoClient} organisationStore := &organisationStore{dynamoClient: lpaDynamoClient, now: time.Now, uuidString: uuid.NewString, newUID: actoruid.New} diff --git a/internal/app/mock_DocumentStore_test.go b/internal/app/mock_DocumentStore_test.go index f729f92602..d3d97d4ce5 100644 --- a/internal/app/mock_DocumentStore_test.go +++ b/internal/app/mock_DocumentStore_test.go @@ -5,7 +5,7 @@ package app import ( context "context" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/document" mock "github.com/stretchr/testify/mock" ) @@ -23,23 +23,23 @@ func (_m *mockDocumentStore) EXPECT() *mockDocumentStore_Expecter { } // GetAll provides a mock function with given fields: _a0 -func (_m *mockDocumentStore) GetAll(_a0 context.Context) (page.Documents, error) { +func (_m *mockDocumentStore) GetAll(_a0 context.Context) (document.Documents, error) { ret := _m.Called(_a0) if len(ret) == 0 { panic("no return value specified for GetAll") } - var r0 page.Documents + var r0 document.Documents var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (page.Documents, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (document.Documents, error)); ok { return rf(_a0) } - if rf, ok := ret.Get(0).(func(context.Context) page.Documents); ok { + if rf, ok := ret.Get(0).(func(context.Context) document.Documents); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(page.Documents) + r0 = ret.Get(0).(document.Documents) } } @@ -70,18 +70,18 @@ func (_c *mockDocumentStore_GetAll_Call) Run(run func(_a0 context.Context)) *moc return _c } -func (_c *mockDocumentStore_GetAll_Call) Return(_a0 page.Documents, _a1 error) *mockDocumentStore_GetAll_Call { +func (_c *mockDocumentStore_GetAll_Call) Return(_a0 document.Documents, _a1 error) *mockDocumentStore_GetAll_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockDocumentStore_GetAll_Call) RunAndReturn(run func(context.Context) (page.Documents, error)) *mockDocumentStore_GetAll_Call { +func (_c *mockDocumentStore_GetAll_Call) RunAndReturn(run func(context.Context) (document.Documents, error)) *mockDocumentStore_GetAll_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: _a0, _a1 -func (_m *mockDocumentStore) Put(_a0 context.Context, _a1 page.Document) error { +func (_m *mockDocumentStore) Put(_a0 context.Context, _a1 document.Document) error { ret := _m.Called(_a0, _a1) if len(ret) == 0 { @@ -89,7 +89,7 @@ func (_m *mockDocumentStore) Put(_a0 context.Context, _a1 page.Document) error { } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, page.Document) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, document.Document) error); ok { r0 = rf(_a0, _a1) } else { r0 = ret.Error(0) @@ -105,14 +105,14 @@ type mockDocumentStore_Put_Call struct { // Put is a helper method to define mock.On call // - _a0 context.Context -// - _a1 page.Document +// - _a1 document.Document func (_e *mockDocumentStore_Expecter) Put(_a0 interface{}, _a1 interface{}) *mockDocumentStore_Put_Call { return &mockDocumentStore_Put_Call{Call: _e.mock.On("Put", _a0, _a1)} } -func (_c *mockDocumentStore_Put_Call) Run(run func(_a0 context.Context, _a1 page.Document)) *mockDocumentStore_Put_Call { +func (_c *mockDocumentStore_Put_Call) Run(run func(_a0 context.Context, _a1 document.Document)) *mockDocumentStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(page.Document)) + run(args[0].(context.Context), args[1].(document.Document)) }) return _c } @@ -122,7 +122,7 @@ func (_c *mockDocumentStore_Put_Call) Return(_a0 error) *mockDocumentStore_Put_C return _c } -func (_c *mockDocumentStore_Put_Call) RunAndReturn(run func(context.Context, page.Document) error) *mockDocumentStore_Put_Call { +func (_c *mockDocumentStore_Put_Call) RunAndReturn(run func(context.Context, document.Document) error) *mockDocumentStore_Put_Call { _c.Call.Return(run) return _c } diff --git a/internal/attorney/attorneydata/store.go b/internal/attorney/attorneydata/store.go index a6f432dd38..bc226cc251 100644 --- a/internal/attorney/attorneydata/store.go +++ b/internal/attorney/attorneydata/store.go @@ -38,8 +38,8 @@ type Store struct { now func() time.Time } -func NewStore(dynamoClient DynamoClient, now func() time.Time) *Store { - return &Store{dynamoClient: dynamoClient, now: now} +func NewStore(dynamoClient DynamoClient) *Store { + return &Store{dynamoClient: dynamoClient, now: time.Now} } func (s *Store) Create(ctx context.Context, shareCode sharecode.Data, email string) (*Provided, error) { diff --git a/internal/attorney/attorneydata/store_test.go b/internal/attorney/attorneydata/store_test.go index b47a1b0ec7..9550dc9b67 100644 --- a/internal/attorney/attorneydata/store_test.go +++ b/internal/attorney/attorneydata/store_test.go @@ -77,7 +77,7 @@ func TestAttorneyStoreCreate(t *testing.T) { WriteTransaction(ctx, expectedTransaction). Return(nil) - attorneyStore := NewStore(dynamoClient, func() time.Time { return now }) + attorneyStore := Store{dynamoClient: dynamoClient, now: func() time.Time { return now }} attorney, err := attorneyStore.Create(ctx, shareCode, "a@example.com") assert.Nil(t, err) diff --git a/internal/certificateprovider/certificateproviderdata/store.go b/internal/certificateprovider/certificateproviderdata/store.go index 8754adc6fe..ce700c1ec3 100644 --- a/internal/certificateprovider/certificateproviderdata/store.go +++ b/internal/certificateprovider/certificateproviderdata/store.go @@ -33,8 +33,8 @@ type DynamoClient interface { WriteTransaction(ctx context.Context, transaction *dynamo.Transaction) error } -func NewStore(dynamoClient DynamoClient, now func() time.Time) *Store { - return &Store{dynamoClient: dynamoClient, now: now} +func NewStore(dynamoClient DynamoClient) *Store { + return &Store{dynamoClient: dynamoClient, now: time.Now} } type Store struct { diff --git a/internal/page/document.go b/internal/document/document.go similarity index 99% rename from internal/page/document.go rename to internal/document/document.go index 397b90f791..8220878b62 100644 --- a/internal/page/document.go +++ b/internal/document/document.go @@ -1,4 +1,4 @@ -package page +package document import ( "slices" diff --git a/internal/page/document_test.go b/internal/document/document_test.go similarity index 99% rename from internal/page/document_test.go rename to internal/document/document_test.go index d249830c63..5d5eb58cfc 100644 --- a/internal/page/document_test.go +++ b/internal/document/document_test.go @@ -1,4 +1,4 @@ -package page +package document import ( "testing" diff --git a/internal/document/mock_DynamoClient_test.go b/internal/document/mock_DynamoClient_test.go new file mode 100644 index 0000000000..da8e64fee3 --- /dev/null +++ b/internal/document/mock_DynamoClient_test.go @@ -0,0 +1,877 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package document + +import ( + context "context" + + 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" +) + +// mockDynamoClient is an autogenerated mock type for the DynamoClient type +type mockDynamoClient struct { + mock.Mock +} + +type mockDynamoClient_Expecter struct { + mock *mock.Mock +} + +func (_m *mockDynamoClient) EXPECT() *mockDynamoClient_Expecter { + return &mockDynamoClient_Expecter{mock: &_m.Mock} +} + +// AllByKeys provides a mock function with given fields: ctx, keys +func (_m *mockDynamoClient) 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 +} + +// mockDynamoClient_AllByKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllByKeys' +type mockDynamoClient_AllByKeys_Call struct { + *mock.Call +} + +// AllByKeys is a helper method to define mock.On call +// - ctx context.Context +// - keys []dynamo.Keys +func (_e *mockDynamoClient_Expecter) AllByKeys(ctx interface{}, keys interface{}) *mockDynamoClient_AllByKeys_Call { + return &mockDynamoClient_AllByKeys_Call{Call: _e.mock.On("AllByKeys", ctx, keys)} +} + +func (_c *mockDynamoClient_AllByKeys_Call) Run(run func(ctx context.Context, keys []dynamo.Keys)) *mockDynamoClient_AllByKeys_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]dynamo.Keys)) + }) + return _c +} + +func (_c *mockDynamoClient_AllByKeys_Call) Return(_a0 []map[string]types.AttributeValue, _a1 error) *mockDynamoClient_AllByKeys_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockDynamoClient_AllByKeys_Call) RunAndReturn(run func(context.Context, []dynamo.Keys) ([]map[string]types.AttributeValue, error)) *mockDynamoClient_AllByKeys_Call { + _c.Call.Return(run) + return _c +} + +// AllByPartialSK provides a mock function with given fields: ctx, pk, partialSK, v +func (_m *mockDynamoClient) AllByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{}) 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, interface{}) error); ok { + r0 = rf(ctx, pk, partialSK, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_AllByPartialSK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllByPartialSK' +type mockDynamoClient_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 interface{} +func (_e *mockDynamoClient_Expecter) AllByPartialSK(ctx interface{}, pk interface{}, partialSK interface{}, v interface{}) *mockDynamoClient_AllByPartialSK_Call { + return &mockDynamoClient_AllByPartialSK_Call{Call: _e.mock.On("AllByPartialSK", ctx, pk, partialSK, v)} +} + +func (_c *mockDynamoClient_AllByPartialSK_Call) Run(run func(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{})) *mockDynamoClient_AllByPartialSK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_AllByPartialSK_Call) Return(_a0 error) *mockDynamoClient_AllByPartialSK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_AllByPartialSK_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, interface{}) error) *mockDynamoClient_AllByPartialSK_Call { + _c.Call.Return(run) + return _c +} + +// AllBySK provides a mock function with given fields: ctx, sk, v +func (_m *mockDynamoClient) AllBySK(ctx context.Context, sk dynamo.SK, v interface{}) 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, interface{}) error); ok { + r0 = rf(ctx, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_AllBySK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllBySK' +type mockDynamoClient_AllBySK_Call struct { + *mock.Call +} + +// AllBySK is a helper method to define mock.On call +// - ctx context.Context +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) AllBySK(ctx interface{}, sk interface{}, v interface{}) *mockDynamoClient_AllBySK_Call { + return &mockDynamoClient_AllBySK_Call{Call: _e.mock.On("AllBySK", ctx, sk, v)} +} + +func (_c *mockDynamoClient_AllBySK_Call) Run(run func(ctx context.Context, sk dynamo.SK, v interface{})) *mockDynamoClient_AllBySK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_AllBySK_Call) Return(_a0 error) *mockDynamoClient_AllBySK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_AllBySK_Call) RunAndReturn(run func(context.Context, dynamo.SK, interface{}) error) *mockDynamoClient_AllBySK_Call { + _c.Call.Return(run) + return _c +} + +// AllKeysByPK provides a mock function with given fields: ctx, pk +func (_m *mockDynamoClient) 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 +} + +// mockDynamoClient_AllKeysByPK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllKeysByPK' +type mockDynamoClient_AllKeysByPK_Call struct { + *mock.Call +} + +// AllKeysByPK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +func (_e *mockDynamoClient_Expecter) AllKeysByPK(ctx interface{}, pk interface{}) *mockDynamoClient_AllKeysByPK_Call { + return &mockDynamoClient_AllKeysByPK_Call{Call: _e.mock.On("AllKeysByPK", ctx, pk)} +} + +func (_c *mockDynamoClient_AllKeysByPK_Call) Run(run func(ctx context.Context, pk dynamo.PK)) *mockDynamoClient_AllKeysByPK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK)) + }) + return _c +} + +func (_c *mockDynamoClient_AllKeysByPK_Call) Return(_a0 []dynamo.Keys, _a1 error) *mockDynamoClient_AllKeysByPK_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockDynamoClient_AllKeysByPK_Call) RunAndReturn(run func(context.Context, dynamo.PK) ([]dynamo.Keys, error)) *mockDynamoClient_AllKeysByPK_Call { + _c.Call.Return(run) + return _c +} + +// BatchPut provides a mock function with given fields: ctx, items +func (_m *mockDynamoClient) BatchPut(ctx context.Context, items []interface{}) 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, []interface{}) error); ok { + r0 = rf(ctx, items) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_BatchPut_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BatchPut' +type mockDynamoClient_BatchPut_Call struct { + *mock.Call +} + +// BatchPut is a helper method to define mock.On call +// - ctx context.Context +// - items []interface{} +func (_e *mockDynamoClient_Expecter) BatchPut(ctx interface{}, items interface{}) *mockDynamoClient_BatchPut_Call { + return &mockDynamoClient_BatchPut_Call{Call: _e.mock.On("BatchPut", ctx, items)} +} + +func (_c *mockDynamoClient_BatchPut_Call) Run(run func(ctx context.Context, items []interface{})) *mockDynamoClient_BatchPut_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_BatchPut_Call) Return(_a0 error) *mockDynamoClient_BatchPut_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_BatchPut_Call) RunAndReturn(run func(context.Context, []interface{}) error) *mockDynamoClient_BatchPut_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, v +func (_m *mockDynamoClient) Create(ctx context.Context, v interface{}) error { + ret := _m.Called(ctx, v) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}) error); ok { + r0 = rf(ctx, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type mockDynamoClient_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - v interface{} +func (_e *mockDynamoClient_Expecter) Create(ctx interface{}, v interface{}) *mockDynamoClient_Create_Call { + return &mockDynamoClient_Create_Call{Call: _e.mock.On("Create", ctx, v)} +} + +func (_c *mockDynamoClient_Create_Call) Run(run func(ctx context.Context, v interface{})) *mockDynamoClient_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_Create_Call) Return(_a0 error) *mockDynamoClient_Create_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_Create_Call) RunAndReturn(run func(context.Context, interface{}) error) *mockDynamoClient_Create_Call { + _c.Call.Return(run) + return _c +} + +// DeleteKeys provides a mock function with given fields: ctx, keys +func (_m *mockDynamoClient) DeleteKeys(ctx context.Context, keys []dynamo.Keys) error { + ret := _m.Called(ctx, keys) + + if len(ret) == 0 { + panic("no return value specified for DeleteKeys") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) error); ok { + r0 = rf(ctx, keys) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_DeleteKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteKeys' +type mockDynamoClient_DeleteKeys_Call struct { + *mock.Call +} + +// DeleteKeys is a helper method to define mock.On call +// - ctx context.Context +// - keys []dynamo.Keys +func (_e *mockDynamoClient_Expecter) DeleteKeys(ctx interface{}, keys interface{}) *mockDynamoClient_DeleteKeys_Call { + return &mockDynamoClient_DeleteKeys_Call{Call: _e.mock.On("DeleteKeys", ctx, keys)} +} + +func (_c *mockDynamoClient_DeleteKeys_Call) Run(run func(ctx context.Context, keys []dynamo.Keys)) *mockDynamoClient_DeleteKeys_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]dynamo.Keys)) + }) + return _c +} + +func (_c *mockDynamoClient_DeleteKeys_Call) Return(_a0 error) *mockDynamoClient_DeleteKeys_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_DeleteKeys_Call) RunAndReturn(run func(context.Context, []dynamo.Keys) error) *mockDynamoClient_DeleteKeys_Call { + _c.Call.Return(run) + return _c +} + +// DeleteOne provides a mock function with given fields: ctx, pk, sk +func (_m *mockDynamoClient) DeleteOne(ctx context.Context, pk dynamo.PK, sk dynamo.SK) error { + ret := _m.Called(ctx, pk, sk) + + if len(ret) == 0 { + panic("no return value specified for DeleteOne") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK) error); ok { + r0 = rf(ctx, pk, sk) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_DeleteOne_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteOne' +type mockDynamoClient_DeleteOne_Call struct { + *mock.Call +} + +// DeleteOne is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - sk dynamo.SK +func (_e *mockDynamoClient_Expecter) DeleteOne(ctx interface{}, pk interface{}, sk interface{}) *mockDynamoClient_DeleteOne_Call { + return &mockDynamoClient_DeleteOne_Call{Call: _e.mock.On("DeleteOne", ctx, pk, sk)} +} + +func (_c *mockDynamoClient_DeleteOne_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK)) *mockDynamoClient_DeleteOne_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK)) + }) + return _c +} + +func (_c *mockDynamoClient_DeleteOne_Call) Return(_a0 error) *mockDynamoClient_DeleteOne_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_DeleteOne_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK) error) *mockDynamoClient_DeleteOne_Call { + _c.Call.Return(run) + return _c +} + +// LatestForActor provides a mock function with given fields: ctx, sk, v +func (_m *mockDynamoClient) LatestForActor(ctx context.Context, sk dynamo.SK, v interface{}) 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, interface{}) error); ok { + r0 = rf(ctx, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_LatestForActor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LatestForActor' +type mockDynamoClient_LatestForActor_Call struct { + *mock.Call +} + +// LatestForActor is a helper method to define mock.On call +// - ctx context.Context +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) LatestForActor(ctx interface{}, sk interface{}, v interface{}) *mockDynamoClient_LatestForActor_Call { + return &mockDynamoClient_LatestForActor_Call{Call: _e.mock.On("LatestForActor", ctx, sk, v)} +} + +func (_c *mockDynamoClient_LatestForActor_Call) Run(run func(ctx context.Context, sk dynamo.SK, v interface{})) *mockDynamoClient_LatestForActor_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_LatestForActor_Call) Return(_a0 error) *mockDynamoClient_LatestForActor_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_LatestForActor_Call) RunAndReturn(run func(context.Context, dynamo.SK, interface{}) error) *mockDynamoClient_LatestForActor_Call { + _c.Call.Return(run) + return _c +} + +// One provides a mock function with given fields: ctx, pk, sk, v +func (_m *mockDynamoClient) One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, pk, sk, v) + + if len(ret) == 0 { + panic("no return value specified for One") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, pk, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_One_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'One' +type mockDynamoClient_One_Call struct { + *mock.Call +} + +// One is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) One(ctx interface{}, pk interface{}, sk interface{}, v interface{}) *mockDynamoClient_One_Call { + return &mockDynamoClient_One_Call{Call: _e.mock.On("One", ctx, pk, sk, v)} +} + +func (_c *mockDynamoClient_One_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{})) *mockDynamoClient_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{})) + }) + return _c +} + +func (_c *mockDynamoClient_One_Call) Return(_a0 error) *mockDynamoClient_One_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_One_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, interface{}) error) *mockDynamoClient_One_Call { + _c.Call.Return(run) + return _c +} + +// OneByPK provides a mock function with given fields: ctx, pk, v +func (_m *mockDynamoClient) OneByPK(ctx context.Context, pk dynamo.PK, v interface{}) error { + ret := _m.Called(ctx, pk, v) + + if len(ret) == 0 { + panic("no return value specified for OneByPK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, interface{}) error); ok { + r0 = rf(ctx, pk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneByPK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneByPK' +type mockDynamoClient_OneByPK_Call struct { + *mock.Call +} + +// OneByPK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneByPK(ctx interface{}, pk interface{}, v interface{}) *mockDynamoClient_OneByPK_Call { + return &mockDynamoClient_OneByPK_Call{Call: _e.mock.On("OneByPK", ctx, pk, v)} +} + +func (_c *mockDynamoClient_OneByPK_Call) Run(run func(ctx context.Context, pk dynamo.PK, v interface{})) *mockDynamoClient_OneByPK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneByPK_Call) Return(_a0 error) *mockDynamoClient_OneByPK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneByPK_Call) RunAndReturn(run func(context.Context, dynamo.PK, interface{}) error) *mockDynamoClient_OneByPK_Call { + _c.Call.Return(run) + return _c +} + +// OneByPartialSK provides a mock function with given fields: ctx, pk, partialSK, v +func (_m *mockDynamoClient) OneByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{}) 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, interface{}) error); ok { + r0 = rf(ctx, pk, partialSK, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneByPartialSK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneByPartialSK' +type mockDynamoClient_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 interface{} +func (_e *mockDynamoClient_Expecter) OneByPartialSK(ctx interface{}, pk interface{}, partialSK interface{}, v interface{}) *mockDynamoClient_OneByPartialSK_Call { + return &mockDynamoClient_OneByPartialSK_Call{Call: _e.mock.On("OneByPartialSK", ctx, pk, partialSK, v)} +} + +func (_c *mockDynamoClient_OneByPartialSK_Call) Run(run func(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{})) *mockDynamoClient_OneByPartialSK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneByPartialSK_Call) Return(_a0 error) *mockDynamoClient_OneByPartialSK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneByPartialSK_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, interface{}) error) *mockDynamoClient_OneByPartialSK_Call { + _c.Call.Return(run) + return _c +} + +// OneBySK provides a mock function with given fields: ctx, sk, v +func (_m *mockDynamoClient) OneBySK(ctx context.Context, sk dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, sk, v) + + if len(ret) == 0 { + panic("no return value specified for OneBySK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneBySK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneBySK' +type mockDynamoClient_OneBySK_Call struct { + *mock.Call +} + +// OneBySK is a helper method to define mock.On call +// - ctx context.Context +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneBySK(ctx interface{}, sk interface{}, v interface{}) *mockDynamoClient_OneBySK_Call { + return &mockDynamoClient_OneBySK_Call{Call: _e.mock.On("OneBySK", ctx, sk, v)} +} + +func (_c *mockDynamoClient_OneBySK_Call) Run(run func(ctx context.Context, sk dynamo.SK, v interface{})) *mockDynamoClient_OneBySK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneBySK_Call) Return(_a0 error) *mockDynamoClient_OneBySK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneBySK_Call) RunAndReturn(run func(context.Context, dynamo.SK, interface{}) error) *mockDynamoClient_OneBySK_Call { + _c.Call.Return(run) + return _c +} + +// OneByUID provides a mock function with given fields: ctx, uid, v +func (_m *mockDynamoClient) OneByUID(ctx context.Context, uid string, v interface{}) error { + ret := _m.Called(ctx, uid, v) + + if len(ret) == 0 { + panic("no return value specified for OneByUID") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, interface{}) error); ok { + r0 = rf(ctx, uid, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneByUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneByUID' +type mockDynamoClient_OneByUID_Call struct { + *mock.Call +} + +// OneByUID is a helper method to define mock.On call +// - ctx context.Context +// - uid string +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneByUID(ctx interface{}, uid interface{}, v interface{}) *mockDynamoClient_OneByUID_Call { + return &mockDynamoClient_OneByUID_Call{Call: _e.mock.On("OneByUID", ctx, uid, v)} +} + +func (_c *mockDynamoClient_OneByUID_Call) Run(run func(ctx context.Context, uid string, v interface{})) *mockDynamoClient_OneByUID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneByUID_Call) Return(_a0 error) *mockDynamoClient_OneByUID_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneByUID_Call) RunAndReturn(run func(context.Context, string, interface{}) error) *mockDynamoClient_OneByUID_Call { + _c.Call.Return(run) + return _c +} + +// Put provides a mock function with given fields: ctx, v +func (_m *mockDynamoClient) Put(ctx context.Context, v interface{}) error { + ret := _m.Called(ctx, v) + + if len(ret) == 0 { + panic("no return value specified for Put") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}) error); ok { + r0 = rf(ctx, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_Put_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Put' +type mockDynamoClient_Put_Call struct { + *mock.Call +} + +// Put is a helper method to define mock.On call +// - ctx context.Context +// - v interface{} +func (_e *mockDynamoClient_Expecter) Put(ctx interface{}, v interface{}) *mockDynamoClient_Put_Call { + return &mockDynamoClient_Put_Call{Call: _e.mock.On("Put", ctx, v)} +} + +func (_c *mockDynamoClient_Put_Call) Run(run func(ctx context.Context, v interface{})) *mockDynamoClient_Put_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_Put_Call) Return(_a0 error) *mockDynamoClient_Put_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_Put_Call) RunAndReturn(run func(context.Context, interface{}) error) *mockDynamoClient_Put_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, pk, sk, values, expression +func (_m *mockDynamoClient) 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 +} + +// mockDynamoClient_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type mockDynamoClient_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 *mockDynamoClient_Expecter) Update(ctx interface{}, pk interface{}, sk interface{}, values interface{}, expression interface{}) *mockDynamoClient_Update_Call { + return &mockDynamoClient_Update_Call{Call: _e.mock.On("Update", ctx, pk, sk, values, expression)} +} + +func (_c *mockDynamoClient_Update_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, values map[string]types.AttributeValue, expression string)) *mockDynamoClient_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 *mockDynamoClient_Update_Call) Return(_a0 error) *mockDynamoClient_Update_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_Update_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, map[string]types.AttributeValue, string) error) *mockDynamoClient_Update_Call { + _c.Call.Return(run) + return _c +} + +// WriteTransaction provides a mock function with given fields: ctx, transaction +func (_m *mockDynamoClient) WriteTransaction(ctx context.Context, transaction *dynamo.Transaction) error { + ret := _m.Called(ctx, transaction) + + if len(ret) == 0 { + panic("no return value specified for WriteTransaction") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *dynamo.Transaction) error); ok { + r0 = rf(ctx, transaction) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_WriteTransaction_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WriteTransaction' +type mockDynamoClient_WriteTransaction_Call struct { + *mock.Call +} + +// WriteTransaction is a helper method to define mock.On call +// - ctx context.Context +// - transaction *dynamo.Transaction +func (_e *mockDynamoClient_Expecter) WriteTransaction(ctx interface{}, transaction interface{}) *mockDynamoClient_WriteTransaction_Call { + return &mockDynamoClient_WriteTransaction_Call{Call: _e.mock.On("WriteTransaction", ctx, transaction)} +} + +func (_c *mockDynamoClient_WriteTransaction_Call) Run(run func(ctx context.Context, transaction *dynamo.Transaction)) *mockDynamoClient_WriteTransaction_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*dynamo.Transaction)) + }) + return _c +} + +func (_c *mockDynamoClient_WriteTransaction_Call) Return(_a0 error) *mockDynamoClient_WriteTransaction_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_WriteTransaction_Call) RunAndReturn(run func(context.Context, *dynamo.Transaction) error) *mockDynamoClient_WriteTransaction_Call { + _c.Call.Return(run) + return _c +} + +// newMockDynamoClient creates a new instance of mockDynamoClient. 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 newMockDynamoClient(t interface { + mock.TestingT + Cleanup(func()) +}) *mockDynamoClient { + mock := &mockDynamoClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/document/mock_EventClient_test.go b/internal/document/mock_EventClient_test.go new file mode 100644 index 0000000000..42eb0cfe03 --- /dev/null +++ b/internal/document/mock_EventClient_test.go @@ -0,0 +1,225 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package document + +import ( + context "context" + + event "github.com/ministryofjustice/opg-modernising-lpa/internal/event" + mock "github.com/stretchr/testify/mock" +) + +// mockEventClient is an autogenerated mock type for the EventClient type +type mockEventClient struct { + mock.Mock +} + +type mockEventClient_Expecter struct { + mock *mock.Mock +} + +func (_m *mockEventClient) EXPECT() *mockEventClient_Expecter { + return &mockEventClient_Expecter{mock: &_m.Mock} +} + +// SendApplicationUpdated provides a mock function with given fields: _a0, _a1 +func (_m *mockEventClient) SendApplicationUpdated(_a0 context.Context, _a1 event.ApplicationUpdated) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for SendApplicationUpdated") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, event.ApplicationUpdated) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockEventClient_SendApplicationUpdated_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendApplicationUpdated' +type mockEventClient_SendApplicationUpdated_Call struct { + *mock.Call +} + +// SendApplicationUpdated is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 event.ApplicationUpdated +func (_e *mockEventClient_Expecter) SendApplicationUpdated(_a0 interface{}, _a1 interface{}) *mockEventClient_SendApplicationUpdated_Call { + return &mockEventClient_SendApplicationUpdated_Call{Call: _e.mock.On("SendApplicationUpdated", _a0, _a1)} +} + +func (_c *mockEventClient_SendApplicationUpdated_Call) Run(run func(_a0 context.Context, _a1 event.ApplicationUpdated)) *mockEventClient_SendApplicationUpdated_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(event.ApplicationUpdated)) + }) + return _c +} + +func (_c *mockEventClient_SendApplicationUpdated_Call) Return(_a0 error) *mockEventClient_SendApplicationUpdated_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockEventClient_SendApplicationUpdated_Call) RunAndReturn(run func(context.Context, event.ApplicationUpdated) error) *mockEventClient_SendApplicationUpdated_Call { + _c.Call.Return(run) + return _c +} + +// SendPreviousApplicationLinked provides a mock function with given fields: _a0, _a1 +func (_m *mockEventClient) SendPreviousApplicationLinked(_a0 context.Context, _a1 event.PreviousApplicationLinked) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for SendPreviousApplicationLinked") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, event.PreviousApplicationLinked) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockEventClient_SendPreviousApplicationLinked_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendPreviousApplicationLinked' +type mockEventClient_SendPreviousApplicationLinked_Call struct { + *mock.Call +} + +// SendPreviousApplicationLinked is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 event.PreviousApplicationLinked +func (_e *mockEventClient_Expecter) SendPreviousApplicationLinked(_a0 interface{}, _a1 interface{}) *mockEventClient_SendPreviousApplicationLinked_Call { + return &mockEventClient_SendPreviousApplicationLinked_Call{Call: _e.mock.On("SendPreviousApplicationLinked", _a0, _a1)} +} + +func (_c *mockEventClient_SendPreviousApplicationLinked_Call) Run(run func(_a0 context.Context, _a1 event.PreviousApplicationLinked)) *mockEventClient_SendPreviousApplicationLinked_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(event.PreviousApplicationLinked)) + }) + return _c +} + +func (_c *mockEventClient_SendPreviousApplicationLinked_Call) Return(_a0 error) *mockEventClient_SendPreviousApplicationLinked_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockEventClient_SendPreviousApplicationLinked_Call) RunAndReturn(run func(context.Context, event.PreviousApplicationLinked) error) *mockEventClient_SendPreviousApplicationLinked_Call { + _c.Call.Return(run) + return _c +} + +// SendReducedFeeRequested provides a mock function with given fields: _a0, _a1 +func (_m *mockEventClient) SendReducedFeeRequested(_a0 context.Context, _a1 event.ReducedFeeRequested) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for SendReducedFeeRequested") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, event.ReducedFeeRequested) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockEventClient_SendReducedFeeRequested_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendReducedFeeRequested' +type mockEventClient_SendReducedFeeRequested_Call struct { + *mock.Call +} + +// SendReducedFeeRequested is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 event.ReducedFeeRequested +func (_e *mockEventClient_Expecter) SendReducedFeeRequested(_a0 interface{}, _a1 interface{}) *mockEventClient_SendReducedFeeRequested_Call { + return &mockEventClient_SendReducedFeeRequested_Call{Call: _e.mock.On("SendReducedFeeRequested", _a0, _a1)} +} + +func (_c *mockEventClient_SendReducedFeeRequested_Call) Run(run func(_a0 context.Context, _a1 event.ReducedFeeRequested)) *mockEventClient_SendReducedFeeRequested_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(event.ReducedFeeRequested)) + }) + return _c +} + +func (_c *mockEventClient_SendReducedFeeRequested_Call) Return(_a0 error) *mockEventClient_SendReducedFeeRequested_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockEventClient_SendReducedFeeRequested_Call) RunAndReturn(run func(context.Context, event.ReducedFeeRequested) error) *mockEventClient_SendReducedFeeRequested_Call { + _c.Call.Return(run) + return _c +} + +// SendUidRequested provides a mock function with given fields: _a0, _a1 +func (_m *mockEventClient) SendUidRequested(_a0 context.Context, _a1 event.UidRequested) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for SendUidRequested") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, event.UidRequested) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockEventClient_SendUidRequested_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendUidRequested' +type mockEventClient_SendUidRequested_Call struct { + *mock.Call +} + +// SendUidRequested is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 event.UidRequested +func (_e *mockEventClient_Expecter) SendUidRequested(_a0 interface{}, _a1 interface{}) *mockEventClient_SendUidRequested_Call { + return &mockEventClient_SendUidRequested_Call{Call: _e.mock.On("SendUidRequested", _a0, _a1)} +} + +func (_c *mockEventClient_SendUidRequested_Call) Run(run func(_a0 context.Context, _a1 event.UidRequested)) *mockEventClient_SendUidRequested_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(event.UidRequested)) + }) + return _c +} + +func (_c *mockEventClient_SendUidRequested_Call) Return(_a0 error) *mockEventClient_SendUidRequested_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockEventClient_SendUidRequested_Call) RunAndReturn(run func(context.Context, event.UidRequested) error) *mockEventClient_SendUidRequested_Call { + _c.Call.Return(run) + return _c +} + +// newMockEventClient creates a new instance of mockEventClient. 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 newMockEventClient(t interface { + mock.TestingT + Cleanup(func()) +}) *mockEventClient { + mock := &mockEventClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/document/mock_S3Client_test.go b/internal/document/mock_S3Client_test.go new file mode 100644 index 0000000000..4d9de10362 --- /dev/null +++ b/internal/document/mock_S3Client_test.go @@ -0,0 +1,226 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package document + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// mockS3Client is an autogenerated mock type for the S3Client type +type mockS3Client struct { + mock.Mock +} + +type mockS3Client_Expecter struct { + mock *mock.Mock +} + +func (_m *mockS3Client) EXPECT() *mockS3Client_Expecter { + return &mockS3Client_Expecter{mock: &_m.Mock} +} + +// DeleteObject provides a mock function with given fields: _a0, _a1 +func (_m *mockS3Client) DeleteObject(_a0 context.Context, _a1 string) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for DeleteObject") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockS3Client_DeleteObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteObject' +type mockS3Client_DeleteObject_Call struct { + *mock.Call +} + +// DeleteObject is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 string +func (_e *mockS3Client_Expecter) DeleteObject(_a0 interface{}, _a1 interface{}) *mockS3Client_DeleteObject_Call { + return &mockS3Client_DeleteObject_Call{Call: _e.mock.On("DeleteObject", _a0, _a1)} +} + +func (_c *mockS3Client_DeleteObject_Call) Run(run func(_a0 context.Context, _a1 string)) *mockS3Client_DeleteObject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string)) + }) + return _c +} + +func (_c *mockS3Client_DeleteObject_Call) Return(_a0 error) *mockS3Client_DeleteObject_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockS3Client_DeleteObject_Call) RunAndReturn(run func(context.Context, string) error) *mockS3Client_DeleteObject_Call { + _c.Call.Return(run) + return _c +} + +// DeleteObjects provides a mock function with given fields: ctx, keys +func (_m *mockS3Client) DeleteObjects(ctx context.Context, keys []string) error { + ret := _m.Called(ctx, keys) + + if len(ret) == 0 { + panic("no return value specified for DeleteObjects") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []string) error); ok { + r0 = rf(ctx, keys) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockS3Client_DeleteObjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteObjects' +type mockS3Client_DeleteObjects_Call struct { + *mock.Call +} + +// DeleteObjects is a helper method to define mock.On call +// - ctx context.Context +// - keys []string +func (_e *mockS3Client_Expecter) DeleteObjects(ctx interface{}, keys interface{}) *mockS3Client_DeleteObjects_Call { + return &mockS3Client_DeleteObjects_Call{Call: _e.mock.On("DeleteObjects", ctx, keys)} +} + +func (_c *mockS3Client_DeleteObjects_Call) Run(run func(ctx context.Context, keys []string)) *mockS3Client_DeleteObjects_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]string)) + }) + return _c +} + +func (_c *mockS3Client_DeleteObjects_Call) Return(_a0 error) *mockS3Client_DeleteObjects_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockS3Client_DeleteObjects_Call) RunAndReturn(run func(context.Context, []string) error) *mockS3Client_DeleteObjects_Call { + _c.Call.Return(run) + return _c +} + +// PutObject provides a mock function with given fields: _a0, _a1, _a2 +func (_m *mockS3Client) PutObject(_a0 context.Context, _a1 string, _a2 []byte) error { + ret := _m.Called(_a0, _a1, _a2) + + if len(ret) == 0 { + panic("no return value specified for PutObject") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, []byte) error); ok { + r0 = rf(_a0, _a1, _a2) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockS3Client_PutObject_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PutObject' +type mockS3Client_PutObject_Call struct { + *mock.Call +} + +// PutObject is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 string +// - _a2 []byte +func (_e *mockS3Client_Expecter) PutObject(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockS3Client_PutObject_Call { + return &mockS3Client_PutObject_Call{Call: _e.mock.On("PutObject", _a0, _a1, _a2)} +} + +func (_c *mockS3Client_PutObject_Call) Run(run func(_a0 context.Context, _a1 string, _a2 []byte)) *mockS3Client_PutObject_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].([]byte)) + }) + return _c +} + +func (_c *mockS3Client_PutObject_Call) Return(_a0 error) *mockS3Client_PutObject_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockS3Client_PutObject_Call) RunAndReturn(run func(context.Context, string, []byte) error) *mockS3Client_PutObject_Call { + _c.Call.Return(run) + return _c +} + +// PutObjectTagging provides a mock function with given fields: _a0, _a1, _a2 +func (_m *mockS3Client) PutObjectTagging(_a0 context.Context, _a1 string, _a2 map[string]string) error { + ret := _m.Called(_a0, _a1, _a2) + + if len(ret) == 0 { + panic("no return value specified for PutObjectTagging") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, map[string]string) error); ok { + r0 = rf(_a0, _a1, _a2) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockS3Client_PutObjectTagging_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'PutObjectTagging' +type mockS3Client_PutObjectTagging_Call struct { + *mock.Call +} + +// PutObjectTagging is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 string +// - _a2 map[string]string +func (_e *mockS3Client_Expecter) PutObjectTagging(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockS3Client_PutObjectTagging_Call { + return &mockS3Client_PutObjectTagging_Call{Call: _e.mock.On("PutObjectTagging", _a0, _a1, _a2)} +} + +func (_c *mockS3Client_PutObjectTagging_Call) Run(run func(_a0 context.Context, _a1 string, _a2 map[string]string)) *mockS3Client_PutObjectTagging_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(map[string]string)) + }) + return _c +} + +func (_c *mockS3Client_PutObjectTagging_Call) Return(_a0 error) *mockS3Client_PutObjectTagging_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockS3Client_PutObjectTagging_Call) RunAndReturn(run func(context.Context, string, map[string]string) error) *mockS3Client_PutObjectTagging_Call { + _c.Call.Return(run) + return _c +} + +// newMockS3Client creates a new instance of mockS3Client. 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 newMockS3Client(t interface { + mock.TestingT + Cleanup(func()) +}) *mockS3Client { + mock := &mockS3Client{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/app/document_store.go b/internal/document/store.go similarity index 54% rename from internal/app/document_store.go rename to internal/document/store.go index 8753807c09..00034304ed 100644 --- a/internal/app/document_store.go +++ b/internal/document/store.go @@ -1,4 +1,4 @@ -package app +package document import ( "context" @@ -6,13 +6,41 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" + dynamodbtypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/random" ) +type DynamoClient interface { + One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error + OneByPK(ctx context.Context, pk dynamo.PK, v interface{}) error + OneByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{}) error + AllByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{}) error + LatestForActor(ctx context.Context, sk dynamo.SK, v interface{}) error + AllBySK(ctx context.Context, sk dynamo.SK, v interface{}) error + AllByKeys(ctx context.Context, keys []dynamo.Keys) ([]map[string]dynamodbtypes.AttributeValue, error) + AllKeysByPK(ctx context.Context, pk dynamo.PK) ([]dynamo.Keys, error) + Put(ctx context.Context, v interface{}) error + Create(ctx context.Context, v interface{}) error + DeleteKeys(ctx context.Context, keys []dynamo.Keys) error + DeleteOne(ctx context.Context, pk dynamo.PK, sk dynamo.SK) error + Update(ctx context.Context, pk dynamo.PK, sk dynamo.SK, values map[string]dynamodbtypes.AttributeValue, expression string) error + BatchPut(ctx context.Context, items []interface{}) error + OneBySK(ctx context.Context, sk dynamo.SK, v interface{}) error + OneByUID(ctx context.Context, uid string, v interface{}) error + WriteTransaction(ctx context.Context, transaction *dynamo.Transaction) error +} + +type S3Client interface { + PutObject(context.Context, string, []byte) error + DeleteObject(context.Context, string) error + DeleteObjects(ctx context.Context, keys []string) error + PutObjectTagging(context.Context, string, map[string]string) error +} + type EventClient interface { SendUidRequested(context.Context, event.UidRequested) error SendApplicationUpdated(context.Context, event.ApplicationUpdated) error @@ -20,7 +48,7 @@ type EventClient interface { SendReducedFeeRequested(context.Context, event.ReducedFeeRequested) error } -type documentStore struct { +type Store struct { dynamoClient DynamoClient s3Client S3Client eventClient EventClient @@ -28,20 +56,20 @@ type documentStore struct { now func() time.Time } -func NewDocumentStore(dynamoClient DynamoClient, s3Client S3Client, eventClient EventClient, randomUUID func() string, now func() time.Time) *documentStore { - return &documentStore{ +func NewStore(dynamoClient DynamoClient, s3Client S3Client, eventClient EventClient) *Store { + return &Store{ dynamoClient: dynamoClient, s3Client: s3Client, eventClient: eventClient, - randomUUID: randomUUID, - now: now, + randomUUID: random.UuidString, + now: time.Now, } } -func (s *documentStore) Create(ctx context.Context, donor *donordata.Provided, filename string, data []byte) (page.Document, error) { +func (s *Store) Create(ctx context.Context, donor *donordata.Provided, filename string, data []byte) (Document, error) { key := donor.LpaUID + "/evidence/" + s.randomUUID() - document := page.Document{ + doc := Document{ PK: dynamo.LpaKey(donor.LpaID), SK: dynamo.DocumentKey(key), Filename: filename, @@ -49,18 +77,18 @@ func (s *documentStore) Create(ctx context.Context, donor *donordata.Provided, f Uploaded: s.now(), } - if err := s.s3Client.PutObject(ctx, document.Key, data); err != nil { - return page.Document{}, err + if err := s.s3Client.PutObject(ctx, doc.Key, data); err != nil { + return Document{}, err } - if err := s.dynamoClient.Create(ctx, document); err != nil { - return page.Document{}, err + if err := s.dynamoClient.Create(ctx, doc); err != nil { + return Document{}, err } - return document, nil + return doc, nil } -func (s *documentStore) GetAll(ctx context.Context) (page.Documents, error) { +func (s *Store) GetAll(ctx context.Context) (Documents, error) { data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err @@ -70,7 +98,7 @@ func (s *documentStore) GetAll(ctx context.Context) (page.Documents, error) { return nil, errors.New("documentStore.GetAll requires LpaID") } - var ds []page.Document + var ds []Document if err := s.dynamoClient.AllByPartialSK(ctx, dynamo.LpaKey(data.LpaID), dynamo.DocumentKey(""), &ds); err != nil && !errors.Is(err, dynamo.NotFoundError{}) { return nil, err } @@ -78,7 +106,7 @@ func (s *documentStore) GetAll(ctx context.Context) (page.Documents, error) { return ds, nil } -func (s *documentStore) UpdateScanResults(ctx context.Context, lpaID, s3ObjectKey string, virusDetected bool) error { +func (s *Store) UpdateScanResults(ctx context.Context, lpaID, s3ObjectKey string, virusDetected bool) error { return s.dynamoClient.Update(ctx, dynamo.LpaKey(lpaID), dynamo.DocumentKey(s3ObjectKey), @@ -89,11 +117,11 @@ func (s *documentStore) UpdateScanResults(ctx context.Context, lpaID, s3ObjectKe "set VirusDetected = :virusDetected, Scanned = :scanned") } -func (s *documentStore) Put(ctx context.Context, document page.Document) error { +func (s *Store) Put(ctx context.Context, document Document) error { return s.dynamoClient.Put(ctx, document) } -func (s *documentStore) DeleteInfectedDocuments(ctx context.Context, documents page.Documents) error { +func (s *Store) DeleteInfectedDocuments(ctx context.Context, documents Documents) error { var dynamoKeys []dynamo.Keys for _, d := range documents { @@ -109,7 +137,7 @@ func (s *documentStore) DeleteInfectedDocuments(ctx context.Context, documents p return s.dynamoClient.DeleteKeys(ctx, dynamoKeys) } -func (s *documentStore) Delete(ctx context.Context, document page.Document) error { +func (s *Store) Delete(ctx context.Context, document Document) error { if err := s.s3Client.DeleteObject(ctx, document.Key); err != nil { return err } @@ -117,7 +145,7 @@ func (s *documentStore) Delete(ctx context.Context, document page.Document) erro return s.dynamoClient.DeleteOne(ctx, document.PK, document.SK) } -func (s *documentStore) Submit(ctx context.Context, donor *donordata.Provided, documents page.Documents) error { +func (s *Store) Submit(ctx context.Context, donor *donordata.Provided, documents Documents) error { var unsentDocuments []any var unsentEvidence []event.Evidence diff --git a/internal/app/document_store_test.go b/internal/document/store_test.go similarity index 80% rename from internal/app/document_store_test.go rename to internal/document/store_test.go index b79b3b2d9d..f2d241ba47 100644 --- a/internal/app/document_store_test.go +++ b/internal/document/store_test.go @@ -1,8 +1,9 @@ -package app +package document import ( "context" "encoding/json" + "errors" "testing" "time" @@ -11,21 +12,12 @@ 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/event" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) -func TestNewDocumentStore(t *testing.T) { - dynamoClient := newMockDynamoClient(t) - s3Client := newMockS3Client(t) - eventClient := newMockEventClient(t) - - expected := &documentStore{dynamoClient: dynamoClient, s3Client: s3Client, eventClient: eventClient} - - assert.Equal(t, expected, NewDocumentStore(dynamoClient, s3Client, eventClient, nil, nil)) -} +var expectedError = errors.New("err") func TestDocumentStoreGetAll(t *testing.T) { ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) @@ -34,21 +26,21 @@ func TestDocumentStoreGetAll(t *testing.T) { dynamoClient. On("AllByPartialSK", ctx, dynamo.LpaKey("123"), dynamo.DocumentKey(""), mock.Anything). Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { - b, _ := json.Marshal(page.Documents{{PK: dynamo.LpaKey("123")}}) + b, _ := json.Marshal(Documents{{PK: dynamo.LpaKey("123")}}) json.Unmarshal(b, v) return nil }) - documentStore := documentStore{dynamoClient: dynamoClient} + documentStore := NewStore(dynamoClient, nil, nil) documents, err := documentStore.GetAll(ctx) assert.Nil(t, err) - assert.Equal(t, page.Documents{{PK: dynamo.LpaKey("123")}}, documents) + assert.Equal(t, Documents{{PK: dynamo.LpaKey("123")}}, documents) } func TestDocumentStoreGetAllMissingSession(t *testing.T) { - documentStore := documentStore{} + documentStore := Store{} _, err := documentStore.GetAll(context.Background()) assert.NotNil(t, err) @@ -57,7 +49,7 @@ func TestDocumentStoreGetAllMissingSession(t *testing.T) { func TestDocumentStoreGetAllMissingLpaIdInSession(t *testing.T) { ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{}) - documentStore := documentStore{} + documentStore := Store{} _, err := documentStore.GetAll(ctx) assert.NotNil(t, err) @@ -70,12 +62,12 @@ func TestDocumentStoreGetAllWhenDynamoClientAllByPartialSKError(t *testing.T) { dynamoClient. On("AllByPartialSK", ctx, dynamo.LpaKey("123"), dynamo.DocumentKey(""), mock.Anything). Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { - b, _ := json.Marshal(page.Documents{{PK: dynamo.LpaKey("123")}}) + b, _ := json.Marshal(Documents{{PK: dynamo.LpaKey("123")}}) json.Unmarshal(b, v) return expectedError }) - documentStore := documentStore{dynamoClient: dynamoClient} + documentStore := Store{dynamoClient: dynamoClient} _, err := documentStore.GetAll(ctx) assert.Equal(t, expectedError, err) @@ -88,16 +80,16 @@ func TestDocumentStoreGetAllWhenNoResults(t *testing.T) { dynamoClient. On("AllByPartialSK", ctx, dynamo.LpaKey("123"), dynamo.DocumentKey(""), mock.Anything). Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { - b, _ := json.Marshal(page.Documents{}) + b, _ := json.Marshal(Documents{}) json.Unmarshal(b, v) return dynamo.NotFoundError{} }) - documentStore := documentStore{dynamoClient: dynamoClient} + documentStore := Store{dynamoClient: dynamoClient} documents, err := documentStore.GetAll(ctx) assert.Nil(t, err) - assert.Equal(t, page.Documents{}, documents) + assert.Equal(t, Documents{}, documents) } func TestDocumentStoreUpdateScanResults(t *testing.T) { @@ -114,7 +106,7 @@ func TestDocumentStoreUpdateScanResults(t *testing.T) { }, "set VirusDetected = :virusDetected, Scanned = :scanned"). Return(nil) - documentStore := documentStore{dynamoClient: dynamoClient} + documentStore := Store{dynamoClient: dynamoClient} err := documentStore.UpdateScanResults(ctx, "123", "object/key", true) @@ -135,7 +127,7 @@ func TestDocumentStoreUpdateScanResultsWhenUpdateError(t *testing.T) { }, "set VirusDetected = :virusDetected, Scanned = :scanned"). Return(expectedError) - documentStore := documentStore{dynamoClient: dynamoClient} + documentStore := Store{dynamoClient: dynamoClient} err := documentStore.UpdateScanResults(ctx, "123", "object/key", true) @@ -147,12 +139,12 @@ func TestDocumentStorePut(t *testing.T) { dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). - Put(ctx, page.Document{Key: "a-key"}). + Put(ctx, Document{Key: "a-key"}). Return(nil) - documentStore := documentStore{dynamoClient: dynamoClient} + documentStore := Store{dynamoClient: dynamoClient} - err := documentStore.Put(ctx, page.Document{Key: "a-key"}) + err := documentStore.Put(ctx, Document{Key: "a-key"}) assert.Nil(t, err) } @@ -162,12 +154,12 @@ func TestDocumentStorePutWhenDynamoClientError(t *testing.T) { dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). - Put(ctx, page.Document{Key: "a-key"}). + Put(ctx, Document{Key: "a-key"}). Return(expectedError) - documentStore := documentStore{dynamoClient: dynamoClient} + documentStore := Store{dynamoClient: dynamoClient} - err := documentStore.Put(ctx, page.Document{Key: "a-key"}) + err := documentStore.Put(ctx, Document{Key: "a-key"}) assert.Equal(t, expectedError, err) } @@ -183,9 +175,9 @@ func TestDeleteInfectedDocuments(t *testing.T) { }). Return(nil) - documentStore := documentStore{dynamoClient: dynamoClient} + documentStore := Store{dynamoClient: dynamoClient} - err := documentStore.DeleteInfectedDocuments(ctx, page.Documents{ + err := documentStore.DeleteInfectedDocuments(ctx, Documents{ {PK: dynamo.LpaKey("a-pk"), SK: dynamo.DocumentKey("a-sk"), Key: "a-key", VirusDetected: true}, {PK: dynamo.LpaKey("another-pk"), SK: dynamo.DocumentKey("another-sk"), Key: "another-key", VirusDetected: true}, }) @@ -204,9 +196,9 @@ func TestDeleteInfectedDocumentsWhenDynamoClientError(t *testing.T) { }). Return(expectedError) - documentStore := documentStore{dynamoClient: dynamoClient} + documentStore := Store{dynamoClient: dynamoClient} - err := documentStore.DeleteInfectedDocuments(ctx, page.Documents{ + err := documentStore.DeleteInfectedDocuments(ctx, Documents{ {PK: dynamo.LpaKey("a-pk"), SK: dynamo.DocumentKey("a-sk"), Key: "a-key", VirusDetected: true}, {PK: dynamo.LpaKey("another-pk"), SK: dynamo.DocumentKey("another-sk"), Key: "another-key", VirusDetected: true}, }) @@ -217,9 +209,9 @@ func TestDeleteInfectedDocumentsWhenDynamoClientError(t *testing.T) { func TestDeleteInfectedDocumentsNonInfectedDocumentsAreNotDeleted(t *testing.T) { ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) - documentStore := documentStore{} + documentStore := Store{} - err := documentStore.DeleteInfectedDocuments(ctx, page.Documents{ + err := documentStore.DeleteInfectedDocuments(ctx, Documents{ {PK: "a-pk", SK: "a-sk", Key: "a-key"}, {PK: "another-pk", SK: "another-sk", Key: "another-key"}, }) @@ -240,9 +232,9 @@ func TestDelete(t *testing.T) { DeleteOne(ctx, dynamo.LpaKey("a-pk"), dynamo.DocumentKey("a-sk")). Return(nil) - documentStore := documentStore{s3Client: s3Client, dynamoClient: dynamoClient} + documentStore := Store{s3Client: s3Client, dynamoClient: dynamoClient} - err := documentStore.Delete(ctx, page.Document{PK: dynamo.LpaKey("a-pk"), SK: dynamo.DocumentKey("a-sk"), Key: "a-key", VirusDetected: true}) + err := documentStore.Delete(ctx, Document{PK: dynamo.LpaKey("a-pk"), SK: dynamo.DocumentKey("a-sk"), Key: "a-key", VirusDetected: true}) assert.Nil(t, err) } @@ -255,9 +247,9 @@ func TestDeleteWhenS3ClientError(t *testing.T) { DeleteObject(ctx, "a-key"). Return(expectedError) - documentStore := documentStore{s3Client: s3Client} + documentStore := Store{s3Client: s3Client} - err := documentStore.Delete(ctx, page.Document{PK: "a-pk", SK: "a-sk", Key: "a-key", VirusDetected: true}) + err := documentStore.Delete(ctx, Document{PK: "a-pk", SK: "a-sk", Key: "a-key", VirusDetected: true}) assert.Equal(t, expectedError, err) } @@ -275,9 +267,9 @@ func TestDeleteWhenDynamoClientError(t *testing.T) { DeleteOne(ctx, dynamo.LpaKey("a-pk"), dynamo.DocumentKey("a-sk")). Return(expectedError) - documentStore := documentStore{s3Client: s3Client, dynamoClient: dynamoClient} + documentStore := Store{s3Client: s3Client, dynamoClient: dynamoClient} - err := documentStore.Delete(ctx, page.Document{PK: dynamo.LpaKey("a-pk"), SK: dynamo.DocumentKey("a-sk"), Key: "a-key", VirusDetected: true}) + err := documentStore.Delete(ctx, Document{PK: dynamo.LpaKey("a-pk"), SK: dynamo.DocumentKey("a-sk"), Key: "a-key", VirusDetected: true}) assert.Equal(t, expectedError, err) } @@ -287,7 +279,7 @@ func TestDocumentStoreSubmit(t *testing.T) { now := time.Now() donor := &donordata.Provided{LpaUID: "lpa-uid", FeeType: pay.HalfFee, EvidenceDelivery: pay.Upload} - documents := page.Documents{ + documents := Documents{ {PK: "a-pk", SK: "a-sk", Key: "a-key", Filename: "a-filename.pdf"}, {PK: "b-pk", SK: "b-sk", Key: "b-key", Filename: "b-filename.png"}, } @@ -316,12 +308,12 @@ func TestDocumentStoreSubmit(t *testing.T) { dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). BatchPut(ctx, []any{ - page.Document{PK: "a-pk", SK: "a-sk", Key: "a-key", Sent: now, Filename: "a-filename.pdf"}, - page.Document{PK: "b-pk", SK: "b-sk", Key: "b-key", Sent: now, Filename: "b-filename.png"}, + Document{PK: "a-pk", SK: "a-sk", Key: "a-key", Sent: now, Filename: "a-filename.pdf"}, + Document{PK: "b-pk", SK: "b-sk", Key: "b-key", Sent: now, Filename: "b-filename.png"}, }). Return(nil) - documentStore := &documentStore{ + documentStore := &Store{ dynamoClient: dynamoClient, eventClient: eventClient, s3Client: s3Client, @@ -336,9 +328,9 @@ func TestDocumentStoreSubmitWhenNoUnsentDocuments(t *testing.T) { ctx := context.Background() donor := &donordata.Provided{LpaUID: "lpa-uid", FeeType: pay.HalfFee, EvidenceDelivery: pay.Upload} - documents := page.Documents{{PK: "a-pk", SK: "a-sk", Key: "a-key", Sent: time.Now()}} + documents := Documents{{PK: "a-pk", SK: "a-sk", Key: "a-key", Sent: time.Now()}} - documentStore := &documentStore{} + documentStore := &Store{} err := documentStore.Submit(ctx, donor, documents) assert.Nil(t, err) @@ -349,14 +341,14 @@ func TestDocumentStoreSubmitWhenS3ClientErrors(t *testing.T) { now := time.Now() donor := &donordata.Provided{LpaUID: "lpa-uid", FeeType: pay.HalfFee, EvidenceDelivery: pay.Upload} - documents := page.Documents{{PK: "a-pk", SK: "a-sk", Key: "a-key"}} + documents := Documents{{PK: "a-pk", SK: "a-sk", Key: "a-key"}} s3Client := newMockS3Client(t) s3Client.EXPECT(). PutObjectTagging(ctx, "a-key", mock.Anything). Return(expectedError) - documentStore := &documentStore{ + documentStore := &Store{ s3Client: s3Client, now: func() time.Time { return now }, } @@ -370,7 +362,7 @@ func TestDocumentStoreSubmitWhenEventClientErrors(t *testing.T) { now := time.Now() donor := &donordata.Provided{LpaUID: "lpa-uid", FeeType: pay.HalfFee, EvidenceDelivery: pay.Upload} - documents := page.Documents{{PK: "a-pk", SK: "a-sk", Key: "a-key"}} + documents := Documents{{PK: "a-pk", SK: "a-sk", Key: "a-key"}} s3Client := newMockS3Client(t) s3Client.EXPECT(). @@ -382,7 +374,7 @@ func TestDocumentStoreSubmitWhenEventClientErrors(t *testing.T) { SendReducedFeeRequested(ctx, mock.Anything). Return(expectedError) - documentStore := &documentStore{ + documentStore := &Store{ eventClient: eventClient, s3Client: s3Client, now: func() time.Time { return now }, @@ -397,7 +389,7 @@ func TestDocumentStoreSubmitWhenDynamoClientErrors(t *testing.T) { now := time.Now() donor := &donordata.Provided{LpaUID: "lpa-uid", FeeType: pay.HalfFee, EvidenceDelivery: pay.Upload} - documents := page.Documents{{PK: "a-pk", SK: "a-sk", Key: "a-key"}} + documents := Documents{{PK: "a-pk", SK: "a-sk", Key: "a-key"}} s3Client := newMockS3Client(t) s3Client.EXPECT(). @@ -414,7 +406,7 @@ func TestDocumentStoreSubmitWhenDynamoClientErrors(t *testing.T) { BatchPut(ctx, mock.Anything). Return(expectedError) - documentStore := &documentStore{ + documentStore := &Store{ dynamoClient: dynamoClient, eventClient: eventClient, s3Client: s3Client, @@ -438,7 +430,7 @@ func TestDocumentCreate(t *testing.T) { PutObject(ctx, "lpa-uid/evidence/a-uuid", data). Return(nil) - expectedDocument := page.Document{ + expectedDocument := Document{ PK: dynamo.LpaKey("lpa-id"), SK: dynamo.DocumentKey("lpa-uid/evidence/a-uuid"), Filename: "a-filename", @@ -451,7 +443,7 @@ func TestDocumentCreate(t *testing.T) { Create(ctx, expectedDocument). Return(nil) - documentStore := &documentStore{ + documentStore := &Store{ dynamoClient: dynamoClient, s3Client: s3Client, now: func() time.Time { return now }, @@ -475,7 +467,7 @@ func TestDocumentCreateWhenS3Error(t *testing.T) { PutObject(ctx, "lpa-uid/evidence/a-uuid", mock.Anything). Return(expectedError) - documentStore := &documentStore{ + documentStore := &Store{ s3Client: s3Client, now: func() time.Time { return now }, randomUUID: func() string { return "a-uuid" }, @@ -504,7 +496,7 @@ func TestDocumentCreateWhenDynamoError(t *testing.T) { Create(ctx, mock.Anything). Return(expectedError) - documentStore := &documentStore{ + documentStore := &Store{ dynamoClient: dynamoClient, s3Client: s3Client, now: func() time.Time { return now }, diff --git a/internal/donor/donorpage/mock_DocumentStore_test.go b/internal/donor/donorpage/mock_DocumentStore_test.go index 2fb562147e..a4aabb091a 100644 --- a/internal/donor/donorpage/mock_DocumentStore_test.go +++ b/internal/donor/donorpage/mock_DocumentStore_test.go @@ -5,10 +5,10 @@ package donorpage import ( context "context" + document "github.com/ministryofjustice/opg-modernising-lpa/internal/document" donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" - mock "github.com/stretchr/testify/mock" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + mock "github.com/stretchr/testify/mock" ) // mockDocumentStore is an autogenerated mock type for the DocumentStore type @@ -25,22 +25,22 @@ func (_m *mockDocumentStore) EXPECT() *mockDocumentStore_Expecter { } // Create provides a mock function with given fields: _a0, _a1, _a2, _a3 -func (_m *mockDocumentStore) Create(_a0 context.Context, _a1 *donordata.Provided, _a2 string, _a3 []byte) (page.Document, error) { +func (_m *mockDocumentStore) Create(_a0 context.Context, _a1 *donordata.Provided, _a2 string, _a3 []byte) (document.Document, error) { ret := _m.Called(_a0, _a1, _a2, _a3) if len(ret) == 0 { panic("no return value specified for Create") } - var r0 page.Document + var r0 document.Document var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *donordata.Provided, string, []byte) (page.Document, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.Provided, string, []byte) (document.Document, error)); ok { return rf(_a0, _a1, _a2, _a3) } - if rf, ok := ret.Get(0).(func(context.Context, *donordata.Provided, string, []byte) page.Document); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.Provided, string, []byte) document.Document); ok { r0 = rf(_a0, _a1, _a2, _a3) } else { - r0 = ret.Get(0).(page.Document) + r0 = ret.Get(0).(document.Document) } if rf, ok := ret.Get(1).(func(context.Context, *donordata.Provided, string, []byte) error); ok { @@ -73,18 +73,18 @@ func (_c *mockDocumentStore_Create_Call) Run(run func(_a0 context.Context, _a1 * return _c } -func (_c *mockDocumentStore_Create_Call) Return(_a0 page.Document, _a1 error) *mockDocumentStore_Create_Call { +func (_c *mockDocumentStore_Create_Call) Return(_a0 document.Document, _a1 error) *mockDocumentStore_Create_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockDocumentStore_Create_Call) RunAndReturn(run func(context.Context, *donordata.Provided, string, []byte) (page.Document, error)) *mockDocumentStore_Create_Call { +func (_c *mockDocumentStore_Create_Call) RunAndReturn(run func(context.Context, *donordata.Provided, string, []byte) (document.Document, error)) *mockDocumentStore_Create_Call { _c.Call.Return(run) return _c } // Delete provides a mock function with given fields: _a0, _a1 -func (_m *mockDocumentStore) Delete(_a0 context.Context, _a1 page.Document) error { +func (_m *mockDocumentStore) Delete(_a0 context.Context, _a1 document.Document) error { ret := _m.Called(_a0, _a1) if len(ret) == 0 { @@ -92,7 +92,7 @@ func (_m *mockDocumentStore) Delete(_a0 context.Context, _a1 page.Document) erro } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, page.Document) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, document.Document) error); ok { r0 = rf(_a0, _a1) } else { r0 = ret.Error(0) @@ -108,14 +108,14 @@ type mockDocumentStore_Delete_Call struct { // Delete is a helper method to define mock.On call // - _a0 context.Context -// - _a1 page.Document +// - _a1 document.Document func (_e *mockDocumentStore_Expecter) Delete(_a0 interface{}, _a1 interface{}) *mockDocumentStore_Delete_Call { return &mockDocumentStore_Delete_Call{Call: _e.mock.On("Delete", _a0, _a1)} } -func (_c *mockDocumentStore_Delete_Call) Run(run func(_a0 context.Context, _a1 page.Document)) *mockDocumentStore_Delete_Call { +func (_c *mockDocumentStore_Delete_Call) Run(run func(_a0 context.Context, _a1 document.Document)) *mockDocumentStore_Delete_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(page.Document)) + run(args[0].(context.Context), args[1].(document.Document)) }) return _c } @@ -125,13 +125,13 @@ func (_c *mockDocumentStore_Delete_Call) Return(_a0 error) *mockDocumentStore_De return _c } -func (_c *mockDocumentStore_Delete_Call) RunAndReturn(run func(context.Context, page.Document) error) *mockDocumentStore_Delete_Call { +func (_c *mockDocumentStore_Delete_Call) RunAndReturn(run func(context.Context, document.Document) error) *mockDocumentStore_Delete_Call { _c.Call.Return(run) return _c } // DeleteInfectedDocuments provides a mock function with given fields: _a0, _a1 -func (_m *mockDocumentStore) DeleteInfectedDocuments(_a0 context.Context, _a1 page.Documents) error { +func (_m *mockDocumentStore) DeleteInfectedDocuments(_a0 context.Context, _a1 document.Documents) error { ret := _m.Called(_a0, _a1) if len(ret) == 0 { @@ -139,7 +139,7 @@ func (_m *mockDocumentStore) DeleteInfectedDocuments(_a0 context.Context, _a1 pa } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, page.Documents) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, document.Documents) error); ok { r0 = rf(_a0, _a1) } else { r0 = ret.Error(0) @@ -155,14 +155,14 @@ type mockDocumentStore_DeleteInfectedDocuments_Call struct { // DeleteInfectedDocuments is a helper method to define mock.On call // - _a0 context.Context -// - _a1 page.Documents +// - _a1 document.Documents func (_e *mockDocumentStore_Expecter) DeleteInfectedDocuments(_a0 interface{}, _a1 interface{}) *mockDocumentStore_DeleteInfectedDocuments_Call { return &mockDocumentStore_DeleteInfectedDocuments_Call{Call: _e.mock.On("DeleteInfectedDocuments", _a0, _a1)} } -func (_c *mockDocumentStore_DeleteInfectedDocuments_Call) Run(run func(_a0 context.Context, _a1 page.Documents)) *mockDocumentStore_DeleteInfectedDocuments_Call { +func (_c *mockDocumentStore_DeleteInfectedDocuments_Call) Run(run func(_a0 context.Context, _a1 document.Documents)) *mockDocumentStore_DeleteInfectedDocuments_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(page.Documents)) + run(args[0].(context.Context), args[1].(document.Documents)) }) return _c } @@ -172,29 +172,29 @@ func (_c *mockDocumentStore_DeleteInfectedDocuments_Call) Return(_a0 error) *moc return _c } -func (_c *mockDocumentStore_DeleteInfectedDocuments_Call) RunAndReturn(run func(context.Context, page.Documents) error) *mockDocumentStore_DeleteInfectedDocuments_Call { +func (_c *mockDocumentStore_DeleteInfectedDocuments_Call) RunAndReturn(run func(context.Context, document.Documents) error) *mockDocumentStore_DeleteInfectedDocuments_Call { _c.Call.Return(run) return _c } // GetAll provides a mock function with given fields: _a0 -func (_m *mockDocumentStore) GetAll(_a0 context.Context) (page.Documents, error) { +func (_m *mockDocumentStore) GetAll(_a0 context.Context) (document.Documents, error) { ret := _m.Called(_a0) if len(ret) == 0 { panic("no return value specified for GetAll") } - var r0 page.Documents + var r0 document.Documents var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (page.Documents, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (document.Documents, error)); ok { return rf(_a0) } - if rf, ok := ret.Get(0).(func(context.Context) page.Documents); ok { + if rf, ok := ret.Get(0).(func(context.Context) document.Documents); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(page.Documents) + r0 = ret.Get(0).(document.Documents) } } @@ -225,18 +225,18 @@ func (_c *mockDocumentStore_GetAll_Call) Run(run func(_a0 context.Context)) *moc return _c } -func (_c *mockDocumentStore_GetAll_Call) Return(_a0 page.Documents, _a1 error) *mockDocumentStore_GetAll_Call { +func (_c *mockDocumentStore_GetAll_Call) Return(_a0 document.Documents, _a1 error) *mockDocumentStore_GetAll_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockDocumentStore_GetAll_Call) RunAndReturn(run func(context.Context) (page.Documents, error)) *mockDocumentStore_GetAll_Call { +func (_c *mockDocumentStore_GetAll_Call) RunAndReturn(run func(context.Context) (document.Documents, error)) *mockDocumentStore_GetAll_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: _a0, _a1 -func (_m *mockDocumentStore) Put(_a0 context.Context, _a1 page.Document) error { +func (_m *mockDocumentStore) Put(_a0 context.Context, _a1 document.Document) error { ret := _m.Called(_a0, _a1) if len(ret) == 0 { @@ -244,7 +244,7 @@ func (_m *mockDocumentStore) Put(_a0 context.Context, _a1 page.Document) error { } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, page.Document) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, document.Document) error); ok { r0 = rf(_a0, _a1) } else { r0 = ret.Error(0) @@ -260,14 +260,14 @@ type mockDocumentStore_Put_Call struct { // Put is a helper method to define mock.On call // - _a0 context.Context -// - _a1 page.Document +// - _a1 document.Document func (_e *mockDocumentStore_Expecter) Put(_a0 interface{}, _a1 interface{}) *mockDocumentStore_Put_Call { return &mockDocumentStore_Put_Call{Call: _e.mock.On("Put", _a0, _a1)} } -func (_c *mockDocumentStore_Put_Call) Run(run func(_a0 context.Context, _a1 page.Document)) *mockDocumentStore_Put_Call { +func (_c *mockDocumentStore_Put_Call) Run(run func(_a0 context.Context, _a1 document.Document)) *mockDocumentStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(page.Document)) + run(args[0].(context.Context), args[1].(document.Document)) }) return _c } @@ -277,13 +277,13 @@ func (_c *mockDocumentStore_Put_Call) Return(_a0 error) *mockDocumentStore_Put_C return _c } -func (_c *mockDocumentStore_Put_Call) RunAndReturn(run func(context.Context, page.Document) error) *mockDocumentStore_Put_Call { +func (_c *mockDocumentStore_Put_Call) RunAndReturn(run func(context.Context, document.Document) error) *mockDocumentStore_Put_Call { _c.Call.Return(run) return _c } // Submit provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockDocumentStore) Submit(_a0 context.Context, _a1 *donordata.Provided, _a2 page.Documents) error { +func (_m *mockDocumentStore) Submit(_a0 context.Context, _a1 *donordata.Provided, _a2 document.Documents) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -291,7 +291,7 @@ func (_m *mockDocumentStore) Submit(_a0 context.Context, _a1 *donordata.Provided } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *donordata.Provided, page.Documents) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.Provided, document.Documents) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -308,14 +308,14 @@ type mockDocumentStore_Submit_Call struct { // Submit is a helper method to define mock.On call // - _a0 context.Context // - _a1 *donordata.Provided -// - _a2 page.Documents +// - _a2 document.Documents func (_e *mockDocumentStore_Expecter) Submit(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockDocumentStore_Submit_Call { return &mockDocumentStore_Submit_Call{Call: _e.mock.On("Submit", _a0, _a1, _a2)} } -func (_c *mockDocumentStore_Submit_Call) Run(run func(_a0 context.Context, _a1 *donordata.Provided, _a2 page.Documents)) *mockDocumentStore_Submit_Call { +func (_c *mockDocumentStore_Submit_Call) Run(run func(_a0 context.Context, _a1 *donordata.Provided, _a2 document.Documents)) *mockDocumentStore_Submit_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*donordata.Provided), args[2].(page.Documents)) + run(args[0].(context.Context), args[1].(*donordata.Provided), args[2].(document.Documents)) }) return _c } @@ -325,7 +325,7 @@ func (_c *mockDocumentStore_Submit_Call) Return(_a0 error) *mockDocumentStore_Su return _c } -func (_c *mockDocumentStore_Submit_Call) RunAndReturn(run func(context.Context, *donordata.Provided, page.Documents) error) *mockDocumentStore_Submit_Call { +func (_c *mockDocumentStore_Submit_Call) RunAndReturn(run func(context.Context, *donordata.Provided, document.Documents) error) *mockDocumentStore_Submit_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/register.go b/internal/donor/donorpage/register.go index e6f32010fe..f7f8fa0aea 100644 --- a/internal/donor/donorpage/register.go +++ b/internal/donor/donorpage/register.go @@ -12,6 +12,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" + "github.com/ministryofjustice/opg-modernising-lpa/internal/document" "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" @@ -121,12 +122,12 @@ type Localizer interface { } type DocumentStore interface { - GetAll(context.Context) (page.Documents, error) - Put(context.Context, page.Document) error - Delete(context.Context, page.Document) error - DeleteInfectedDocuments(context.Context, page.Documents) error - Create(context.Context, *donordata.Provided, string, []byte) (page.Document, error) - Submit(context.Context, *donordata.Provided, page.Documents) error + GetAll(context.Context) (document.Documents, error) + Put(context.Context, document.Document) error + Delete(context.Context, document.Document) error + DeleteInfectedDocuments(context.Context, document.Documents) error + Create(context.Context, *donordata.Provided, string, []byte) (document.Document, error) + Submit(context.Context, *donordata.Provided, document.Documents) error } type EventClient interface { diff --git a/internal/donor/donorpage/upload_evidence.go b/internal/donor/donorpage/upload_evidence.go index 3d8d287313..b8fea19b44 100644 --- a/internal/donor/donorpage/upload_evidence.go +++ b/internal/donor/donorpage/upload_evidence.go @@ -13,6 +13,7 @@ import ( "github.com/gabriel-vasile/mimetype" "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + "github.com/ministryofjustice/opg-modernising-lpa/internal/document" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" @@ -55,7 +56,7 @@ type uploadEvidenceData struct { Errors validation.List NumberOfAllowedFiles int FeeType pay.FeeType - Documents page.Documents + Documents document.Documents MimeTypes []string Deleted string StartScan string @@ -88,7 +89,7 @@ func UploadEvidence(tmpl template.Template, logger Logger, payer Handler, docume if data.Errors.None() { switch form.Action { case "upload": - var uploadedDocuments []page.Document + var uploadedDocuments []document.Document for _, file := range form.Files { document, err := documentStore.Create(r.Context(), donor, file.Filename, file.Data) diff --git a/internal/donor/donorpage/upload_evidence_sse_test.go b/internal/donor/donorpage/upload_evidence_sse_test.go index 223fbbc3a4..d4c6d58c03 100644 --- a/internal/donor/donorpage/upload_evidence_sse_test.go +++ b/internal/donor/donorpage/upload_evidence_sse_test.go @@ -7,8 +7,8 @@ import ( "testing" "time" + "github.com/ministryofjustice/opg-modernising-lpa/internal/document" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/stretchr/testify/assert" ) @@ -19,19 +19,19 @@ func TestUploadEvidenceSSE(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Scanned: false}, {Scanned: true}, }, nil).Once() documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Scanned: false}, {Scanned: true}, }, nil).Once() documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Scanned: true}, {Scanned: true}, }, nil).Once() @@ -55,7 +55,7 @@ func TestUploadEvidenceSSEOnDonorStoreError(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Scanned: false}, {Scanned: true}, }, expectedError) @@ -77,7 +77,7 @@ func TestUploadEvidenceSSEOnDonorStoreErrorWhenRefreshingDocuments(t *testing.T) documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Scanned: false}, {Scanned: true}, }, nil). @@ -85,7 +85,7 @@ func TestUploadEvidenceSSEOnDonorStoreErrorWhenRefreshingDocuments(t *testing.T) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Scanned: false}, {Scanned: true}, }, expectedError). diff --git a/internal/donor/donorpage/upload_evidence_test.go b/internal/donor/donorpage/upload_evidence_test.go index eb5563175a..d1a63875f9 100644 --- a/internal/donor/donorpage/upload_evidence_test.go +++ b/internal/donor/donorpage/upload_evidence_test.go @@ -12,6 +12,7 @@ import ( "strings" "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/document" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -29,7 +30,7 @@ func TestGetUploadEvidence(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{{Scanned: false}}, nil) + Return(document.Documents{{Scanned: false}}, nil) template := newMockTemplate(t) template.EXPECT(). @@ -38,7 +39,7 @@ func TestGetUploadEvidence(t *testing.T) { NumberOfAllowedFiles: 5, FeeType: pay.FullFee, MimeTypes: acceptedMimeTypes(), - Documents: page.Documents{{Scanned: false}}, + Documents: document.Documents{{Scanned: false}}, }). Return(nil) @@ -68,7 +69,7 @@ func TestGetUploadEvidenceWhenTemplateErrors(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{{Scanned: false}}, nil) + Return(document.Documents{{Scanned: false}}, nil) template := newMockTemplate(t) template.EXPECT(). @@ -104,10 +105,10 @@ func TestPostUploadEvidenceWithUploadActionAcceptedFileTypes(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{}, nil) + Return(document.Documents{}, nil) documentStore.EXPECT(). Create(r.Context(), &donordata.Provided{LpaID: "lpa-id", LpaUID: "lpa-uid", FeeType: pay.HalfFee}, filename, mock.Anything). - Return(page.Document{ + Return(document.Document{ PK: dynamo.LpaKey("lpa-id"), SK: dynamo.DocumentKey("lpa-uid/evidence/a-uid"), Filename: filename, @@ -118,7 +119,7 @@ func TestPostUploadEvidenceWithUploadActionAcceptedFileTypes(t *testing.T) { template.EXPECT(). Execute(w, &uploadEvidenceData{ App: testAppData, - Documents: page.Documents{{ + Documents: document.Documents{{ PK: dynamo.LpaKey("lpa-id"), SK: dynamo.DocumentKey("lpa-uid/evidence/a-uid"), Filename: filename, @@ -159,10 +160,10 @@ func TestPostUploadEvidenceWithUploadActionMultipleFiles(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{}, nil) + Return(document.Documents{}, nil) documentStore.EXPECT(). Create(r.Context(), &donordata.Provided{LpaID: "lpa-id", LpaUID: "lpa-uid", FeeType: pay.HalfFee}, "dummy.pdf", mock.Anything). - Return(page.Document{ + Return(document.Document{ PK: dynamo.LpaKey("lpa-id"), SK: dynamo.DocumentKey("lpa-uid/evidence/a-uid"), Filename: "dummy.pdf", @@ -171,7 +172,7 @@ func TestPostUploadEvidenceWithUploadActionMultipleFiles(t *testing.T) { Once() documentStore.EXPECT(). Create(r.Context(), &donordata.Provided{LpaID: "lpa-id", LpaUID: "lpa-uid", FeeType: pay.HalfFee}, "dummy.png", mock.Anything). - Return(page.Document{ + Return(document.Document{ PK: dynamo.LpaKey("lpa-id"), SK: dynamo.DocumentKey("lpa-uid/evidence/a-uid"), Filename: "dummy.png", @@ -183,7 +184,7 @@ func TestPostUploadEvidenceWithUploadActionMultipleFiles(t *testing.T) { template.EXPECT(). Execute(w, &uploadEvidenceData{ App: testAppData, - Documents: page.Documents{ + Documents: document.Documents{ { PK: dynamo.LpaKey("lpa-id"), SK: dynamo.DocumentKey("lpa-uid/evidence/a-uid"), @@ -232,10 +233,10 @@ func TestPostUploadEvidenceWithUploadActionFilenameSpecialCharactersAreEscaped(t documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{}, nil) + Return(document.Documents{}, nil) documentStore.EXPECT(). Create(r.Context(), &donordata.Provided{LpaID: "lpa-id", LpaUID: "lpa-uid", FeeType: pay.HalfFee}, "<img src=1 onerror=alert(document.domain)>’ brute.heic", mock.Anything). - Return(page.Document{ + Return(document.Document{ PK: dynamo.LpaKey("lpa-id"), SK: dynamo.DocumentKey("lpa-uid/evidence/a-uid"), Filename: "<img src=1 onerror=alert(document.domain)>’ brute.heic", @@ -246,7 +247,7 @@ func TestPostUploadEvidenceWithUploadActionFilenameSpecialCharactersAreEscaped(t template.EXPECT(). Execute(w, &uploadEvidenceData{ App: testAppData, - Documents: page.Documents{ + Documents: document.Documents{ { PK: dynamo.LpaKey("lpa-id"), SK: dynamo.DocumentKey("lpa-uid/evidence/a-uid"), @@ -274,7 +275,7 @@ func TestPostUploadEvidenceWithPayAction(t *testing.T) { donor := &donordata.Provided{LpaID: "lpa-id", LpaUID: "lpa-uid", FeeType: pay.HalfFee, EvidenceDelivery: pay.Upload} - documents := page.Documents{{ + documents := document.Documents{{ PK: dynamo.LpaKey("lpa-id"), SK: dynamo.DocumentKey("lpa-uid/evidence/a-uid"), Filename: "safe.file", @@ -317,7 +318,7 @@ func TestPostUploadEvidenceWithPayActionWhenPayerError(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{}, nil) + Return(document.Documents{}, nil) documentStore.EXPECT(). Submit(r.Context(), mock.Anything, mock.Anything). Return(nil) @@ -344,7 +345,7 @@ func TestPostUploadEvidenceWithPayActionWhenDocumentStoreSubmitErrors(t *testing documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{{ + Return(document.Documents{{ PK: dynamo.LpaKey("lpa-id"), SK: dynamo.DocumentKey("lpa-uid/evidence/a-uid"), Filename: "safe.file", @@ -371,7 +372,7 @@ func TestPostUploadEvidenceWithPayActionWhenUnscannedDocument(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{{ + Return(document.Documents{{ PK: dynamo.LpaKey("lpa-id"), SK: dynamo.DocumentKey("lpa-uid/evidence/a-uid"), Filename: "safe.file", @@ -406,7 +407,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFiles(t *testing.T) documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Filename: "a", VirusDetected: true}, {Filename: "b", VirusDetected: false}, {Filename: "c", VirusDetected: true}, @@ -414,7 +415,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFiles(t *testing.T) }, nil). Once() documentStore.EXPECT(). - DeleteInfectedDocuments(r.Context(), page.Documents{ + DeleteInfectedDocuments(r.Context(), document.Documents{ {Filename: "a", VirusDetected: true}, {Filename: "b", VirusDetected: false}, {Filename: "c", VirusDetected: true}, @@ -423,7 +424,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFiles(t *testing.T) Return(nil) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Filename: "b", VirusDetected: false}, }, nil). Once() @@ -432,7 +433,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFiles(t *testing.T) template.EXPECT(). Execute(w, &uploadEvidenceData{ App: testAppData, - Documents: page.Documents{{Filename: "b", VirusDetected: false}}, + Documents: document.Documents{{Filename: "b", VirusDetected: false}}, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), FeeType: pay.HalfFee, @@ -454,7 +455,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithoutInfectedFiles(t *testing. documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Filename: "a", VirusDetected: false}, }, nil) @@ -462,7 +463,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithoutInfectedFiles(t *testing. template.EXPECT(). Execute(w, &uploadEvidenceData{ App: testAppData, - Documents: page.Documents{{Filename: "a", VirusDetected: false}}, + Documents: document.Documents{{Filename: "a", VirusDetected: false}}, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), FeeType: pay.HalfFee, @@ -483,7 +484,7 @@ func TestPostUploadEvidenceWithPayActionWithInfectedFilesWhenDocumentStoreGetAll documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Filename: "a", VirusDetected: true}, {Filename: "b", VirusDetected: false}, {Filename: "c", VirusDetected: true}, @@ -504,14 +505,14 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFilesWhenDocumentSto documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Filename: "a", VirusDetected: true}, {Filename: "b", VirusDetected: false}, {Filename: "c", VirusDetected: true}, {Filename: "d", VirusDetected: true}, }, nil) documentStore.EXPECT(). - DeleteInfectedDocuments(r.Context(), page.Documents{ + DeleteInfectedDocuments(r.Context(), document.Documents{ {Filename: "a", VirusDetected: true}, {Filename: "b", VirusDetected: false}, {Filename: "c", VirusDetected: true}, @@ -533,7 +534,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFilesWhenDocumentSto documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Filename: "a", VirusDetected: true}, {Filename: "b", VirusDetected: false}, {Filename: "c", VirusDetected: true}, @@ -541,7 +542,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFilesWhenDocumentSto }, nil). Once() documentStore.EXPECT(). - DeleteInfectedDocuments(r.Context(), page.Documents{ + DeleteInfectedDocuments(r.Context(), document.Documents{ {Filename: "a", VirusDetected: true}, {Filename: "b", VirusDetected: false}, {Filename: "c", VirusDetected: true}, @@ -550,7 +551,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFilesWhenDocumentSto Return(nil) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Filename: "b", VirusDetected: false}, }, expectedError). Once() @@ -569,7 +570,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFilesWhenTemplateErr documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Filename: "a", VirusDetected: true}, {Filename: "b", VirusDetected: false}, {Filename: "c", VirusDetected: true}, @@ -577,7 +578,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFilesWhenTemplateErr }, nil). Once() documentStore.EXPECT(). - DeleteInfectedDocuments(r.Context(), page.Documents{ + DeleteInfectedDocuments(r.Context(), document.Documents{ {Filename: "a", VirusDetected: true}, {Filename: "b", VirusDetected: false}, {Filename: "c", VirusDetected: true}, @@ -586,7 +587,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFilesWhenTemplateErr Return(nil) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Filename: "b", VirusDetected: false}, }, nil). Once() @@ -595,7 +596,7 @@ func TestPostUploadEvidenceWithScanResultsActionWithInfectedFilesWhenTemplateErr template.EXPECT(). Execute(w, &uploadEvidenceData{ App: testAppData, - Documents: page.Documents{{Filename: "b", VirusDetected: false}}, + Documents: document.Documents{{Filename: "b", VirusDetected: false}}, NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), FeeType: pay.HalfFee, @@ -624,7 +625,7 @@ func TestPostUploadEvidenceWhenBadCsrfField(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{}, nil) + Return(document.Documents{}, nil) template := newMockTemplate(t) template.EXPECT(). @@ -634,7 +635,7 @@ func TestPostUploadEvidenceWhenBadCsrfField(t *testing.T) { MimeTypes: acceptedMimeTypes(), Errors: validation.With("upload", validation.CustomError{Label: "errorGenericUploadProblem"}), FeeType: pay.FullFee, - Documents: page.Documents{}, + Documents: document.Documents{}, }). Return(nil) @@ -664,7 +665,7 @@ func TestPostUploadEvidenceWhenBadActionField(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{}, nil) + Return(document.Documents{}, nil) template := newMockTemplate(t) template.EXPECT(). @@ -674,7 +675,7 @@ func TestPostUploadEvidenceWhenBadActionField(t *testing.T) { MimeTypes: acceptedMimeTypes(), Errors: validation.With("upload", validation.CustomError{Label: "errorGenericUploadProblem"}), FeeType: pay.FullFee, - Documents: page.Documents{}, + Documents: document.Documents{}, }). Return(nil) @@ -712,7 +713,7 @@ func TestPostUploadEvidenceNumberOfFilesLimitPassed(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{}, nil) + Return(document.Documents{}, nil) template := newMockTemplate(t) template.EXPECT(). @@ -722,7 +723,7 @@ func TestPostUploadEvidenceNumberOfFilesLimitPassed(t *testing.T) { MimeTypes: acceptedMimeTypes(), Errors: validation.With("upload", validation.CustomError{Label: "errorTooManyFiles"}), FeeType: pay.FullFee, - Documents: page.Documents{}, + Documents: document.Documents{}, }). Return(nil) @@ -797,7 +798,7 @@ func TestPostUploadEvidenceWhenBadUpload(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{}, nil) + Return(document.Documents{}, nil) template := newMockTemplate(t) template.EXPECT(). @@ -807,7 +808,7 @@ func TestPostUploadEvidenceWhenBadUpload(t *testing.T) { MimeTypes: acceptedMimeTypes(), Errors: validation.With("upload", tc.expectedError), FeeType: pay.FullFee, - Documents: page.Documents{}, + Documents: document.Documents{}, }). Return(nil) @@ -842,12 +843,12 @@ func TestGetUploadEvidenceDeleteEvidence(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}, {Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png"}, }, nil) documentStore.EXPECT(). - Delete(r.Context(), page.Document{Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}). + Delete(r.Context(), document.Document{Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}). Return(nil) template := newMockTemplate(t) @@ -857,7 +858,7 @@ func TestGetUploadEvidenceDeleteEvidence(t *testing.T) { NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), FeeType: pay.FullFee, - Documents: page.Documents{ + Documents: document.Documents{ {Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png"}, }, Deleted: "dummy.pdf", @@ -891,7 +892,7 @@ func TestGetUploadEvidenceDeleteEvidenceWhenUnexpectedFieldName(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}, }, nil) @@ -902,7 +903,7 @@ func TestGetUploadEvidenceDeleteEvidenceWhenUnexpectedFieldName(t *testing.T) { NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), FeeType: pay.FullFee, - Documents: page.Documents{ + Documents: document.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}, }, Errors: validation.With("delete", validation.CustomError{Label: "errorGenericUploadProblem"}), @@ -936,12 +937,12 @@ func TestGetUploadEvidenceDeleteEvidenceWhenDocumentStoreDeleteError(t *testing. documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}, {Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png"}, }, nil) documentStore.EXPECT(). - Delete(r.Context(), page.Document{Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}). + Delete(r.Context(), document.Document{Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}). Return(expectedError) err := UploadEvidence(nil, nil, nil, documentStore)(testAppData, w, r, &donordata.Provided{}) @@ -970,12 +971,12 @@ func TestGetUploadEvidenceDeleteEvidenceWhenTemplateError(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}, {Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png"}, }, nil) documentStore.EXPECT(). - Delete(r.Context(), page.Document{Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}). + Delete(r.Context(), document.Document{Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}). Return(nil) template := newMockTemplate(t) @@ -985,7 +986,7 @@ func TestGetUploadEvidenceDeleteEvidenceWhenTemplateError(t *testing.T) { NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), FeeType: pay.FullFee, - Documents: page.Documents{ + Documents: document.Documents{ {Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png"}, }, Deleted: "dummy.pdf", @@ -1015,12 +1016,12 @@ func TestPostUploadEvidenceWithCloseConnectionAction(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf", Scanned: true}, {Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}, }, nil) documentStore.EXPECT(). - Delete(r.Context(), page.Document{Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}). + Delete(r.Context(), document.Document{Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}). Return(nil) template := newMockTemplate(t) @@ -1030,7 +1031,7 @@ func TestPostUploadEvidenceWithCloseConnectionAction(t *testing.T) { NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), FeeType: pay.HalfFee, - Documents: page.Documents{ + Documents: document.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf", Scanned: true}, }, Errors: validation.With("upload", validation.CustomError{Label: "errorGenericUploadProblem"}), @@ -1064,12 +1065,12 @@ func TestPostUploadEvidenceWithCloseConnectionActionWhenDocumentStoreDeleteError documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf", Scanned: true}, {Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}, }, nil) documentStore.EXPECT(). - Delete(r.Context(), page.Document{Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}). + Delete(r.Context(), document.Document{Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}). Return(expectedError) err := UploadEvidence(nil, nil, nil, documentStore)(testAppData, w, r, &donordata.Provided{LpaUID: "lpa-uid", FeeType: pay.HalfFee}) @@ -1098,12 +1099,12 @@ func TestPostUploadEvidenceWithCloseConnectionActionWhenTemplateError(t *testing documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf", Scanned: true}, {Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}, }, nil) documentStore.EXPECT(). - Delete(r.Context(), page.Document{Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}). + Delete(r.Context(), document.Document{Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}). Return(nil) template := newMockTemplate(t) @@ -1113,7 +1114,7 @@ func TestPostUploadEvidenceWithCloseConnectionActionWhenTemplateError(t *testing NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), FeeType: pay.HalfFee, - Documents: page.Documents{ + Documents: document.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf", Scanned: true}, }, Errors: validation.With("upload", validation.CustomError{Label: "errorGenericUploadProblem"}), @@ -1146,12 +1147,12 @@ func TestPostUploadEvidenceWithCancelUploadAction(t *testing.T) { documentStore := newMockDocumentStore(t) documentStore.EXPECT(). GetAll(r.Context()). - Return(page.Documents{ + Return(document.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf", Scanned: true}, {Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}, }, nil) documentStore.EXPECT(). - Delete(r.Context(), page.Document{Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}). + Delete(r.Context(), document.Document{Key: "lpa-uid/evidence/another-uid", Filename: "dummy.png", Scanned: false}). Return(nil) template := newMockTemplate(t) @@ -1161,7 +1162,7 @@ func TestPostUploadEvidenceWithCancelUploadAction(t *testing.T) { NumberOfAllowedFiles: 5, MimeTypes: acceptedMimeTypes(), FeeType: pay.HalfFee, - Documents: page.Documents{ + Documents: document.Documents{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf", Scanned: true}, }, }). diff --git a/internal/page/fixtures/donor.go b/internal/page/fixtures/donor.go index b6d68f403b..8d7ddaa5ce 100644 --- a/internal/page/fixtures/donor.go +++ b/internal/page/fixtures/donor.go @@ -13,6 +13,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" + "github.com/ministryofjustice/opg-modernising-lpa/internal/document" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" @@ -35,9 +36,9 @@ type DynamoClient interface { } type DocumentStore interface { - GetAll(context.Context) (page.Documents, error) - Put(context.Context, page.Document) error - Create(ctx context.Context, donor *donordata.Provided, filename string, data []byte) (page.Document, error) + GetAll(context.Context) (document.Documents, error) + Put(context.Context, document.Document) error + Create(ctx context.Context, donor *donordata.Provided, filename string, data []byte) (document.Document, error) } var progressValues = []string{ diff --git a/internal/sharecode/mock_DynamoClient_test.go b/internal/sharecode/mock_DynamoClient_test.go new file mode 100644 index 0000000000..97ba3d0f08 --- /dev/null +++ b/internal/sharecode/mock_DynamoClient_test.go @@ -0,0 +1,277 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package sharecode + +import ( + context "context" + + dynamo "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + mock "github.com/stretchr/testify/mock" +) + +// mockDynamoClient is an autogenerated mock type for the DynamoClient type +type mockDynamoClient struct { + mock.Mock +} + +type mockDynamoClient_Expecter struct { + mock *mock.Mock +} + +func (_m *mockDynamoClient) EXPECT() *mockDynamoClient_Expecter { + return &mockDynamoClient_Expecter{mock: &_m.Mock} +} + +// DeleteOne provides a mock function with given fields: ctx, pk, sk +func (_m *mockDynamoClient) DeleteOne(ctx context.Context, pk dynamo.PK, sk dynamo.SK) error { + ret := _m.Called(ctx, pk, sk) + + if len(ret) == 0 { + panic("no return value specified for DeleteOne") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK) error); ok { + r0 = rf(ctx, pk, sk) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_DeleteOne_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteOne' +type mockDynamoClient_DeleteOne_Call struct { + *mock.Call +} + +// DeleteOne is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - sk dynamo.SK +func (_e *mockDynamoClient_Expecter) DeleteOne(ctx interface{}, pk interface{}, sk interface{}) *mockDynamoClient_DeleteOne_Call { + return &mockDynamoClient_DeleteOne_Call{Call: _e.mock.On("DeleteOne", ctx, pk, sk)} +} + +func (_c *mockDynamoClient_DeleteOne_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK)) *mockDynamoClient_DeleteOne_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK)) + }) + return _c +} + +func (_c *mockDynamoClient_DeleteOne_Call) Return(_a0 error) *mockDynamoClient_DeleteOne_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_DeleteOne_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK) error) *mockDynamoClient_DeleteOne_Call { + _c.Call.Return(run) + return _c +} + +// One provides a mock function with given fields: ctx, pk, sk, v +func (_m *mockDynamoClient) One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, pk, sk, v) + + if len(ret) == 0 { + panic("no return value specified for One") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, pk, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_One_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'One' +type mockDynamoClient_One_Call struct { + *mock.Call +} + +// One is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) One(ctx interface{}, pk interface{}, sk interface{}, v interface{}) *mockDynamoClient_One_Call { + return &mockDynamoClient_One_Call{Call: _e.mock.On("One", ctx, pk, sk, v)} +} + +func (_c *mockDynamoClient_One_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{})) *mockDynamoClient_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{})) + }) + return _c +} + +func (_c *mockDynamoClient_One_Call) Return(_a0 error) *mockDynamoClient_One_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_One_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, interface{}) error) *mockDynamoClient_One_Call { + _c.Call.Return(run) + return _c +} + +// OneByPK provides a mock function with given fields: ctx, pk, v +func (_m *mockDynamoClient) OneByPK(ctx context.Context, pk dynamo.PK, v interface{}) error { + ret := _m.Called(ctx, pk, v) + + if len(ret) == 0 { + panic("no return value specified for OneByPK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, interface{}) error); ok { + r0 = rf(ctx, pk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneByPK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneByPK' +type mockDynamoClient_OneByPK_Call struct { + *mock.Call +} + +// OneByPK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneByPK(ctx interface{}, pk interface{}, v interface{}) *mockDynamoClient_OneByPK_Call { + return &mockDynamoClient_OneByPK_Call{Call: _e.mock.On("OneByPK", ctx, pk, v)} +} + +func (_c *mockDynamoClient_OneByPK_Call) Run(run func(ctx context.Context, pk dynamo.PK, v interface{})) *mockDynamoClient_OneByPK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneByPK_Call) Return(_a0 error) *mockDynamoClient_OneByPK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneByPK_Call) RunAndReturn(run func(context.Context, dynamo.PK, interface{}) error) *mockDynamoClient_OneByPK_Call { + _c.Call.Return(run) + return _c +} + +// OneBySK provides a mock function with given fields: ctx, sk, v +func (_m *mockDynamoClient) OneBySK(ctx context.Context, sk dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, sk, v) + + if len(ret) == 0 { + panic("no return value specified for OneBySK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneBySK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneBySK' +type mockDynamoClient_OneBySK_Call struct { + *mock.Call +} + +// OneBySK is a helper method to define mock.On call +// - ctx context.Context +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneBySK(ctx interface{}, sk interface{}, v interface{}) *mockDynamoClient_OneBySK_Call { + return &mockDynamoClient_OneBySK_Call{Call: _e.mock.On("OneBySK", ctx, sk, v)} +} + +func (_c *mockDynamoClient_OneBySK_Call) Run(run func(ctx context.Context, sk dynamo.SK, v interface{})) *mockDynamoClient_OneBySK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneBySK_Call) Return(_a0 error) *mockDynamoClient_OneBySK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneBySK_Call) RunAndReturn(run func(context.Context, dynamo.SK, interface{}) error) *mockDynamoClient_OneBySK_Call { + _c.Call.Return(run) + return _c +} + +// Put provides a mock function with given fields: ctx, v +func (_m *mockDynamoClient) Put(ctx context.Context, v interface{}) error { + ret := _m.Called(ctx, v) + + if len(ret) == 0 { + panic("no return value specified for Put") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}) error); ok { + r0 = rf(ctx, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_Put_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Put' +type mockDynamoClient_Put_Call struct { + *mock.Call +} + +// Put is a helper method to define mock.On call +// - ctx context.Context +// - v interface{} +func (_e *mockDynamoClient_Expecter) Put(ctx interface{}, v interface{}) *mockDynamoClient_Put_Call { + return &mockDynamoClient_Put_Call{Call: _e.mock.On("Put", ctx, v)} +} + +func (_c *mockDynamoClient_Put_Call) Run(run func(ctx context.Context, v interface{})) *mockDynamoClient_Put_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_Put_Call) Return(_a0 error) *mockDynamoClient_Put_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_Put_Call) RunAndReturn(run func(context.Context, interface{}) error) *mockDynamoClient_Put_Call { + _c.Call.Return(run) + return _c +} + +// newMockDynamoClient creates a new instance of mockDynamoClient. 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 newMockDynamoClient(t interface { + mock.TestingT + Cleanup(func()) +}) *mockDynamoClient { + mock := &mockDynamoClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/app/share_code_store.go b/internal/sharecode/store.go similarity index 71% rename from internal/app/share_code_store.go rename to internal/sharecode/store.go index 202f339803..964788597a 100644 --- a/internal/app/share_code_store.go +++ b/internal/sharecode/store.go @@ -1,4 +1,4 @@ -package app +package sharecode import ( "context" @@ -9,10 +9,9 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) -type ShareCodeStoreDynamoClient interface { +type DynamoClient interface { One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error OneByPK(ctx context.Context, pk dynamo.PK, v interface{}) error OneBySK(ctx context.Context, sk dynamo.SK, v interface{}) error @@ -20,17 +19,17 @@ type ShareCodeStoreDynamoClient interface { DeleteOne(ctx context.Context, pk dynamo.PK, sk dynamo.SK) error } -type shareCodeStore struct { - dynamoClient ShareCodeStoreDynamoClient +type Store struct { + dynamoClient DynamoClient now func() time.Time } -func NewShareCodeStore(dynamoClient ShareCodeStoreDynamoClient) *shareCodeStore { - return &shareCodeStore{dynamoClient: dynamoClient, now: time.Now} +func NewStore(dynamoClient DynamoClient) *Store { + return &Store{dynamoClient: dynamoClient, now: time.Now} } -func (s *shareCodeStore) Get(ctx context.Context, actorType actor.Type, shareCode string) (sharecode.Data, error) { - var data sharecode.Data +func (s *Store) Get(ctx context.Context, actorType actor.Type, shareCode string) (Data, error) { + var data Data pk, err := shareCodeKey(actorType, shareCode) if err != nil { @@ -38,17 +37,17 @@ func (s *shareCodeStore) Get(ctx context.Context, actorType actor.Type, shareCod } if err := s.dynamoClient.OneByPK(ctx, pk, &data); err != nil { - return sharecode.Data{}, err + return Data{}, err } if !data.LpaLinkedAt.IsZero() { - return sharecode.Data{}, dynamo.NotFoundError{} + return Data{}, dynamo.NotFoundError{} } return data, err } -func (s *shareCodeStore) Put(ctx context.Context, actorType actor.Type, shareCode string, data sharecode.Data) error { +func (s *Store) Put(ctx context.Context, actorType actor.Type, shareCode string, data Data) error { pk, err := shareCodeKey(actorType, shareCode) if err != nil { return err @@ -60,7 +59,7 @@ func (s *shareCodeStore) Put(ctx context.Context, actorType actor.Type, shareCod return s.dynamoClient.Put(ctx, data) } -func (s *shareCodeStore) PutDonor(ctx context.Context, shareCode string, data sharecode.Data) error { +func (s *Store) PutDonor(ctx context.Context, shareCode string, data Data) error { organisationKey, ok := data.LpaOwnerKey.Organisation() if !ok { return errors.New("shareCodeStore.PutDonor can only be used by organisations") @@ -73,8 +72,8 @@ func (s *shareCodeStore) PutDonor(ctx context.Context, shareCode string, data sh return s.dynamoClient.Put(ctx, data) } -func (s *shareCodeStore) GetDonor(ctx context.Context) (sharecode.Data, error) { - var data sharecode.Data +func (s *Store) GetDonor(ctx context.Context) (Data, error) { + var data Data sessionData, err := appcontext.SessionFromContext(ctx) if err != nil { @@ -87,7 +86,7 @@ func (s *shareCodeStore) GetDonor(ctx context.Context) (sharecode.Data, error) { return data, err } -func (s *shareCodeStore) Delete(ctx context.Context, shareCode sharecode.Data) error { +func (s *Store) Delete(ctx context.Context, shareCode Data) error { return s.dynamoClient.DeleteOne(ctx, shareCode.PK, shareCode.SK) } diff --git a/internal/app/share_code_store_test.go b/internal/sharecode/store_test.go similarity index 73% rename from internal/app/share_code_store_test.go rename to internal/sharecode/store_test.go index 56929cb1d5..e250c1ac12 100644 --- a/internal/app/share_code_store_test.go +++ b/internal/sharecode/store_test.go @@ -1,18 +1,46 @@ -package app +package sharecode import ( "context" + "encoding/json" + "errors" "testing" "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) +var ( + expectedError = errors.New("err") + testNow = time.Date(2023, time.April, 2, 3, 4, 5, 6, time.UTC) + testNowFn = func() time.Time { return testNow } +) + +func (m *mockDynamoClient) ExpectOneByPK(ctx, pk, data interface{}, err error) { + m. + On("OneByPK", ctx, pk, mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }). + Once() +} + +func (m *mockDynamoClient) ExpectOneBySK(ctx, sk, data interface{}, err error) { + m. + On("OneBySK", ctx, sk, mock.Anything). + Return(func(ctx context.Context, sk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} + func TestShareCodeStoreGet(t *testing.T) { testcases := map[string]struct { t actor.Type @@ -35,14 +63,14 @@ func TestShareCodeStoreGet(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { ctx := context.Background() - data := sharecode.Data{LpaKey: "lpa-id"} + data := Data{LpaKey: "lpa-id"} dynamoClient := newMockDynamoClient(t) dynamoClient. ExpectOneByPK(ctx, tc.pk, data, nil) - shareCodeStore := &shareCodeStore{dynamoClient: dynamoClient} + shareCodeStore := &Store{dynamoClient: dynamoClient} result, err := shareCodeStore.Get(ctx, tc.t, "123") assert.Nil(t, err) @@ -57,18 +85,18 @@ func TestShareCodeStoreGetWhenLinked(t *testing.T) { dynamoClient := newMockDynamoClient(t) dynamoClient. ExpectOneByPK(ctx, dynamo.ShareKey(dynamo.DonorShareKey("123")), - sharecode.Data{LpaLinkedAt: time.Now()}, nil) + Data{LpaLinkedAt: time.Now()}, nil) - shareCodeStore := &shareCodeStore{dynamoClient: dynamoClient} + shareCodeStore := &Store{dynamoClient: dynamoClient} result, err := shareCodeStore.Get(ctx, actor.TypeDonor, "123") assert.Equal(t, dynamo.NotFoundError{}, err) - assert.Equal(t, sharecode.Data{}, result) + assert.Equal(t, Data{}, result) } func TestShareCodeStoreGetForBadActorType(t *testing.T) { ctx := context.Background() - shareCodeStore := &shareCodeStore{} + shareCodeStore := &Store{} _, err := shareCodeStore.Get(ctx, actor.TypeIndependentWitness, "123") assert.NotNil(t, err) @@ -76,14 +104,14 @@ func TestShareCodeStoreGetForBadActorType(t *testing.T) { func TestShareCodeStoreGetOnError(t *testing.T) { ctx := context.Background() - data := sharecode.Data{LpaKey: "lpa-id"} + data := Data{LpaKey: "lpa-id"} dynamoClient := newMockDynamoClient(t) dynamoClient. ExpectOneByPK(ctx, dynamo.ShareKey(dynamo.AttorneyShareKey("123")), data, expectedError) - shareCodeStore := &shareCodeStore{dynamoClient: dynamoClient} + shareCodeStore := &Store{dynamoClient: dynamoClient} _, err := shareCodeStore.Get(ctx, actor.TypeAttorney, "123") assert.Equal(t, expectedError, err) @@ -111,14 +139,14 @@ func TestShareCodeStorePut(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { ctx := context.Background() - data := sharecode.Data{PK: tc.pk, SK: dynamo.ShareSortKey(dynamo.MetadataKey("123")), LpaKey: "lpa-id"} + data := Data{PK: tc.pk, SK: dynamo.ShareSortKey(dynamo.MetadataKey("123")), LpaKey: "lpa-id"} dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). Put(ctx, data). Return(nil) - shareCodeStore := &shareCodeStore{dynamoClient: dynamoClient} + shareCodeStore := &Store{dynamoClient: dynamoClient} err := shareCodeStore.Put(ctx, tc.actor, "123", data) assert.Nil(t, err) @@ -128,9 +156,9 @@ func TestShareCodeStorePut(t *testing.T) { func TestShareCodeStorePutForBadActorType(t *testing.T) { ctx := context.Background() - shareCodeStore := &shareCodeStore{} + shareCodeStore := &Store{} - err := shareCodeStore.Put(ctx, actor.TypePersonToNotify, "123", sharecode.Data{}) + err := shareCodeStore.Put(ctx, actor.TypePersonToNotify, "123", Data{}) assert.NotNil(t, err) } @@ -142,15 +170,15 @@ func TestShareCodeStorePutOnError(t *testing.T) { Put(ctx, mock.Anything). Return(expectedError) - shareCodeStore := &shareCodeStore{dynamoClient: dynamoClient} + shareCodeStore := &Store{dynamoClient: dynamoClient} - err := shareCodeStore.Put(ctx, actor.TypeAttorney, "123", sharecode.Data{LpaKey: "123"}) + err := shareCodeStore.Put(ctx, actor.TypeAttorney, "123", Data{LpaKey: "123"}) assert.Equal(t, expectedError, err) } func TestNewShareCodeStore(t *testing.T) { client := newMockDynamoClient(t) - store := NewShareCodeStore(client) + store := NewStore(client) assert.Equal(t, client, store.dynamoClient) assert.NotNil(t, store.now) @@ -161,14 +189,14 @@ func TestShareCodeStoreGetDonor(t *testing.T) { OrganisationID: "org-id", LpaID: "lpa-id", }) - data := sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id")} + data := Data{LpaKey: dynamo.LpaKey("lpa-id")} dynamoClient := newMockDynamoClient(t) dynamoClient. ExpectOneBySK(ctx, dynamo.DonorInviteKey(dynamo.OrganisationKey("org-id"), dynamo.LpaKey("lpa-id")), data, expectedError) - shareCodeStore := &shareCodeStore{dynamoClient: dynamoClient} + shareCodeStore := &Store{dynamoClient: dynamoClient} result, err := shareCodeStore.GetDonor(ctx) assert.Equal(t, expectedError, err) @@ -177,7 +205,7 @@ func TestShareCodeStoreGetDonor(t *testing.T) { func TestShareCodeStoreGetDonorWithSessionMissing(t *testing.T) { ctx := context.Background() - shareCodeStore := &shareCodeStore{} + shareCodeStore := &Store{} _, err := shareCodeStore.GetDonor(ctx) assert.NotNil(t, err) @@ -188,7 +216,7 @@ func TestShareCodeStorePutDonor(t *testing.T) { dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). - Put(ctx, sharecode.Data{ + Put(ctx, Data{ PK: dynamo.ShareKey(dynamo.DonorShareKey("123")), SK: dynamo.ShareSortKey(dynamo.DonorInviteKey(dynamo.OrganisationKey("org-id"), dynamo.LpaKey("lpa-id"))), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), @@ -197,18 +225,18 @@ func TestShareCodeStorePutDonor(t *testing.T) { }). Return(nil) - shareCodeStore := &shareCodeStore{dynamoClient: dynamoClient, now: testNowFn} + shareCodeStore := &Store{dynamoClient: dynamoClient, now: testNowFn} - err := shareCodeStore.PutDonor(ctx, "123", sharecode.Data{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")}) + err := shareCodeStore.PutDonor(ctx, "123", Data{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")}) assert.Nil(t, err) } func TestShareCodeStorePutDonorWhenDonor(t *testing.T) { ctx := context.Background() - shareCodeStore := &shareCodeStore{} + shareCodeStore := &Store{} - err := shareCodeStore.PutDonor(ctx, "123", sharecode.Data{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")}) + err := shareCodeStore.PutDonor(ctx, "123", Data{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")}) assert.Error(t, err) } @@ -222,9 +250,9 @@ func TestShareCodeStoreDelete(t *testing.T) { DeleteOne(ctx, pk, sk). Return(nil) - shareCodeStore := &shareCodeStore{dynamoClient: dynamoClient} + shareCodeStore := &Store{dynamoClient: dynamoClient} - err := shareCodeStore.Delete(ctx, sharecode.Data{LpaKey: "123", PK: pk, SK: sk}) + err := shareCodeStore.Delete(ctx, Data{LpaKey: "123", PK: pk, SK: sk}) assert.Nil(t, err) } @@ -236,9 +264,9 @@ func TestShareCodeStoreDeleteOnError(t *testing.T) { DeleteOne(ctx, mock.Anything, mock.Anything). Return(expectedError) - shareCodeStore := &shareCodeStore{dynamoClient: dynamoClient} + shareCodeStore := &Store{dynamoClient: dynamoClient} - err := shareCodeStore.Delete(ctx, sharecode.Data{}) + err := shareCodeStore.Delete(ctx, Data{}) assert.Equal(t, expectedError, err) }