diff --git a/internal/app/donor_store.go b/internal/app/donor_store.go index d0ae7a7a85..2f904b5ff8 100644 --- a/internal/app/donor_store.go +++ b/internal/app/donor_store.go @@ -3,6 +3,7 @@ package app import ( "context" "errors" + "log" "time" "github.com/aws/aws-sdk-go-v2/service/s3" @@ -189,40 +190,42 @@ func (s *donorStore) Put(ctx context.Context, lpa *page.Lpa) error { } if lpa.UID != "" && lpa.Tasks.PayForLpa.IsPending() { + log.Println("reduced-fee-requested event start") + documents, err := s.documentStore.GetAll(ctx) if err != nil { s.logger.Print(err) return s.dynamoClient.Put(ctx, lpa) } - var unsentKeys []string + var unsentDocuments page.Documents for _, document := range documents { - if document.Sent.IsZero() && !document.Scanned { - unsentKeys = append(unsentKeys, document.Key) + if document.Sent.IsZero() && document.Scanned && !document.VirusDetected { + unsentDocuments = append(unsentDocuments, document) } } - if len(unsentKeys) > 0 { + log.Println("reduced-fee-requested unsentDocuments: ", len(unsentDocuments)) + + if len(unsentDocuments) > 0 { + log.Println("reduced-fee-requested sending event") + if err := s.eventClient.SendReducedFeeRequested(ctx, event.ReducedFeeRequested{ UID: lpa.UID, RequestType: lpa.FeeType.String(), - Evidence: unsentKeys, + Evidence: unsentDocuments.Keys(), EvidenceDelivery: lpa.EvidenceDelivery.String(), }); err != nil { return err } + log.Println("reduced-fee-requested sent event") - var updatedDocuments page.Documents - - for _, document := range documents { - if document.Sent.IsZero() && !document.Scanned { - document.Sent = s.now() - updatedDocuments = append(updatedDocuments, document) - } + for i := range unsentDocuments { + unsentDocuments[i].Sent = s.now() } - if err := s.documentStore.BatchPut(ctx, updatedDocuments); err != nil { + if err := s.documentStore.BatchPut(ctx, unsentDocuments); err != nil { s.logger.Print(err) } } diff --git a/internal/app/donor_store_test.go b/internal/app/donor_store_test.go index c53fd88f69..0d92eac619 100644 --- a/internal/app/donor_store_test.go +++ b/internal/app/donor_store_test.go @@ -483,10 +483,10 @@ func TestDonorStorePutWhenReducedFeeRequestedAndUnsentDocuments(t *testing.T) { documentStore. On("GetAll", ctx). Return(page.Documents{ - {Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf"}, + {Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf", Scanned: true}, }, nil) documentStore. - On("BatchPut", ctx, []page.Document{{Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf", Sent: now}}). + On("BatchPut", ctx, []page.Document{{Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf", Scanned: true, Sent: now}}). Return(nil) donorStore := &donorStore{dynamoClient: dynamoClient, eventClient: eventClient, now: func() time.Time { return now }, documentStore: documentStore} @@ -585,7 +585,7 @@ func TestDonorStorePutWhenReducedFeeRequestedAndUnsentDocumentsWhenEventClientSe documentStore. On("GetAll", ctx). Return(page.Documents{ - {Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf"}, + {Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf", Scanned: true}, }, nil) donorStore := &donorStore{eventClient: eventClient, now: func() time.Time { return now }, documentStore: documentStore} @@ -622,10 +622,10 @@ func TestDonorStorePutWhenReducedFeeRequestedAndUnsentDocumentsWhenDocumentStore documentStore. On("GetAll", ctx). Return(page.Documents{ - {Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf"}, + {Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf", Scanned: true}, }, nil) documentStore. - On("BatchPut", ctx, []page.Document{{Key: "lpa-uid-evidence-a-uid", Filename: "whatever.pdf", Sent: now}}). + On("BatchPut", ctx, mock.Anything). Return(expectedError) logger := newMockLogger(t)