Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLPAB-1284 Use details from the latest LPA to populate your-details page #722

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions cmd/event-received/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ type uidEvent struct {

//go:generate mockery --testonly --inpackage --name dynamodbClient --structname mockDynamodbClient
type dynamodbClient interface {
Put(context.Context, interface{}) error
GetOneByUID(context.Context, string, interface{}) error
Get(ctx context.Context, pk, sk string, v interface{}) error
One(ctx context.Context, pk, sk string, v interface{}) error
OneByUID(ctx context.Context, uid string, v interface{}) error
Put(ctx context.Context, v interface{}) error
}

//go:generate mockery --testonly --inpackage --name shareCodeSender --structname mockShareCodeSender
Expand Down Expand Up @@ -106,7 +106,7 @@ func handleEvidenceReceived(ctx context.Context, client dynamodbClient, event ev
}

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

Expand All @@ -128,12 +128,12 @@ func handleFeeApproved(ctx context.Context, dynamoClient dynamodbClient, event e
}

var key dynamo.Key
if err := dynamoClient.GetOneByUID(ctx, v.UID, &key); err != nil {
if err := dynamoClient.OneByUID(ctx, v.UID, &key); err != nil {
return fmt.Errorf("failed to resolve uid for 'fee-approved': %w", err)
}

var lpa page.Lpa
if err := dynamoClient.Get(ctx, key.PK, key.SK, &lpa); err != nil {
if err := dynamoClient.One(ctx, key.PK, key.SK, &lpa); err != nil {
return fmt.Errorf("failed to get LPA for 'fee-approved': %w", err)
}

Expand All @@ -157,7 +157,7 @@ func handleMoreEvidenceRequired(ctx context.Context, client dynamodbClient, even
}

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

Expand All @@ -166,7 +166,7 @@ func handleMoreEvidenceRequired(ctx context.Context, client dynamodbClient, even
}

var lpa page.Lpa
if err := client.Get(ctx, key.PK, key.SK, &lpa); err != nil {
if err := client.One(ctx, key.PK, key.SK, &lpa); err != nil {
return fmt.Errorf("failed to get LPA for 'more-evidence-required': %w", err)
}

Expand All @@ -186,7 +186,7 @@ func handleFeeDenied(ctx context.Context, client dynamodbClient, event events.Cl
}

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

Expand All @@ -195,7 +195,7 @@ func handleFeeDenied(ctx context.Context, client dynamodbClient, event events.Cl
}

var lpa page.Lpa
if err := client.Get(ctx, key.PK, key.SK, &lpa); err != nil {
if err := client.One(ctx, key.PK, key.SK, &lpa); err != nil {
return fmt.Errorf("failed to get LPA for 'fee-denied': %w", err)
}

Expand Down
64 changes: 32 additions & 32 deletions cmd/event-received/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestHandleEvidenceReceived(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
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"})
json.Unmarshal(b, v)
Expand All @@ -53,7 +53,7 @@ func TestHandleEvidenceReceivedWhenClientGetError(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(expectedError)

err := handleEvidenceReceived(ctx, client, event)
Expand All @@ -69,7 +69,7 @@ func TestHandleEvidenceReceivedWhenLpaMissingPK(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{})
json.Unmarshal(b, v)
Expand All @@ -89,7 +89,7 @@ func TestHandleEvidenceReceivedWhenClientPutError(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
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"})
json.Unmarshal(b, v)
Expand All @@ -115,14 +115,14 @@ func TestHandleFeeApproved(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
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"})
json.Unmarshal(b, v)
return nil
})
client.
On("Get", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
Expand All @@ -141,7 +141,7 @@ func TestHandleFeeApproved(t *testing.T) {
assert.Nil(t, err)
}

func TestHandleFeeApprovedWhenDynamoClientGetOneByUIDError(t *testing.T) {
func TestHandleFeeApprovedWhenDynamoClientOneByUIDError(t *testing.T) {
ctx := context.Background()
event := events.CloudWatchEvent{
DetailType: "fee-approved",
Expand All @@ -150,7 +150,7 @@ func TestHandleFeeApprovedWhenDynamoClientGetOneByUIDError(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(expectedError)

err := handleFeeApproved(ctx, client, event, nil, page.AppData{})
Expand All @@ -166,14 +166,14 @@ func TestHandleFeeApprovedWhenDynamoClientGetError(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
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"})
json.Unmarshal(b, v)
return nil
})
client.
On("Get", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(expectedError)

err := handleFeeApproved(ctx, client, event, nil, page.AppData{})
Expand All @@ -189,14 +189,14 @@ func TestHandleFeeApprovedWhenDynamoClientPutError(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(page.Lpa{PK: "LPA#123", SK: "#DONOR#456"})
json.Unmarshal(b, v)
return nil
})
client.
On("Get", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
Expand All @@ -219,14 +219,14 @@ func TestHandleFeeApprovedWhenShareCodeSenderError(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
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"})
json.Unmarshal(b, v)
return nil
})
client.
On("Get", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
Expand Down Expand Up @@ -254,14 +254,14 @@ func TestHandleMoreEvidenceRequired(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
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"})
json.Unmarshal(b, v)
return nil
})
client.
On("Get", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
Expand All @@ -275,7 +275,7 @@ func TestHandleMoreEvidenceRequired(t *testing.T) {
assert.Nil(t, err)
}

func TestHandleMoreEvidenceRequiredWhenGetOneByUIDError(t *testing.T) {
func TestHandleMoreEvidenceRequiredWhenOneByUIDError(t *testing.T) {
ctx := context.Background()
event := events.CloudWatchEvent{
DetailType: "more-evidence-required",
Expand All @@ -284,7 +284,7 @@ func TestHandleMoreEvidenceRequiredWhenGetOneByUIDError(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(expectedError)

err := handleMoreEvidenceRequired(ctx, client, event)
Expand All @@ -300,7 +300,7 @@ func TestHandleMoreEvidenceRequiredWhenPKMissing(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{})
json.Unmarshal(b, v)
Expand All @@ -321,14 +321,14 @@ func TestHandleMoreEvidenceRequiredWhenGetError(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
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"})
json.Unmarshal(b, v)
return nil
})
client.
On("Get", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(expectedError)

err := handleMoreEvidenceRequired(ctx, client, event)
Expand All @@ -344,14 +344,14 @@ func TestHandleMoreEvidenceRequiredWhenPutError(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
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"})
json.Unmarshal(b, v)
return nil
})
client.
On("Get", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
Expand All @@ -374,14 +374,14 @@ func TestHandleFeeDenied(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
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"})
json.Unmarshal(b, v)
return nil
})
client.
On("Get", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
Expand All @@ -395,7 +395,7 @@ func TestHandleFeeDenied(t *testing.T) {
assert.Nil(t, err)
}

func TestHandleFeeDeniedWhenGetOneByUIDError(t *testing.T) {
func TestHandleFeeDeniedWhenOneByUIDError(t *testing.T) {
ctx := context.Background()
event := events.CloudWatchEvent{
DetailType: "fee-denied",
Expand All @@ -404,7 +404,7 @@ func TestHandleFeeDeniedWhenGetOneByUIDError(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(expectedError)

err := handleFeeDenied(ctx, client, event)
Expand All @@ -420,7 +420,7 @@ func TestHandleFeeDeniedWhenPKMissing(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything).
Return(func(ctx context.Context, uid string, v interface{}) error {
b, _ := json.Marshal(dynamo.Key{})
json.Unmarshal(b, v)
Expand All @@ -441,14 +441,14 @@ func TestHandleFeeDeniedWhenGetError(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
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"})
json.Unmarshal(b, v)
return nil
})
client.
On("Get", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(expectedError)

err := handleFeeDenied(ctx, client, event)
Expand All @@ -464,14 +464,14 @@ func TestHandleFeeDeniedWhenPutError(t *testing.T) {

client := newMockDynamodbClient(t)
client.
On("GetOneByUID", ctx, "M-1111-2222-3333", mock.Anything).
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"})
json.Unmarshal(b, v)
return nil
})
client.
On("Get", ctx, "LPA#123", "#DONOR#456", mock.Anything).
On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything).
Return(func(ctx context.Context, pk, sk string, v interface{}) error {
b, _ := json.Marshal(page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
Expand Down
20 changes: 10 additions & 10 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.

Loading
Loading