From 65ad13418cd67483468f03f7459bf11b7d5dfefc Mon Sep 17 00:00:00 2001 From: Alex Saunders Date: Tue, 17 Oct 2023 16:22:21 +0100 Subject: [PATCH 01/19] handle document-scanned events --- Makefile | 3 + cmd/event-received/main.go | 91 +++++--- cmd/event-received/main_test.go | 221 +++++++------------- go.sum | 58 +---- internal/app/donor_store.go | 12 +- internal/app/donor_store_test.go | 18 +- internal/page/data.go | 61 +++++- internal/page/data_test.go | 13 +- internal/page/donor/upload_evidence.go | 8 +- internal/page/donor/upload_evidence_test.go | 23 +- web/template/upload_evidence.gohtml | 4 +- 11 files changed, 239 insertions(+), 273 deletions(-) diff --git a/Makefile b/Makefile index 096d72e201..eb62376064 100644 --- a/Makefile +++ b/Makefile @@ -104,5 +104,8 @@ emit-fee-denied: ##@app emits a fee-denied event with the given UID e.g. emit-fe emit-more-evidence-required: ##@app emits a more-evidence-required event with the given UID e.g. emit-more-evidence-required UID=abc-123 curl "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"version":"0","id":"63eb7e5f-1f10-4744-bba9-e16d327c3b98","detail-type":"more-evidence-required","source":"opg.poas.sirius","account":"653761790766","time":"2023-08-30T13:40:30Z","region":"eu-west-1","resources":[],"detail":{"UID":"$(UID)"}}' +emit-document-scanned: ##@app emits a document-scanned event with the given UID, S3 key and result and e.g. emit-document-scanned UID=abc-123 key=doc/key virus_detected=false + curl "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"version":"0","id":"63eb7e5f-1f10-4744-bba9-e16d327c3b98","detail-type":"document-scanned","source":"opg.poas.sirius","account":"653761790766","time":"2023-08-30T13:40:30Z","region":"eu-west-1","resources":[],"detail":{"UID":"$(UID)","key":"$(key)","virus_detected":$(virus_detected)}}' + logs: ##@app tails logs for all containers running docker compose -f docker/docker-compose.yml -f docker/docker-compose.dev.yml logs -f diff --git a/cmd/event-received/main.go b/cmd/event-received/main.go index dbb436b2a7..c82d8ad038 100644 --- a/cmd/event-received/main.go +++ b/cmd/event-received/main.go @@ -27,6 +27,12 @@ type uidEvent struct { UID string `json:"uid"` } +type documentScannedEvent struct { + UID string `json:"uid"` + Key string `json:"key"` + VirusDetected bool `json:"virus_detected"` +} + //go:generate mockery --testonly --inpackage --name dynamodbClient --structname mockDynamodbClient type dynamodbClient interface { One(ctx context.Context, pk, sk string, v interface{}) error @@ -95,6 +101,8 @@ func Handler(ctx context.Context, event events.CloudWatchEvent) error { return handleMoreEvidenceRequired(ctx, dynamoClient, event, now) case "fee-denied": return handleFeeDenied(ctx, dynamoClient, event, now) + case "document-scanned": + return handleDocumentScanned(ctx, dynamoClient, event, now) default: return fmt.Errorf("unknown event received: %s", event.DetailType) } @@ -128,14 +136,9 @@ func handleFeeApproved(ctx context.Context, dynamoClient dynamodbClient, event e return fmt.Errorf("failed to unmarshal 'fee-approved' detail: %w", err) } - var key dynamo.Key - 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.One(ctx, key.PK, key.SK, &lpa); err != nil { - return fmt.Errorf("failed to get LPA for 'fee-approved': %w", err) + lpa, err := getLpaByUID(ctx, dynamoClient, v.UID, "fee-approved") + if err != nil { + return err } lpa.Tasks.PayForLpa = actor.PaymentTaskCompleted @@ -158,18 +161,9 @@ func handleMoreEvidenceRequired(ctx context.Context, client dynamodbClient, even return fmt.Errorf("failed to unmarshal 'more-evidence-required' detail: %w", err) } - var key dynamo.Key - if err := client.OneByUID(ctx, v.UID, &key); err != nil { - return fmt.Errorf("failed to resolve uid for 'more-evidence-required': %w", err) - } - - if key.PK == "" { - return errors.New("PK missing from LPA in response to 'more-evidence-required'") - } - - var lpa page.Lpa - 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) + lpa, err := getLpaByUID(ctx, client, v.UID, "more-evidence-required") + if err != nil { + return err } lpa.Tasks.PayForLpa = actor.PaymentTaskMoreEvidenceRequired @@ -188,30 +182,67 @@ func handleFeeDenied(ctx context.Context, client dynamodbClient, event events.Cl return fmt.Errorf("failed to unmarshal 'fee-denied' detail: %w", err) } - var key dynamo.Key - if err := client.OneByUID(ctx, v.UID, &key); err != nil { - return fmt.Errorf("failed to resolve uid for 'fee-denied': %w", err) + lpa, err := getLpaByUID(ctx, client, v.UID, "fee-denied") + if err != nil { + return err } - if key.PK == "" { - return errors.New("PK missing from LPA in response to 'fee-denied'") + lpa.Tasks.PayForLpa = actor.PaymentTaskDenied + lpa.UpdatedAt = now() + + if err := client.Put(ctx, lpa); err != nil { + return fmt.Errorf("failed to update LPA task status for 'fee-denied': %w", err) } - var lpa page.Lpa - if err := client.One(ctx, key.PK, key.SK, &lpa); err != nil { - return fmt.Errorf("failed to get LPA for 'fee-denied': %w", err) + return nil +} + +func handleDocumentScanned(ctx context.Context, client dynamodbClient, event events.CloudWatchEvent, now func() time.Time) error { + var v documentScannedEvent + if err := json.Unmarshal(event.Detail, &v); err != nil { + return fmt.Errorf("failed to unmarshal 'document-scanned' detail: %w", err) + } + + lpa, err := getLpaByUID(ctx, client, v.UID, "document-scanned") + if err != nil { + return err + } + + evidence := lpa.Evidence.GetByKey(v.Key) + evidence.Scanned = now() + evidence.VirusDetected = v.VirusDetected + + if ok := lpa.Evidence.Update(evidence); !ok { + return errors.New("failed to update evidence on LPA for 'document-scanned'") } - lpa.Tasks.PayForLpa = actor.PaymentTaskDenied lpa.UpdatedAt = now() if err := client.Put(ctx, lpa); err != nil { - return fmt.Errorf("failed to update LPA task status for 'fee-denied': %w", err) + return fmt.Errorf("failed to update LPA for 'document-scanned': %w", err) } return nil } +func getLpaByUID(ctx context.Context, client dynamodbClient, uid, eventName string) (page.Lpa, error) { + var key dynamo.Key + if err := client.OneByUID(ctx, uid, &key); err != nil { + return page.Lpa{}, fmt.Errorf("failed to resolve uid for '%s': %w", eventName, err) + } + + if key.PK == "" { + return page.Lpa{}, fmt.Errorf("PK missing from LPA in response to '%s'", eventName) + } + + var lpa page.Lpa + if err := client.One(ctx, key.PK, key.SK, &lpa); err != nil { + return page.Lpa{}, fmt.Errorf("failed to get LPA for '%s': %w", eventName, err) + } + + return lpa, nil +} + func main() { lambda.Start(Handler) } diff --git a/cmd/event-received/main_test.go b/cmd/event-received/main_test.go index 730c1cfdaa..bcfbc7b9e6 100644 --- a/cmd/event-received/main_test.go +++ b/cmd/event-received/main_test.go @@ -18,9 +18,9 @@ import ( ) var expectedError = errors.New("err") +var ctx = context.Background() func TestHandleEvidenceReceived(t *testing.T) { - ctx := context.Background() event := events.CloudWatchEvent{ DetailType: "evidence-required", Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), @@ -46,7 +46,6 @@ func TestHandleEvidenceReceived(t *testing.T) { } func TestHandleEvidenceReceivedWhenClientGetError(t *testing.T) { - ctx := context.Background() event := events.CloudWatchEvent{ DetailType: "evidence-required", Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), @@ -62,7 +61,6 @@ func TestHandleEvidenceReceivedWhenClientGetError(t *testing.T) { } func TestHandleEvidenceReceivedWhenLpaMissingPK(t *testing.T) { - ctx := context.Background() event := events.CloudWatchEvent{ DetailType: "evidence-required", Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), @@ -82,7 +80,6 @@ func TestHandleEvidenceReceivedWhenLpaMissingPK(t *testing.T) { } func TestHandleEvidenceReceivedWhenClientPutError(t *testing.T) { - ctx := context.Background() event := events.CloudWatchEvent{ DetailType: "evidence-required", Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), @@ -108,7 +105,6 @@ func TestHandleEvidenceReceivedWhenClientPutError(t *testing.T) { } func TestHandleFeeApproved(t *testing.T) { - ctx := context.Background() event := events.CloudWatchEvent{ DetailType: "fee-approved", Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), @@ -144,47 +140,7 @@ func TestHandleFeeApproved(t *testing.T) { assert.Nil(t, err) } -func TestHandleFeeApprovedWhenDynamoClientOneByUIDError(t *testing.T) { - ctx := context.Background() - event := events.CloudWatchEvent{ - DetailType: "fee-approved", - Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), - } - - client := newMockDynamodbClient(t) - client. - On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything). - Return(expectedError) - - err := handleFeeApproved(ctx, client, event, nil, page.AppData{}, time.Now) - assert.Equal(t, fmt.Errorf("failed to resolve uid for 'fee-approved': %w", expectedError), err) -} - -func TestHandleFeeApprovedWhenDynamoClientGetError(t *testing.T) { - ctx := context.Background() - event := events.CloudWatchEvent{ - DetailType: "fee-approved", - Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), - } - - 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"}) - json.Unmarshal(b, v) - return nil - }) - client. - On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything). - Return(expectedError) - - err := handleFeeApproved(ctx, client, event, nil, page.AppData{}, time.Now) - assert.Equal(t, fmt.Errorf("failed to get LPA for 'fee-approved': %w", expectedError), err) -} - func TestHandleFeeApprovedWhenDynamoClientPutError(t *testing.T) { - ctx := context.Background() event := events.CloudWatchEvent{ DetailType: "fee-approved", Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), @@ -216,7 +172,6 @@ func TestHandleFeeApprovedWhenDynamoClientPutError(t *testing.T) { } func TestHandleFeeApprovedWhenShareCodeSenderError(t *testing.T) { - ctx := context.Background() event := events.CloudWatchEvent{ DetailType: "fee-approved", Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), @@ -253,7 +208,6 @@ func TestHandleFeeApprovedWhenShareCodeSenderError(t *testing.T) { } func TestHandleMoreEvidenceRequired(t *testing.T) { - ctx := context.Background() event := events.CloudWatchEvent{ DetailType: "more-evidence-required", Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), @@ -284,50 +238,45 @@ func TestHandleMoreEvidenceRequired(t *testing.T) { assert.Nil(t, err) } -func TestHandleMoreEvidenceRequiredWhenOneByUIDError(t *testing.T) { - ctx := context.Background() +func TestHandleMoreEvidenceRequiredWhenPutError(t *testing.T) { event := events.CloudWatchEvent{ DetailType: "more-evidence-required", Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), } - client := newMockDynamodbClient(t) - client. - On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything). - Return(expectedError) - - err := handleMoreEvidenceRequired(ctx, client, event, time.Now) - assert.Equal(t, fmt.Errorf("failed to resolve uid for 'more-evidence-required': %w", expectedError), err) -} - -func TestHandleMoreEvidenceRequiredWhenPKMissing(t *testing.T) { - ctx := context.Background() - event := events.CloudWatchEvent{ - DetailType: "more-evidence-required", - Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), - } + now := time.Now() 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{}) + b, _ := json.Marshal(dynamo.Key{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: page.Tasks{PayForLpa: actor.PaymentTaskPending}}) + json.Unmarshal(b, v) + return nil + }) + client. + On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}). + Return(expectedError) - err := handleMoreEvidenceRequired(ctx, client, event, time.Now) - - assert.Equal(t, errors.New("PK missing from LPA in response to 'more-evidence-required'"), err) + err := handleMoreEvidenceRequired(ctx, client, event, func() time.Time { return now }) + assert.Equal(t, fmt.Errorf("failed to update LPA task status for 'more-evidence-required': %w", expectedError), err) } -func TestHandleMoreEvidenceRequiredWhenGetError(t *testing.T) { - ctx := context.Background() +func TestHandleFeeDenied(t *testing.T) { event := events.CloudWatchEvent{ - DetailType: "more-evidence-required", + DetailType: "fee-denied", Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), } + now := time.Now() + client := newMockDynamodbClient(t) client. On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything). @@ -338,16 +287,22 @@ func TestHandleMoreEvidenceRequiredWhenGetError(t *testing.T) { }) client. On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything). - Return(expectedError) + 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) + return nil + }) + client. + On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}). + Return(nil) - err := handleMoreEvidenceRequired(ctx, client, event, time.Now) - assert.Equal(t, fmt.Errorf("failed to get LPA for 'more-evidence-required': %w", expectedError), err) + err := handleFeeDenied(ctx, client, event, func() time.Time { return now }) + assert.Nil(t, err) } -func TestHandleMoreEvidenceRequiredWhenPutError(t *testing.T) { - ctx := context.Background() +func TestHandleFeeDeniedWhenPutError(t *testing.T) { event := events.CloudWatchEvent{ - DetailType: "more-evidence-required", + DetailType: "fee-denied", Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), } @@ -369,18 +324,17 @@ func TestHandleMoreEvidenceRequiredWhenPutError(t *testing.T) { return nil }) client. - On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskMoreEvidenceRequired}, UpdatedAt: now}). + On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}). Return(expectedError) - err := handleMoreEvidenceRequired(ctx, client, event, func() time.Time { return now }) - assert.Equal(t, fmt.Errorf("failed to update LPA task status for 'more-evidence-required': %w", expectedError), err) + err := handleFeeDenied(ctx, client, event, func() time.Time { return now }) + assert.Equal(t, fmt.Errorf("failed to update LPA task status for 'fee-denied': %w", expectedError), err) } -func TestHandleFeeDenied(t *testing.T) { - ctx := context.Background() +func TestHandleDocumentScanned(t *testing.T) { event := events.CloudWatchEvent{ - DetailType: "fee-denied", - Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), + DetailType: "document-scanned", + Detail: json.RawMessage(`{"uid":"M-1111-2222-3333", "key": "document/key", "virus_detected": false}`), } now := time.Now() @@ -396,87 +350,79 @@ 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: page.Tasks{PayForLpa: actor.PaymentTaskPending}}) + b, _ := json.Marshal(page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Evidence: page.Evidence{ + Documents: []page.Document{{Key: "document/key"}}, + }}) json.Unmarshal(b, v) return nil }) client. - On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}). + On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", UpdatedAt: now, Evidence: page.Evidence{ + Documents: []page.Document{{Key: "document/key", Scanned: now, VirusDetected: false}}, + }}). Return(nil) - err := handleFeeDenied(ctx, client, event, func() time.Time { return now }) + err := handleDocumentScanned(ctx, client, event, func() time.Time { return now }) assert.Nil(t, err) } -func TestHandleFeeDeniedWhenOneByUIDError(t *testing.T) { - ctx := context.Background() - event := events.CloudWatchEvent{ - DetailType: "fee-denied", - Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), - } +func TestGetLpaByUID(t *testing.T) { + expectedLpa := page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Evidence: page.Evidence{ + Documents: []page.Document{{Key: "document/key"}}, + }} client := newMockDynamodbClient(t) client. On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything). - Return(expectedError) + 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("One", ctx, "LPA#123", "#DONOR#456", mock.Anything). + Return(func(ctx context.Context, pk, sk string, v interface{}) error { + b, _ := json.Marshal(expectedLpa) + json.Unmarshal(b, v) + return nil + }) - err := handleFeeDenied(ctx, client, event, time.Now) - assert.Equal(t, fmt.Errorf("failed to resolve uid for 'fee-denied': %w", expectedError), err) -} + lpa, err := getLpaByUID(ctx, client, "M-1111-2222-3333", "an-event") -func TestHandleFeeDeniedWhenPKMissing(t *testing.T) { - ctx := context.Background() - event := events.CloudWatchEvent{ - DetailType: "fee-denied", - Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), - } + assert.Equal(t, expectedLpa, lpa) + assert.Nil(t, err) +} +func TestGetLpaByUIDWhenClientOneByUidError(t *testing.T) { 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{}) - json.Unmarshal(b, v) - return nil - }) + Return(expectedError) - err := handleFeeDenied(ctx, client, event, time.Now) + lpa, err := getLpaByUID(ctx, client, "M-1111-2222-3333", "an-event") - assert.Equal(t, errors.New("PK missing from LPA in response to 'fee-denied'"), err) + assert.Equal(t, page.Lpa{}, lpa) + assert.Equal(t, fmt.Errorf("failed to resolve uid for 'an-event': %w", expectedError), err) } -func TestHandleFeeDeniedWhenGetError(t *testing.T) { - ctx := context.Background() - event := events.CloudWatchEvent{ - DetailType: "fee-denied", - Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), - } - +func TestGetLpaByUIDWhenPKMissing(t *testing.T) { 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{SK: "#DONOR#456"}) json.Unmarshal(b, v) return nil }) - client. - On("One", ctx, "LPA#123", "#DONOR#456", mock.Anything). - Return(expectedError) - err := handleFeeDenied(ctx, client, event, time.Now) - assert.Equal(t, fmt.Errorf("failed to get LPA for 'fee-denied': %w", expectedError), err) -} + lpa, err := getLpaByUID(ctx, client, "M-1111-2222-3333", "an-event") -func TestHandleFeeDeniedWhenPutError(t *testing.T) { - ctx := context.Background() - event := events.CloudWatchEvent{ - DetailType: "fee-denied", - Detail: json.RawMessage(`{"uid":"M-1111-2222-3333"}`), - } + assert.Equal(t, page.Lpa{}, lpa) + assert.Equal(t, errors.New("PK missing from LPA in response to 'an-event'"), err) - now := time.Now() +} +func TestGetLpaByUIDWhenClientOneError(t *testing.T) { client := newMockDynamodbClient(t) client. On("OneByUID", ctx, "M-1111-2222-3333", mock.Anything). @@ -487,15 +433,10 @@ 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: page.Tasks{PayForLpa: actor.PaymentTaskPending}}) - json.Unmarshal(b, v) - return nil - }) - client. - On("Put", ctx, page.Lpa{PK: "LPA#123", SK: "#DONOR#456", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskDenied}, UpdatedAt: now}). Return(expectedError) - err := handleFeeDenied(ctx, client, event, func() time.Time { return now }) - assert.Equal(t, fmt.Errorf("failed to update LPA task status for 'fee-denied': %w", expectedError), err) + lpa, err := getLpaByUID(ctx, client, "M-1111-2222-3333", "an-event") + + assert.Equal(t, page.Lpa{}, lpa) + assert.Equal(t, fmt.Errorf("failed to get LPA for 'an-event': %w", expectedError), err) } diff --git a/go.sum b/go.sum index 5c3e692404..089f3012ff 100644 --- a/go.sum +++ b/go.sum @@ -6,101 +6,57 @@ github.com/MicahParks/keyfunc v1.9.0 h1:lhKd5xrFHLNOWrDc4Tyb/Q1AJ4LCzQ48GVJyVIID github.com/MicahParks/keyfunc v1.9.0/go.mod h1:IdnCilugA0O/99dW+/MkvlyrsX8+L8+x95xuVNtM5jw= github.com/aws/aws-lambda-go v1.41.0 h1:l/5fyVb6Ud9uYd411xdHZzSf2n86TakxzpvIoz7l+3Y= github.com/aws/aws-lambda-go v1.41.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM= -github.com/aws/aws-sdk-go-v2 v1.21.0 h1:gMT0IW+03wtYJhRqTVYn0wLzwdnK9sRMcxmtfGzRdJc= github.com/aws/aws-sdk-go-v2 v1.21.0/go.mod h1:/RfNgGmRxI+iFOB1OeJUyxiU+9s88k3pfHvDagGEp0M= github.com/aws/aws-sdk-go-v2 v1.21.2 h1:+LXZ0sgo8quN9UOKXXzAWRT3FWd4NxeXWOZom9pE7GA= github.com/aws/aws-sdk-go-v2 v1.21.2/go.mod h1:ErQhvNuEMhJjweavOYhxVkn2RUx7kQXVATHrjKtxIpM= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13 h1:OPLEkmhXf6xFPiz0bLeDArZIDx1NNS4oJyG4nv3Gct0= -github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13/go.mod h1:gpAbvyDGQFozTEmlTFO8XcQKHzubdq0LzRyJpG6MiXM= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 h1:Sc82v7tDQ/vdU1WtuSyzZ1I7y/68j//HJ6uozND1IDs= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14/go.mod h1:9NCTOURS8OpxvoAVHq79LK81/zC78hfRWFn+aL0SPcY= -github.com/aws/aws-sdk-go-v2/config v1.18.43 h1:IgdUtTRvUDC6eiJBqU6vh7bHFNAEBjQ8S+qJ7zVhDOs= -github.com/aws/aws-sdk-go-v2/config v1.18.43/go.mod h1:NiFev8qlgg8MPzw3fO/EwzMZeZwlJEKGwfpjRPA9Nvw= github.com/aws/aws-sdk-go-v2/config v1.18.45 h1:Aka9bI7n8ysuwPeFdm77nfbyHCAKQ3z9ghB3S/38zes= github.com/aws/aws-sdk-go-v2/config v1.18.45/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE= -github.com/aws/aws-sdk-go-v2/credentials v1.13.41 h1:dgbKq1tamtboYAKSXWbqL0lKO9rmEzEhbZFh9JQW/Bg= -github.com/aws/aws-sdk-go-v2/credentials v1.13.41/go.mod h1:cc3Fn7DkKbJalPtQnudHGZZ8ml9+hwtbc1CJONsYYqk= github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8= github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg= -github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.40 h1:YS/4hWmEIgAgUcFWPWmeBvyjH1Bttvfn1gHYC3T0Jd0= -github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.40/go.mod h1:W4jFsOeGAVrQZWgoRY52fjYObqfjletWUlq4cssiBdw= github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.42 h1:taACSYOzbwyrJPvzX0ucCkB9gxkIkcYkuXkUhNRsnJ0= github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.42/go.mod h1:y4dbQK/yjYJ2HXqx57/G8FvLckKtN61s/IWNVvP5k9E= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.11 h1:uDZJF1hu0EVT/4bogChk8DyjSF6fof6uL/0Y26Ma7Fg= -github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.11/go.mod h1:TEPP4tENqBGO99KwVpV9MlOX4NSrSLP8u3KRy2CDwA8= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 h1:22dGT7PneFMx4+b3pz7lMTRyN8ZKH7M2cW4GP9yUS2g= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41/go.mod h1:CrObHAuPneJBlfEJ5T3szXOUkLEThaGfvnhTf33buas= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 h1:nFBQlGtkbPzp/NjZLuFxRqmT91rLJkgvsEQs68h962Y= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43/go.mod h1:auo+PiyLl0n1l8A0e8RIeR8tOzYPfZZH/JNlrJ8igTQ= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35 h1:SijA0mgjV8E+8G45ltVHs0fvKpTj8xmZJ3VwhGKtUSI= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35/go.mod h1:SJC1nEVVva1g3pHAIdCp7QsRIkMmLAgoDquQ9Rr8kYw= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 h1:JRVhO25+r3ar2mKGP7E0LDl8K9/G36gjlqca5iQbaqc= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37/go.mod h1:Qe+2KtKml+FEsQF/DHmDV+xjtche/hwoF75EG4UlHW8= -github.com/aws/aws-sdk-go-v2/internal/ini v1.3.43 h1:g+qlObJH4Kn4n21g69DjspU0hKTjWtq7naZ9OLCv0ew= -github.com/aws/aws-sdk-go-v2/internal/ini v1.3.43/go.mod h1:rzfdUlfA+jdgLDmPKjd3Chq9V7LVLYo1Nz++Wb91aRo= github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4= github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.4 h1:6lJvvkQ9HmbHZ4h/IEwclwv2mrTW8Uq1SOB/kXy0mfw= -github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.4/go.mod h1:1PrKYwxTM+zjpw9Y41KFtoJCQrJ34Z47Y4VgVbfndjo= github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.6 h1:wmGLw2i8ZTlHLw7a9ULGfQbuccw8uIiNr6sol5bFzc8= github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.6/go.mod h1:Q0Hq2X/NuL7z8b1Dww8rmOFl+jzusKEcyvkKspwdpyc= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.22.0 h1:kjsywH3KdJnqo6XgHGE8eCoeZ9GsnVIUBILY93YjzKg= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.22.0/go.mod h1:X3ThW5RPV19hi7bnQ0RMAiBjZbzxj4rZlj+qdctbMWY= github.com/aws/aws-sdk-go-v2/service/dynamodb v1.22.2 h1:s7oacej7gZm+Bcq5BxZIlm5HWjEyKiWtOt405QZ+WOA= github.com/aws/aws-sdk-go-v2/service/dynamodb v1.22.2/go.mod h1:1HkLh8vaL4obF95fne7ZOu7sxomS/+vkBt3/+gqqwE4= -github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.15.5 h1:xoalM/e1YsT6jkLKl6KA9HUiJANwn2ypJsM9lhW2WP0= -github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.15.5/go.mod h1:7QtKdGj66zM4g5hPgxHRQgFGLGal4EgwggTw5OZH56c= github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.15.7 h1:WCeS9WZbIqEKCbgIkrHB5jw/9mO2QMYTLPF8wee3v4Y= github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.15.7/go.mod h1:uT1paW42RVCVEoAEbWKu98gEI0GMBWUsT/H+pI4ODJQ= -github.com/aws/aws-sdk-go-v2/service/eventbridge v1.22.0 h1:7jKqbCPZ14W7B5qgZBV3KKWW1X0rriF0gEO64QaY02k= -github.com/aws/aws-sdk-go-v2/service/eventbridge v1.22.0/go.mod h1:NgudPBMWkilaPx7oOPoZ4DXjGn0oa0MuClQRdUthUwg= github.com/aws/aws-sdk-go-v2/service/eventbridge v1.22.2 h1:OyuAwr4t1emvQdH+M6BqZR/0a67SUOm6glJ2ot6NQE4= github.com/aws/aws-sdk-go-v2/service/eventbridge v1.22.2/go.mod h1:z29eBmJY+MYzdT1gbSdcjXgJ5CMVw3wKcclrxcitLqw= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.14 h1:m0QTSI6pZYJTk5WSKx3fm5cNW/DCicVzULBgU/6IyD0= -github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.14/go.mod h1:dDilntgHy9WnHXsh7dDtUPgHKEfTJIBUTHM8OWm0f/0= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15 h1:7R8uRYyXzdD71KWVCL78lJZltah6VVznXBazvKjfH58= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15/go.mod h1:26SQUPcTNgV1Tapwdt4a1rOsYRsnBsJHLMPoxK2b0d8= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.36 h1:eev2yZX7esGRjqRbnVk1UxMLw4CyVZDpZXRCcy75oQk= -github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.36/go.mod h1:lGnOkH9NJATw0XEPcAknFBj3zzNTEGRHtSw+CwC1YTg= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.38 h1:skaFGzv+3kA+v2BPKhuekeb1Hbb105+44r8ASC+q5SE= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.38/go.mod h1:epIZoRSSbRIwLPJU5F+OldHhwZPBdpDeQkRdCeY3+00= -github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.35 h1:UKjpIDLVF90RfV88XurdduMoTxPqtGHZMIDYZQM7RO4= -github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.35/go.mod h1:B3dUg0V6eJesUTi+m27NUkj7n8hdDKYUpxj8f4+TqaQ= github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.37 h1:4LoizcvPT9A0tiAFhepxn0bGZXkzvN0pG0epydY3Pno= github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.37/go.mod h1:7xBUZyP6LeLc+5Ym9PG7atqw4sR28sBtYcHETik+bPE= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35 h1:CdzPW9kKitgIiLV1+MHobfR5Xg25iYnyzWZhyQuSlDI= -github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.35/go.mod h1:QGF2Rs33W5MaN9gYdEQOBBFPLwTZkEhRwI33f7KIG0o= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.4 h1:v0jkRigbSD6uOdwcaUQmgEwG1BkPfAPDqaeNt/29ghg= -github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.4/go.mod h1:LhTyt8J04LL+9cIt7pYJ5lbS/U98ZmXovLOR/4LUsk8= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.6 h1:9ulSU5ClouoPIYhDQdg9tpl83d5Yb91PXTKK+17q+ow= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.6/go.mod h1:lnc2taBsR9nTlz9meD+lhFZZ9EWY712QHrRflWpTcOA= -github.com/aws/aws-sdk-go-v2/service/s3 v1.40.0 h1:wl5dxN1NONhTDQD9uaEvNsDRX29cBmGED/nl0jkWlt4= -github.com/aws/aws-sdk-go-v2/service/s3 v1.40.0/go.mod h1:rDGMZA7f4pbmTtPOk5v5UM2lmX6UAbRnMDJeDvnH7AM= github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2 h1:Ll5/YVCOzRB+gxPqs2uD0R7/MyATC0w85626glSKmp4= github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2/go.mod h1:Zjfqt7KhQK+PO1bbOsFNzKgaq7TcxzmEoDWN8lM0qzQ= -github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.21.3 h1:H6ZipEknzu7RkJW3w2PP75zd8XOdR35AEY5D57YrJtA= -github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.21.3/go.mod h1:5W2cYXDPabUmwULErlC92ffLhtTuyv4ai+5HhdbhfNo= github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.21.5 h1:BvRGAAdEHo+0tpyOlKV14Z49O/iyhqiddIntd0KQ3EA= github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.21.5/go.mod h1:A108ijf0IFtqhYApU+Gia80aPSAUfi9dItm+h5fWGJE= github.com/aws/aws-sdk-go-v2/service/sqs v1.24.5 h1:RyDpTOMEJO6ycxw1vU/6s0KLFaH3M0z/z9gXHSndPTk= github.com/aws/aws-sdk-go-v2/service/sqs v1.24.5/go.mod h1:RZBu4jmYz3Nikzpu/VuVvRnTEJ5a+kf36WT2fcl5Q+Q= -github.com/aws/aws-sdk-go-v2/service/sso v1.15.0 h1:vuGK1vHNP9zx0PfOrtPumbwR2af0ATQ1Z2H6p75AgRQ= -github.com/aws/aws-sdk-go-v2/service/sso v1.15.0/go.mod h1:fIAwKQKBFu90pBxx07BFOMJLpRUGu8VOzLJakeY+0K4= github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k= github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.1 h1:8lKOidPkmSmfUtiTgtdXWgaKItCZ/g75/jEk6Ql6GsA= -github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.1/go.mod h1:yygr8ACQRY2PrEcy3xsUI357stq2AxnFM6DIsR9lij4= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg= -github.com/aws/aws-sdk-go-v2/service/sts v1.23.0 h1:pyvfUqkNLMipdKNAtu7OVbRxUrR2BMaKccIPpk/Hkak= -github.com/aws/aws-sdk-go-v2/service/sts v1.23.0/go.mod h1:VC7JDqsqiwXukYEDjoHh9U0fOJtNWh04FPQz4ct4GGU= github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU= github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ= -github.com/aws/smithy-go v1.14.2 h1:MJU9hqBGbvWZdApzpvoF2WAIJDbtjK2NDJSiJP7HblQ= github.com/aws/smithy-go v1.14.2/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8= github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= @@ -121,8 +77,6 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= -github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/getyoti/yoti-go-sdk/v3 v3.10.0 h1:uAGXQQQCWoMKpjrVHSK8b110EjC+ORJwAI7yvlNHpr0= @@ -214,8 +168,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/ministryofjustice/opg-go-common v0.0.0-20231002150139-ed6f6387fc7e h1:JLWcj/iVBRSHJNDvCP8WwCEX+1EpsmSymQIxI6/BdFc= -github.com/ministryofjustice/opg-go-common v0.0.0-20231002150139-ed6f6387fc7e/go.mod h1:1RmCNi6dkAv8umAgNHp8RkuBoSKLlxp1UtfsGYH7ufc= github.com/ministryofjustice/opg-go-common v0.0.0-20231009133357-1f236d604316 h1:iuo6s75firLntoOAU+SCaRnXUHlLfTIxru8hBlYsECw= github.com/ministryofjustice/opg-go-common v0.0.0-20231009133357-1f236d604316/go.mod h1:1RmCNi6dkAv8umAgNHp8RkuBoSKLlxp1UtfsGYH7ufc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -286,8 +238,6 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= -golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -314,8 +264,8 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -345,8 +295,6 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200323144430-8dcfad9e016e/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -367,8 +315,6 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go. google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= -google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ= google.golang.org/grpc v1.58.3/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= diff --git a/internal/app/donor_store.go b/internal/app/donor_store.go index 156de864fa..e04092f991 100644 --- a/internal/app/donor_store.go +++ b/internal/app/donor_store.go @@ -174,9 +174,9 @@ func (s *donorStore) Put(ctx context.Context, lpa *page.Lpa) error { if lpa.UID != "" && lpa.Tasks.PayForLpa.IsPending() && lpa.HasUnsentReducedFeesEvidence() { var unsentKeys []string - for _, evidence := range lpa.EvidenceKeys { - if evidence.Sent.IsZero() { - unsentKeys = append(unsentKeys, evidence.Key) + for _, document := range lpa.Evidence.Documents { + if document.Sent.IsZero() { + unsentKeys = append(unsentKeys, document.Key) } } @@ -187,9 +187,9 @@ func (s *donorStore) Put(ctx context.Context, lpa *page.Lpa) error { }); err != nil { s.logger.Print(err) } else { - for i, evidence := range lpa.EvidenceKeys { - if evidence.Sent.IsZero() { - lpa.EvidenceKeys[i].Sent = s.now() + for i, document := range lpa.Evidence.Documents { + if document.Sent.IsZero() { + lpa.Evidence.Documents[i].Sent = s.now() } } } diff --git a/internal/app/donor_store_test.go b/internal/app/donor_store_test.go index 22a791984a..637b3793e7 100644 --- a/internal/app/donor_store_test.go +++ b/internal/app/donor_store_test.go @@ -476,7 +476,7 @@ func TestDonorStorePutWhenReducedFeeRequested(t *testing.T) { UID: "M-1111", UpdatedAt: now, FeeType: page.HalfFee, - EvidenceKeys: []page.Evidence{{Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf", Sent: now}}, + Evidence: page.Evidence{Documents: []page.Document{{Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf", Sent: now}}}, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, HasSentApplicationUpdatedEvent: true, }). @@ -499,7 +499,7 @@ func TestDonorStorePutWhenReducedFeeRequested(t *testing.T) { ID: "5", UID: "M-1111", FeeType: page.HalfFee, - EvidenceKeys: []page.Evidence{{Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf"}}, + Evidence: page.Evidence{Documents: []page.Document{{Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf"}}}, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, HasSentApplicationUpdatedEvent: true, }) @@ -519,11 +519,11 @@ func TestDonorStorePutWhenReducedFeeRequestedSentAndUnsentFees(t *testing.T) { UID: "M-1111", UpdatedAt: now, FeeType: page.HalfFee, - EvidenceKeys: []page.Evidence{ + Evidence: page.Evidence{Documents: []page.Document{ {Key: "lpa-uid-evidence-a-uid-1", Filename: "whatever.pdf", Sent: now}, {Key: "lpa-uid-evidence-a-uid-2", Filename: "whenever.pdf", Sent: now}, {Key: "lpa-uid-evidence-a-uid-3", Filename: "whoever.pdf", Sent: now}, - }, + }}, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, HasSentApplicationUpdatedEvent: true, }). @@ -546,11 +546,11 @@ func TestDonorStorePutWhenReducedFeeRequestedSentAndUnsentFees(t *testing.T) { ID: "5", UID: "M-1111", FeeType: page.HalfFee, - EvidenceKeys: []page.Evidence{ + Evidence: page.Evidence{Documents: []page.Document{ {Key: "lpa-uid-evidence-a-uid-1", Filename: "whatever.pdf"}, {Key: "lpa-uid-evidence-a-uid-2", Filename: "whenever.pdf", Sent: now}, {Key: "lpa-uid-evidence-a-uid-3", Filename: "whoever.pdf"}, - }, + }}, Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, HasSentApplicationUpdatedEvent: true, }) @@ -574,7 +574,7 @@ func TestDonorStorePutWhenReducedFeeRequestedWontResend(t *testing.T) { ID: "5", UID: "M-1111", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, - EvidenceKeys: []page.Evidence{{Key: "lpa-uid-evidence-a-uid-1", Filename: "whatever.pdf", Sent: now}}, + Evidence: page.Evidence{Documents: []page.Document{{Key: "lpa-uid-evidence-a-uid-1", Filename: "whatever.pdf", Sent: now}}}, HasSentApplicationUpdatedEvent: true, }) assert.Nil(t, err) @@ -592,7 +592,7 @@ func TestDonorStorePutWhenReducedFeeRequestedWhenError(t *testing.T) { ID: "5", UID: "M-1111", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, - EvidenceKeys: []page.Evidence{{Sent: now}, {}}, + Evidence: page.Evidence{Documents: []page.Document{{Sent: now}, {}}}, UpdatedAt: now, HasSentApplicationUpdatedEvent: true, }). @@ -615,7 +615,7 @@ func TestDonorStorePutWhenReducedFeeRequestedWhenError(t *testing.T) { ID: "5", UID: "M-1111", Tasks: page.Tasks{PayForLpa: actor.PaymentTaskPending}, - EvidenceKeys: []page.Evidence{{Sent: now}, {}}, + Evidence: page.Evidence{Documents: []page.Document{{Sent: now}, {}}}, HasSentApplicationUpdatedEvent: true, }) assert.Nil(t, err) diff --git a/internal/page/data.go b/internal/page/data.go index cbc64446c6..75f0b0547e 100644 --- a/internal/page/data.go +++ b/internal/page/data.go @@ -181,17 +181,64 @@ type Lpa struct { // FeeType is the type of fee the user is applying for FeeType FeeType - // EvidenceKeys is the S3 keys for uploaded evidence with a record of when it's been sent to caseworkers - EvidenceKeys []Evidence + // Evidence is the documents uploaded by a donor to apply for non-full fees + Evidence Evidence HasSentApplicationUpdatedEvent bool HasSentPreviousApplicationLinkedEvent bool } type Evidence struct { - Key string - Filename string - Sent time.Time + Documents []Document +} + +func (es *Evidence) Delete(documentKey string) bool { + idx := slices.IndexFunc(es.Documents, func(d Document) bool { return d.Key == documentKey }) + if idx == -1 { + return false + } + + es.Documents = slices.Delete(es.Documents, idx, idx+1) + + return true +} + +func (es *Evidence) Keys() []string { + var keys []string + + for _, d := range es.Documents { + keys = append(keys, d.Key) + } + + return keys +} + +func (es *Evidence) GetByKey(key string) Document { + for _, d := range es.Documents { + if d.Key == key { + return d + } + } + + return Document{} +} + +func (es *Evidence) Update(document Document) bool { + idx := slices.IndexFunc(es.Documents, func(d Document) bool { return d.Key == document.Key }) + if idx == -1 { + return false + } else { + es.Documents[idx] = document + return true + } +} + +type Document struct { + Key string + Filename string + Sent time.Time + Scanned time.Time + VirusDetected bool } type Payment struct { @@ -504,8 +551,8 @@ func (l *Lpa) FeeAmount() int { } func (l *Lpa) HasUnsentReducedFeesEvidence() bool { - for _, evidence := range l.EvidenceKeys { - if evidence.Sent.IsZero() { + for _, document := range l.Evidence.Documents { + if document.Sent.IsZero() { return true } } diff --git a/internal/page/data_test.go b/internal/page/data_test.go index 5c3c558462..befcddd1f8 100644 --- a/internal/page/data_test.go +++ b/internal/page/data_test.go @@ -1102,17 +1102,14 @@ func TestFeeAmount(t *testing.T) { } func TestHasUnsentReducedFeesEvidence(t *testing.T) { - lpa := Lpa{EvidenceKeys: []Evidence{ - {Sent: time.Now()}, - {}, - {Sent: time.Now()}, - }} + lpa := Lpa{Evidence: Evidence{Documents: []Document{ + {Sent: time.Now()}, {}, {Sent: time.Now()}}}, + } assert.True(t, lpa.HasUnsentReducedFeesEvidence()) - lpa.EvidenceKeys = []Evidence{ - {Sent: time.Now()}, - {Sent: time.Now()}, + lpa.Evidence = Evidence{Documents: []Document{ + {Sent: time.Now()}, {Sent: time.Now()}}, } assert.False(t, lpa.HasUnsentReducedFeesEvidence()) diff --git a/internal/page/donor/upload_evidence.go b/internal/page/donor/upload_evidence.go index 20d3b532c8..70c33b1b94 100644 --- a/internal/page/donor/upload_evidence.go +++ b/internal/page/donor/upload_evidence.go @@ -53,7 +53,7 @@ type uploadEvidenceData struct { Errors validation.List NumberOfAllowedFiles int FeeType page.FeeType - Evidence []page.Evidence + Evidence page.Evidence MimeTypes []string } @@ -63,7 +63,7 @@ func UploadEvidence(tmpl template.Template, payer Payer, donorStore DonorStore, App: appData, NumberOfAllowedFiles: numberOfAllowedFiles, FeeType: lpa.FeeType, - Evidence: lpa.EvidenceKeys, + Evidence: lpa.Evidence, MimeTypes: acceptedMimeTypes(), } @@ -89,14 +89,14 @@ func UploadEvidence(tmpl template.Template, payer Payer, donorStore DonorStore, return err } - lpa.EvidenceKeys = append(lpa.EvidenceKeys, page.Evidence{Key: key, Filename: file.Filename}) + lpa.Evidence.Documents = append(lpa.Evidence.Documents, page.Document{Key: key, Filename: file.Filename}) } if err := donorStore.Put(r.Context(), lpa); err != nil { return err } - data.Evidence = lpa.EvidenceKeys + data.Evidence = lpa.Evidence } else { return payer.Pay(appData, w, r, lpa) } diff --git a/internal/page/donor/upload_evidence_test.go b/internal/page/donor/upload_evidence_test.go index 63d420e221..cd3a665b71 100644 --- a/internal/page/donor/upload_evidence_test.go +++ b/internal/page/donor/upload_evidence_test.go @@ -98,10 +98,11 @@ func TestPostUploadEvidenceWithUploadActionAcceptedFileTypes(t *testing.T) { })). Return(nil, nil) - evidence := []page.Evidence{ + evidence := page.Evidence{Documents: []page.Document{ {Key: "lpa-uid/evidence/a-uid", Filename: filename}, - } - updatedLpa := &page.Lpa{UID: "lpa-uid", EvidenceKeys: evidence, FeeType: page.HalfFee} + }} + + updatedLpa := &page.Lpa{UID: "lpa-uid", Evidence: evidence, FeeType: page.HalfFee} donorStore := newMockDonorStore(t) donorStore. @@ -163,11 +164,11 @@ func TestPostUploadEvidenceWithUploadActionMultipleFiles(t *testing.T) { })). Return(nil, nil) - evidence := []page.Evidence{ + evidence := page.Evidence{Documents: []page.Document{ {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}, {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.png"}, - } - updatedLpa := &page.Lpa{UID: "lpa-uid", EvidenceKeys: evidence, FeeType: page.HalfFee} + }} + updatedLpa := &page.Lpa{UID: "lpa-uid", Evidence: evidence, FeeType: page.HalfFee} donorStore := newMockDonorStore(t) donorStore. @@ -228,10 +229,10 @@ func TestPostUploadEvidenceWithUploadActionFilenameSpecialCharactersAreEscaped(t })). Return(nil, nil) - evidence := []page.Evidence{ + evidence := page.Evidence{Documents: []page.Document{ {Key: "lpa-uid/evidence/a-uid", Filename: "<img src=1 onerror=alert(document.domain)>’ brute.heic"}, - } - updatedLpa := &page.Lpa{UID: "lpa-uid", EvidenceKeys: evidence, FeeType: page.HalfFee} + }} + updatedLpa := &page.Lpa{UID: "lpa-uid", Evidence: evidence, FeeType: page.HalfFee} donorStore := newMockDonorStore(t) donorStore. @@ -517,8 +518,8 @@ func TestPostUploadEvidenceWhenDonorStoreError(t *testing.T) { })). Return(nil, nil) - updatedLpa := &page.Lpa{UID: "lpa-uid", EvidenceKeys: []page.Evidence{ - {Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}, + updatedLpa := &page.Lpa{UID: "lpa-uid", Evidence: page.Evidence{ + Documents: []page.Document{{Key: "lpa-uid/evidence/a-uid", Filename: "dummy.pdf"}}, }} donorStore := newMockDonorStore(t) diff --git a/web/template/upload_evidence.gohtml b/web/template/upload_evidence.gohtml index b96152d644..2a2e4075bd 100644 --- a/web/template/upload_evidence.gohtml +++ b/web/template/upload_evidence.gohtml @@ -3,7 +3,7 @@ {{ define "pageTitle" }}{{ tr .App "uploadYourEvidence" }}{{ end }} {{ define "main" }} - {{ $evidenceCount := (len .Evidence) }} + {{ $evidenceCount := (len .Evidence.Documents) }} {{ if gt $evidenceCount 0 }}