diff --git a/cmd/event-received/factory.go b/cmd/event-received/factory.go index 37c8dc4611..0384abbf07 100644 --- a/cmd/event-received/factory.go +++ b/cmd/event-received/factory.go @@ -162,7 +162,7 @@ func (f *Factory) ShareCodeSender(ctx context.Context) (ShareCodeSender, error) return nil, err } - f.shareCodeSender = sharecode.NewShareCodeSender(sharecode.NewStore(f.dynamoClient), notifyClient, f.appPublicURL, random.String, event.NewClient(f.cfg, f.eventBusName)) + f.shareCodeSender = sharecode.NewSender(sharecode.NewStore(f.dynamoClient), notifyClient, f.appPublicURL, random.String, event.NewClient(f.cfg, f.eventBusName)) } return f.shareCodeSender, nil diff --git a/internal/app/app.go b/internal/app/app.go index 64b1a8188d..37abbee584 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -106,7 +106,7 @@ func App( memberStore := supporter.NewMemberStore(lpaDynamoClient) progressTracker := task.ProgressTracker{Localizer: localizer} - shareCodeSender := sharecode.NewShareCodeSender(shareCodeStore, notifyClient, appPublicURL, random.String, eventClient) + shareCodeSender := sharecode.NewSender(shareCodeStore, notifyClient, appPublicURL, random.String, eventClient) witnessCodeSender := page.NewWitnessCodeSender(donorStore, notifyClient) lpaStoreResolvingService := lpastore.NewResolvingService(donorStore, lpaStoreClient) diff --git a/internal/sharecode/sender.go b/internal/sharecode/sender.go index 6990dcc4ad..88ecd30006 100644 --- a/internal/sharecode/sender.go +++ b/internal/sharecode/sender.go @@ -48,7 +48,7 @@ type EventClient interface { SendPaperFormRequested(ctx context.Context, paperFormRequestedEvent event.PaperFormRequested) error } -type ShareCodeSender struct { +type Sender struct { testCode string shareCodeStore ShareCodeStore notifyClient NotifyClient @@ -57,8 +57,8 @@ type ShareCodeSender struct { eventClient EventClient } -func NewShareCodeSender(shareCodeStore ShareCodeStore, notifyClient NotifyClient, appPublicURL string, randomString func(int) string, eventClient EventClient) *ShareCodeSender { - return &ShareCodeSender{ +func NewSender(shareCodeStore ShareCodeStore, notifyClient NotifyClient, appPublicURL string, randomString func(int) string, eventClient EventClient) *Sender { + return &Sender{ shareCodeStore: shareCodeStore, notifyClient: notifyClient, appPublicURL: appPublicURL, @@ -67,7 +67,7 @@ func NewShareCodeSender(shareCodeStore ShareCodeStore, notifyClient NotifyClient } } -func (s *ShareCodeSender) UseTestCode(shareCode string) { +func (s *Sender) UseTestCode(shareCode string) { s.testCode = shareCode } @@ -83,7 +83,7 @@ type CertificateProviderInvite struct { CertificateProviderEmail string } -func (s *ShareCodeSender) SendCertificateProviderInvite(ctx context.Context, appData appcontext.Data, invite CertificateProviderInvite) error { +func (s *Sender) SendCertificateProviderInvite(ctx context.Context, appData appcontext.Data, invite CertificateProviderInvite) error { shareCode, err := s.createShareCode(ctx, invite.LpaKey, invite.LpaOwnerKey, invite.CertificateProviderUID, actor.TypeCertificateProvider) if err != nil { return err @@ -102,7 +102,7 @@ func (s *ShareCodeSender) SendCertificateProviderInvite(ctx context.Context, app }) } -func (s *ShareCodeSender) SendCertificateProviderPrompt(ctx context.Context, appData appcontext.Data, donor *donordata.Provided) error { +func (s *Sender) SendCertificateProviderPrompt(ctx context.Context, appData appcontext.Data, donor *donordata.Provided) error { shareCode, err := s.createShareCode(ctx, donor.PK, donor.SK, donor.CertificateProvider.UID, actor.TypeCertificateProvider) if err != nil { return err @@ -121,7 +121,7 @@ func (s *ShareCodeSender) SendCertificateProviderPrompt(ctx context.Context, app }) } -func (s *ShareCodeSender) SendAttorneys(ctx context.Context, appData appcontext.Data, donor *lpadata.Lpa) error { +func (s *Sender) SendAttorneys(ctx context.Context, appData appcontext.Data, donor *lpadata.Lpa) error { if err := s.sendTrustCorporation(ctx, appData, donor, donor.Attorneys.TrustCorporation); err != nil { return err } @@ -144,7 +144,7 @@ func (s *ShareCodeSender) SendAttorneys(ctx context.Context, appData appcontext. return nil } -func (s *ShareCodeSender) sendOriginalAttorney(ctx context.Context, appData appcontext.Data, lpa *lpadata.Lpa, attorney lpadata.Attorney) error { +func (s *Sender) sendOriginalAttorney(ctx context.Context, appData appcontext.Data, lpa *lpadata.Lpa, attorney lpadata.Attorney) error { shareCode, err := s.createShareCode(ctx, lpa.LpaKey, lpa.LpaOwnerKey, attorney.UID, actor.TypeAttorney) if err != nil { return err @@ -167,7 +167,7 @@ func (s *ShareCodeSender) sendOriginalAttorney(ctx context.Context, appData appc }) } -func (s *ShareCodeSender) sendReplacementAttorney(ctx context.Context, appData appcontext.Data, lpa *lpadata.Lpa, attorney lpadata.Attorney) error { +func (s *Sender) sendReplacementAttorney(ctx context.Context, appData appcontext.Data, lpa *lpadata.Lpa, attorney lpadata.Attorney) error { shareCode, err := s.createShareCode(ctx, lpa.LpaKey, lpa.LpaOwnerKey, attorney.UID, actor.TypeReplacementAttorney) if err != nil { return err @@ -190,7 +190,7 @@ func (s *ShareCodeSender) sendReplacementAttorney(ctx context.Context, appData a }) } -func (s *ShareCodeSender) sendTrustCorporation(ctx context.Context, appData appcontext.Data, lpa *lpadata.Lpa, trustCorporation lpadata.TrustCorporation) error { +func (s *Sender) sendTrustCorporation(ctx context.Context, appData appcontext.Data, lpa *lpadata.Lpa, trustCorporation lpadata.TrustCorporation) error { if trustCorporation.Name == "" { return nil } @@ -217,7 +217,7 @@ func (s *ShareCodeSender) sendTrustCorporation(ctx context.Context, appData appc }) } -func (s *ShareCodeSender) sendReplacementTrustCorporation(ctx context.Context, appData appcontext.Data, lpa *lpadata.Lpa, trustCorporation lpadata.TrustCorporation) error { +func (s *Sender) sendReplacementTrustCorporation(ctx context.Context, appData appcontext.Data, lpa *lpadata.Lpa, trustCorporation lpadata.TrustCorporation) error { if trustCorporation.Name == "" { return nil } @@ -244,7 +244,7 @@ func (s *ShareCodeSender) sendReplacementTrustCorporation(ctx context.Context, a }) } -func (s *ShareCodeSender) createShareCode(ctx context.Context, lpaKey dynamo.LpaKeyType, lpaOwnerKey dynamo.LpaOwnerKeyType, actorUID actoruid.UID, actorType actor.Type) (string, error) { +func (s *Sender) createShareCode(ctx context.Context, lpaKey dynamo.LpaKeyType, lpaOwnerKey dynamo.LpaOwnerKeyType, actorUID actoruid.UID, actorType actor.Type) (string, error) { shareCode := s.randomString(12) if s.testCode != "" { shareCode = s.testCode @@ -266,7 +266,7 @@ func (s *ShareCodeSender) createShareCode(ctx context.Context, lpaKey dynamo.Lpa return shareCode, nil } -func (s *ShareCodeSender) sendEmail(ctx context.Context, to string, lpaUID string, email notify.Email) error { +func (s *Sender) sendEmail(ctx context.Context, to string, lpaUID string, email notify.Email) error { if err := s.notifyClient.SendActorEmail(ctx, to, lpaUID, email); err != nil { return fmt.Errorf("email failed: %w", err) } @@ -274,7 +274,7 @@ func (s *ShareCodeSender) sendEmail(ctx context.Context, to string, lpaUID strin return nil } -func (s *ShareCodeSender) sendPaperForm(ctx context.Context, lpaUID string, actorType actor.Type, actorUID actoruid.UID, shareCode string) error { +func (s *Sender) sendPaperForm(ctx context.Context, lpaUID string, actorType actor.Type, actorUID actoruid.UID, shareCode string) error { return s.eventClient.SendPaperFormRequested(ctx, event.PaperFormRequested{ UID: lpaUID, ActorType: actorType.String(), diff --git a/internal/sharecode/sender_test.go b/internal/sharecode/sender_test.go index a9eb938fa2..432ecb207c 100644 --- a/internal/sharecode/sender_test.go +++ b/internal/sharecode/sender_test.go @@ -86,7 +86,7 @@ func TestShareCodeSenderSendCertificateProviderInvite(t *testing.T) { }). Return(nil) - sender := NewShareCodeSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) err := sender.SendCertificateProviderInvite(ctx, TestAppData, CertificateProviderInvite{ LpaKey: dynamo.LpaKey("lpa"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")), @@ -194,7 +194,7 @@ func TestShareCodeSenderSendCertificateProviderInviteWithTestCode(t *testing.T) Once(). Return(nil) - sender := NewShareCodeSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) if tc.useTestCode { sender.UseTestCode("abcdef123456") @@ -264,7 +264,7 @@ func TestShareCodeSenderSendCertificateProviderInviteWhenEmailErrors(t *testing. SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewShareCodeSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) err := sender.SendCertificateProviderInvite(ctx, TestAppData, CertificateProviderInvite{ LpaUID: donor.LpaUID, Type: donor.Type, @@ -286,7 +286,7 @@ func TestShareCodeSenderSendCertificateProviderInviteWhenShareCodeStoreErrors(t Put(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewShareCodeSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) err := sender.SendCertificateProviderInvite(ctx, TestAppData, CertificateProviderInvite{}) assert.Equal(t, expectedError, errors.Unwrap(err)) @@ -338,7 +338,7 @@ func TestShareCodeSenderSendCertificateProviderPromptOnline(t *testing.T) { }). Return(nil) - sender := NewShareCodeSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, donor) assert.Nil(t, err) @@ -386,7 +386,7 @@ func TestShareCodeSenderSendCertificateProviderPromptPaper(t *testing.T) { }). Return(nil) - sender := NewShareCodeSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, donor) assert.Nil(t, err) @@ -474,7 +474,7 @@ func TestShareCodeSenderSendCertificateProviderPromptWithTestCode(t *testing.T) Once(). Return(nil) - sender := NewShareCodeSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) if tc.useTestCode { sender.UseTestCode("abcdef123456") @@ -503,7 +503,7 @@ func TestShareCodeSenderSendCertificateProviderPromptPaperWhenShareCodeStoreErro Put(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewShareCodeSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, donor) assert.ErrorIs(t, err, expectedError) @@ -528,7 +528,7 @@ func TestShareCodeSenderSendCertificateProviderPromptPaperWhenEventClientError(t SendPaperFormRequested(mock.Anything, mock.Anything). Return(expectedError) - sender := NewShareCodeSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, donor) assert.Equal(t, expectedError, err) @@ -567,7 +567,7 @@ func TestShareCodeSenderSendCertificateProviderPromptWhenEmailErrors(t *testing. SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewShareCodeSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, donor) assert.Equal(t, expectedError, errors.Unwrap(err)) @@ -581,7 +581,7 @@ func TestShareCodeSenderSendCertificateProviderPromptWhenShareCodeStoreErrors(t Put(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewShareCodeSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, &donordata.Provided{}) assert.Equal(t, expectedError, errors.Unwrap(err)) @@ -768,7 +768,7 @@ func TestShareCodeSenderSendAttorneys(t *testing.T) { }). Return(nil) - sender := NewShareCodeSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, eventClient) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, eventClient) err := sender.SendAttorneys(ctx, TestAppData, donor) assert.Nil(t, err) @@ -839,7 +839,7 @@ func TestShareCodeSenderSendAttorneysTrustCorporationsNoEmail(t *testing.T) { }). Return(nil) - sender := NewShareCodeSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, eventClient) err := sender.SendAttorneys(ctx, TestAppData, donor) assert.Nil(t, err) @@ -926,7 +926,7 @@ func TestShareCodeSenderSendAttorneysWithTestCode(t *testing.T) { }). Return(nil) - sender := NewShareCodeSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) if tc.useTestCode { sender.UseTestCode("abcdef123456") @@ -978,7 +978,7 @@ func TestShareCodeSenderSendAttorneysWhenEmailErrors(t *testing.T) { SendActorEmail(ctx, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewShareCodeSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, notifyClient, "http://app", testRandomStringFn, nil) err := sender.SendAttorneys(ctx, TestAppData, donor) assert.Equal(t, expectedError, errors.Unwrap(err)) @@ -992,7 +992,7 @@ func TestShareCodeSenderSendAttorneysWhenShareCodeStoreErrors(t *testing.T) { Put(mock.Anything, mock.Anything, mock.Anything, mock.Anything). Return(expectedError) - sender := NewShareCodeSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) + sender := NewSender(shareCodeStore, nil, "http://app", testRandomStringFn, nil) err := sender.SendAttorneys(ctx, TestAppData, &lpadata.Lpa{ Attorneys: lpadata.Attorneys{Attorneys: []lpadata.Attorney{{Email: "hey@example.com"}}}, })