Skip to content

Commit

Permalink
MLPAB-2321 test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
acsauk committed Nov 26, 2024
1 parent a819bb3 commit 0589032
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 99 deletions.
31 changes: 16 additions & 15 deletions cmd/event-received/mock_dynamodbClient_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 49 additions & 48 deletions internal/app/mock_DynamoClient_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions internal/dynamo/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"),
Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand Down
31 changes: 16 additions & 15 deletions internal/scheduled/mock_DynamoClient_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions internal/scheduled/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
19 changes: 5 additions & 14 deletions internal/scheduled/store_test.go
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)},
Expand All @@ -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}
Expand All @@ -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{})

Expand All @@ -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().
Expand Down

0 comments on commit 0589032

Please sign in to comment.