Skip to content

Commit

Permalink
Merge 7578927 into 6ff2db5
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Nov 17, 2023
2 parents 6ff2db5 + 7578927 commit 11696e8
Show file tree
Hide file tree
Showing 215 changed files with 2,188 additions and 2,079 deletions.
10 changes: 5 additions & 5 deletions cmd/event-received/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,19 @@ func handleObjectTagsAdded(ctx context.Context, dynamodbClient dynamodbClient, e
return nil
}

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

if key.PK == "" {
return page.Lpa{}, fmt.Errorf("PK missing from LPA in response")
return actor.DonorProvidedDetails{}, fmt.Errorf("PK missing from LPA in response")
}

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

return lpa, nil
Expand Down
48 changes: 24 additions & 24 deletions cmd/event-received/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,17 @@ func TestHandleFeeApproved(t *testing.T) {
client.
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: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
Return(nil)

shareCodeSender := newMockShareCodeSender(t)
shareCodeSender.
On("SendCertificateProvider", ctx, notify.CertificateProviderInviteEmail, page.AppData{}, false, &page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
On("SendCertificateProvider", ctx, notify.CertificateProviderInviteEmail, page.AppData{}, false, &actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
Return(nil)

err := handleFeeApproved(ctx, client, event, shareCodeSender, page.AppData{}, func() time.Time { return now })
Expand All @@ -218,19 +218,19 @@ 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(page.Lpa{PK: "LPA#123", SK: "#DONOR#456"})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#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(page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
Return(expectedError)

err := handleFeeApproved(ctx, client, event, nil, page.AppData{}, func() time.Time { return now })
Expand All @@ -256,17 +256,17 @@ func TestHandleFeeApprovedWhenShareCodeSenderError(t *testing.T) {
client.
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: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
Return(nil)

shareCodeSender := newMockShareCodeSender(t)
shareCodeSender.
On("SendCertificateProvider", ctx, notify.CertificateProviderInviteEmail, page.AppData{}, false, &page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
On("SendCertificateProvider", ctx, notify.CertificateProviderInviteEmail, page.AppData{}, false, &actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskCompleted}, UpdatedAt: now}).
Return(expectedError)

err := handleFeeApproved(ctx, client, event, shareCodeSender, page.AppData{}, func() time.Time { return now })
Expand All @@ -292,12 +292,12 @@ func TestHandleMoreEvidenceRequired(t *testing.T) {
client.
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: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}).
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}).
Return(nil)

err := handleMoreEvidenceRequired(ctx, client, event, func() time.Time { return now })
Expand All @@ -323,12 +323,12 @@ func TestHandleMoreEvidenceRequiredWhenPutError(t *testing.T) {
client.
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: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}).
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}).
Return(expectedError)

err := handleMoreEvidenceRequired(ctx, client, event, func() time.Time { return now })
Expand All @@ -354,12 +354,12 @@ func TestHandleFeeDenied(t *testing.T) {
client.
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: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}).
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}).
Return(nil)

err := handleFeeDenied(ctx, client, event, func() time.Time { return now })
Expand All @@ -385,12 +385,12 @@ func TestHandleFeeDeniedWhenPutError(t *testing.T) {
client.
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: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
b, _ := json.Marshal(actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
client.
On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}).
On("Put", ctx, actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}).
Return(expectedError)

err := handleFeeDenied(ctx, client, event, func() time.Time { return now })
Expand Down Expand Up @@ -429,7 +429,7 @@ func TestHandleObjectTagsAdded(t *testing.T) {
dynamoClient.
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{ID: "123", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
b, _ := json.Marshal(actor.DonorProvidedDetails{ID: "123", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
Expand Down Expand Up @@ -515,7 +515,7 @@ func TestHandleObjectTagsAddedWhenDynamoClientOneByUIDError(t *testing.T) {
dynamoClient.
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{ID: "123", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
b, _ := json.Marshal(actor.DonorProvidedDetails{ID: "123", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return expectedError
})
Expand Down Expand Up @@ -549,7 +549,7 @@ func TestHandleObjectTagsAddedWhenDocumentStoreUpdateScanResultsError(t *testing
dynamoClient.
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{ID: "123", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
b, _ := json.Marshal(actor.DonorProvidedDetails{ID: "123", Tasks: actor.DonorTasks{PayForLpa: actor.PaymentTaskPending}})
json.Unmarshal(b, v)
return nil
})
Expand All @@ -564,7 +564,7 @@ func TestHandleObjectTagsAddedWhenDocumentStoreUpdateScanResultsError(t *testing
}

func TestGetLpaByUID(t *testing.T) {
expectedLpa := page.Lpa{PK: "LPA#123", SK: "#DONOR#456"}
expectedLpa := actor.DonorProvidedDetails{PK: "LPA#123", SK: "#DONOR#456"}

client := newMockDynamodbClient(t)
client.
Expand Down Expand Up @@ -596,7 +596,7 @@ func TestGetLpaByUIDWhenClientOneByUidError(t *testing.T) {

lpa, err := getLpaByUID(ctx, client, "M-1111-2222-3333")

assert.Equal(t, page.Lpa{}, lpa)
assert.Equal(t, actor.DonorProvidedDetails{}, lpa)
assert.Equal(t, fmt.Errorf("failed to resolve uid: %w", expectedError), err)
}

Expand All @@ -612,7 +612,7 @@ func TestGetLpaByUIDWhenPKMissing(t *testing.T) {

lpa, err := getLpaByUID(ctx, client, "M-1111-2222-3333")

assert.Equal(t, page.Lpa{}, lpa)
assert.Equal(t, actor.DonorProvidedDetails{}, lpa)
assert.Equal(t, errors.New("PK missing from LPA in response"), err)
}

Expand All @@ -631,6 +631,6 @@ func TestGetLpaByUIDWhenClientOneError(t *testing.T) {

lpa, err := getLpaByUID(ctx, client, "M-1111-2222-3333")

assert.Equal(t, page.Lpa{}, lpa)
assert.Equal(t, actor.DonorProvidedDetails{}, lpa)
assert.Equal(t, fmt.Errorf("failed to get LPA: %w", expectedError), err)
}
3 changes: 2 additions & 1 deletion cmd/event-received/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/aws/aws-sdk-go-v2/config"
dynamodbtypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/app"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
Expand Down Expand Up @@ -50,7 +51,7 @@ type s3Client interface {

//go:generate mockery --testonly --inpackage --name shareCodeSender --structname mockShareCodeSender
type shareCodeSender interface {
SendCertificateProvider(context.Context, notify.Template, page.AppData, bool, *page.Lpa) error
SendCertificateProvider(context.Context, notify.Template, page.AppData, bool, *actor.DonorProvidedDetails) error
}

//go:generate mockery --testonly --inpackage --name DocumentStore --structname mockDocumentStore
Expand Down
9 changes: 6 additions & 3 deletions cmd/event-received/mock_shareCodeSender_test.go

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

9 changes: 9 additions & 0 deletions internal/actor/can_be_used_when.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package actor

//go:generate enumerator -type CanBeUsedWhen -linecomment -trimprefix -empty
type CanBeUsedWhen uint8

const (
CanBeUsedWhenCapacityLost CanBeUsedWhen = iota + 1 // when-capacity-lost
CanBeUsedWhenHasCapacity // when-has-capacity
)
29 changes: 29 additions & 0 deletions internal/actor/can_be_used_when_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package actor

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCanBeUsedWhen(t *testing.T) {
values := map[CanBeUsedWhen]string{CanBeUsedWhenCapacityLost: "when-capacity-lost", CanBeUsedWhenHasCapacity: "when-has-capacity"}

for value, s := range values {
t.Run(fmt.Sprintf("parse(%s)", s), func(t *testing.T) {
parsed, err := ParseCanBeUsedWhen(s)
assert.Nil(t, err)
assert.Equal(t, value, parsed)
})

t.Run(fmt.Sprintf("string(%s)", s), func(t *testing.T) {
assert.Equal(t, s, value.String())
})
}

t.Run("parse invalid", func(t *testing.T) {
_, err := ParseCanBeUsedWhen("invalid")
assert.NotNil(t, err)
})
}
Loading

0 comments on commit 11696e8

Please sign in to comment.