Skip to content

Commit

Permalink
Merge 5854f86 into 97047f5
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Apr 23, 2024
2 parents 97047f5 + 5854f86 commit 9002be8
Show file tree
Hide file tree
Showing 22 changed files with 369 additions and 356 deletions.
70 changes: 35 additions & 35 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.Key{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"),
"SK": dynamo.EvidenceReceivedKey(),
}).
Return(nil)

Expand Down Expand Up @@ -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.Key{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"),
"SK": dynamo.EvidenceReceivedKey(),
}).
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.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.Key{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("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}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: 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.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("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}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: 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.Key{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("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}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: 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.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.Key{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("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}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: 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.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.Key{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("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}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: 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.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.Key{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("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}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: 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.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.Key{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("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}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: 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.Key{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("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}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456"), Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
Expand Down
24 changes: 12 additions & 12 deletions cmd/event-received/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ 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.Key{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
dynamoClient.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{LpaID: "123", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
Expand Down Expand Up @@ -127,12 +127,12 @@ 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.Key{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
dynamoClient.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{LpaID: "123", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
Expand Down Expand Up @@ -161,12 +161,12 @@ 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.Key{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
dynamoClient.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(actor.DonorProvidedDetails{LpaID: "123", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
Expand All @@ -183,18 +183,18 @@ 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.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.Key{PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("456")})
json.Unmarshal(b, v)
return nil
})
client.
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, dynamo.LpaKey("123"), dynamo.DonorKey("456"), mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(expectedDonor)
json.Unmarshal(b, v)
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.Key{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.Key{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
2 changes: 1 addition & 1 deletion internal/app/attorney_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (s *attorneyStore) GetAny(ctx context.Context) ([]*actor.AttorneyProvidedDe
}

var attorneys []*actor.AttorneyProvidedDetails
err = s.dynamoClient.AllByPartialSK(ctx, dynamo.LpaKey(data.LpaID), "#ATTORNEY#", &attorneys)
err = s.dynamoClient.AllByPartialSK(ctx, dynamo.LpaKey(data.LpaID), dynamo.AttorneyKey(""), &attorneys)

return attorneys, err
}
Expand Down
Loading

0 comments on commit 9002be8

Please sign in to comment.