diff --git a/cmd/event-received/mock_dynamodbClient_test.go b/cmd/event-received/mock_dynamodbClient_test.go index 4b8208c1a9..5757bf2a08 100644 --- a/cmd/event-received/mock_dynamodbClient_test.go +++ b/cmd/event-received/mock_dynamodbClient_test.go @@ -22,17 +22,17 @@ func (_m *mockDynamodbClient) EXPECT() *mockDynamodbClient_Expecter { return &mockDynamodbClient_Expecter{mock: &_m.Mock} } -// AllScheduledEventsByUID provides a mock function with given fields: ctx, uid, v -func (_m *mockDynamodbClient) AllByLpaUIDAndPartialSK(ctx context.Context, uid string, v interface{}) error { - ret := _m.Called(ctx, uid, v) +// AllByLpaUIDAndPartialSK provides a mock function with given fields: ctx, uid, partialSK, v +func (_m *mockDynamodbClient) AllByLpaUIDAndPartialSK(ctx context.Context, uid string, partialSK string, v interface{}) error { + ret := _m.Called(ctx, uid, partialSK, v) if len(ret) == 0 { - panic("no return value specified for AllScheduledEventsByUID") + panic("no return value specified for AllByLpaUIDAndPartialSK") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, interface{}) error); ok { - r0 = rf(ctx, uid, v) + if rf, ok := ret.Get(0).(func(context.Context, string, string, interface{}) error); ok { + r0 = rf(ctx, uid, partialSK, v) } else { r0 = ret.Error(0) } @@ -40,32 +40,33 @@ func (_m *mockDynamodbClient) AllByLpaUIDAndPartialSK(ctx context.Context, uid s return r0 } -// mockDynamodbClient_AllScheduledEventsByUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllScheduledEventsByUID' -type mockDynamodbClient_AllScheduledEventsByUID_Call struct { +// mockDynamodbClient_AllByLpaUIDAndPartialSK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllByLpaUIDAndPartialSK' +type mockDynamodbClient_AllByLpaUIDAndPartialSK_Call struct { *mock.Call } -// AllScheduledEventsByUID is a helper method to define mock.On call +// AllByLpaUIDAndPartialSK is a helper method to define mock.On call // - ctx context.Context // - uid string +// - partialSK string // - v interface{} -func (_e *mockDynamodbClient_Expecter) AllScheduledEventsByUID(ctx interface{}, uid interface{}, v interface{}) *mockDynamodbClient_AllScheduledEventsByUID_Call { - return &mockDynamodbClient_AllScheduledEventsByUID_Call{Call: _e.mock.On("AllScheduledEventsByUID", ctx, uid, v)} +func (_e *mockDynamodbClient_Expecter) AllByLpaUIDAndPartialSK(ctx interface{}, uid interface{}, partialSK interface{}, v interface{}) *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call { + return &mockDynamodbClient_AllByLpaUIDAndPartialSK_Call{Call: _e.mock.On("AllByLpaUIDAndPartialSK", ctx, uid, partialSK, v)} } -func (_c *mockDynamodbClient_AllScheduledEventsByUID_Call) Run(run func(ctx context.Context, uid string, v interface{})) *mockDynamodbClient_AllScheduledEventsByUID_Call { +func (_c *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call) Run(run func(ctx context.Context, uid string, partialSK string, v interface{})) *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(interface{})) + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(interface{})) }) return _c } -func (_c *mockDynamodbClient_AllScheduledEventsByUID_Call) Return(_a0 error) *mockDynamodbClient_AllScheduledEventsByUID_Call { +func (_c *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call) Return(_a0 error) *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call { _c.Call.Return(_a0) return _c } -func (_c *mockDynamodbClient_AllScheduledEventsByUID_Call) RunAndReturn(run func(context.Context, string, interface{}) error) *mockDynamodbClient_AllScheduledEventsByUID_Call { +func (_c *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call) RunAndReturn(run func(context.Context, string, string, interface{}) error) *mockDynamodbClient_AllByLpaUIDAndPartialSK_Call { _c.Call.Return(run) return _c } diff --git a/internal/app/mock_DynamoClient_test.go b/internal/app/mock_DynamoClient_test.go index a980bfd8e0..7a3030d4d9 100644 --- a/internal/app/mock_DynamoClient_test.go +++ b/internal/app/mock_DynamoClient_test.go @@ -83,6 +83,55 @@ func (_c *mockDynamoClient_AllByKeys_Call) RunAndReturn(run func(context.Context return _c } +// AllByLpaUIDAndPartialSK provides a mock function with given fields: ctx, uid, partialSK, v +func (_m *mockDynamoClient) AllByLpaUIDAndPartialSK(ctx context.Context, uid string, partialSK string, v interface{}) error { + ret := _m.Called(ctx, uid, partialSK, v) + + if len(ret) == 0 { + panic("no return value specified for AllByLpaUIDAndPartialSK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, string, interface{}) error); ok { + r0 = rf(ctx, uid, partialSK, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_AllByLpaUIDAndPartialSK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllByLpaUIDAndPartialSK' +type mockDynamoClient_AllByLpaUIDAndPartialSK_Call struct { + *mock.Call +} + +// AllByLpaUIDAndPartialSK is a helper method to define mock.On call +// - ctx context.Context +// - uid string +// - partialSK string +// - v interface{} +func (_e *mockDynamoClient_Expecter) AllByLpaUIDAndPartialSK(ctx interface{}, uid interface{}, partialSK interface{}, v interface{}) *mockDynamoClient_AllByLpaUIDAndPartialSK_Call { + return &mockDynamoClient_AllByLpaUIDAndPartialSK_Call{Call: _e.mock.On("AllByLpaUIDAndPartialSK", ctx, uid, partialSK, v)} +} + +func (_c *mockDynamoClient_AllByLpaUIDAndPartialSK_Call) Run(run func(ctx context.Context, uid string, partialSK string, v interface{})) *mockDynamoClient_AllByLpaUIDAndPartialSK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_AllByLpaUIDAndPartialSK_Call) Return(_a0 error) *mockDynamoClient_AllByLpaUIDAndPartialSK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_AllByLpaUIDAndPartialSK_Call) RunAndReturn(run func(context.Context, string, string, interface{}) error) *mockDynamoClient_AllByLpaUIDAndPartialSK_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) @@ -239,54 +288,6 @@ func (_c *mockDynamoClient_AllKeysByPK_Call) RunAndReturn(run func(context.Conte return _c } -// AllScheduledEventsByUID provides a mock function with given fields: ctx, uid, v -func (_m *mockDynamoClient) AllByLpaUIDAndPartialSK(ctx context.Context, uid string, v interface{}) error { - ret := _m.Called(ctx, uid, v) - - if len(ret) == 0 { - panic("no return value specified for AllScheduledEventsByUID") - } - - 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_AllScheduledEventsByUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllScheduledEventsByUID' -type mockDynamoClient_AllScheduledEventsByUID_Call struct { - *mock.Call -} - -// AllScheduledEventsByUID is a helper method to define mock.On call -// - ctx context.Context -// - uid string -// - v interface{} -func (_e *mockDynamoClient_Expecter) AllScheduledEventsByUID(ctx interface{}, uid interface{}, v interface{}) *mockDynamoClient_AllScheduledEventsByUID_Call { - return &mockDynamoClient_AllScheduledEventsByUID_Call{Call: _e.mock.On("AllScheduledEventsByUID", ctx, uid, v)} -} - -func (_c *mockDynamoClient_AllScheduledEventsByUID_Call) Run(run func(ctx context.Context, uid string, v interface{})) *mockDynamoClient_AllScheduledEventsByUID_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(interface{})) - }) - return _c -} - -func (_c *mockDynamoClient_AllScheduledEventsByUID_Call) Return(_a0 error) *mockDynamoClient_AllScheduledEventsByUID_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *mockDynamoClient_AllScheduledEventsByUID_Call) RunAndReturn(run func(context.Context, string, interface{}) error) *mockDynamoClient_AllScheduledEventsByUID_Call { - _c.Call.Return(run) - return _c -} - // AnyByPK provides a mock function with given fields: ctx, pk, v func (_m *mockDynamoClient) AnyByPK(ctx context.Context, pk dynamo.PK, v interface{}) error { ret := _m.Called(ctx, pk, v) diff --git a/internal/dynamo/client_test.go b/internal/dynamo/client_test.go index ccedaa2371..430e525935 100644 --- a/internal/dynamo/client_test.go +++ b/internal/dynamo/client_test.go @@ -974,7 +974,7 @@ func TestAllScheduledEventsByUID(t *testing.T) { }, ExpressionAttributeValues: map[string]types.AttributeValue{ ":LpaUID": &types.AttributeValueMemberS{Value: "lpa-uid"}, - ":SK": &types.AttributeValueMemberS{Value: scheduledPrefix}, + ":SK": &types.AttributeValueMemberS{Value: "partial-sk"}, }, KeyConditionExpression: aws.String("#LpaUID = :LpaUID"), FilterExpression: aws.String("begins_with(#SK, :SK)"), @@ -984,7 +984,7 @@ func TestAllScheduledEventsByUID(t *testing.T) { c := &Client{table: "this", svc: dynamoDB} var v []map[string]string - err := c.AllByLpaUIDAndPartialSK(ctx, "lpa-uid", &v) + err := c.AllByLpaUIDAndPartialSK(ctx, "lpa-uid", "partial-sk", &v) assert.Nil(t, err) } @@ -997,7 +997,7 @@ func TestAllScheduledEventsByUIDWhenQueryError(t *testing.T) { c := &Client{table: "this", svc: dynamoDB} var v []map[string]string - err := c.AllByLpaUIDAndPartialSK(ctx, "lpa-uid", &v) + err := c.AllByLpaUIDAndPartialSK(ctx, "lpa-uid", "partial-sk", &v) assert.Equal(t, fmt.Errorf("failed to query scheduled event by UID: %w", expectedError), err) } @@ -1010,7 +1010,7 @@ func TestAllScheduledEventsByUIDWhenNoResults(t *testing.T) { c := &Client{table: "this", svc: dynamoDB} var v []map[string]string - err := c.AllByLpaUIDAndPartialSK(ctx, "lpa-uid", &v) + err := c.AllByLpaUIDAndPartialSK(ctx, "lpa-uid", "partial-sk", &v) assert.Equal(t, NotFoundError{}, err) } @@ -1026,7 +1026,7 @@ func TestAllScheduledEventsByUIDWhenUnmarshalError(t *testing.T) { c := &Client{table: "this", svc: dynamoDB} var v []map[string]string - err := c.AllByLpaUIDAndPartialSK(ctx, "lpa-uid", v) + err := c.AllByLpaUIDAndPartialSK(ctx, "lpa-uid", "partial-sk", v) assert.Error(t, err) } diff --git a/internal/scheduled/mock_DynamoClient_test.go b/internal/scheduled/mock_DynamoClient_test.go index 5334e0e7dd..786930bd32 100644 --- a/internal/scheduled/mock_DynamoClient_test.go +++ b/internal/scheduled/mock_DynamoClient_test.go @@ -22,17 +22,17 @@ func (_m *mockDynamoClient) EXPECT() *mockDynamoClient_Expecter { return &mockDynamoClient_Expecter{mock: &_m.Mock} } -// AllScheduledEventsByUID provides a mock function with given fields: ctx, uid, v -func (_m *mockDynamoClient) AllScheduledEventsByUID(ctx context.Context, uid string, v interface{}) error { - ret := _m.Called(ctx, uid, v) +// AllByLpaUIDAndPartialSK provides a mock function with given fields: ctx, uid, partialSK, v +func (_m *mockDynamoClient) AllByLpaUIDAndPartialSK(ctx context.Context, uid string, partialSK string, v interface{}) error { + ret := _m.Called(ctx, uid, partialSK, v) if len(ret) == 0 { - panic("no return value specified for AllScheduledEventsByUID") + panic("no return value specified for AllByLpaUIDAndPartialSK") } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, string, interface{}) error); ok { - r0 = rf(ctx, uid, v) + if rf, ok := ret.Get(0).(func(context.Context, string, string, interface{}) error); ok { + r0 = rf(ctx, uid, partialSK, v) } else { r0 = ret.Error(0) } @@ -40,32 +40,33 @@ func (_m *mockDynamoClient) AllScheduledEventsByUID(ctx context.Context, uid str return r0 } -// mockDynamoClient_AllScheduledEventsByUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllScheduledEventsByUID' -type mockDynamoClient_AllScheduledEventsByUID_Call struct { +// mockDynamoClient_AllByLpaUIDAndPartialSK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllByLpaUIDAndPartialSK' +type mockDynamoClient_AllByLpaUIDAndPartialSK_Call struct { *mock.Call } -// AllScheduledEventsByUID is a helper method to define mock.On call +// AllByLpaUIDAndPartialSK is a helper method to define mock.On call // - ctx context.Context // - uid string +// - partialSK string // - v interface{} -func (_e *mockDynamoClient_Expecter) AllScheduledEventsByUID(ctx interface{}, uid interface{}, v interface{}) *mockDynamoClient_AllScheduledEventsByUID_Call { - return &mockDynamoClient_AllScheduledEventsByUID_Call{Call: _e.mock.On("AllScheduledEventsByUID", ctx, uid, v)} +func (_e *mockDynamoClient_Expecter) AllByLpaUIDAndPartialSK(ctx interface{}, uid interface{}, partialSK interface{}, v interface{}) *mockDynamoClient_AllByLpaUIDAndPartialSK_Call { + return &mockDynamoClient_AllByLpaUIDAndPartialSK_Call{Call: _e.mock.On("AllByLpaUIDAndPartialSK", ctx, uid, partialSK, v)} } -func (_c *mockDynamoClient_AllScheduledEventsByUID_Call) Run(run func(ctx context.Context, uid string, v interface{})) *mockDynamoClient_AllScheduledEventsByUID_Call { +func (_c *mockDynamoClient_AllByLpaUIDAndPartialSK_Call) Run(run func(ctx context.Context, uid string, partialSK string, v interface{})) *mockDynamoClient_AllByLpaUIDAndPartialSK_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(interface{})) + run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(interface{})) }) return _c } -func (_c *mockDynamoClient_AllScheduledEventsByUID_Call) Return(_a0 error) *mockDynamoClient_AllScheduledEventsByUID_Call { +func (_c *mockDynamoClient_AllByLpaUIDAndPartialSK_Call) Return(_a0 error) *mockDynamoClient_AllByLpaUIDAndPartialSK_Call { _c.Call.Return(_a0) return _c } -func (_c *mockDynamoClient_AllScheduledEventsByUID_Call) RunAndReturn(run func(context.Context, string, interface{}) error) *mockDynamoClient_AllScheduledEventsByUID_Call { +func (_c *mockDynamoClient_AllByLpaUIDAndPartialSK_Call) RunAndReturn(run func(context.Context, string, string, interface{}) error) *mockDynamoClient_AllByLpaUIDAndPartialSK_Call { _c.Call.Return(run) return _c } diff --git a/internal/scheduled/mock_test.go b/internal/scheduled/mock_test.go index 5250972fc8..26c86cf83a 100644 --- a/internal/scheduled/mock_test.go +++ b/internal/scheduled/mock_test.go @@ -4,11 +4,19 @@ import ( "context" "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" + "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" ) -func (c *mockDynamoClient_AllScheduledEventsByUID_Call) SetData(data any) { - c.Run(func(_ context.Context, _ string, v any) { +func (c *mockDynamoClient_AllByLpaUIDAndPartialSK_Call) SetData(data any) { + c.Run(func(_ context.Context, _, _ string, v any) { b, _ := attributevalue.Marshal(data) attributevalue.Unmarshal(b, v) }) } + +func (c *mockDynamoClient_AnyByPK_Call) SetData(row *Event) { + c.Run(func(_ context.Context, _ dynamo.PK, v any) { + b, _ := attributevalue.Marshal(row) + attributevalue.Unmarshal(b, v) + }) +} diff --git a/internal/scheduled/store_test.go b/internal/scheduled/store_test.go index d82af359f2..ff86b3263c 100644 --- a/internal/scheduled/store_test.go +++ b/internal/scheduled/store_test.go @@ -1,23 +1,14 @@ package scheduled import ( - "context" "testing" "time" - "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) -func (c *mockDynamoClient_AnyByPK_Call) SetData(row *Event) { - c.Run(func(_ context.Context, _ dynamo.PK, v any) { - b, _ := attributevalue.Marshal(row) - attributevalue.Unmarshal(b, v) - }) -} - func TestNewStore(t *testing.T) { dynamoClient := newMockDynamoClient(t) store := NewStore(dynamoClient) @@ -112,7 +103,7 @@ func TestDeleteAllByUID(t *testing.T) { dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). - AllScheduledEventsByUID(ctx, "lpa-uid", mock.Anything). + AllByLpaUIDAndPartialSK(ctx, "lpa-uid", dynamo.PartialScheduleKey(), mock.Anything). Return(nil). SetData([]Event{ {LpaUID: "lpa-uid", PK: dynamo.ScheduledDayKey(now), SK: dynamo.ScheduledKey(now, 98)}, @@ -131,10 +122,10 @@ func TestDeleteAllByUID(t *testing.T) { assert.Nil(t, err) } -func TestDeleteAllByUIDWhenAllScheduledEventsByUIDErrors(t *testing.T) { +func TestDeleteAllByUIDWhenAllByLpaUIDAndPartialSKErrors(t *testing.T) { dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). - AllScheduledEventsByUID(ctx, mock.Anything, mock.Anything). + AllByLpaUIDAndPartialSK(ctx, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) store := &Store{dynamoClient: dynamoClient, now: testNowFn} @@ -146,7 +137,7 @@ func TestDeleteAllByUIDWhenAllScheduledEventsByUIDErrors(t *testing.T) { func TestDeleteAllByUIDWhenNoEventsFound(t *testing.T) { dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). - AllScheduledEventsByUID(ctx, mock.Anything, mock.Anything). + AllByLpaUIDAndPartialSK(ctx, mock.Anything, mock.Anything, mock.Anything). Return(nil). SetData([]Event{}) @@ -159,7 +150,7 @@ func TestDeleteAllByUIDWhenNoEventsFound(t *testing.T) { func TestDeleteAllByUIDWhenDeleteManyByUIDErrors(t *testing.T) { dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). - AllScheduledEventsByUID(ctx, mock.Anything, mock.Anything). + AllByLpaUIDAndPartialSK(ctx, mock.Anything, mock.Anything, mock.Anything). Return(nil). SetData([]Event{{LpaUID: "lpa-uid"}}) dynamoClient.EXPECT().