Skip to content

Commit

Permalink
Move witness code and share code senders (#1416)
Browse files Browse the repository at this point in the history
* Move share code sender to sharecode package

* Rename sharecode.ShareCodeSender -> Sender

* Move WitnessCodeSender from page to donor package

* Rename sharecodedata Data to Link
  • Loading branch information
hawx authored Aug 9, 2024
1 parent d9cf8d7 commit d5ea280
Show file tree
Hide file tree
Showing 64 changed files with 2,325 additions and 477 deletions.
5 changes: 2 additions & 3 deletions cmd/event-received/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/random"
"github.com/ministryofjustice/opg-modernising-lpa/internal/search"
"github.com/ministryofjustice/opg-modernising-lpa/internal/secrets"
Expand All @@ -40,7 +39,7 @@ type SecretsClient interface {
}

type ShareCodeSender interface {
SendCertificateProviderInvite(context.Context, appcontext.Data, page.CertificateProviderInvite) error
SendCertificateProviderInvite(context.Context, appcontext.Data, sharecode.CertificateProviderInvite) error
SendCertificateProviderPrompt(context.Context, appcontext.Data, *donordata.Provided) error
SendAttorneys(context.Context, appcontext.Data, *lpadata.Lpa) error
}
Expand Down Expand Up @@ -163,7 +162,7 @@ func (f *Factory) ShareCodeSender(ctx context.Context) (ShareCodeSender, error)
return nil, err
}

f.shareCodeSender = page.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
Expand Down
14 changes: 7 additions & 7 deletions cmd/event-received/mock_shareCodeSender_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cmd/event-received/sirius_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"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/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/pay"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode"
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
)

Expand Down Expand Up @@ -228,7 +228,7 @@ func handleDonorSubmissionCompleted(ctx context.Context, client dynamodbClient,
}

if lpa.CertificateProvider.Channel.IsOnline() {
if err := shareCodeSender.SendCertificateProviderInvite(ctx, appData, page.CertificateProviderInvite{
if err := shareCodeSender.SendCertificateProviderInvite(ctx, appData, sharecode.CertificateProviderInvite{
LpaKey: lpa.LpaKey,
LpaOwnerKey: lpa.LpaOwnerKey,
LpaUID: lpa.LpaUID,
Expand Down
6 changes: 3 additions & 3 deletions cmd/event-received/sirius_event_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid"
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"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/lpastore/lpadata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/pay"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode"
"github.com/ministryofjustice/opg-modernising-lpa/internal/task"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -754,7 +754,7 @@ func TestHandleDonorSubmissionCompleted(t *testing.T) {

shareCodeSender := newMockShareCodeSender(t)
shareCodeSender.EXPECT().
SendCertificateProviderInvite(ctx, appData, page.CertificateProviderInvite{
SendCertificateProviderInvite(ctx, appData, sharecode.CertificateProviderInvite{
DonorFirstNames: "Dave",
DonorFullName: "Dave Smith",
CertificateProviderUID: uid,
Expand Down
4 changes: 2 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func App(
memberStore := supporter.NewMemberStore(lpaDynamoClient)
progressTracker := task.ProgressTracker{Localizer: localizer}

shareCodeSender := page.NewShareCodeSender(shareCodeStore, notifyClient, appPublicURL, random.String, eventClient)
witnessCodeSender := page.NewWitnessCodeSender(donorStore, notifyClient)
shareCodeSender := sharecode.NewSender(shareCodeStore, notifyClient, appPublicURL, random.String, eventClient)
witnessCodeSender := donor.NewWitnessCodeSender(donorStore, notifyClient, localizer)

lpaStoreResolvingService := lpastore.NewResolvingService(donorStore, lpaStoreClient)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode/sharecodedata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
Expand Down Expand Up @@ -173,7 +173,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) {
LpaData(r).
Return(&sesh.LpaDataSession{LpaID: "lpa-id"}, nil)

shareCodeData := sharecode.Data{
shareCodeData := sharecodedata.Link{
LpaKey: dynamo.LpaKey("lpa-id"),
LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")),
ActorUID: tc.uid,
Expand Down Expand Up @@ -235,7 +235,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOutWhenAttorneyNotFound(t *testing
LpaData(r).
Return(&sesh.LpaDataSession{LpaID: "lpa-id"}, nil)

shareCodeData := sharecode.Data{
shareCodeData := sharecodedata.Link{
LpaKey: dynamo.LpaKey("lpa-id"),
LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")),
ActorUID: actoruid.New(),
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOutErrors(t *testing.T) {
r, _ := http.NewRequest(http.MethodPost, "/?referenceNumber=123", nil)
ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"})

shareCodeData := sharecode.Data{
shareCodeData := sharecodedata.Link{
LpaKey: dynamo.LpaKey("lpa-id"),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode/sharecodedata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestPostEnterReferenceNumberOptOut(t *testing.T) {
shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Return(sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("session-id")), ActorUID: uid}, nil)
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("session-id")), ActorUID: uid}, nil)

sessionStore := newMockSessionStore(t)
sessionStore.EXPECT().
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestPostEnterReferenceNumberOptOutErrors(t *testing.T) {
shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(mock.Anything, mock.Anything, mock.Anything).
Return(sharecode.Data{}, expectedError)
Return(sharecodedata.Link{}, expectedError)

return shareCodeStore
},
Expand All @@ -119,7 +119,7 @@ func TestPostEnterReferenceNumberOptOutErrors(t *testing.T) {
shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(mock.Anything, mock.Anything, mock.Anything).
Return(sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id")}, nil)
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id")}, nil)

return shareCodeStore
},
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestPostEnterReferenceNumberOptOutOnShareCodeStoreNotFoundError(t *testing.
shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Return(sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("session-id"))}, dynamo.NotFoundError{})
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("session-id"))}, dynamo.NotFoundError{})

err := EnterReferenceNumberOptOut(template.Execute, shareCodeStore, nil)(testAppData, w, r)

Expand Down
22 changes: 11 additions & 11 deletions internal/attorney/attorneypage/enter_reference_number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode/sharecodedata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -73,27 +73,27 @@ func TestGetEnterReferenceNumberOnTemplateError(t *testing.T) {

func TestPostEnterReferenceNumber(t *testing.T) {
testcases := map[string]struct {
shareCode sharecode.Data
shareCode sharecodedata.Link
session *sesh.LoginSession
isReplacement bool
isTrustCorporation bool
}{
"attorney": {
shareCode: sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("")), ActorUID: testUID},
shareCode: sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("")), ActorUID: testUID},
session: &sesh.LoginSession{Sub: "hey", Email: "[email protected]"},
},
"replacement": {
shareCode: sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("")), ActorUID: testUID, IsReplacementAttorney: true},
shareCode: sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("")), ActorUID: testUID, IsReplacementAttorney: true},
session: &sesh.LoginSession{Sub: "hey", Email: "[email protected]"},
isReplacement: true,
},
"trust corporation": {
shareCode: sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("")), ActorUID: testUID, IsTrustCorporation: true},
shareCode: sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("")), ActorUID: testUID, IsTrustCorporation: true},
session: &sesh.LoginSession{Sub: "hey", Email: "[email protected]"},
isTrustCorporation: true,
},
"replacement trust corporation": {
shareCode: sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("")), ActorUID: testUID, IsReplacementAttorney: true, IsTrustCorporation: true},
shareCode: sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("")), ActorUID: testUID, IsReplacementAttorney: true, IsTrustCorporation: true},
session: &sesh.LoginSession{Sub: "hey", Email: "[email protected]"},
isReplacement: true,
isTrustCorporation: true,
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestPostEnterReferenceNumber(t *testing.T) {
}

func TestPostEnterReferenceNumberWhenConditionalCheckFailed(t *testing.T) {
shareCode := sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("")), ActorUID: testUID}
shareCode := sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("")), ActorUID: testUID}

form := url.Values{
"reference-number": {"abcdef123456"},
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestPostEnterReferenceNumberOnDonorStoreError(t *testing.T) {
shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Return(sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey(""))}, expectedError)
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey(""))}, expectedError)

err := EnterReferenceNumber(nil, shareCodeStore, nil, nil)(testAppData, w, r)

Expand Down Expand Up @@ -220,7 +220,7 @@ func TestPostEnterReferenceNumberOnShareCodeStoreNotFoundError(t *testing.T) {
shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Return(sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey(""))}, dynamo.NotFoundError{})
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey(""))}, dynamo.NotFoundError{})

err := EnterReferenceNumber(template.Execute, shareCodeStore, nil, nil)(testAppData, w, r)

Expand All @@ -242,7 +242,7 @@ func TestPostEnterReferenceNumberOnSessionGetError(t *testing.T) {
shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Return(sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey(""))}, nil)
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey(""))}, nil)

sessionStore := newMockSessionStore(t)
sessionStore.EXPECT().
Expand All @@ -266,7 +266,7 @@ func TestPostEnterReferenceNumberOnAttorneyStoreError(t *testing.T) {
shareCodeStore := newMockShareCodeStore(t)
shareCodeStore.EXPECT().
Get(r.Context(), actor.TypeAttorney, "abcdef123456").
Return(sharecode.Data{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey(""))}, nil)
Return(sharecodedata.Link{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey(""))}, nil)

attorneyStore := newMockAttorneyStore(t)
attorneyStore.EXPECT().
Expand Down
Loading

0 comments on commit d5ea280

Please sign in to comment.