Skip to content

Commit

Permalink
MLPAB-2034 Type the dynamo keys (#1198)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Apr 25, 2024
1 parent 6e4f205 commit 5c2ada2
Show file tree
Hide file tree
Showing 56 changed files with 1,806 additions and 821 deletions.
10 changes: 5 additions & 5 deletions cmd/event-received/cloud_watch_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ func handleEvidenceReceived(ctx context.Context, client dynamodbClient, event ev
return fmt.Errorf("failed to unmarshal detail: %w", err)
}

var key dynamo.Key
var key dynamo.Keys
if err := client.OneByUID(ctx, v.UID, &key); err != nil {
return fmt.Errorf("failed to resolve uid: %w", err)
}

if key.PK == "" {
if key.PK == nil {
return fmt.Errorf("PK missing from LPA in response")
}

if err := client.Put(ctx, map[string]string{"PK": key.PK, "SK": dynamo.EvidenceReceivedKey()}); err != nil {
if err := client.Put(ctx, map[string]string{"PK": key.PK.PK(), "SK": dynamo.EvidenceReceivedKey().SK()}); err != nil {
return fmt.Errorf("failed to persist evidence received: %w", err)
}

Expand Down Expand Up @@ -209,7 +209,7 @@ func handleDonorSubmissionCompleted(ctx context.Context, client dynamodbClient,
return fmt.Errorf("failed to unmarshal detail: %w", err)
}

var key dynamo.Key
var key dynamo.Keys
if err := client.OneByUID(ctx, v.UID, &key); !errors.Is(err, dynamo.NotFoundError{}) {
return err
}
Expand All @@ -218,7 +218,7 @@ func handleDonorSubmissionCompleted(ctx context.Context, client dynamodbClient,

if err := client.Put(ctx, &actor.DonorProvidedDetails{
PK: dynamo.LpaKey(lpaID),
SK: dynamo.DonorKey("PAPER"),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("PAPER")),
LpaID: lpaID,
LpaUID: v.UID,
CreatedAt: now(),
Expand Down
90 changes: 45 additions & 45 deletions cmd/event-received/cloud_watch_event_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ func TestHandleEvidenceReceived(t *testing.T) {
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123")})
json.Unmarshal(b, v)
return nil
})
client.EXPECT().
Put(ctx, map[string]string{
"PK": "LPA#123",
"SK": "#EVIDENCE_RECEIVED",
"PK": dynamo.LpaKey("123").PK(),
"SK": dynamo.EvidenceReceivedKey().SK(),
}).
Return(nil)

Expand Down Expand Up @@ -139,7 +139,7 @@ func TestHandleEvidenceReceivedWhenLpaMissingPK(t *testing.T) {
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{})
b, _ := json.Marshal(dynamo.Keys{})
json.Unmarshal(b, v)
return nil
})
Expand All @@ -158,14 +158,14 @@ func TestHandleEvidenceReceivedWhenClientPutError(t *testing.T) {
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123")})
json.Unmarshal(b, v)
return nil
})
client.EXPECT().
Put(ctx, map[string]string{
"PK": "LPA#123",
"SK": "#EVIDENCE_RECEIVED",
"PK": dynamo.LpaKey("123").PK(),
"SK": dynamo.EvidenceReceivedKey().SK(),
}).
Return(expectedError)

Expand All @@ -180,21 +180,21 @@ func TestHandleFeeApproved(t *testing.T) {
}

now := time.Now()
updated := &actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}
updated := &actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}
updated.Hash, _ = updated.GenerateHash()

client := newMockDynamodbClient(t)
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456"))})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
Expand Down Expand Up @@ -228,14 +228,14 @@ func TestHandleFeeApprovedWhenDynamoClientPutError(t *testing.T) {
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456"))})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
Expand All @@ -259,14 +259,14 @@ func TestHandleFeeApprovedWhenShareCodeSenderError(t *testing.T) {
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
Expand All @@ -290,21 +290,21 @@ func TestHandleFeeApprovedWhenLpaStoreError(t *testing.T) {
}

now := time.Now()
updated := &actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}
updated := &actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}
updated.Hash, _ = updated.GenerateHash()

client := newMockDynamodbClient(t)
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
Expand Down Expand Up @@ -333,21 +333,21 @@ func TestHandleMoreEvidenceRequired(t *testing.T) {
}

now := time.Now()
updated := &actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}
updated := &actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}
updated.Hash, _ = updated.GenerateHash()

client := newMockDynamodbClient(t)
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
Expand All @@ -366,21 +366,21 @@ func TestHandleMoreEvidenceRequiredWhenPutError(t *testing.T) {
}

now := time.Now()
updated := &actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}
updated := &actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}
updated.Hash, _ = updated.GenerateHash()

client := newMockDynamodbClient(t)
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
Expand All @@ -399,21 +399,21 @@ func TestHandleFeeDenied(t *testing.T) {
}

now := time.Now()
updated := &actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}
updated := &actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}
updated.Hash, _ = updated.GenerateHash()

client := newMockDynamodbClient(t)
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
Expand All @@ -437,14 +437,14 @@ func TestHandleFeeDeniedWhenPutError(t *testing.T) {
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
Expand Down Expand Up @@ -482,7 +482,7 @@ func TestHandleDonorSubmissionCompleted(t *testing.T) {
client.EXPECT().
Put(ctx, &actor.DonorProvidedDetails{
PK: dynamo.LpaKey(testUuidString),
SK: dynamo.DonorKey("PAPER"),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("PAPER")),
LpaID: testUuidString,
LpaUID: "M-1111-2222-3333",
CreatedAt: testNow,
Expand Down
4 changes: 2 additions & 2 deletions cmd/event-received/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func putDonor(ctx context.Context, donor *actor.DonorProvidedDetails, now func()
}

func getDonorByLpaUID(ctx context.Context, client dynamodbClient, uid string) (*actor.DonorProvidedDetails, error) {
var key dynamo.Key
var key dynamo.Keys
if err := client.OneByUID(ctx, uid, &key); err != nil {
return nil, fmt.Errorf("failed to resolve uid: %w", err)
}

if key.PK == "" {
if key.PK == nil {
return nil, fmt.Errorf("PK missing from LPA in response")
}

Expand Down
32 changes: 16 additions & 16 deletions cmd/event-received/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func TestHandleObjectTagsAdded(t *testing.T) {
dynamoClient.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
dynamoClient.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{LpaID: "123", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
Expand Down Expand Up @@ -127,13 +127,13 @@ func TestHandleObjectTagsAddedWhenDynamoClientOneByUIDError(t *testing.T) {
dynamoClient.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
dynamoClient.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{LpaID: "123", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return expectedError
Expand Down Expand Up @@ -161,13 +161,13 @@ func TestHandleObjectTagsAddedWhenDocumentStoreUpdateScanResultsError(t *testing
dynamoClient.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
dynamoClient.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{LpaID: "123", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
Expand All @@ -183,19 +183,19 @@ func TestHandleObjectTagsAddedWhenDocumentStoreUpdateScanResultsError(t *testing
}

func TestGetLpaByUID(t *testing.T) {
expectedDonor := &actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456"}
expectedDonor := &actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456"))}

client := newMockDynamodbClient(t)
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error {
b, _ := json.Marshal(expectedDonor)
json.Unmarshal(b, v)
return nil
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestGetLpaByUIDWhenPKMissing(t *testing.T) {
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
Expand All @@ -240,12 +240,12 @@ func TestGetLpaByUIDWhenClientOneError(t *testing.T) {
client.
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(dynamo.Keys{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.EXPECT().
One(ctx, "LPA#123", "#DONOR#456", mock.Anything).
One(ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(expectedError)

lpa, err := getDonorByLpaUID(ctx, client, "M-1111-2222-3333")
Expand Down
Loading

0 comments on commit 5c2ada2

Please sign in to comment.