Skip to content

Commit

Permalink
Merge 9930017 into c286654
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Nov 7, 2023
2 parents c286654 + 9930017 commit 5905ae7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
29 changes: 16 additions & 13 deletions internal/app/donor_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"context"
"errors"
"log"
"time"

"github.com/aws/aws-sdk-go-v2/service/s3"
Expand Down Expand Up @@ -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)
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/app/donor_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5905ae7

Please sign in to comment.