Skip to content

Commit

Permalink
Move uses from actor.* to donordata.* (#1393)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Aug 1, 2024
1 parent 54008c6 commit 4293ce7
Show file tree
Hide file tree
Showing 249 changed files with 3,202 additions and 3,263 deletions.
6 changes: 3 additions & 3 deletions cmd/event-received/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/aws/aws-sdk-go-v2/aws"
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/app"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lambda"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
Expand All @@ -28,7 +28,7 @@ type LambdaClient interface {
}

type LpaStoreClient interface {
SendLpa(ctx context.Context, donor *actor.DonorProvidedDetails) error
SendLpa(ctx context.Context, donor *donordata.DonorProvidedDetails) error
Lpa(ctx context.Context, uid string) (*lpastore.Lpa, error)
}

Expand All @@ -38,7 +38,7 @@ type SecretsClient interface {

type ShareCodeSender interface {
SendCertificateProviderInvite(context.Context, page.AppData, page.CertificateProviderInvite) error
SendCertificateProviderPrompt(context.Context, page.AppData, *actor.DonorProvidedDetails) error
SendCertificateProviderPrompt(context.Context, page.AppData, *donordata.DonorProvidedDetails) error
SendAttorneys(context.Context, page.AppData, *lpastore.Lpa) error
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/event-received/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/aws/aws-lambda-go/events"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
)

Expand Down Expand Up @@ -52,7 +52,7 @@ func handleObjectTagsAdded(ctx context.Context, dynamodbClient dynamodbClient, e
return nil
}

func putDonor(ctx context.Context, donor *actor.DonorProvidedDetails, now func() time.Time, client dynamodbClient) error {
func putDonor(ctx context.Context, donor *donordata.DonorProvidedDetails, now func() time.Time, client dynamodbClient) error {
donor.UpdatedAt = now()
if err := donor.UpdateHash(); err != nil {
return err
Expand All @@ -61,7 +61,7 @@ func putDonor(ctx context.Context, donor *actor.DonorProvidedDetails, now func()
return client.Put(ctx, donor)
}

func getDonorByLpaUID(ctx context.Context, client dynamodbClient, uid string) (*actor.DonorProvidedDetails, error) {
func getDonorByLpaUID(ctx context.Context, client dynamodbClient, uid string) (*donordata.DonorProvidedDetails, error) {
var key dynamo.Keys
if err := client.OneByUID(ctx, uid, &key); err != nil {
return nil, fmt.Errorf("failed to resolve uid: %w", err)
Expand All @@ -71,7 +71,7 @@ func getDonorByLpaUID(ctx context.Context, client dynamodbClient, uid string) (*
return nil, fmt.Errorf("PK missing from LPA in response")
}

var donor actor.DonorProvidedDetails
var donor donordata.DonorProvidedDetails
if err := client.One(ctx, key.PK, key.SK, &donor); err != nil {
return nil, fmt.Errorf("failed to get LPA: %w", err)
}
Expand Down
11 changes: 6 additions & 5 deletions cmd/event-received/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-sdk-go-v2/aws"
"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/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
Expand Down Expand Up @@ -48,7 +49,7 @@ func TestHandleObjectTagsAdded(t *testing.T) {
dynamoClient.
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}})
b, _ := json.Marshal(donordata.DonorProvidedDetails{LpaID: "123", Tasks: donordata.DonorTasks{PayForLpa: task.PaymentStatePending}})
json.Unmarshal(b, v)
return nil
})
Expand Down Expand Up @@ -134,7 +135,7 @@ func TestHandleObjectTagsAddedWhenDynamoClientOneByUIDError(t *testing.T) {
dynamoClient.
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}})
b, _ := json.Marshal(donordata.DonorProvidedDetails{LpaID: "123", Tasks: donordata.DonorTasks{PayForLpa: task.PaymentStatePending}})
json.Unmarshal(b, v)
return expectedError
})
Expand Down Expand Up @@ -168,7 +169,7 @@ func TestHandleObjectTagsAddedWhenDocumentStoreUpdateScanResultsError(t *testing
dynamoClient.
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}})
b, _ := json.Marshal(donordata.DonorProvidedDetails{LpaID: "123", Tasks: donordata.DonorTasks{PayForLpa: task.PaymentStatePending}})
json.Unmarshal(b, v)
return nil
})
Expand All @@ -183,7 +184,7 @@ func TestHandleObjectTagsAddedWhenDocumentStoreUpdateScanResultsError(t *testing
}

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

client := newMockDynamodbClient(t)
client.
Expand Down
12 changes: 6 additions & 6 deletions cmd/event-received/lpastore_event_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/aws/aws-lambda-go/events"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand All @@ -26,7 +26,7 @@ func TestLpaStoreEventHandlerHandleLpaUpdated(t *testing.T) {
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"PERFECT"}`),
}

updated := &actor.DonorProvidedDetails{
updated := &donordata.DonorProvidedDetails{
PK: dynamo.LpaKey("123"),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")),
PerfectAt: testNow,
Expand All @@ -45,7 +45,7 @@ func TestLpaStoreEventHandlerHandleLpaUpdated(t *testing.T) {
client.
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"))})
b, _ := json.Marshal(donordata.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456"))})
json.Unmarshal(b, v)
return nil
})
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestLpaStoreEventHandlerHandleLpaUpdatedWhenDynamoGetErrors(t *testing.T) {
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"PERFECT"}`),
}

updated := &actor.DonorProvidedDetails{
updated := &donordata.DonorProvidedDetails{
PK: dynamo.LpaKey("123"),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")),
PerfectAt: testNow,
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestLpaStoreEventHandlerHandleLpaUpdatedWhenDynamoPutErrors(t *testing.T) {
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"PERFECT"}`),
}

updated := &actor.DonorProvidedDetails{
updated := &donordata.DonorProvidedDetails{
PK: dynamo.LpaKey("123"),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")),
PerfectAt: testNow,
Expand All @@ -133,7 +133,7 @@ func TestLpaStoreEventHandlerHandleLpaUpdatedWhenDynamoPutErrors(t *testing.T) {
client.
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"))})
b, _ := json.Marshal(donordata.DonorProvidedDetails{PK: dynamo.LpaKey("123"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456"))})
json.Unmarshal(b, v)
return nil
})
Expand Down
12 changes: 6 additions & 6 deletions cmd/event-received/makeregister_event_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/date"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
Expand Down Expand Up @@ -61,9 +61,9 @@ func TestHandleUidRequested(t *testing.T) {
dynamoClient.
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, _ := attributevalue.Marshal(&actor.DonorProvidedDetails{
Donor: actor.Donor{FirstNames: "a", LastName: "b", Address: place.Address{Line1: "a"}, DateOfBirth: dob},
Type: actor.LpaTypePersonalWelfare,
b, _ := attributevalue.Marshal(&donordata.DonorProvidedDetails{
Donor: donordata.Donor{FirstNames: "a", LastName: "b", Address: place.Address{Line1: "a"}, DateOfBirth: dob},
Type: donordata.LpaTypePersonalWelfare,
CreatedAt: testNow,
LpaUID: "M-1111-2222-3333",
PK: dynamo.LpaKey("123"),
Expand All @@ -77,7 +77,7 @@ func TestHandleUidRequested(t *testing.T) {
eventClient.EXPECT().
SendApplicationUpdated(ctx, event.ApplicationUpdated{
UID: "M-1111-2222-3333",
Type: actor.LpaTypePersonalWelfare.String(),
Type: donordata.LpaTypePersonalWelfare.String(),
CreatedAt: testNow,
Donor: event.ApplicationUpdatedDonor{
FirstNames: "a",
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestHandleUidRequestedWhenEventClientErrors(t *testing.T) {
dynamoClient.
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, _ := attributevalue.Marshal(&actor.DonorProvidedDetails{})
b, _ := attributevalue.Marshal(&donordata.DonorProvidedDetails{})
attributevalue.Unmarshal(b, v)
return nil
})
Expand Down
13 changes: 7 additions & 6 deletions cmd/event-received/sirius_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"time"

"github.com/aws/aws-lambda-go/events"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/pay"
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
)

type siriusEventHandler struct{}
Expand Down Expand Up @@ -109,7 +110,7 @@ func handleFeeApproved(ctx context.Context, client dynamodbClient, event events.
}

if donor.FeeAmount() == 0 {
donor.Tasks.PayForLpa = actor.PaymentTaskCompleted
donor.Tasks.PayForLpa = task.PaymentStateCompleted

if donor.Tasks.ConfirmYourIdentityAndSign.IsCompleted() {
if err := lpaStoreClient.SendLpa(ctx, donor); err != nil {
Expand All @@ -121,7 +122,7 @@ func handleFeeApproved(ctx context.Context, client dynamodbClient, event events.
}
}
} else {
donor.Tasks.PayForLpa = actor.PaymentTaskApproved
donor.Tasks.PayForLpa = task.PaymentStateApproved
}

if err := putDonor(ctx, donor, now, client); err != nil {
Expand All @@ -146,7 +147,7 @@ func handleFurtherInfoRequested(ctx context.Context, client dynamodbClient, even
return nil
}

donor.Tasks.PayForLpa = actor.PaymentTaskMoreEvidenceRequired
donor.Tasks.PayForLpa = task.PaymentStateMoreEvidenceRequired

if err := putDonor(ctx, donor, now, client); err != nil {
return fmt.Errorf("failed to update LPA task status: %w", err)
Expand All @@ -171,7 +172,7 @@ func handleFeeDenied(ctx context.Context, client dynamodbClient, event events.Cl
}

donor.FeeType = pay.FullFee
donor.Tasks.PayForLpa = actor.PaymentTaskDenied
donor.Tasks.PayForLpa = task.PaymentStateDenied

if err := putDonor(ctx, donor, now, client); err != nil {
return fmt.Errorf("failed to update LPA task status: %w", err)
Expand All @@ -193,7 +194,7 @@ func handleDonorSubmissionCompleted(ctx context.Context, client dynamodbClient,

lpaID := uuidString()

if err := client.Put(ctx, &actor.DonorProvidedDetails{
if err := client.Put(ctx, &donordata.DonorProvidedDetails{
PK: dynamo.LpaKey(lpaID),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("PAPER")),
LpaID: lpaID,
Expand Down
Loading

0 comments on commit 4293ce7

Please sign in to comment.