From a4ad5ee3894abbd2eaa78a6ae295cb600f94267e Mon Sep 17 00:00:00 2001 From: Joshua Hawxwell Date: Thu, 1 Aug 2024 11:05:47 +0100 Subject: [PATCH] Move donor store to new package and use appcontext everywhere (#1388) --- .mockery.yaml | 3 +- .../mock_lpaStoreClient_test.go | 15 +- .../mock_shareCodeSender_test.go | 15 +- internal/app/app.go | 14 +- internal/app/app_test.go | 80 +- internal/app/dashboard_store.go | 3 +- internal/app/dashboard_store_test.go | 15 +- internal/app/document_store.go | 10 +- internal/app/document_store_test.go | 29 +- internal/app/evidence_received_store.go | 4 +- internal/app/evidence_received_store_test.go | 9 +- internal/app/member_store.go | 22 +- internal/app/member_store_test.go | 65 +- .../app/mock_LpaStoreResolvingService_test.go | 19 +- internal/app/organisation_store.go | 8 +- internal/app/organisation_store_test.go | 25 +- internal/app/share_code_store.go | 4 +- internal/app/share_code_store_test.go | 3 +- ...irm_dont_want_to_be_attorney_logged_out.go | 3 +- ...ont_want_to_be_attorney_logged_out_test.go | 9 +- .../confirm_dont_want_to_be_attorney_test.go | 5 +- .../attorneypage/enter_reference_number.go | 3 +- .../enter_reference_number_test.go | 5 +- internal/attorney/attorneypage/register.go | 7 +- .../attorney/attorneypage/register_test.go | 19 +- ...t_to_be_certificate_provider_logged_out.go | 3 +- ...be_certificate_provider_logged_out_test.go | 7 +- ...nt_want_to_be_certificate_provider_test.go | 3 +- .../enter_reference_number.go | 3 +- .../enter_reference_number_test.go | 5 +- .../mock_DonorStore_test.go | 29 +- .../certificateproviderpage/register.go | 5 +- .../certificateproviderpage/register_test.go | 13 +- .../donor/donordata/mock_DynamoClient_test.go | 877 ++++++++++++++++++ .../donor/donordata/mock_EventClient_test.go | 225 +++++ internal/donor/donordata/mock_Logger_test.go | 171 ++++ .../donor/donordata/mock_SearchClient_test.go | 84 ++ .../donor/donordata/mock_UidClient_test.go | 94 ++ internal/donor/donordata/mock_test.go | 100 ++ .../donordata/store.go} | 114 ++- .../donordata/store_test.go} | 286 ++---- internal/donor/donorpage/lpa_type.go | 3 +- internal/donor/donorpage/lpa_type_test.go | 11 +- .../donorpage/mock_DocumentStore_test.go | 31 +- .../donor/donorpage/mock_DonorStore_test.go | 43 +- .../donorpage/mock_GetDonorStore_test.go | 17 +- internal/donor/donorpage/mock_Handler_test.go | 14 +- .../donorpage/mock_LpaStoreClient_test.go | 27 +- .../donorpage/mock_ShareCodeSender_test.go | 15 +- .../donorpage/mock_WitnessCodeSender_test.go | 27 +- internal/donor/donorpage/register.go | 7 +- internal/donor/donorpage/register_test.go | 15 +- internal/lpastore/mock_DonorStore_test.go | 17 +- internal/page/data.go | 3 - internal/page/fixtures/attorney.go | 15 +- .../page/fixtures/certificate_provider.go | 11 +- internal/page/fixtures/dashboard.go | 17 +- internal/page/fixtures/donor.go | 19 +- internal/page/fixtures/supporter.go | 13 +- internal/page/mock_DonorStore_test.go | 29 +- internal/page/supporter/login_callback.go | 3 +- .../page/supporter/login_callback_test.go | 13 +- .../page/supporter/mock_DonorStore_test.go | 43 +- .../supporter/mock_OrganisationStore_test.go | 16 +- internal/page/supporter/register.go | 9 +- internal/page/supporter/register_test.go | 47 +- internal/search/client.go | 4 +- internal/search/client_test.go | 36 +- internal/telemetry/telemetry.go | 4 +- 69 files changed, 2266 insertions(+), 656 deletions(-) create mode 100644 internal/donor/donordata/mock_DynamoClient_test.go create mode 100644 internal/donor/donordata/mock_EventClient_test.go create mode 100644 internal/donor/donordata/mock_Logger_test.go create mode 100644 internal/donor/donordata/mock_SearchClient_test.go create mode 100644 internal/donor/donordata/mock_UidClient_test.go create mode 100644 internal/donor/donordata/mock_test.go rename internal/{app/donor_store.go => donor/donordata/store.go} (69%) rename internal/{app/donor_store_test.go => donor/donordata/store_test.go} (62%) diff --git a/.mockery.yaml b/.mockery.yaml index a5b1d5e30d..21c3b78575 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -12,13 +12,14 @@ packages: github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneypage: github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata: github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderpage: + github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata: + github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donorpage: github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo: github.com/ministryofjustice/opg-modernising-lpa/internal/event: github.com/ministryofjustice/opg-modernising-lpa/internal/lambda: github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore: github.com/ministryofjustice/opg-modernising-lpa/internal/notify: github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin: - github.com/ministryofjustice/opg-modernising-lpa/internal/page/donor: github.com/ministryofjustice/opg-modernising-lpa/internal/page/supporter: github.com/ministryofjustice/opg-modernising-lpa/internal/page: github.com/ministryofjustice/opg-modernising-lpa/internal/pay: diff --git a/cmd/event-received/mock_lpaStoreClient_test.go b/cmd/event-received/mock_lpaStoreClient_test.go index 0ed30d83d0..d914407d56 100644 --- a/cmd/event-received/mock_lpaStoreClient_test.go +++ b/cmd/event-received/mock_lpaStoreClient_test.go @@ -5,8 +5,7 @@ package main import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" lpastore "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" mock "github.com/stretchr/testify/mock" @@ -85,7 +84,7 @@ func (_c *mockLpaStoreClient_Lpa_Call) RunAndReturn(run func(context.Context, st } // SendLpa provides a mock function with given fields: ctx, donor -func (_m *mockLpaStoreClient) SendLpa(ctx context.Context, donor *actor.DonorProvidedDetails) error { +func (_m *mockLpaStoreClient) SendLpa(ctx context.Context, donor *donordata.DonorProvidedDetails) error { ret := _m.Called(ctx, donor) if len(ret) == 0 { @@ -93,7 +92,7 @@ func (_m *mockLpaStoreClient) SendLpa(ctx context.Context, donor *actor.DonorPro } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *actor.DonorProvidedDetails) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.DonorProvidedDetails) error); ok { r0 = rf(ctx, donor) } else { r0 = ret.Error(0) @@ -109,14 +108,14 @@ type mockLpaStoreClient_SendLpa_Call struct { // SendLpa is a helper method to define mock.On call // - ctx context.Context -// - donor *actor.DonorProvidedDetails +// - donor *donordata.DonorProvidedDetails func (_e *mockLpaStoreClient_Expecter) SendLpa(ctx interface{}, donor interface{}) *mockLpaStoreClient_SendLpa_Call { return &mockLpaStoreClient_SendLpa_Call{Call: _e.mock.On("SendLpa", ctx, donor)} } -func (_c *mockLpaStoreClient_SendLpa_Call) Run(run func(ctx context.Context, donor *actor.DonorProvidedDetails)) *mockLpaStoreClient_SendLpa_Call { +func (_c *mockLpaStoreClient_SendLpa_Call) Run(run func(ctx context.Context, donor *donordata.DonorProvidedDetails)) *mockLpaStoreClient_SendLpa_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*actor.DonorProvidedDetails)) + run(args[0].(context.Context), args[1].(*donordata.DonorProvidedDetails)) }) return _c } @@ -126,7 +125,7 @@ func (_c *mockLpaStoreClient_SendLpa_Call) Return(_a0 error) *mockLpaStoreClient return _c } -func (_c *mockLpaStoreClient_SendLpa_Call) RunAndReturn(run func(context.Context, *actor.DonorProvidedDetails) error) *mockLpaStoreClient_SendLpa_Call { +func (_c *mockLpaStoreClient_SendLpa_Call) RunAndReturn(run func(context.Context, *donordata.DonorProvidedDetails) error) *mockLpaStoreClient_SendLpa_Call { _c.Call.Return(run) return _c } diff --git a/cmd/event-received/mock_shareCodeSender_test.go b/cmd/event-received/mock_shareCodeSender_test.go index 9e4f684d7a..176280bfcc 100644 --- a/cmd/event-received/mock_shareCodeSender_test.go +++ b/cmd/event-received/mock_shareCodeSender_test.go @@ -5,8 +5,7 @@ package main import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" lpastore "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" mock "github.com/stretchr/testify/mock" @@ -124,7 +123,7 @@ func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) RunAndReturn(r } // SendCertificateProviderPrompt provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context, _a1 page.AppData, _a2 *actor.DonorProvidedDetails) error { +func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context, _a1 page.AppData, _a2 *donordata.DonorProvidedDetails) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -132,7 +131,7 @@ func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, page.AppData, *actor.DonorProvidedDetails) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, page.AppData, *donordata.DonorProvidedDetails) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -149,14 +148,14 @@ type mockShareCodeSender_SendCertificateProviderPrompt_Call struct { // SendCertificateProviderPrompt is a helper method to define mock.On call // - _a0 context.Context // - _a1 page.AppData -// - _a2 *actor.DonorProvidedDetails +// - _a2 *donordata.DonorProvidedDetails func (_e *mockShareCodeSender_Expecter) SendCertificateProviderPrompt(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockShareCodeSender_SendCertificateProviderPrompt_Call { return &mockShareCodeSender_SendCertificateProviderPrompt_Call{Call: _e.mock.On("SendCertificateProviderPrompt", _a0, _a1, _a2)} } -func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) Run(run func(_a0 context.Context, _a1 page.AppData, _a2 *actor.DonorProvidedDetails)) *mockShareCodeSender_SendCertificateProviderPrompt_Call { +func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) Run(run func(_a0 context.Context, _a1 page.AppData, _a2 *donordata.DonorProvidedDetails)) *mockShareCodeSender_SendCertificateProviderPrompt_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(page.AppData), args[2].(*actor.DonorProvidedDetails)) + run(args[0].(context.Context), args[1].(page.AppData), args[2].(*donordata.DonorProvidedDetails)) }) return _c } @@ -166,7 +165,7 @@ func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) Return(_a0 err return _c } -func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) RunAndReturn(run func(context.Context, page.AppData, *actor.DonorProvidedDetails) error) *mockShareCodeSender_SendCertificateProviderPrompt_Call { +func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) RunAndReturn(run func(context.Context, page.AppData, *donordata.DonorProvidedDetails) error) *mockShareCodeSender_SendCertificateProviderPrompt_Call { _c.Call.Return(run) return _c } diff --git a/internal/app/app.go b/internal/app/app.go index 3c65600937..7b26745d3e 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -11,10 +11,12 @@ import ( "github.com/google/uuid" "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneypage" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderpage" + "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donorpage" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" @@ -91,15 +93,7 @@ func App( ) http.Handler { documentStore := NewDocumentStore(lpaDynamoClient, s3Client, eventClient, random.UuidString, time.Now) - donorStore := &donorStore{ - dynamoClient: lpaDynamoClient, - eventClient: eventClient, - logger: logger, - uuidString: uuid.NewString, - newUID: actoruid.New, - now: time.Now, - searchClient: searchClient, - } + donorStore := donordata.NewStore(lpaDynamoClient, eventClient, logger, searchClient) certificateProviderStore := certificateproviderdata.NewStore(lpaDynamoClient, time.Now) attorneyStore := attorneydata.NewStore(lpaDynamoClient, time.Now) shareCodeStore := &shareCodeStore{dynamoClient: lpaDynamoClient, now: time.Now} @@ -277,7 +271,7 @@ func makeHandle(mux *http.ServeMux, errorHandler page.ErrorHandler, sessionStore } appData.SessionID = loginSession.SessionID() - ctx = page.ContextWithSessionData(ctx, &page.SessionData{SessionID: appData.SessionID}) + ctx = page.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: appData.SessionID}) } if err := h(appData, w, r.WithContext(page.ContextWithAppData(ctx, appData))); err != nil { diff --git a/internal/app/app_test.go b/internal/app/app_test.go index 1d35fcb895..46b3ababe8 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -1,14 +1,22 @@ package app import ( + "context" + "encoding/json" + "errors" "log/slog" "net/http" "net/http/httptest" "net/url" "strings" "testing" + "time" + "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" @@ -18,8 +26,76 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/search" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" "github.com/stretchr/testify/assert" + mock "github.com/stretchr/testify/mock" ) +var ( + ctx = context.Background() + expectedError = errors.New("err") + testNow = time.Date(2023, time.April, 2, 3, 4, 5, 6, time.UTC) + testNowFn = func() time.Time { return testNow } + testUID = actoruid.New() + testUIDFn = func() actoruid.UID { return testUID } +) + +func (m *mockDynamoClient) ExpectOne(ctx, pk, sk, data interface{}, err error) { + m. + On("One", ctx, pk, sk, mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }). + Once() +} + +func (m *mockDynamoClient) ExpectAllBySK(ctx, sk, data interface{}, err error) { + m. + On("AllBySK", ctx, sk, mock.Anything). + Return(func(ctx context.Context, sk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} + +func (m *mockDynamoClient) ExpectAllByKeys(ctx context.Context, keys []dynamo.Keys, data []map[string]types.AttributeValue, err error) { + m.EXPECT(). + AllByKeys(ctx, keys). + Return(data, err) +} + +func (m *mockDynamoClient) ExpectOneBySK(ctx, sk, data interface{}, err error) { + m. + On("OneBySK", ctx, sk, mock.Anything). + Return(func(ctx context.Context, sk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} + +func (m *mockDynamoClient) ExpectAllByPartialSK(ctx, pk, partialSk, data interface{}, err error) { + m. + On("AllByPartialSK", ctx, pk, partialSk, mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} + +func (m *mockDynamoClient) ExpectOneByPK(ctx, pk, data interface{}, err error) { + m. + On("OneByPK", ctx, pk, mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }). + Once() +} + func TestApp(t *testing.T) { app := App(true, &slog.Logger{}, &localize.Localizer{}, localize.En, template.Templates{}, template.Templates{}, template.Templates{}, template.Templates{}, template.Templates{}, nil, nil, "http://public.url", &pay.Client{}, ¬ify.Client{}, &place.Client{}, &onelogin.Client{}, nil, nil, nil, &search.Client{}) @@ -66,8 +142,8 @@ func TestMakeHandleRequireSession(t *testing.T) { }, appData) assert.Equal(t, w, hw) - sessionData, _ := page.SessionDataFromContext(hr.Context()) - assert.Equal(t, &page.SessionData{SessionID: "cmFuZG9t"}, sessionData) + sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) + assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil diff --git a/internal/app/dashboard_store.go b/internal/app/dashboard_store.go index 2261961a53..0708488a23 100644 --- a/internal/app/dashboard_store.go +++ b/internal/app/dashboard_store.go @@ -8,6 +8,7 @@ import ( "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" @@ -61,7 +62,7 @@ func (s *dashboardStore) SubExistsForActorType(ctx context.Context, sub string, } func (s *dashboardStore) GetAll(ctx context.Context) (donor, attorney, certificateProvider []page.LpaAndActorTasks, err error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, nil, nil, err } diff --git a/internal/app/dashboard_store_test.go b/internal/app/dashboard_store_test.go index eda2ab2090..7ae268d06f 100644 --- a/internal/app/dashboard_store_test.go +++ b/internal/app/dashboard_store_test.go @@ -8,6 +8,7 @@ import ( "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" @@ -123,7 +124,7 @@ func TestDashboardStoreGetAll(t *testing.T) { for name, attributeValues := range testCases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: sessionID}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: sessionID}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), @@ -203,7 +204,7 @@ func TestDashboardStoreGetAllSubmittedForAttorneys(t *testing.T) { IsReplacement: true, } - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: sessionID}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: sessionID}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), @@ -249,7 +250,7 @@ func TestDashboardStoreGetAllWhenResolveErrors(t *testing.T) { donor := &actor.DonorProvidedDetails{LpaID: "0", LpaUID: "M", UpdatedAt: aTime, SK: dynamo.LpaOwnerKey(dynamo.DonorKey(sessionID)), PK: dynamo.LpaKey("0")} - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: sessionID}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: sessionID}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), @@ -272,7 +273,7 @@ func TestDashboardStoreGetAllWhenResolveErrors(t *testing.T) { } func TestDashboardStoreGetAllWhenNone(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), @@ -288,7 +289,7 @@ func TestDashboardStoreGetAllWhenNone(t *testing.T) { } func TestDashboardStoreGetAllWhenAllForActorErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), @@ -301,7 +302,7 @@ func TestDashboardStoreGetAllWhenAllForActorErrors(t *testing.T) { } func TestDashboardStoreGetAllWhenAllByKeysErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), @@ -317,7 +318,7 @@ func TestDashboardStoreGetAllWhenAllByKeysErrors(t *testing.T) { } func TestDashboardStoreGetAllWhenReferenceGetErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), diff --git a/internal/app/document_store.go b/internal/app/document_store.go index 439316f260..c0179295be 100644 --- a/internal/app/document_store.go +++ b/internal/app/document_store.go @@ -7,11 +7,19 @@ import ( "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) +type EventClient interface { + SendUidRequested(context.Context, event.UidRequested) error + SendApplicationUpdated(context.Context, event.ApplicationUpdated) error + SendPreviousApplicationLinked(context.Context, event.PreviousApplicationLinked) error + SendReducedFeeRequested(context.Context, event.ReducedFeeRequested) error +} + type documentStore struct { dynamoClient DynamoClient s3Client S3Client @@ -53,7 +61,7 @@ func (s *documentStore) Create(ctx context.Context, donor *actor.DonorProvidedDe } func (s *documentStore) GetAll(ctx context.Context) (page.Documents, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } diff --git a/internal/app/document_store_test.go b/internal/app/document_store_test.go index 6a70b2626f..b0fefdb371 100644 --- a/internal/app/document_store_test.go +++ b/internal/app/document_store_test.go @@ -8,6 +8,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -27,7 +28,7 @@ func TestNewDocumentStore(t *testing.T) { } func TestDocumentStoreGetAll(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -54,7 +55,7 @@ func TestDocumentStoreGetAllMissingSessionData(t *testing.T) { } func TestDocumentStoreGetAllMissingLpaIdInSession(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}) documentStore := documentStore{} _, err := documentStore.GetAll(ctx) @@ -63,7 +64,7 @@ func TestDocumentStoreGetAllMissingLpaIdInSession(t *testing.T) { } func TestDocumentStoreGetAllWhenDynamoClientAllByPartialSKError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -81,7 +82,7 @@ func TestDocumentStoreGetAllWhenDynamoClientAllByPartialSKError(t *testing.T) { } func TestDocumentStoreGetAllWhenNoResults(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -100,7 +101,7 @@ func TestDocumentStoreGetAllWhenNoResults(t *testing.T) { } func TestDocumentStoreUpdateScanResults(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). Update( @@ -121,7 +122,7 @@ func TestDocumentStoreUpdateScanResults(t *testing.T) { } func TestDocumentStoreUpdateScanResultsWhenUpdateError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). Update( @@ -142,7 +143,7 @@ func TestDocumentStoreUpdateScanResultsWhenUpdateError(t *testing.T) { } func TestDocumentStorePut(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -157,7 +158,7 @@ func TestDocumentStorePut(t *testing.T) { } func TestDocumentStorePutWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -172,7 +173,7 @@ func TestDocumentStorePutWhenDynamoClientError(t *testing.T) { } func TestDeleteInfectedDocuments(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -193,7 +194,7 @@ func TestDeleteInfectedDocuments(t *testing.T) { } func TestDeleteInfectedDocumentsWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -214,7 +215,7 @@ func TestDeleteInfectedDocumentsWhenDynamoClientError(t *testing.T) { } func TestDeleteInfectedDocumentsNonInfectedDocumentsAreNotDeleted(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) documentStore := documentStore{} @@ -227,7 +228,7 @@ func TestDeleteInfectedDocumentsNonInfectedDocumentsAreNotDeleted(t *testing.T) } func TestDelete(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) s3Client := newMockS3Client(t) s3Client.EXPECT(). @@ -247,7 +248,7 @@ func TestDelete(t *testing.T) { } func TestDeleteWhenS3ClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) s3Client := newMockS3Client(t) s3Client.EXPECT(). @@ -262,7 +263,7 @@ func TestDeleteWhenS3ClientError(t *testing.T) { } func TestDeleteWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) s3Client := newMockS3Client(t) s3Client.EXPECT(). diff --git a/internal/app/evidence_received_store.go b/internal/app/evidence_received_store.go index 2107db833f..d7bc59ee6c 100644 --- a/internal/app/evidence_received_store.go +++ b/internal/app/evidence_received_store.go @@ -4,8 +4,8 @@ import ( "context" "errors" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) type evidenceReceivedStore struct { @@ -13,7 +13,7 @@ type evidenceReceivedStore struct { } func (s *evidenceReceivedStore) Get(ctx context.Context) (bool, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return false, err } diff --git a/internal/app/evidence_received_store_test.go b/internal/app/evidence_received_store_test.go index 533d8c5ebf..39e4f62db5 100644 --- a/internal/app/evidence_received_store_test.go +++ b/internal/app/evidence_received_store_test.go @@ -5,13 +5,14 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/stretchr/testify/assert" ) func TestEvidenceReceivedStoreGet(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.EvidenceReceivedKey(), nil, nil) @@ -24,7 +25,7 @@ func TestEvidenceReceivedStoreGet(t *testing.T) { } func TestEvidenceReceivedStoreGetWhenFalse(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.EvidenceReceivedKey(), nil, dynamo.NotFoundError{}) @@ -42,11 +43,11 @@ func TestEvidenceReceivedStoreGetWithSessionMissing(t *testing.T) { evidenceReceivedStore := &evidenceReceivedStore{dynamoClient: nil} _, err := evidenceReceivedStore.Get(ctx) - assert.Equal(t, page.SessionMissingError{}, err) + assert.Equal(t, appcontext.SessionMissingError{}, err) } func TestEvidenceReceivedStoreGetWhenDataStoreError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.EvidenceReceivedKey(), &actor.DonorProvidedDetails{LpaID: "an-id"}, expectedError) diff --git a/internal/app/member_store.go b/internal/app/member_store.go index e8ffafcd15..eefbf9c0e4 100644 --- a/internal/app/member_store.go +++ b/internal/app/member_store.go @@ -9,8 +9,8 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) type memberStore struct { @@ -20,7 +20,7 @@ type memberStore struct { } func (s *memberStore) CreateMemberInvite(ctx context.Context, organisation *actor.Organisation, firstNames, lastname, email, referenceNumber string, permission actor.Permission) error { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return err } @@ -58,7 +58,7 @@ func (s *memberStore) DeleteMemberInvite(ctx context.Context, organisationID, em } func (s *memberStore) Create(ctx context.Context, firstNames, lastName string) (*actor.Member, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -106,7 +106,7 @@ func (s *memberStore) Create(ctx context.Context, firstNames, lastName string) ( } func (s *memberStore) CreateFromInvite(ctx context.Context, invite *actor.MemberInvite) error { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return err } @@ -151,7 +151,7 @@ func (s *memberStore) CreateFromInvite(ctx context.Context, invite *actor.Member } func (s *memberStore) InvitedMember(ctx context.Context) (*actor.MemberInvite, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -169,7 +169,7 @@ func (s *memberStore) InvitedMember(ctx context.Context) (*actor.MemberInvite, e } func (s *memberStore) InvitedMembers(ctx context.Context) ([]*actor.MemberInvite, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -187,7 +187,7 @@ func (s *memberStore) InvitedMembers(ctx context.Context) ([]*actor.MemberInvite } func (s *memberStore) InvitedMembersByEmail(ctx context.Context) ([]*actor.MemberInvite, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -205,7 +205,7 @@ func (s *memberStore) InvitedMembersByEmail(ctx context.Context) ([]*actor.Membe } func (s *memberStore) GetAll(ctx context.Context) ([]*actor.Member, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -227,7 +227,7 @@ func (s *memberStore) GetAll(ctx context.Context) ([]*actor.Member, error) { } func (s *memberStore) GetByID(ctx context.Context, memberID string) (*actor.Member, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -250,7 +250,7 @@ func (s *memberStore) GetByID(ctx context.Context, memberID string) (*actor.Memb } func (s *memberStore) Get(ctx context.Context) (*actor.Member, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -272,7 +272,7 @@ func (s *memberStore) Get(ctx context.Context) (*actor.Member, error) { } func (s *memberStore) GetAny(ctx context.Context) (*actor.Member, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } diff --git a/internal/app/member_store_test.go b/internal/app/member_store_test.go index a95566c1e2..f2023cf33d 100644 --- a/internal/app/member_store_test.go +++ b/internal/app/member_store_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/stretchr/testify/assert" @@ -12,7 +13,7 @@ import ( ) func TestMemberStoreCreateMemberInvite(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -39,7 +40,7 @@ func TestMemberStoreCreateMemberInvite(t *testing.T) { func TestMemberStoreCreateMemberInviteWithSessionMissing(t *testing.T) { testcases := map[string]context.Context{ "missing session": context.Background(), - "missing OrganisationID": page.ContextWithSessionData(context.Background(), &page.SessionData{}), + "missing OrganisationID": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), } memberStore := &memberStore{now: testNowFn} @@ -55,7 +56,7 @@ func TestMemberStoreCreateMemberInviteWithSessionMissing(t *testing.T) { } func TestMemberStoreInvitedMember(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{Email: "a@example.org"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{Email: "a@example.org"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOneBySK(ctx, dynamo.MemberInviteKey("a@example.org"), &actor.MemberInvite{OrganisationID: "an-id"}, nil) @@ -69,7 +70,7 @@ func TestMemberStoreInvitedMember(t *testing.T) { } func TestMemberStoreInvitedMemberWhenDynamoError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{Email: "a@example.org"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{Email: "a@example.org"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOneBySK(ctx, mock.Anything, mock.Anything, expectedError) @@ -83,7 +84,7 @@ func TestMemberStoreInvitedMemberWhenDynamoError(t *testing.T) { func TestMemberStoreInvitedMemberWhenSessionMissing(t *testing.T) { testcases := map[string]context.Context{ - "no email": page.ContextWithSessionData(context.Background(), &page.SessionData{}), + "no email": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), "no session data": context.Background(), } @@ -99,7 +100,7 @@ func TestMemberStoreInvitedMemberWhenSessionMissing(t *testing.T) { } func TestMemberStoreCreateMemberInviteWhenErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -113,7 +114,7 @@ func TestMemberStoreCreateMemberInviteWhenErrors(t *testing.T) { } func TestMemberStoreInvitedMembers(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllByPartialSK(ctx, dynamo.OrganisationKey("an-id"), @@ -129,7 +130,7 @@ func TestMemberStoreInvitedMembers(t *testing.T) { func TestMemberStoreInvitedMembersWhenSessionMissing(t *testing.T) { testcases := map[string]context.Context{ - "no organisation id": page.ContextWithSessionData(context.Background(), &page.SessionData{}), + "no organisation id": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), "no session data": context.Background(), } @@ -145,7 +146,7 @@ func TestMemberStoreInvitedMembersWhenSessionMissing(t *testing.T) { } func TestMemberStoreInvitedMembersWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllByPartialSK(ctx, dynamo.OrganisationKey("an-id"), @@ -159,7 +160,7 @@ func TestMemberStoreInvitedMembersWhenDynamoClientError(t *testing.T) { } func TestMemberStoreInvitedMembersByEmail(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{Email: "a@example.org"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{Email: "a@example.org"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.MemberInviteKey("a@example.org"), []*actor.MemberInvite{ @@ -179,7 +180,7 @@ func TestMemberStoreInvitedMembersByEmail(t *testing.T) { } func TestMemberStoreInvitedMembersByEmailWhenDynamoError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{Email: "a@example.org"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{Email: "a@example.org"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, mock.Anything, mock.Anything, expectedError) @@ -193,7 +194,7 @@ func TestMemberStoreInvitedMembersByEmailWhenDynamoError(t *testing.T) { func TestMemberStoreInvitedMembersByEmailWhenSessionMissing(t *testing.T) { testcases := map[string]context.Context{ - "no email": page.ContextWithSessionData(context.Background(), &page.SessionData{}), + "no email": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), "no session data": context.Background(), } @@ -243,7 +244,7 @@ func TestPutWhenDynamoError(t *testing.T) { } func TestMemberStoreGetAll(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllByPartialSK(ctx, dynamo.OrganisationKey("an-id"), @@ -259,7 +260,7 @@ func TestMemberStoreGetAll(t *testing.T) { func TestMemberStoreGetAllWhenSessionMissing(t *testing.T) { testcases := map[string]context.Context{ - "no organisation ID": page.ContextWithSessionData(context.Background(), &page.SessionData{}), + "no organisation ID": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), "no session data": context.Background(), } @@ -275,7 +276,7 @@ func TestMemberStoreGetAllWhenSessionMissing(t *testing.T) { } func TestMemberStoreGetAllWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllByPartialSK(ctx, dynamo.OrganisationKey("an-id"), @@ -289,7 +290,7 @@ func TestMemberStoreGetAllWhenDynamoClientError(t *testing.T) { } func TestMemberStoreGet(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{ + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{ OrganisationID: "a-uuid", SessionID: "session-id", }) @@ -309,8 +310,8 @@ func TestMemberStoreGet(t *testing.T) { func TestMemberStoreGetWithSessionMissing(t *testing.T) { testcases := map[string]context.Context{ - "no session id": page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "id"}), - "no organisation id": page.ContextWithSessionData(context.Background(), &page.SessionData{}), + "no session id": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "id"}), + "no organisation id": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), "no session data": context.Background(), } @@ -325,7 +326,7 @@ func TestMemberStoreGetWithSessionMissing(t *testing.T) { } func TestMemberStoreGetWhenErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "a-uuid", SessionID: "session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "a-uuid", SessionID: "session-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -338,7 +339,7 @@ func TestMemberStoreGetWhenErrors(t *testing.T) { } func TestMemberStoreCreate(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id", Email: "email@example.com"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id", Email: "email@example.com"}) expectedMember := &actor.Member{ PK: dynamo.OrganisationKey("a-uuid"), SK: dynamo.MemberKey("session-id"), @@ -378,8 +379,8 @@ func TestMemberStoreCreate(t *testing.T) { func TestMemberStoreCreateWhenSessionMissing(t *testing.T) { testCases := map[string]context.Context{ "missing session": context.Background(), - "missing email": page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "a"}), - "missing session ID": page.ContextWithSessionData(context.Background(), &page.SessionData{Email: "a"}), + "missing email": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "a"}), + "missing session ID": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{Email: "a"}), } for name, ctx := range testCases { @@ -393,7 +394,7 @@ func TestMemberStoreCreateWhenSessionMissing(t *testing.T) { } func TestMemberStoreCreateWhenDynamoErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id", Email: "a"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id", Email: "a"}) testcases := map[string]struct { dynamoClientSetup func(*mockDynamoClient) @@ -434,7 +435,7 @@ func TestMemberStoreCreateWhenDynamoErrors(t *testing.T) { } func TestMemberStoreCreateFromInvite(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) invite := &actor.MemberInvite{ PK: "pk", @@ -485,7 +486,7 @@ func TestMemberStoreCreateFromInvite(t *testing.T) { func TestMemberStoreCreateFromInviteWhenSessionMissing(t *testing.T) { testCases := map[string]context.Context{ "missing session": context.Background(), - "missing session ID": page.ContextWithSessionData(context.Background(), &page.SessionData{}), + "missing session ID": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), } for name, ctx := range testCases { @@ -517,7 +518,7 @@ func TestMemberStoreCreateFromInviteWhenDynamoErrors(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -546,7 +547,7 @@ func TestMemberStoreCreateFromInviteWhenDynamoErrors(t *testing.T) { } func TestMemberStoreGetByID(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "org-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "org-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -578,7 +579,7 @@ func TestMemberStoreGetByID(t *testing.T) { func TestMemberStoreGetByIDWhenMissingSession(t *testing.T) { testCases := map[string]context.Context{ "missing session": context.Background(), - "missing organisation ID": page.ContextWithSessionData(context.Background(), &page.SessionData{}), + "missing organisation ID": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), } for name, ctx := range testCases { @@ -607,7 +608,7 @@ func TestMemberStoreGetByIDWhenDynamoClientErrors(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "org-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "org-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -630,7 +631,7 @@ func TestMemberStoreGetByIDWhenDynamoClientErrors(t *testing.T) { } func TestMemberStoreGetAny(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) expectedMember := &actor.Member{ID: "a"} @@ -649,7 +650,7 @@ func TestMemberStoreGetAny(t *testing.T) { func TestMemberStoreGetAnyWhenMissingSession(t *testing.T) { testCases := map[string]context.Context{ "missing session": context.Background(), - "missing session ID": page.ContextWithSessionData(context.Background(), &page.SessionData{}), + "missing session ID": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), } for name, ctx := range testCases { @@ -664,7 +665,7 @@ func TestMemberStoreGetAnyWhenMissingSession(t *testing.T) { } func TestMemberStoreGetAnyWhenDynamoClientErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient. diff --git a/internal/app/mock_LpaStoreResolvingService_test.go b/internal/app/mock_LpaStoreResolvingService_test.go index 8ebc29b836..9c7cdc28a0 100644 --- a/internal/app/mock_LpaStoreResolvingService_test.go +++ b/internal/app/mock_LpaStoreResolvingService_test.go @@ -5,8 +5,7 @@ package app import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" lpastore "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" mock "github.com/stretchr/testify/mock" @@ -26,7 +25,7 @@ func (_m *mockLpaStoreResolvingService) EXPECT() *mockLpaStoreResolvingService_E } // ResolveList provides a mock function with given fields: ctx, donors -func (_m *mockLpaStoreResolvingService) ResolveList(ctx context.Context, donors []*actor.DonorProvidedDetails) ([]*lpastore.Lpa, error) { +func (_m *mockLpaStoreResolvingService) ResolveList(ctx context.Context, donors []*donordata.DonorProvidedDetails) ([]*lpastore.Lpa, error) { ret := _m.Called(ctx, donors) if len(ret) == 0 { @@ -35,10 +34,10 @@ func (_m *mockLpaStoreResolvingService) ResolveList(ctx context.Context, donors var r0 []*lpastore.Lpa var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []*actor.DonorProvidedDetails) ([]*lpastore.Lpa, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, []*donordata.DonorProvidedDetails) ([]*lpastore.Lpa, error)); ok { return rf(ctx, donors) } - if rf, ok := ret.Get(0).(func(context.Context, []*actor.DonorProvidedDetails) []*lpastore.Lpa); ok { + if rf, ok := ret.Get(0).(func(context.Context, []*donordata.DonorProvidedDetails) []*lpastore.Lpa); ok { r0 = rf(ctx, donors) } else { if ret.Get(0) != nil { @@ -46,7 +45,7 @@ func (_m *mockLpaStoreResolvingService) ResolveList(ctx context.Context, donors } } - if rf, ok := ret.Get(1).(func(context.Context, []*actor.DonorProvidedDetails) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, []*donordata.DonorProvidedDetails) error); ok { r1 = rf(ctx, donors) } else { r1 = ret.Error(1) @@ -62,14 +61,14 @@ type mockLpaStoreResolvingService_ResolveList_Call struct { // ResolveList is a helper method to define mock.On call // - ctx context.Context -// - donors []*actor.DonorProvidedDetails +// - donors []*donordata.DonorProvidedDetails func (_e *mockLpaStoreResolvingService_Expecter) ResolveList(ctx interface{}, donors interface{}) *mockLpaStoreResolvingService_ResolveList_Call { return &mockLpaStoreResolvingService_ResolveList_Call{Call: _e.mock.On("ResolveList", ctx, donors)} } -func (_c *mockLpaStoreResolvingService_ResolveList_Call) Run(run func(ctx context.Context, donors []*actor.DonorProvidedDetails)) *mockLpaStoreResolvingService_ResolveList_Call { +func (_c *mockLpaStoreResolvingService_ResolveList_Call) Run(run func(ctx context.Context, donors []*donordata.DonorProvidedDetails)) *mockLpaStoreResolvingService_ResolveList_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]*actor.DonorProvidedDetails)) + run(args[0].(context.Context), args[1].([]*donordata.DonorProvidedDetails)) }) return _c } @@ -79,7 +78,7 @@ func (_c *mockLpaStoreResolvingService_ResolveList_Call) Return(_a0 []*lpastore. return _c } -func (_c *mockLpaStoreResolvingService_ResolveList_Call) RunAndReturn(run func(context.Context, []*actor.DonorProvidedDetails) ([]*lpastore.Lpa, error)) *mockLpaStoreResolvingService_ResolveList_Call { +func (_c *mockLpaStoreResolvingService_ResolveList_Call) RunAndReturn(run func(context.Context, []*donordata.DonorProvidedDetails) ([]*lpastore.Lpa, error)) *mockLpaStoreResolvingService_ResolveList_Call { _c.Call.Return(run) return _c } diff --git a/internal/app/organisation_store.go b/internal/app/organisation_store.go index 9a3e711a92..e3e26956b3 100644 --- a/internal/app/organisation_store.go +++ b/internal/app/organisation_store.go @@ -8,8 +8,8 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) type organisationStore struct { @@ -30,7 +30,7 @@ type organisationLink struct { } func (s *organisationStore) Create(ctx context.Context, member *actor.Member, name string) (*actor.Organisation, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -55,7 +55,7 @@ func (s *organisationStore) Create(ctx context.Context, member *actor.Member, na } func (s *organisationStore) Get(ctx context.Context) (*actor.Organisation, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -87,7 +87,7 @@ func (s *organisationStore) Put(ctx context.Context, organisation *actor.Organis } func (s *organisationStore) CreateLPA(ctx context.Context) (*actor.DonorProvidedDetails, error) { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } diff --git a/internal/app/organisation_store_test.go b/internal/app/organisation_store_test.go index 9ed4a9c46d..c775f8918b 100644 --- a/internal/app/organisation_store_test.go +++ b/internal/app/organisation_store_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/stretchr/testify/assert" @@ -12,7 +13,7 @@ import ( ) func TestOrganisationStoreCreate(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id", Email: "a@example.org"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", Email: "a@example.org"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -40,7 +41,7 @@ func TestOrganisationStoreCreate(t *testing.T) { func TestOrganisationStoreCreateWithSessionMissing(t *testing.T) { testcases := map[string]context.Context{ - "no session id": page.ContextWithSessionData(context.Background(), &page.SessionData{Email: "a@example.org"}), + "no session id": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{Email: "a@example.org"}), "no session data": context.Background(), } @@ -56,7 +57,7 @@ func TestOrganisationStoreCreateWithSessionMissing(t *testing.T) { } func TestOrganisationStoreCreateWhenErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id", Email: "a@example.org"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", Email: "a@example.org"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -71,7 +72,7 @@ func TestOrganisationStoreCreateWhenErrors(t *testing.T) { } func TestOrganisationStoreGet(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) organisation := &actor.Organisation{Name: "A name"} member := actor.Member{PK: dynamo.OrganisationKey("a-uuid")} @@ -89,7 +90,7 @@ func TestOrganisationStoreGet(t *testing.T) { } func TestOrganisationStoreGetWhenOrganisationDeleted(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) organisation := &actor.Organisation{Name: "A name", DeletedAt: testNow} member := actor.Member{PK: dynamo.OrganisationKey("a-uuid")} @@ -110,7 +111,7 @@ func TestOrganisationStoreGetWhenOrganisationDeleted(t *testing.T) { func TestOrganisationStoreGetWithSessionErrors(t *testing.T) { testcases := map[string]context.Context{ "missing": context.Background(), - "missing SessionID": page.ContextWithSessionData(context.Background(), &page.SessionData{}), + "missing SessionID": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), } for name, ctx := range testcases { @@ -136,7 +137,7 @@ func TestOrganisationStoreGetWhenErrors(t *testing.T) { }, } - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) member := actor.Member{PK: dynamo.OrganisationKey("a-uuid")} for name, tc := range testcases { @@ -176,7 +177,7 @@ func TestOrganisationStorePut(t *testing.T) { } func TestOrganisationStoreCreateLPA(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) expectedDonor := &actor.DonorProvidedDetails{ PK: dynamo.LpaKey("a-uuid"), SK: dynamo.LpaOwnerKey(dynamo.OrganisationKey("an-id")), @@ -210,7 +211,7 @@ func TestOrganisationStoreCreateLPA(t *testing.T) { func TestOrganisationStoreCreateLPAWithSessionMissing(t *testing.T) { testCases := map[string]context.Context{ "missing session": context.Background(), - "missing organisation ID": page.ContextWithSessionData(context.Background(), &page.SessionData{}), + "missing organisation ID": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), } for name, ctx := range testCases { @@ -224,7 +225,7 @@ func TestOrganisationStoreCreateLPAWithSessionMissing(t *testing.T) { } func TestOrganisationStoreCreateLPAWhenDynamoError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -244,7 +245,7 @@ func TestOrganisationStoreCreateLPAWhenDynamoError(t *testing.T) { } func TestOrganisationStoreSoftDelete(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "an-id", SessionID: "session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id", SessionID: "session-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -258,7 +259,7 @@ func TestOrganisationStoreSoftDelete(t *testing.T) { } func TestOrganisationStoreSoftDeleteWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{OrganisationID: "an-id", SessionID: "session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id", SessionID: "session-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). diff --git a/internal/app/share_code_store.go b/internal/app/share_code_store.go index eeb6e9a99a..26d5c55aab 100644 --- a/internal/app/share_code_store.go +++ b/internal/app/share_code_store.go @@ -7,8 +7,8 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) type ShareCodeStoreDynamoClient interface { @@ -75,7 +75,7 @@ func (s *shareCodeStore) PutDonor(ctx context.Context, shareCode string, data ac func (s *shareCodeStore) GetDonor(ctx context.Context) (actor.ShareCodeData, error) { var data actor.ShareCodeData - sessionData, err := page.SessionDataFromContext(ctx) + sessionData, err := appcontext.SessionDataFromContext(ctx) if err != nil { return data, err } diff --git a/internal/app/share_code_store_test.go b/internal/app/share_code_store_test.go index 066193e214..7ffedbacc7 100644 --- a/internal/app/share_code_store_test.go +++ b/internal/app/share_code_store_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/stretchr/testify/assert" @@ -156,7 +157,7 @@ func TestNewShareCodeStore(t *testing.T) { } func TestShareCodeStoreGetDonor(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{ + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{ OrganisationID: "org-id", LpaID: "lpa-id", }) diff --git a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out.go b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out.go index 24b7155e21..aa3190030f 100644 --- a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out.go +++ b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out.go @@ -8,6 +8,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -27,7 +28,7 @@ func ConfirmDontWantToBeAttorneyLoggedOut(tmpl template.Template, shareCodeStore return err } - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: session.LpaID}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: session.LpaID}) lpa, err := lpaStoreResolvingService.Get(ctx) if err != nil { diff --git a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out_test.go b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out_test.go index 37ea99aa63..3e6717d55c 100644 --- a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out_test.go +++ b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_logged_out_test.go @@ -8,6 +8,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" @@ -30,7 +31,7 @@ func TestGetConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) { lpaStoreResolvingService := newMockLpaStoreResolvingService(t) lpaStoreResolvingService.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: "lpa-id"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: "lpa-id"})). Return(&lpa, nil) template := newMockTemplate(t) @@ -143,7 +144,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) { t.Run(name, func(t *testing.T) { r, _ := http.NewRequest(http.MethodPost, "/?referenceNumber=123", nil) w := httptest.NewRecorder() - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: "lpa-id"}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: "lpa-id"}) sessionStore := newMockSessionStore(t) sessionStore.EXPECT(). @@ -220,7 +221,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) { func TestPostConfirmDontWantToBeAttorneyLoggedOutWhenAttorneyNotFound(t *testing.T) { r, _ := http.NewRequest(http.MethodPost, "/?referenceNumber=123", nil) w := httptest.NewRecorder() - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: "lpa-id"}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: "lpa-id"}) sessionStore := newMockSessionStore(t) sessionStore.EXPECT(). @@ -256,7 +257,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOutWhenAttorneyNotFound(t *testing func TestPostConfirmDontWantToBeAttorneyLoggedOutErrors(t *testing.T) { r, _ := http.NewRequest(http.MethodPost, "/?referenceNumber=123", nil) - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: "lpa-id"}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: "lpa-id"}) shareCodeData := actor.ShareCodeData{ LpaKey: dynamo.LpaKey("lpa-id"), diff --git a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_test.go b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_test.go index 4515badeed..1ed0c6c21e 100644 --- a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_test.go +++ b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney_test.go @@ -9,6 +9,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" @@ -81,7 +82,7 @@ func TestGetConfirmDontWantToBeAttorneyWhenTemplateErrors(t *testing.T) { } func TestPostConfirmDontWantToBeAttorney(t *testing.T) { - r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) + r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) w := httptest.NewRecorder() uid := actoruid.New() @@ -137,7 +138,7 @@ func TestPostConfirmDontWantToBeAttorney(t *testing.T) { } func TestPostConfirmDontWantToBeAttorneyWhenAttorneyNotFound(t *testing.T) { - r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) + r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) w := httptest.NewRecorder() uid := actoruid.New() diff --git a/internal/attorney/attorneypage/enter_reference_number.go b/internal/attorney/attorneypage/enter_reference_number.go index c0bec7a52b..2142eab3eb 100644 --- a/internal/attorney/attorneypage/enter_reference_number.go +++ b/internal/attorney/attorneypage/enter_reference_number.go @@ -6,6 +6,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -46,7 +47,7 @@ func EnterReferenceNumber(tmpl template.Template, shareCodeStore ShareCodeStore, return err } - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{ + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{ SessionID: session.SessionID(), LpaID: shareCode.LpaKey.ID(), }) diff --git a/internal/attorney/attorneypage/enter_reference_number_test.go b/internal/attorney/attorneypage/enter_reference_number_test.go index c6019c1be4..b2ff86c88b 100644 --- a/internal/attorney/attorneypage/enter_reference_number_test.go +++ b/internal/attorney/attorneypage/enter_reference_number_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -115,9 +116,9 @@ func TestPostEnterReferenceNumber(t *testing.T) { attorneyStore := newMockAttorneyStore(t) attorneyStore.EXPECT(). Create(mock.MatchedBy(func(ctx context.Context) bool { - session, _ := page.SessionDataFromContext(ctx) + session, _ := appcontext.SessionDataFromContext(ctx) - return assert.Equal(t, &page.SessionData{SessionID: "aGV5", LpaID: "lpa-id"}, session) + return assert.Equal(t, &appcontext.SessionData{SessionID: "aGV5", LpaID: "lpa-id"}, session) }), tc.shareCode, "a@example.com"). Return(&attorneydata.Provided{}, nil) diff --git a/internal/attorney/attorneypage/register.go b/internal/attorney/attorneypage/register.go index 61fb97d459..534dc06a81 100644 --- a/internal/attorney/attorneypage/register.go +++ b/internal/attorney/attorneypage/register.go @@ -8,6 +8,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" @@ -169,7 +170,7 @@ func makeHandle(mux *http.ServeMux, store SessionStore, errorHandler page.ErrorH } appData.SessionID = session.SessionID() - ctx = page.ContextWithSessionData(ctx, &page.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID}) + ctx = page.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID}) } if err := h(appData, w, r.WithContext(page.ContextWithAppData(ctx, appData))); err != nil { @@ -196,13 +197,13 @@ func makeAttorneyHandle(mux *http.ServeMux, store SessionStore, errorHandler pag appData.SessionID = session.SessionID() - sessionData, err := page.SessionDataFromContext(ctx) + sessionData, err := appcontext.SessionDataFromContext(ctx) if err == nil { sessionData.SessionID = appData.SessionID sessionData.LpaID = appData.LpaID ctx = page.ContextWithSessionData(ctx, sessionData) } else { - ctx = page.ContextWithSessionData(ctx, &page.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID}) + ctx = page.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID}) } attorney, err := attorneyStore.Get(ctx) diff --git a/internal/attorney/attorneypage/register_test.go b/internal/attorney/attorneypage/register_test.go index 0b9fe8f87a..d6d6d093f7 100644 --- a/internal/attorney/attorneypage/register_test.go +++ b/internal/attorney/attorneypage/register_test.go @@ -9,6 +9,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -54,7 +55,7 @@ func TestMakeHandle(t *testing.T) { } func TestMakeHandleRequireSessionExistingSessionData(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "ignored-session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored-session-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/path?a=b", nil) @@ -73,9 +74,9 @@ func TestMakeHandleRequireSessionExistingSessionData(t *testing.T) { }, appData) assert.Equal(t, w, hw) - sessionData, _ := page.SessionDataFromContext(hr.Context()) + sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) - assert.Equal(t, &page.SessionData{SessionID: "cmFuZG9t"}, sessionData) + assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil }) @@ -146,7 +147,7 @@ func TestMakeHandleNoSessionRequired(t *testing.T) { } func TestMakeAttorneyHandleExistingSessionData(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "ignored-session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored-session-id"}) uid := actoruid.New() w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/attorney/lpa-id/path?a=b", nil) @@ -177,9 +178,9 @@ func TestMakeAttorneyHandleExistingSessionData(t *testing.T) { }, appData) assert.Equal(t, w, hw) - sessionData, _ := page.SessionDataFromContext(hr.Context()) + sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) - assert.Equal(t, &page.SessionData{SessionID: "cmFuZG9t", LpaID: "lpa-id"}, sessionData) + assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t", LpaID: "lpa-id"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil }) @@ -244,9 +245,9 @@ func TestMakeAttorneyHandleExistingLpaData(t *testing.T) { }, appData) assert.Equal(t, w, hw) - sessionData, _ := page.SessionDataFromContext(hr.Context()) + sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) - assert.Equal(t, &page.SessionData{LpaID: "lpa-id", SessionID: "cmFuZG9t"}, sessionData) + assert.Equal(t, &appcontext.SessionData{LpaID: "lpa-id", SessionID: "cmFuZG9t"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil }) @@ -262,7 +263,7 @@ func TestMakeAttorneyHandleExistingLpaData(t *testing.T) { func TestMakeAttorneyHandleExistingSessionDataWhenCannotGoToURL(t *testing.T) { path := page.Paths.Attorney.Sign - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "ignored-session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored-session-id"}) uid := actoruid.New() w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, path.Format("123"), nil) diff --git a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out.go b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out.go index dd16345103..4d34c986f0 100644 --- a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out.go +++ b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out.go @@ -7,6 +7,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -26,7 +27,7 @@ func ConfirmDontWantToBeCertificateProviderLoggedOut(tmpl template.Template, sha return err } - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: session.LpaID}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: session.LpaID}) lpa, err := lpaStoreResolvingService.Get(ctx) if err != nil { diff --git a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out_test.go b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out_test.go index e65652f0f2..ea4f22dd7a 100644 --- a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out_test.go +++ b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_logged_out_test.go @@ -8,6 +8,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" @@ -30,7 +31,7 @@ func TestGetConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { lpaStoreResolvingService := newMockLpaStoreResolvingService(t) lpaStoreResolvingService.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: "lpa-id"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: "lpa-id"})). Return(&lpa, nil) template := newMockTemplate(t) @@ -130,7 +131,7 @@ func TestGetConfirmDontWantToBeCertificateProviderLoggedOutErrors(t *testing.T) func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { r, _ := http.NewRequest(http.MethodPost, "/?referenceNumber=123", nil) w := httptest.NewRecorder() - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: "lpa-id"}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: "lpa-id"}) testcases := map[string]struct { lpa lpastore.Lpa @@ -294,7 +295,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { func TestPostConfirmDontWantToBeCertificateProviderLoggedOutErrors(t *testing.T) { r, _ := http.NewRequest(http.MethodPost, "/?referenceNumber=123", nil) - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{LpaID: "lpa-id"}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: "lpa-id"}) shareCodeData := actor.ShareCodeData{ LpaKey: dynamo.LpaKey("lpa-id"), diff --git a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_test.go b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_test.go index f87aeb7962..4ccbed6a51 100644 --- a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_test.go +++ b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider_test.go @@ -9,6 +9,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -94,7 +95,7 @@ func TestGetConfirmDontWantToBeCertificateProviderErrors(t *testing.T) { } func TestPostConfirmDontWantToBeCertificateProvider(t *testing.T) { - r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) + r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) w := httptest.NewRecorder() uid := actoruid.New() diff --git a/internal/certificateprovider/certificateproviderpage/enter_reference_number.go b/internal/certificateprovider/certificateproviderpage/enter_reference_number.go index 55ebc6e814..7eb2545a7e 100644 --- a/internal/certificateprovider/certificateproviderpage/enter_reference_number.go +++ b/internal/certificateprovider/certificateproviderpage/enter_reference_number.go @@ -6,6 +6,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -46,7 +47,7 @@ func EnterReferenceNumber(tmpl template.Template, shareCodeStore ShareCodeStore, return err } - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{ + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{ SessionID: session.SessionID(), LpaID: shareCode.LpaKey.ID(), }) diff --git a/internal/certificateprovider/certificateproviderpage/enter_reference_number_test.go b/internal/certificateprovider/certificateproviderpage/enter_reference_number_test.go index 7194e325f0..6a79f8893c 100644 --- a/internal/certificateprovider/certificateproviderpage/enter_reference_number_test.go +++ b/internal/certificateprovider/certificateproviderpage/enter_reference_number_test.go @@ -10,6 +10,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -87,9 +88,9 @@ func TestPostEnterReferenceNumber(t *testing.T) { certificateProviderStore := newMockCertificateProviderStore(t) certificateProviderStore.EXPECT(). Create(mock.MatchedBy(func(ctx context.Context) bool { - session, _ := page.SessionDataFromContext(ctx) + session, _ := appcontext.SessionDataFromContext(ctx) - return assert.Equal(t, &page.SessionData{SessionID: "aGV5", LpaID: "lpa-id"}, session) + return assert.Equal(t, &appcontext.SessionData{SessionID: "aGV5", LpaID: "lpa-id"}, session) }), shareCodeData, "a@b.com"). Return(&certificateproviderdata.Provided{}, nil) diff --git a/internal/certificateprovider/certificateproviderpage/mock_DonorStore_test.go b/internal/certificateprovider/certificateproviderpage/mock_DonorStore_test.go index 1a00f8d0f8..a85b6e6ea7 100644 --- a/internal/certificateprovider/certificateproviderpage/mock_DonorStore_test.go +++ b/internal/certificateprovider/certificateproviderpage/mock_DonorStore_test.go @@ -5,8 +5,7 @@ package certificateproviderpage import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" mock "github.com/stretchr/testify/mock" ) @@ -24,23 +23,23 @@ func (_m *mockDonorStore) EXPECT() *mockDonorStore_Expecter { } // GetAny provides a mock function with given fields: ctx -func (_m *mockDonorStore) GetAny(ctx context.Context) (*actor.DonorProvidedDetails, error) { +func (_m *mockDonorStore) GetAny(ctx context.Context) (*donordata.DonorProvidedDetails, error) { ret := _m.Called(ctx) if len(ret) == 0 { panic("no return value specified for GetAny") } - var r0 *actor.DonorProvidedDetails + var r0 *donordata.DonorProvidedDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*actor.DonorProvidedDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (*donordata.DonorProvidedDetails, error)); ok { return rf(ctx) } - if rf, ok := ret.Get(0).(func(context.Context) *actor.DonorProvidedDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context) *donordata.DonorProvidedDetails); ok { r0 = rf(ctx) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*actor.DonorProvidedDetails) + r0 = ret.Get(0).(*donordata.DonorProvidedDetails) } } @@ -71,18 +70,18 @@ func (_c *mockDonorStore_GetAny_Call) Run(run func(ctx context.Context)) *mockDo return _c } -func (_c *mockDonorStore_GetAny_Call) Return(_a0 *actor.DonorProvidedDetails, _a1 error) *mockDonorStore_GetAny_Call { +func (_c *mockDonorStore_GetAny_Call) Return(_a0 *donordata.DonorProvidedDetails, _a1 error) *mockDonorStore_GetAny_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockDonorStore_GetAny_Call) RunAndReturn(run func(context.Context) (*actor.DonorProvidedDetails, error)) *mockDonorStore_GetAny_Call { +func (_c *mockDonorStore_GetAny_Call) RunAndReturn(run func(context.Context) (*donordata.DonorProvidedDetails, error)) *mockDonorStore_GetAny_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: ctx, donor -func (_m *mockDonorStore) Put(ctx context.Context, donor *actor.DonorProvidedDetails) error { +func (_m *mockDonorStore) Put(ctx context.Context, donor *donordata.DonorProvidedDetails) error { ret := _m.Called(ctx, donor) if len(ret) == 0 { @@ -90,7 +89,7 @@ func (_m *mockDonorStore) Put(ctx context.Context, donor *actor.DonorProvidedDet } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *actor.DonorProvidedDetails) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.DonorProvidedDetails) error); ok { r0 = rf(ctx, donor) } else { r0 = ret.Error(0) @@ -106,14 +105,14 @@ type mockDonorStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - donor *actor.DonorProvidedDetails +// - donor *donordata.DonorProvidedDetails func (_e *mockDonorStore_Expecter) Put(ctx interface{}, donor interface{}) *mockDonorStore_Put_Call { return &mockDonorStore_Put_Call{Call: _e.mock.On("Put", ctx, donor)} } -func (_c *mockDonorStore_Put_Call) Run(run func(ctx context.Context, donor *actor.DonorProvidedDetails)) *mockDonorStore_Put_Call { +func (_c *mockDonorStore_Put_Call) Run(run func(ctx context.Context, donor *donordata.DonorProvidedDetails)) *mockDonorStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*actor.DonorProvidedDetails)) + run(args[0].(context.Context), args[1].(*donordata.DonorProvidedDetails)) }) return _c } @@ -123,7 +122,7 @@ func (_c *mockDonorStore_Put_Call) Return(_a0 error) *mockDonorStore_Put_Call { return _c } -func (_c *mockDonorStore_Put_Call) RunAndReturn(run func(context.Context, *actor.DonorProvidedDetails) error) *mockDonorStore_Put_Call { +func (_c *mockDonorStore_Put_Call) RunAndReturn(run func(context.Context, *donordata.DonorProvidedDetails) error) *mockDonorStore_Put_Call { _c.Call.Return(run) return _c } diff --git a/internal/certificateprovider/certificateproviderpage/register.go b/internal/certificateprovider/certificateproviderpage/register.go index 1a5dc56b68..fa44b520eb 100644 --- a/internal/certificateprovider/certificateproviderpage/register.go +++ b/internal/certificateprovider/certificateproviderpage/register.go @@ -9,6 +9,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" @@ -205,13 +206,13 @@ func makeCertificateProviderHandle(mux *http.ServeMux, sessionStore SessionStore appData.SessionID = session.SessionID() - sessionData, err := page.SessionDataFromContext(ctx) + sessionData, err := appcontext.SessionDataFromContext(ctx) if err == nil { sessionData.SessionID = appData.SessionID sessionData.LpaID = appData.LpaID ctx = page.ContextWithSessionData(ctx, sessionData) } else { - ctx = page.ContextWithSessionData(ctx, &page.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID}) + ctx = page.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID}) } certificateProvider, err := certificateProviderStore.Get(ctx) diff --git a/internal/certificateprovider/certificateproviderpage/register_test.go b/internal/certificateprovider/certificateproviderpage/register_test.go index 37058f3c69..027a133415 100644 --- a/internal/certificateprovider/certificateproviderpage/register_test.go +++ b/internal/certificateprovider/certificateproviderpage/register_test.go @@ -9,6 +9,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" @@ -40,7 +41,7 @@ func TestMakeHandle(t *testing.T) { }, appData) assert.Equal(t, w, hw) - sessionData, _ := page.SessionDataFromContext(hr.Context()) + sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) assert.Nil(t, sessionData) hw.WriteHeader(http.StatusTeapot) @@ -71,7 +72,7 @@ func TestMakeHandleErrors(t *testing.T) { } func TestMakeCertificateProviderHandle(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "ignored-session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored-session-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/certificate-provider/123/path?a=b", nil) @@ -98,8 +99,8 @@ func TestMakeCertificateProviderHandle(t *testing.T) { assert.Equal(t, &certificateproviderdata.Provided{LpaID: "123"}, certificateProvider) - sessionData, _ := page.SessionDataFromContext(hr.Context()) - assert.Equal(t, &page.SessionData{LpaID: "123", SessionID: "cmFuZG9t"}, sessionData) + sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) + assert.Equal(t, &appcontext.SessionData{LpaID: "123", SessionID: "cmFuZG9t"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil @@ -114,7 +115,7 @@ func TestMakeCertificateProviderHandle(t *testing.T) { func TestMakeCertificateProviderHandleWhenCannotGoToURL(t *testing.T) { path := page.Paths.CertificateProvider.ProvideCertificate - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "ignored-session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored-session-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, path.Format("123"), nil) @@ -164,7 +165,7 @@ func TestMakeCertificateProviderHandleSessionError(t *testing.T) { } func TestMakeCertificateProviderHandleWhenAttorneyStoreError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "ignored-session-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored-session-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/certificate-provider/id/path", nil) diff --git a/internal/donor/donordata/mock_DynamoClient_test.go b/internal/donor/donordata/mock_DynamoClient_test.go new file mode 100644 index 0000000000..a5fe8adb11 --- /dev/null +++ b/internal/donor/donordata/mock_DynamoClient_test.go @@ -0,0 +1,877 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package donordata + +import ( + context "context" + + dynamo "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + mock "github.com/stretchr/testify/mock" + + types "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" +) + +// mockDynamoClient is an autogenerated mock type for the DynamoClient type +type mockDynamoClient struct { + mock.Mock +} + +type mockDynamoClient_Expecter struct { + mock *mock.Mock +} + +func (_m *mockDynamoClient) EXPECT() *mockDynamoClient_Expecter { + return &mockDynamoClient_Expecter{mock: &_m.Mock} +} + +// AllByKeys provides a mock function with given fields: ctx, keys +func (_m *mockDynamoClient) AllByKeys(ctx context.Context, keys []dynamo.Keys) ([]map[string]types.AttributeValue, error) { + ret := _m.Called(ctx, keys) + + if len(ret) == 0 { + panic("no return value specified for AllByKeys") + } + + var r0 []map[string]types.AttributeValue + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) ([]map[string]types.AttributeValue, error)); ok { + return rf(ctx, keys) + } + if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) []map[string]types.AttributeValue); ok { + r0 = rf(ctx, keys) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]map[string]types.AttributeValue) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, []dynamo.Keys) error); ok { + r1 = rf(ctx, keys) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockDynamoClient_AllByKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllByKeys' +type mockDynamoClient_AllByKeys_Call struct { + *mock.Call +} + +// AllByKeys is a helper method to define mock.On call +// - ctx context.Context +// - keys []dynamo.Keys +func (_e *mockDynamoClient_Expecter) AllByKeys(ctx interface{}, keys interface{}) *mockDynamoClient_AllByKeys_Call { + return &mockDynamoClient_AllByKeys_Call{Call: _e.mock.On("AllByKeys", ctx, keys)} +} + +func (_c *mockDynamoClient_AllByKeys_Call) Run(run func(ctx context.Context, keys []dynamo.Keys)) *mockDynamoClient_AllByKeys_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]dynamo.Keys)) + }) + return _c +} + +func (_c *mockDynamoClient_AllByKeys_Call) Return(_a0 []map[string]types.AttributeValue, _a1 error) *mockDynamoClient_AllByKeys_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockDynamoClient_AllByKeys_Call) RunAndReturn(run func(context.Context, []dynamo.Keys) ([]map[string]types.AttributeValue, error)) *mockDynamoClient_AllByKeys_Call { + _c.Call.Return(run) + return _c +} + +// AllByPartialSK provides a mock function with given fields: ctx, pk, partialSK, v +func (_m *mockDynamoClient) AllByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, pk, partialSK, v) + + if len(ret) == 0 { + panic("no return value specified for AllByPartialSK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, pk, partialSK, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_AllByPartialSK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllByPartialSK' +type mockDynamoClient_AllByPartialSK_Call struct { + *mock.Call +} + +// AllByPartialSK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - partialSK dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) AllByPartialSK(ctx interface{}, pk interface{}, partialSK interface{}, v interface{}) *mockDynamoClient_AllByPartialSK_Call { + return &mockDynamoClient_AllByPartialSK_Call{Call: _e.mock.On("AllByPartialSK", ctx, pk, partialSK, v)} +} + +func (_c *mockDynamoClient_AllByPartialSK_Call) Run(run func(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{})) *mockDynamoClient_AllByPartialSK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_AllByPartialSK_Call) Return(_a0 error) *mockDynamoClient_AllByPartialSK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_AllByPartialSK_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, interface{}) error) *mockDynamoClient_AllByPartialSK_Call { + _c.Call.Return(run) + return _c +} + +// AllBySK provides a mock function with given fields: ctx, sk, v +func (_m *mockDynamoClient) AllBySK(ctx context.Context, sk dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, sk, v) + + if len(ret) == 0 { + panic("no return value specified for AllBySK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_AllBySK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllBySK' +type mockDynamoClient_AllBySK_Call struct { + *mock.Call +} + +// AllBySK is a helper method to define mock.On call +// - ctx context.Context +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) AllBySK(ctx interface{}, sk interface{}, v interface{}) *mockDynamoClient_AllBySK_Call { + return &mockDynamoClient_AllBySK_Call{Call: _e.mock.On("AllBySK", ctx, sk, v)} +} + +func (_c *mockDynamoClient_AllBySK_Call) Run(run func(ctx context.Context, sk dynamo.SK, v interface{})) *mockDynamoClient_AllBySK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_AllBySK_Call) Return(_a0 error) *mockDynamoClient_AllBySK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_AllBySK_Call) RunAndReturn(run func(context.Context, dynamo.SK, interface{}) error) *mockDynamoClient_AllBySK_Call { + _c.Call.Return(run) + return _c +} + +// AllKeysByPK provides a mock function with given fields: ctx, pk +func (_m *mockDynamoClient) AllKeysByPK(ctx context.Context, pk dynamo.PK) ([]dynamo.Keys, error) { + ret := _m.Called(ctx, pk) + + if len(ret) == 0 { + panic("no return value specified for AllKeysByPK") + } + + var r0 []dynamo.Keys + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK) ([]dynamo.Keys, error)); ok { + return rf(ctx, pk) + } + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK) []dynamo.Keys); ok { + r0 = rf(ctx, pk) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]dynamo.Keys) + } + } + + if rf, ok := ret.Get(1).(func(context.Context, dynamo.PK) error); ok { + r1 = rf(ctx, pk) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockDynamoClient_AllKeysByPK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AllKeysByPK' +type mockDynamoClient_AllKeysByPK_Call struct { + *mock.Call +} + +// AllKeysByPK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +func (_e *mockDynamoClient_Expecter) AllKeysByPK(ctx interface{}, pk interface{}) *mockDynamoClient_AllKeysByPK_Call { + return &mockDynamoClient_AllKeysByPK_Call{Call: _e.mock.On("AllKeysByPK", ctx, pk)} +} + +func (_c *mockDynamoClient_AllKeysByPK_Call) Run(run func(ctx context.Context, pk dynamo.PK)) *mockDynamoClient_AllKeysByPK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK)) + }) + return _c +} + +func (_c *mockDynamoClient_AllKeysByPK_Call) Return(_a0 []dynamo.Keys, _a1 error) *mockDynamoClient_AllKeysByPK_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockDynamoClient_AllKeysByPK_Call) RunAndReturn(run func(context.Context, dynamo.PK) ([]dynamo.Keys, error)) *mockDynamoClient_AllKeysByPK_Call { + _c.Call.Return(run) + return _c +} + +// BatchPut provides a mock function with given fields: ctx, items +func (_m *mockDynamoClient) BatchPut(ctx context.Context, items []interface{}) error { + ret := _m.Called(ctx, items) + + if len(ret) == 0 { + panic("no return value specified for BatchPut") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []interface{}) error); ok { + r0 = rf(ctx, items) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_BatchPut_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BatchPut' +type mockDynamoClient_BatchPut_Call struct { + *mock.Call +} + +// BatchPut is a helper method to define mock.On call +// - ctx context.Context +// - items []interface{} +func (_e *mockDynamoClient_Expecter) BatchPut(ctx interface{}, items interface{}) *mockDynamoClient_BatchPut_Call { + return &mockDynamoClient_BatchPut_Call{Call: _e.mock.On("BatchPut", ctx, items)} +} + +func (_c *mockDynamoClient_BatchPut_Call) Run(run func(ctx context.Context, items []interface{})) *mockDynamoClient_BatchPut_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_BatchPut_Call) Return(_a0 error) *mockDynamoClient_BatchPut_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_BatchPut_Call) RunAndReturn(run func(context.Context, []interface{}) error) *mockDynamoClient_BatchPut_Call { + _c.Call.Return(run) + return _c +} + +// Create provides a mock function with given fields: ctx, v +func (_m *mockDynamoClient) Create(ctx context.Context, v interface{}) error { + ret := _m.Called(ctx, v) + + if len(ret) == 0 { + panic("no return value specified for Create") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}) error); ok { + r0 = rf(ctx, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_Create_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Create' +type mockDynamoClient_Create_Call struct { + *mock.Call +} + +// Create is a helper method to define mock.On call +// - ctx context.Context +// - v interface{} +func (_e *mockDynamoClient_Expecter) Create(ctx interface{}, v interface{}) *mockDynamoClient_Create_Call { + return &mockDynamoClient_Create_Call{Call: _e.mock.On("Create", ctx, v)} +} + +func (_c *mockDynamoClient_Create_Call) Run(run func(ctx context.Context, v interface{})) *mockDynamoClient_Create_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_Create_Call) Return(_a0 error) *mockDynamoClient_Create_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_Create_Call) RunAndReturn(run func(context.Context, interface{}) error) *mockDynamoClient_Create_Call { + _c.Call.Return(run) + return _c +} + +// DeleteKeys provides a mock function with given fields: ctx, keys +func (_m *mockDynamoClient) DeleteKeys(ctx context.Context, keys []dynamo.Keys) error { + ret := _m.Called(ctx, keys) + + if len(ret) == 0 { + panic("no return value specified for DeleteKeys") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) error); ok { + r0 = rf(ctx, keys) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_DeleteKeys_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteKeys' +type mockDynamoClient_DeleteKeys_Call struct { + *mock.Call +} + +// DeleteKeys is a helper method to define mock.On call +// - ctx context.Context +// - keys []dynamo.Keys +func (_e *mockDynamoClient_Expecter) DeleteKeys(ctx interface{}, keys interface{}) *mockDynamoClient_DeleteKeys_Call { + return &mockDynamoClient_DeleteKeys_Call{Call: _e.mock.On("DeleteKeys", ctx, keys)} +} + +func (_c *mockDynamoClient_DeleteKeys_Call) Run(run func(ctx context.Context, keys []dynamo.Keys)) *mockDynamoClient_DeleteKeys_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].([]dynamo.Keys)) + }) + return _c +} + +func (_c *mockDynamoClient_DeleteKeys_Call) Return(_a0 error) *mockDynamoClient_DeleteKeys_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_DeleteKeys_Call) RunAndReturn(run func(context.Context, []dynamo.Keys) error) *mockDynamoClient_DeleteKeys_Call { + _c.Call.Return(run) + return _c +} + +// DeleteOne provides a mock function with given fields: ctx, pk, sk +func (_m *mockDynamoClient) DeleteOne(ctx context.Context, pk dynamo.PK, sk dynamo.SK) error { + ret := _m.Called(ctx, pk, sk) + + if len(ret) == 0 { + panic("no return value specified for DeleteOne") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK) error); ok { + r0 = rf(ctx, pk, sk) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_DeleteOne_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteOne' +type mockDynamoClient_DeleteOne_Call struct { + *mock.Call +} + +// DeleteOne is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - sk dynamo.SK +func (_e *mockDynamoClient_Expecter) DeleteOne(ctx interface{}, pk interface{}, sk interface{}) *mockDynamoClient_DeleteOne_Call { + return &mockDynamoClient_DeleteOne_Call{Call: _e.mock.On("DeleteOne", ctx, pk, sk)} +} + +func (_c *mockDynamoClient_DeleteOne_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK)) *mockDynamoClient_DeleteOne_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK)) + }) + return _c +} + +func (_c *mockDynamoClient_DeleteOne_Call) Return(_a0 error) *mockDynamoClient_DeleteOne_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_DeleteOne_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK) error) *mockDynamoClient_DeleteOne_Call { + _c.Call.Return(run) + return _c +} + +// LatestForActor provides a mock function with given fields: ctx, sk, v +func (_m *mockDynamoClient) LatestForActor(ctx context.Context, sk dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, sk, v) + + if len(ret) == 0 { + panic("no return value specified for LatestForActor") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_LatestForActor_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LatestForActor' +type mockDynamoClient_LatestForActor_Call struct { + *mock.Call +} + +// LatestForActor is a helper method to define mock.On call +// - ctx context.Context +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) LatestForActor(ctx interface{}, sk interface{}, v interface{}) *mockDynamoClient_LatestForActor_Call { + return &mockDynamoClient_LatestForActor_Call{Call: _e.mock.On("LatestForActor", ctx, sk, v)} +} + +func (_c *mockDynamoClient_LatestForActor_Call) Run(run func(ctx context.Context, sk dynamo.SK, v interface{})) *mockDynamoClient_LatestForActor_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_LatestForActor_Call) Return(_a0 error) *mockDynamoClient_LatestForActor_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_LatestForActor_Call) RunAndReturn(run func(context.Context, dynamo.SK, interface{}) error) *mockDynamoClient_LatestForActor_Call { + _c.Call.Return(run) + return _c +} + +// One provides a mock function with given fields: ctx, pk, sk, v +func (_m *mockDynamoClient) One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, pk, sk, v) + + if len(ret) == 0 { + panic("no return value specified for One") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, pk, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_One_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'One' +type mockDynamoClient_One_Call struct { + *mock.Call +} + +// One is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) One(ctx interface{}, pk interface{}, sk interface{}, v interface{}) *mockDynamoClient_One_Call { + return &mockDynamoClient_One_Call{Call: _e.mock.On("One", ctx, pk, sk, v)} +} + +func (_c *mockDynamoClient_One_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{})) *mockDynamoClient_One_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_One_Call) Return(_a0 error) *mockDynamoClient_One_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_One_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, interface{}) error) *mockDynamoClient_One_Call { + _c.Call.Return(run) + return _c +} + +// OneByPK provides a mock function with given fields: ctx, pk, v +func (_m *mockDynamoClient) OneByPK(ctx context.Context, pk dynamo.PK, v interface{}) error { + ret := _m.Called(ctx, pk, v) + + if len(ret) == 0 { + panic("no return value specified for OneByPK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, interface{}) error); ok { + r0 = rf(ctx, pk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneByPK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneByPK' +type mockDynamoClient_OneByPK_Call struct { + *mock.Call +} + +// OneByPK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneByPK(ctx interface{}, pk interface{}, v interface{}) *mockDynamoClient_OneByPK_Call { + return &mockDynamoClient_OneByPK_Call{Call: _e.mock.On("OneByPK", ctx, pk, v)} +} + +func (_c *mockDynamoClient_OneByPK_Call) Run(run func(ctx context.Context, pk dynamo.PK, v interface{})) *mockDynamoClient_OneByPK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneByPK_Call) Return(_a0 error) *mockDynamoClient_OneByPK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneByPK_Call) RunAndReturn(run func(context.Context, dynamo.PK, interface{}) error) *mockDynamoClient_OneByPK_Call { + _c.Call.Return(run) + return _c +} + +// OneByPartialSK provides a mock function with given fields: ctx, pk, partialSK, v +func (_m *mockDynamoClient) OneByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, pk, partialSK, v) + + if len(ret) == 0 { + panic("no return value specified for OneByPartialSK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, pk, partialSK, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneByPartialSK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneByPartialSK' +type mockDynamoClient_OneByPartialSK_Call struct { + *mock.Call +} + +// OneByPartialSK is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - partialSK dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneByPartialSK(ctx interface{}, pk interface{}, partialSK interface{}, v interface{}) *mockDynamoClient_OneByPartialSK_Call { + return &mockDynamoClient_OneByPartialSK_Call{Call: _e.mock.On("OneByPartialSK", ctx, pk, partialSK, v)} +} + +func (_c *mockDynamoClient_OneByPartialSK_Call) Run(run func(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{})) *mockDynamoClient_OneByPartialSK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneByPartialSK_Call) Return(_a0 error) *mockDynamoClient_OneByPartialSK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneByPartialSK_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, interface{}) error) *mockDynamoClient_OneByPartialSK_Call { + _c.Call.Return(run) + return _c +} + +// OneBySK provides a mock function with given fields: ctx, sk, v +func (_m *mockDynamoClient) OneBySK(ctx context.Context, sk dynamo.SK, v interface{}) error { + ret := _m.Called(ctx, sk, v) + + if len(ret) == 0 { + panic("no return value specified for OneBySK") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.SK, interface{}) error); ok { + r0 = rf(ctx, sk, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneBySK_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneBySK' +type mockDynamoClient_OneBySK_Call struct { + *mock.Call +} + +// OneBySK is a helper method to define mock.On call +// - ctx context.Context +// - sk dynamo.SK +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneBySK(ctx interface{}, sk interface{}, v interface{}) *mockDynamoClient_OneBySK_Call { + return &mockDynamoClient_OneBySK_Call{Call: _e.mock.On("OneBySK", ctx, sk, v)} +} + +func (_c *mockDynamoClient_OneBySK_Call) Run(run func(ctx context.Context, sk dynamo.SK, v interface{})) *mockDynamoClient_OneBySK_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.SK), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneBySK_Call) Return(_a0 error) *mockDynamoClient_OneBySK_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneBySK_Call) RunAndReturn(run func(context.Context, dynamo.SK, interface{}) error) *mockDynamoClient_OneBySK_Call { + _c.Call.Return(run) + return _c +} + +// OneByUID provides a mock function with given fields: ctx, uid, v +func (_m *mockDynamoClient) OneByUID(ctx context.Context, uid string, v interface{}) error { + ret := _m.Called(ctx, uid, v) + + if len(ret) == 0 { + panic("no return value specified for OneByUID") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, interface{}) error); ok { + r0 = rf(ctx, uid, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_OneByUID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'OneByUID' +type mockDynamoClient_OneByUID_Call struct { + *mock.Call +} + +// OneByUID is a helper method to define mock.On call +// - ctx context.Context +// - uid string +// - v interface{} +func (_e *mockDynamoClient_Expecter) OneByUID(ctx interface{}, uid interface{}, v interface{}) *mockDynamoClient_OneByUID_Call { + return &mockDynamoClient_OneByUID_Call{Call: _e.mock.On("OneByUID", ctx, uid, v)} +} + +func (_c *mockDynamoClient_OneByUID_Call) Run(run func(ctx context.Context, uid string, v interface{})) *mockDynamoClient_OneByUID_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(string), args[2].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_OneByUID_Call) Return(_a0 error) *mockDynamoClient_OneByUID_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_OneByUID_Call) RunAndReturn(run func(context.Context, string, interface{}) error) *mockDynamoClient_OneByUID_Call { + _c.Call.Return(run) + return _c +} + +// Put provides a mock function with given fields: ctx, v +func (_m *mockDynamoClient) Put(ctx context.Context, v interface{}) error { + ret := _m.Called(ctx, v) + + if len(ret) == 0 { + panic("no return value specified for Put") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, interface{}) error); ok { + r0 = rf(ctx, v) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_Put_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Put' +type mockDynamoClient_Put_Call struct { + *mock.Call +} + +// Put is a helper method to define mock.On call +// - ctx context.Context +// - v interface{} +func (_e *mockDynamoClient_Expecter) Put(ctx interface{}, v interface{}) *mockDynamoClient_Put_Call { + return &mockDynamoClient_Put_Call{Call: _e.mock.On("Put", ctx, v)} +} + +func (_c *mockDynamoClient_Put_Call) Run(run func(ctx context.Context, v interface{})) *mockDynamoClient_Put_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(interface{})) + }) + return _c +} + +func (_c *mockDynamoClient_Put_Call) Return(_a0 error) *mockDynamoClient_Put_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_Put_Call) RunAndReturn(run func(context.Context, interface{}) error) *mockDynamoClient_Put_Call { + _c.Call.Return(run) + return _c +} + +// Update provides a mock function with given fields: ctx, pk, sk, values, expression +func (_m *mockDynamoClient) Update(ctx context.Context, pk dynamo.PK, sk dynamo.SK, values map[string]types.AttributeValue, expression string) error { + ret := _m.Called(ctx, pk, sk, values, expression) + + if len(ret) == 0 { + panic("no return value specified for Update") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, dynamo.PK, dynamo.SK, map[string]types.AttributeValue, string) error); ok { + r0 = rf(ctx, pk, sk, values, expression) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_Update_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Update' +type mockDynamoClient_Update_Call struct { + *mock.Call +} + +// Update is a helper method to define mock.On call +// - ctx context.Context +// - pk dynamo.PK +// - sk dynamo.SK +// - values map[string]types.AttributeValue +// - expression string +func (_e *mockDynamoClient_Expecter) Update(ctx interface{}, pk interface{}, sk interface{}, values interface{}, expression interface{}) *mockDynamoClient_Update_Call { + return &mockDynamoClient_Update_Call{Call: _e.mock.On("Update", ctx, pk, sk, values, expression)} +} + +func (_c *mockDynamoClient_Update_Call) Run(run func(ctx context.Context, pk dynamo.PK, sk dynamo.SK, values map[string]types.AttributeValue, expression string)) *mockDynamoClient_Update_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(dynamo.PK), args[2].(dynamo.SK), args[3].(map[string]types.AttributeValue), args[4].(string)) + }) + return _c +} + +func (_c *mockDynamoClient_Update_Call) Return(_a0 error) *mockDynamoClient_Update_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_Update_Call) RunAndReturn(run func(context.Context, dynamo.PK, dynamo.SK, map[string]types.AttributeValue, string) error) *mockDynamoClient_Update_Call { + _c.Call.Return(run) + return _c +} + +// WriteTransaction provides a mock function with given fields: ctx, transaction +func (_m *mockDynamoClient) WriteTransaction(ctx context.Context, transaction *dynamo.Transaction) error { + ret := _m.Called(ctx, transaction) + + if len(ret) == 0 { + panic("no return value specified for WriteTransaction") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, *dynamo.Transaction) error); ok { + r0 = rf(ctx, transaction) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockDynamoClient_WriteTransaction_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WriteTransaction' +type mockDynamoClient_WriteTransaction_Call struct { + *mock.Call +} + +// WriteTransaction is a helper method to define mock.On call +// - ctx context.Context +// - transaction *dynamo.Transaction +func (_e *mockDynamoClient_Expecter) WriteTransaction(ctx interface{}, transaction interface{}) *mockDynamoClient_WriteTransaction_Call { + return &mockDynamoClient_WriteTransaction_Call{Call: _e.mock.On("WriteTransaction", ctx, transaction)} +} + +func (_c *mockDynamoClient_WriteTransaction_Call) Run(run func(ctx context.Context, transaction *dynamo.Transaction)) *mockDynamoClient_WriteTransaction_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*dynamo.Transaction)) + }) + return _c +} + +func (_c *mockDynamoClient_WriteTransaction_Call) Return(_a0 error) *mockDynamoClient_WriteTransaction_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockDynamoClient_WriteTransaction_Call) RunAndReturn(run func(context.Context, *dynamo.Transaction) error) *mockDynamoClient_WriteTransaction_Call { + _c.Call.Return(run) + return _c +} + +// newMockDynamoClient creates a new instance of mockDynamoClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockDynamoClient(t interface { + mock.TestingT + Cleanup(func()) +}) *mockDynamoClient { + mock := &mockDynamoClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/donor/donordata/mock_EventClient_test.go b/internal/donor/donordata/mock_EventClient_test.go new file mode 100644 index 0000000000..0b47f8b3f5 --- /dev/null +++ b/internal/donor/donordata/mock_EventClient_test.go @@ -0,0 +1,225 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package donordata + +import ( + context "context" + + event "github.com/ministryofjustice/opg-modernising-lpa/internal/event" + mock "github.com/stretchr/testify/mock" +) + +// mockEventClient is an autogenerated mock type for the EventClient type +type mockEventClient struct { + mock.Mock +} + +type mockEventClient_Expecter struct { + mock *mock.Mock +} + +func (_m *mockEventClient) EXPECT() *mockEventClient_Expecter { + return &mockEventClient_Expecter{mock: &_m.Mock} +} + +// SendApplicationUpdated provides a mock function with given fields: _a0, _a1 +func (_m *mockEventClient) SendApplicationUpdated(_a0 context.Context, _a1 event.ApplicationUpdated) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for SendApplicationUpdated") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, event.ApplicationUpdated) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockEventClient_SendApplicationUpdated_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendApplicationUpdated' +type mockEventClient_SendApplicationUpdated_Call struct { + *mock.Call +} + +// SendApplicationUpdated is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 event.ApplicationUpdated +func (_e *mockEventClient_Expecter) SendApplicationUpdated(_a0 interface{}, _a1 interface{}) *mockEventClient_SendApplicationUpdated_Call { + return &mockEventClient_SendApplicationUpdated_Call{Call: _e.mock.On("SendApplicationUpdated", _a0, _a1)} +} + +func (_c *mockEventClient_SendApplicationUpdated_Call) Run(run func(_a0 context.Context, _a1 event.ApplicationUpdated)) *mockEventClient_SendApplicationUpdated_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(event.ApplicationUpdated)) + }) + return _c +} + +func (_c *mockEventClient_SendApplicationUpdated_Call) Return(_a0 error) *mockEventClient_SendApplicationUpdated_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockEventClient_SendApplicationUpdated_Call) RunAndReturn(run func(context.Context, event.ApplicationUpdated) error) *mockEventClient_SendApplicationUpdated_Call { + _c.Call.Return(run) + return _c +} + +// SendPreviousApplicationLinked provides a mock function with given fields: _a0, _a1 +func (_m *mockEventClient) SendPreviousApplicationLinked(_a0 context.Context, _a1 event.PreviousApplicationLinked) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for SendPreviousApplicationLinked") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, event.PreviousApplicationLinked) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockEventClient_SendPreviousApplicationLinked_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendPreviousApplicationLinked' +type mockEventClient_SendPreviousApplicationLinked_Call struct { + *mock.Call +} + +// SendPreviousApplicationLinked is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 event.PreviousApplicationLinked +func (_e *mockEventClient_Expecter) SendPreviousApplicationLinked(_a0 interface{}, _a1 interface{}) *mockEventClient_SendPreviousApplicationLinked_Call { + return &mockEventClient_SendPreviousApplicationLinked_Call{Call: _e.mock.On("SendPreviousApplicationLinked", _a0, _a1)} +} + +func (_c *mockEventClient_SendPreviousApplicationLinked_Call) Run(run func(_a0 context.Context, _a1 event.PreviousApplicationLinked)) *mockEventClient_SendPreviousApplicationLinked_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(event.PreviousApplicationLinked)) + }) + return _c +} + +func (_c *mockEventClient_SendPreviousApplicationLinked_Call) Return(_a0 error) *mockEventClient_SendPreviousApplicationLinked_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockEventClient_SendPreviousApplicationLinked_Call) RunAndReturn(run func(context.Context, event.PreviousApplicationLinked) error) *mockEventClient_SendPreviousApplicationLinked_Call { + _c.Call.Return(run) + return _c +} + +// SendReducedFeeRequested provides a mock function with given fields: _a0, _a1 +func (_m *mockEventClient) SendReducedFeeRequested(_a0 context.Context, _a1 event.ReducedFeeRequested) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for SendReducedFeeRequested") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, event.ReducedFeeRequested) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockEventClient_SendReducedFeeRequested_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendReducedFeeRequested' +type mockEventClient_SendReducedFeeRequested_Call struct { + *mock.Call +} + +// SendReducedFeeRequested is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 event.ReducedFeeRequested +func (_e *mockEventClient_Expecter) SendReducedFeeRequested(_a0 interface{}, _a1 interface{}) *mockEventClient_SendReducedFeeRequested_Call { + return &mockEventClient_SendReducedFeeRequested_Call{Call: _e.mock.On("SendReducedFeeRequested", _a0, _a1)} +} + +func (_c *mockEventClient_SendReducedFeeRequested_Call) Run(run func(_a0 context.Context, _a1 event.ReducedFeeRequested)) *mockEventClient_SendReducedFeeRequested_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(event.ReducedFeeRequested)) + }) + return _c +} + +func (_c *mockEventClient_SendReducedFeeRequested_Call) Return(_a0 error) *mockEventClient_SendReducedFeeRequested_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockEventClient_SendReducedFeeRequested_Call) RunAndReturn(run func(context.Context, event.ReducedFeeRequested) error) *mockEventClient_SendReducedFeeRequested_Call { + _c.Call.Return(run) + return _c +} + +// SendUidRequested provides a mock function with given fields: _a0, _a1 +func (_m *mockEventClient) SendUidRequested(_a0 context.Context, _a1 event.UidRequested) error { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for SendUidRequested") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, event.UidRequested) error); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockEventClient_SendUidRequested_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SendUidRequested' +type mockEventClient_SendUidRequested_Call struct { + *mock.Call +} + +// SendUidRequested is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 event.UidRequested +func (_e *mockEventClient_Expecter) SendUidRequested(_a0 interface{}, _a1 interface{}) *mockEventClient_SendUidRequested_Call { + return &mockEventClient_SendUidRequested_Call{Call: _e.mock.On("SendUidRequested", _a0, _a1)} +} + +func (_c *mockEventClient_SendUidRequested_Call) Run(run func(_a0 context.Context, _a1 event.UidRequested)) *mockEventClient_SendUidRequested_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(event.UidRequested)) + }) + return _c +} + +func (_c *mockEventClient_SendUidRequested_Call) Return(_a0 error) *mockEventClient_SendUidRequested_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockEventClient_SendUidRequested_Call) RunAndReturn(run func(context.Context, event.UidRequested) error) *mockEventClient_SendUidRequested_Call { + _c.Call.Return(run) + return _c +} + +// newMockEventClient creates a new instance of mockEventClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockEventClient(t interface { + mock.TestingT + Cleanup(func()) +}) *mockEventClient { + mock := &mockEventClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/donor/donordata/mock_Logger_test.go b/internal/donor/donordata/mock_Logger_test.go new file mode 100644 index 0000000000..0a7e17fa1f --- /dev/null +++ b/internal/donor/donordata/mock_Logger_test.go @@ -0,0 +1,171 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package donordata + +import ( + context "context" + + mock "github.com/stretchr/testify/mock" +) + +// mockLogger is an autogenerated mock type for the Logger type +type mockLogger struct { + mock.Mock +} + +type mockLogger_Expecter struct { + mock *mock.Mock +} + +func (_m *mockLogger) EXPECT() *mockLogger_Expecter { + return &mockLogger_Expecter{mock: &_m.Mock} +} + +// ErrorContext provides a mock function with given fields: ctx, msg, args +func (_m *mockLogger) ErrorContext(ctx context.Context, msg string, args ...interface{}) { + var _ca []interface{} + _ca = append(_ca, ctx, msg) + _ca = append(_ca, args...) + _m.Called(_ca...) +} + +// mockLogger_ErrorContext_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ErrorContext' +type mockLogger_ErrorContext_Call struct { + *mock.Call +} + +// ErrorContext is a helper method to define mock.On call +// - ctx context.Context +// - msg string +// - args ...interface{} +func (_e *mockLogger_Expecter) ErrorContext(ctx interface{}, msg interface{}, args ...interface{}) *mockLogger_ErrorContext_Call { + return &mockLogger_ErrorContext_Call{Call: _e.mock.On("ErrorContext", + append([]interface{}{ctx, msg}, args...)...)} +} + +func (_c *mockLogger_ErrorContext_Call) Run(run func(ctx context.Context, msg string, args ...interface{})) *mockLogger_ErrorContext_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(context.Context), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *mockLogger_ErrorContext_Call) Return() *mockLogger_ErrorContext_Call { + _c.Call.Return() + return _c +} + +func (_c *mockLogger_ErrorContext_Call) RunAndReturn(run func(context.Context, string, ...interface{})) *mockLogger_ErrorContext_Call { + _c.Call.Return(run) + return _c +} + +// InfoContext provides a mock function with given fields: ctx, msg, args +func (_m *mockLogger) InfoContext(ctx context.Context, msg string, args ...interface{}) { + var _ca []interface{} + _ca = append(_ca, ctx, msg) + _ca = append(_ca, args...) + _m.Called(_ca...) +} + +// mockLogger_InfoContext_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'InfoContext' +type mockLogger_InfoContext_Call struct { + *mock.Call +} + +// InfoContext is a helper method to define mock.On call +// - ctx context.Context +// - msg string +// - args ...interface{} +func (_e *mockLogger_Expecter) InfoContext(ctx interface{}, msg interface{}, args ...interface{}) *mockLogger_InfoContext_Call { + return &mockLogger_InfoContext_Call{Call: _e.mock.On("InfoContext", + append([]interface{}{ctx, msg}, args...)...)} +} + +func (_c *mockLogger_InfoContext_Call) Run(run func(ctx context.Context, msg string, args ...interface{})) *mockLogger_InfoContext_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(context.Context), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *mockLogger_InfoContext_Call) Return() *mockLogger_InfoContext_Call { + _c.Call.Return() + return _c +} + +func (_c *mockLogger_InfoContext_Call) RunAndReturn(run func(context.Context, string, ...interface{})) *mockLogger_InfoContext_Call { + _c.Call.Return(run) + return _c +} + +// WarnContext provides a mock function with given fields: ctx, msg, args +func (_m *mockLogger) WarnContext(ctx context.Context, msg string, args ...interface{}) { + var _ca []interface{} + _ca = append(_ca, ctx, msg) + _ca = append(_ca, args...) + _m.Called(_ca...) +} + +// mockLogger_WarnContext_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WarnContext' +type mockLogger_WarnContext_Call struct { + *mock.Call +} + +// WarnContext is a helper method to define mock.On call +// - ctx context.Context +// - msg string +// - args ...interface{} +func (_e *mockLogger_Expecter) WarnContext(ctx interface{}, msg interface{}, args ...interface{}) *mockLogger_WarnContext_Call { + return &mockLogger_WarnContext_Call{Call: _e.mock.On("WarnContext", + append([]interface{}{ctx, msg}, args...)...)} +} + +func (_c *mockLogger_WarnContext_Call) Run(run func(ctx context.Context, msg string, args ...interface{})) *mockLogger_WarnContext_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]interface{}, len(args)-2) + for i, a := range args[2:] { + if a != nil { + variadicArgs[i] = a.(interface{}) + } + } + run(args[0].(context.Context), args[1].(string), variadicArgs...) + }) + return _c +} + +func (_c *mockLogger_WarnContext_Call) Return() *mockLogger_WarnContext_Call { + _c.Call.Return() + return _c +} + +func (_c *mockLogger_WarnContext_Call) RunAndReturn(run func(context.Context, string, ...interface{})) *mockLogger_WarnContext_Call { + _c.Call.Return(run) + return _c +} + +// newMockLogger creates a new instance of mockLogger. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockLogger(t interface { + mock.TestingT + Cleanup(func()) +}) *mockLogger { + mock := &mockLogger{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/donor/donordata/mock_SearchClient_test.go b/internal/donor/donordata/mock_SearchClient_test.go new file mode 100644 index 0000000000..aa24492cba --- /dev/null +++ b/internal/donor/donordata/mock_SearchClient_test.go @@ -0,0 +1,84 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package donordata + +import ( + context "context" + + search "github.com/ministryofjustice/opg-modernising-lpa/internal/search" + mock "github.com/stretchr/testify/mock" +) + +// mockSearchClient is an autogenerated mock type for the SearchClient type +type mockSearchClient struct { + mock.Mock +} + +type mockSearchClient_Expecter struct { + mock *mock.Mock +} + +func (_m *mockSearchClient) EXPECT() *mockSearchClient_Expecter { + return &mockSearchClient_Expecter{mock: &_m.Mock} +} + +// Index provides a mock function with given fields: ctx, lpa +func (_m *mockSearchClient) Index(ctx context.Context, lpa search.Lpa) error { + ret := _m.Called(ctx, lpa) + + if len(ret) == 0 { + panic("no return value specified for Index") + } + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, search.Lpa) error); ok { + r0 = rf(ctx, lpa) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// mockSearchClient_Index_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Index' +type mockSearchClient_Index_Call struct { + *mock.Call +} + +// Index is a helper method to define mock.On call +// - ctx context.Context +// - lpa search.Lpa +func (_e *mockSearchClient_Expecter) Index(ctx interface{}, lpa interface{}) *mockSearchClient_Index_Call { + return &mockSearchClient_Index_Call{Call: _e.mock.On("Index", ctx, lpa)} +} + +func (_c *mockSearchClient_Index_Call) Run(run func(ctx context.Context, lpa search.Lpa)) *mockSearchClient_Index_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(search.Lpa)) + }) + return _c +} + +func (_c *mockSearchClient_Index_Call) Return(_a0 error) *mockSearchClient_Index_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *mockSearchClient_Index_Call) RunAndReturn(run func(context.Context, search.Lpa) error) *mockSearchClient_Index_Call { + _c.Call.Return(run) + return _c +} + +// newMockSearchClient creates a new instance of mockSearchClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockSearchClient(t interface { + mock.TestingT + Cleanup(func()) +}) *mockSearchClient { + mock := &mockSearchClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/donor/donordata/mock_UidClient_test.go b/internal/donor/donordata/mock_UidClient_test.go new file mode 100644 index 0000000000..58bef952a9 --- /dev/null +++ b/internal/donor/donordata/mock_UidClient_test.go @@ -0,0 +1,94 @@ +// Code generated by mockery v2.42.2. DO NOT EDIT. + +package donordata + +import ( + context "context" + + uid "github.com/ministryofjustice/opg-modernising-lpa/internal/uid" + mock "github.com/stretchr/testify/mock" +) + +// mockUidClient is an autogenerated mock type for the UidClient type +type mockUidClient struct { + mock.Mock +} + +type mockUidClient_Expecter struct { + mock *mock.Mock +} + +func (_m *mockUidClient) EXPECT() *mockUidClient_Expecter { + return &mockUidClient_Expecter{mock: &_m.Mock} +} + +// CreateCase provides a mock function with given fields: _a0, _a1 +func (_m *mockUidClient) CreateCase(_a0 context.Context, _a1 *uid.CreateCaseRequestBody) (uid.CreateCaseResponse, error) { + ret := _m.Called(_a0, _a1) + + if len(ret) == 0 { + panic("no return value specified for CreateCase") + } + + var r0 uid.CreateCaseResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *uid.CreateCaseRequestBody) (uid.CreateCaseResponse, error)); ok { + return rf(_a0, _a1) + } + if rf, ok := ret.Get(0).(func(context.Context, *uid.CreateCaseRequestBody) uid.CreateCaseResponse); ok { + r0 = rf(_a0, _a1) + } else { + r0 = ret.Get(0).(uid.CreateCaseResponse) + } + + if rf, ok := ret.Get(1).(func(context.Context, *uid.CreateCaseRequestBody) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// mockUidClient_CreateCase_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateCase' +type mockUidClient_CreateCase_Call struct { + *mock.Call +} + +// CreateCase is a helper method to define mock.On call +// - _a0 context.Context +// - _a1 *uid.CreateCaseRequestBody +func (_e *mockUidClient_Expecter) CreateCase(_a0 interface{}, _a1 interface{}) *mockUidClient_CreateCase_Call { + return &mockUidClient_CreateCase_Call{Call: _e.mock.On("CreateCase", _a0, _a1)} +} + +func (_c *mockUidClient_CreateCase_Call) Run(run func(_a0 context.Context, _a1 *uid.CreateCaseRequestBody)) *mockUidClient_CreateCase_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(context.Context), args[1].(*uid.CreateCaseRequestBody)) + }) + return _c +} + +func (_c *mockUidClient_CreateCase_Call) Return(_a0 uid.CreateCaseResponse, _a1 error) *mockUidClient_CreateCase_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *mockUidClient_CreateCase_Call) RunAndReturn(run func(context.Context, *uid.CreateCaseRequestBody) (uid.CreateCaseResponse, error)) *mockUidClient_CreateCase_Call { + _c.Call.Return(run) + return _c +} + +// newMockUidClient creates a new instance of mockUidClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func newMockUidClient(t interface { + mock.TestingT + Cleanup(func()) +}) *mockUidClient { + mock := &mockUidClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/internal/donor/donordata/mock_test.go b/internal/donor/donordata/mock_test.go new file mode 100644 index 0000000000..2e073d0eeb --- /dev/null +++ b/internal/donor/donordata/mock_test.go @@ -0,0 +1,100 @@ +package donordata + +import ( + "context" + "encoding/json" + "errors" + "time" + + "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" + "github.com/stretchr/testify/mock" +) + +var ( + ctx = context.Background() + expectedError = errors.New("err") + testNow = time.Date(2023, time.April, 2, 3, 4, 5, 6, time.UTC) + testNowFn = func() time.Time { return testNow } + testUID = actoruid.New() + testUIDFn = func() actoruid.UID { return testUID } +) + +func (m *mockDynamoClient) ExpectOne(ctx, pk, sk, data interface{}, err error) { + m. + On("One", ctx, pk, sk, mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }). + Once() +} + +func (m *mockDynamoClient) ExpectOneByPK(ctx, pk, data interface{}, err error) { + m. + On("OneByPK", ctx, pk, mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }). + Once() +} + +func (m *mockDynamoClient) ExpectOneByPartialSK(ctx, pk, partialSk, data interface{}, err error) { + m. + On("OneByPartialSK", ctx, pk, partialSk, mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} + +func (m *mockDynamoClient) ExpectAllByPartialSK(ctx, pk, partialSk, data interface{}, err error) { + m. + On("AllByPartialSK", ctx, pk, partialSk, mock.Anything). + Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} + +func (m *mockDynamoClient) ExpectAllBySK(ctx, sk, data interface{}, err error) { + m. + On("AllBySK", ctx, sk, mock.Anything). + Return(func(ctx context.Context, sk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} + +func (m *mockDynamoClient) ExpectLatestForActor(ctx, sk, data interface{}, err error) { + m. + On("LatestForActor", ctx, sk, mock.Anything). + Return(func(ctx context.Context, sk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} + +func (m *mockDynamoClient) ExpectAllByKeys(ctx context.Context, keys []dynamo.Keys, data []map[string]types.AttributeValue, err error) { + m.EXPECT(). + AllByKeys(ctx, keys). + Return(data, err) +} + +func (m *mockDynamoClient) ExpectOneBySK(ctx, sk, data interface{}, err error) { + m. + On("OneBySK", ctx, sk, mock.Anything). + Return(func(ctx context.Context, sk dynamo.SK, v interface{}) error { + b, _ := json.Marshal(data) + json.Unmarshal(b, v) + return err + }) +} diff --git a/internal/app/donor_store.go b/internal/donor/donordata/store.go similarity index 69% rename from internal/app/donor_store.go rename to internal/donor/donordata/store.go index 9109897253..dc0f886112 100644 --- a/internal/app/donor_store.go +++ b/internal/donor/donordata/store.go @@ -1,4 +1,4 @@ -package app +package donordata import ( "context" @@ -7,15 +7,45 @@ import ( "time" "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + dynamodbtypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" + "github.com/google/uuid" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "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/search" + "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" + "github.com/ministryofjustice/opg-modernising-lpa/internal/task" + "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" "github.com/ministryofjustice/opg-modernising-lpa/internal/uid" ) +type Logger interface { + InfoContext(ctx context.Context, msg string, args ...any) + WarnContext(ctx context.Context, msg string, args ...any) + ErrorContext(ctx context.Context, msg string, args ...any) +} + +type DynamoClient interface { + One(ctx context.Context, pk dynamo.PK, sk dynamo.SK, v interface{}) error + OneByPK(ctx context.Context, pk dynamo.PK, v interface{}) error + OneByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{}) error + AllByPartialSK(ctx context.Context, pk dynamo.PK, partialSK dynamo.SK, v interface{}) error + LatestForActor(ctx context.Context, sk dynamo.SK, v interface{}) error + AllBySK(ctx context.Context, sk dynamo.SK, v interface{}) error + AllByKeys(ctx context.Context, keys []dynamo.Keys) ([]map[string]dynamodbtypes.AttributeValue, error) + AllKeysByPK(ctx context.Context, pk dynamo.PK) ([]dynamo.Keys, error) + Put(ctx context.Context, v interface{}) error + Create(ctx context.Context, v interface{}) error + DeleteKeys(ctx context.Context, keys []dynamo.Keys) error + DeleteOne(ctx context.Context, pk dynamo.PK, sk dynamo.SK) error + Update(ctx context.Context, pk dynamo.PK, sk dynamo.SK, values map[string]dynamodbtypes.AttributeValue, expression string) error + BatchPut(ctx context.Context, items []interface{}) error + OneBySK(ctx context.Context, sk dynamo.SK, v interface{}) error + OneByUID(ctx context.Context, uid string, v interface{}) error + WriteTransaction(ctx context.Context, transaction *dynamo.Transaction) error +} + type UidClient interface { CreateCase(context.Context, *uid.CreateCaseRequestBody) (uid.CreateCaseResponse, error) } @@ -27,6 +57,10 @@ type EventClient interface { SendReducedFeeRequested(context.Context, event.ReducedFeeRequested) error } +type SearchClient interface { + Index(ctx context.Context, lpa search.Lpa) error +} + type donorStore struct { dynamoClient DynamoClient eventClient EventClient @@ -37,8 +71,20 @@ type donorStore struct { searchClient SearchClient } -func (s *donorStore) Create(ctx context.Context) (*actor.DonorProvidedDetails, error) { - data, err := page.SessionDataFromContext(ctx) +func NewStore(dynamoClient DynamoClient, eventClient EventClient, logger Logger, searchClient SearchClient) *donorStore { + return &donorStore{ + dynamoClient: dynamoClient, + eventClient: eventClient, + logger: logger, + uuidString: uuid.NewString, + newUID: actoruid.New, + now: time.Now, + searchClient: searchClient, + } +} + +func (s *donorStore) Create(ctx context.Context) (*DonorProvidedDetails, error) { + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -50,15 +96,15 @@ func (s *donorStore) Create(ctx context.Context) (*actor.DonorProvidedDetails, e lpaID := s.uuidString() donorUID := s.newUID() - donor := &actor.DonorProvidedDetails{ + donor := &DonorProvidedDetails{ PK: dynamo.LpaKey(lpaID), SK: dynamo.LpaOwnerKey(dynamo.DonorKey(data.SessionID)), LpaID: lpaID, CreatedAt: s.now(), Version: 1, - Donor: actor.Donor{ + Donor: Donor{ UID: donorUID, - Channel: actor.ChannelOnline, + Channel: ChannelOnline, }, } @@ -83,11 +129,11 @@ func (s *donorStore) Create(ctx context.Context) (*actor.DonorProvidedDetails, e return nil, err } - if err := s.dynamoClient.Create(ctx, lpaLink{ + if err := s.dynamoClient.Create(ctx, temporary.LpaLink{ PK: dynamo.LpaKey(lpaID), SK: dynamo.SubKey(data.SessionID), DonorKey: dynamo.LpaOwnerKey(dynamo.DonorKey(data.SessionID)), - ActorType: actor.TypeDonor, + ActorType: temporary.ActorTypeDonor, UpdatedAt: s.now(), }); err != nil { return nil, err @@ -112,13 +158,13 @@ type lpaReference struct { // for the organisation ID that holds the Lpa data; // 2. an lpaLink which allows // the Lpa to be shown on the donor's dashboard. -func (s *donorStore) Link(ctx context.Context, shareCode actor.ShareCodeData, donorEmail string) error { +func (s *donorStore) Link(ctx context.Context, shareCode sharecode.ShareCodeData, donorEmail string) error { organisationKey, ok := shareCode.LpaOwnerKey.Organisation() if !ok { return errors.New("donorStore.Link can only be used with organisations") } - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return err } @@ -127,10 +173,10 @@ func (s *donorStore) Link(ctx context.Context, shareCode actor.ShareCodeData, do return errors.New("donorStore.Link requires SessionID") } - var link lpaLink + var link temporary.LpaLink if err := s.dynamoClient.OneByPartialSK(ctx, shareCode.LpaKey, dynamo.SubKey(""), &link); err != nil && !errors.Is(err, dynamo.NotFoundError{}) { return err - } else if link.ActorType == actor.TypeDonor { + } else if link.ActorType == temporary.ActorTypeDonor { return errors.New("a donor link already exists for " + shareCode.LpaKey.ID()) } @@ -143,11 +189,11 @@ func (s *donorStore) Link(ctx context.Context, shareCode actor.ShareCodeData, do SK: dynamo.DonorKey(data.SessionID), ReferencedSK: organisationKey, }). - Create(lpaLink{ + Create(temporary.LpaLink{ PK: shareCode.LpaKey, SK: dynamo.SubKey(data.SessionID), DonorKey: shareCode.LpaOwnerKey, - ActorType: actor.TypeDonor, + ActorType: temporary.ActorTypeDonor, UpdatedAt: s.now(), }). Put(shareCode) @@ -155,8 +201,8 @@ func (s *donorStore) Link(ctx context.Context, shareCode actor.ShareCodeData, do return s.dynamoClient.WriteTransaction(ctx, transaction) } -func (s *donorStore) GetAny(ctx context.Context) (*actor.DonorProvidedDetails, error) { - data, err := page.SessionDataFromContext(ctx) +func (s *donorStore) GetAny(ctx context.Context) (*DonorProvidedDetails, error) { + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -171,7 +217,7 @@ func (s *donorStore) GetAny(ctx context.Context) (*actor.DonorProvidedDetails, e } var donor struct { - actor.DonorProvidedDetails + DonorProvidedDetails ReferencedSK dynamo.OrganisationKeyType } if err := s.dynamoClient.OneByPartialSK(ctx, dynamo.LpaKey(data.LpaID), sk, &donor); err != nil { @@ -185,8 +231,8 @@ func (s *donorStore) GetAny(ctx context.Context) (*actor.DonorProvidedDetails, e return &donor.DonorProvidedDetails, err } -func (s *donorStore) Get(ctx context.Context) (*actor.DonorProvidedDetails, error) { - data, err := page.SessionDataFromContext(ctx) +func (s *donorStore) Get(ctx context.Context) (*DonorProvidedDetails, error) { + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -201,7 +247,7 @@ func (s *donorStore) Get(ctx context.Context) (*actor.DonorProvidedDetails, erro } var donor struct { - actor.DonorProvidedDetails + DonorProvidedDetails ReferencedSK dynamo.OrganisationKeyType } if err := s.dynamoClient.One(ctx, dynamo.LpaKey(data.LpaID), sk, &donor); err != nil { @@ -215,8 +261,8 @@ func (s *donorStore) Get(ctx context.Context) (*actor.DonorProvidedDetails, erro return &donor.DonorProvidedDetails, err } -func (s *donorStore) Latest(ctx context.Context) (*actor.DonorProvidedDetails, error) { - data, err := page.SessionDataFromContext(ctx) +func (s *donorStore) Latest(ctx context.Context) (*DonorProvidedDetails, error) { + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return nil, err } @@ -225,7 +271,7 @@ func (s *donorStore) Latest(ctx context.Context) (*actor.DonorProvidedDetails, e return nil, errors.New("donorStore.Latest requires SessionID") } - var donor *actor.DonorProvidedDetails + var donor *DonorProvidedDetails if err := s.dynamoClient.LatestForActor(ctx, dynamo.DonorKey(data.SessionID), &donor); err != nil { return nil, err } @@ -233,7 +279,7 @@ func (s *donorStore) Latest(ctx context.Context) (*actor.DonorProvidedDetails, e return donor, nil } -func (s *donorStore) GetByKeys(ctx context.Context, keys []dynamo.Keys) ([]actor.DonorProvidedDetails, error) { +func (s *donorStore) GetByKeys(ctx context.Context, keys []dynamo.Keys) ([]DonorProvidedDetails, error) { if len(keys) == 0 { return nil, nil } @@ -243,10 +289,10 @@ func (s *donorStore) GetByKeys(ctx context.Context, keys []dynamo.Keys) ([]actor return nil, err } - var donors []actor.DonorProvidedDetails + var donors []DonorProvidedDetails err = attributevalue.UnmarshalListOfMaps(items, &donors) - mappedDonors := map[string]actor.DonorProvidedDetails{} + mappedDonors := map[string]DonorProvidedDetails{} for _, donor := range donors { mappedDonors[donor.PK.PK()+"|"+donor.SK.SK()] = donor } @@ -259,14 +305,14 @@ func (s *donorStore) GetByKeys(ctx context.Context, keys []dynamo.Keys) ([]actor return donors, err } -func (s *donorStore) Put(ctx context.Context, donor *actor.DonorProvidedDetails) error { +func (s *donorStore) Put(ctx context.Context, donor *DonorProvidedDetails) error { if !donor.HashChanged() { return nil } // Enforces donor to send notifications to certificate provider when LPA data has changed if donor.CheckedHashChanged() && donor.Tasks.CheckYourLpa.Completed() { - donor.Tasks.CheckYourLpa = actor.TaskInProgress + donor.Tasks.CheckYourLpa = task.StateInProgress } if err := donor.UpdateHash(); err != nil { @@ -312,7 +358,7 @@ func (s *donorStore) Put(ctx context.Context, donor *actor.DonorProvidedDetails) } func (s *donorStore) Delete(ctx context.Context) error { - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return err } @@ -341,13 +387,13 @@ func (s *donorStore) Delete(ctx context.Context) error { return s.dynamoClient.DeleteKeys(ctx, keys) } -func (s *donorStore) DeleteDonorAccess(ctx context.Context, shareCodeData actor.ShareCodeData) error { +func (s *donorStore) DeleteDonorAccess(ctx context.Context, shareCodeData sharecode.ShareCodeData) error { organisationKey, ok := shareCodeData.LpaOwnerKey.Organisation() if !ok { return errors.New("donorStore.DeleteDonorAccess can only be used with organisations") } - data, err := page.SessionDataFromContext(ctx) + data, err := appcontext.SessionDataFromContext(ctx) if err != nil { return err } @@ -360,7 +406,7 @@ func (s *donorStore) DeleteDonorAccess(ctx context.Context, shareCodeData actor. return errors.New("cannot remove access to another organisations LPA") } - var link lpaLink + var link temporary.LpaLink if err := s.dynamoClient.OneByPartialSK(ctx, shareCodeData.LpaKey, dynamo.SubKey(""), &link); err != nil { return err } diff --git a/internal/app/donor_store_test.go b/internal/donor/donordata/store_test.go similarity index 62% rename from internal/app/donor_store_test.go rename to internal/donor/donordata/store_test.go index 73b48718ca..038ebddfeb 100644 --- a/internal/app/donor_store_test.go +++ b/internal/donor/donordata/store_test.go @@ -1,8 +1,7 @@ -package app +package donordata import ( "context" - "encoding/json" "errors" "log/slog" "testing" @@ -10,133 +9,48 @@ import ( "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/search" + "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" + "github.com/ministryofjustice/opg-modernising-lpa/internal/task" + "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" "github.com/mitchellh/hashstructure/v2" "github.com/stretchr/testify/assert" mock "github.com/stretchr/testify/mock" ) -var ( - ctx = context.Background() - expectedError = errors.New("err") - testNow = time.Date(2023, time.April, 2, 3, 4, 5, 6, time.UTC) - testNowFn = func() time.Time { return testNow } - testUID = actoruid.New() - testUIDFn = func() actoruid.UID { return testUID } -) - -func (m *mockDynamoClient) ExpectOne(ctx, pk, sk, data interface{}, err error) { - m. - On("One", ctx, pk, sk, mock.Anything). - Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { - b, _ := json.Marshal(data) - json.Unmarshal(b, v) - return err - }). - Once() -} - -func (m *mockDynamoClient) ExpectOneByPK(ctx, pk, data interface{}, err error) { - m. - On("OneByPK", ctx, pk, mock.Anything). - Return(func(ctx context.Context, pk dynamo.PK, v interface{}) error { - b, _ := json.Marshal(data) - json.Unmarshal(b, v) - return err - }). - Once() -} - -func (m *mockDynamoClient) ExpectOneByPartialSK(ctx, pk, partialSk, data interface{}, err error) { - m. - On("OneByPartialSK", ctx, pk, partialSk, mock.Anything). - Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { - b, _ := json.Marshal(data) - json.Unmarshal(b, v) - return err - }) -} - -func (m *mockDynamoClient) ExpectAllByPartialSK(ctx, pk, partialSk, data interface{}, err error) { - m. - On("AllByPartialSK", ctx, pk, partialSk, mock.Anything). - Return(func(ctx context.Context, pk dynamo.PK, partialSk dynamo.SK, v interface{}) error { - b, _ := json.Marshal(data) - json.Unmarshal(b, v) - return err - }) -} - -func (m *mockDynamoClient) ExpectAllBySK(ctx, sk, data interface{}, err error) { - m. - On("AllBySK", ctx, sk, mock.Anything). - Return(func(ctx context.Context, sk dynamo.SK, v interface{}) error { - b, _ := json.Marshal(data) - json.Unmarshal(b, v) - return err - }) -} - -func (m *mockDynamoClient) ExpectLatestForActor(ctx, sk, data interface{}, err error) { - m. - On("LatestForActor", ctx, sk, mock.Anything). - Return(func(ctx context.Context, sk dynamo.SK, v interface{}) error { - b, _ := json.Marshal(data) - json.Unmarshal(b, v) - return err - }) -} - -func (m *mockDynamoClient) ExpectAllByKeys(ctx context.Context, keys []dynamo.Keys, data []map[string]types.AttributeValue, err error) { - m.EXPECT(). - AllByKeys(ctx, keys). - Return(data, err) -} - -func (m *mockDynamoClient) ExpectOneBySK(ctx, sk, data interface{}, err error) { - m. - On("OneBySK", ctx, sk, mock.Anything). - Return(func(ctx context.Context, sk dynamo.SK, v interface{}) error { - b, _ := json.Marshal(data) - json.Unmarshal(b, v) - return err - }) -} - func TestDonorStoreGetAny(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id"}) dynamoClient := newMockDynamoClient(t) - dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey(""), &actor.DonorProvidedDetails{LpaID: "an-id"}, nil) + dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey(""), &DonorProvidedDetails{LpaID: "an-id"}, nil) donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }} lpa, err := donorStore.GetAny(ctx) assert.Nil(t, err) - assert.Equal(t, &actor.DonorProvidedDetails{LpaID: "an-id"}, lpa) + assert.Equal(t, &DonorProvidedDetails{LpaID: "an-id"}, lpa) } func TestDonorStoreGetAnyWhenOrganisation(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id", OrganisationID: "x"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", OrganisationID: "x"}) dynamoClient := newMockDynamoClient(t) - dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.OrganisationKey(""), &actor.DonorProvidedDetails{LpaID: "an-id"}, nil) + dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.OrganisationKey(""), &DonorProvidedDetails{LpaID: "an-id"}, nil) donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }} lpa, err := donorStore.GetAny(ctx) assert.Nil(t, err) - assert.Equal(t, &actor.DonorProvidedDetails{LpaID: "an-id"}, lpa) + assert.Equal(t, &DonorProvidedDetails{LpaID: "an-id"}, lpa) } func TestDonorStoreGetAnyWhenReference(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey(""), @@ -146,27 +60,27 @@ func TestDonorStoreGetAnyWhenReference(t *testing.T) { ReferencedSK: dynamo.OrganisationKey("org"), }, nil) dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.OrganisationKey("org"), - &actor.DonorProvidedDetails{LpaID: "an-id"}, nil) + &DonorProvidedDetails{LpaID: "an-id"}, nil) donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }} lpa, err := donorStore.GetAny(ctx) assert.Nil(t, err) - assert.Equal(t, &actor.DonorProvidedDetails{SK: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")), LpaID: "an-id"}, lpa) + assert.Equal(t, &DonorProvidedDetails{SK: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")), LpaID: "an-id"}, lpa) } func TestDonorStoreGetAnyWithSessionMissing(t *testing.T) { donorStore := &donorStore{dynamoClient: nil, uuidString: func() string { return "10100000" }} _, err := donorStore.GetAny(ctx) - assert.Equal(t, page.SessionMissingError{}, err) + assert.Equal(t, appcontext.SessionMissingError{}, err) } func TestDonorStoreGetAnyWhenDataStoreError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id"}) dynamoClient := newMockDynamoClient(t) - dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey(""), &actor.DonorProvidedDetails{LpaID: "an-id"}, expectedError) + dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey(""), &DonorProvidedDetails{LpaID: "an-id"}, expectedError) donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }} @@ -175,7 +89,7 @@ func TestDonorStoreGetAnyWhenDataStoreError(t *testing.T) { } func TestDonorStoreGetAnyWhenReferenceErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey(""), @@ -195,58 +109,58 @@ func TestDonorStoreGetAnyWhenReferenceErrors(t *testing.T) { func TestDonorStoreGet(t *testing.T) { testCases := map[string]struct { - sessionData *page.SessionData + sessionData *appcontext.SessionData expectedSK dynamo.SK }{ "donor": { - sessionData: &page.SessionData{LpaID: "an-id", SessionID: "456"}, + sessionData: &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}, expectedSK: dynamo.DonorKey("456"), }, "organisation": { - sessionData: &page.SessionData{LpaID: "an-id", SessionID: "456", OrganisationID: "789"}, + sessionData: &appcontext.SessionData{LpaID: "an-id", SessionID: "456", OrganisationID: "789"}, expectedSK: dynamo.OrganisationKey("789"), }, } for name, tc := range testCases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), tc.sessionData) + ctx := appcontext.ContextWithSessionData(context.Background(), tc.sessionData) dynamoClient := newMockDynamoClient(t) - dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), tc.expectedSK, &actor.DonorProvidedDetails{LpaID: "an-id"}, nil) + dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), tc.expectedSK, &DonorProvidedDetails{LpaID: "an-id"}, nil) donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }} lpa, err := donorStore.Get(ctx) assert.Nil(t, err) - assert.Equal(t, &actor.DonorProvidedDetails{LpaID: "an-id"}, lpa) + assert.Equal(t, &DonorProvidedDetails{LpaID: "an-id"}, lpa) }) } } func TestDonorStoreGetWhenReferenced(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey("456"), lpaReference{ReferencedSK: dynamo.OrganisationKey("789")}, nil) - dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.OrganisationKey("789"), &actor.DonorProvidedDetails{LpaID: "an-id"}, expectedError) + dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.OrganisationKey("789"), &DonorProvidedDetails{LpaID: "an-id"}, expectedError) donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }} lpa, err := donorStore.Get(ctx) assert.Equal(t, expectedError, err) - assert.Equal(t, &actor.DonorProvidedDetails{LpaID: "an-id"}, lpa) + assert.Equal(t, &DonorProvidedDetails{LpaID: "an-id"}, lpa) } func TestDonorStoreGetWithSessionMissing(t *testing.T) { donorStore := &donorStore{dynamoClient: nil, uuidString: func() string { return "10100000" }} _, err := donorStore.Get(ctx) - assert.Equal(t, page.SessionMissingError{}, err) + assert.Equal(t, appcontext.SessionMissingError{}, err) } func TestDonorStoreGetWhenDataStoreError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey("456"), lpaReference{ReferencedSK: "ref"}, expectedError) @@ -258,30 +172,30 @@ func TestDonorStoreGetWhenDataStoreError(t *testing.T) { } func TestDonorStoreLatest(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) - dynamoClient.ExpectLatestForActor(ctx, dynamo.DonorKey("456"), &actor.DonorProvidedDetails{LpaID: "an-id"}, nil) + dynamoClient.ExpectLatestForActor(ctx, dynamo.DonorKey("456"), &DonorProvidedDetails{LpaID: "an-id"}, nil) donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }} lpa, err := donorStore.Latest(ctx) assert.Nil(t, err) - assert.Equal(t, &actor.DonorProvidedDetails{LpaID: "an-id"}, lpa) + assert.Equal(t, &DonorProvidedDetails{LpaID: "an-id"}, lpa) } func TestDonorStoreLatestWithSessionMissing(t *testing.T) { donorStore := &donorStore{dynamoClient: nil, uuidString: func() string { return "10100000" }} _, err := donorStore.Latest(ctx) - assert.Equal(t, page.SessionMissingError{}, err) + assert.Equal(t, appcontext.SessionMissingError{}, err) } func TestDonorStoreLatestWhenDataStoreError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) - dynamoClient.ExpectLatestForActor(ctx, dynamo.DonorKey("456"), &actor.DonorProvidedDetails{LpaID: "an-id"}, expectedError) + dynamoClient.ExpectLatestForActor(ctx, dynamo.DonorKey("456"), &DonorProvidedDetails{LpaID: "an-id"}, expectedError) donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }} @@ -295,7 +209,7 @@ func TestDonorStoreGetByKeys(t *testing.T) { {PK: dynamo.LpaKey("2"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("b"))}, {PK: dynamo.LpaKey("3"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("c"))}, } - donors := []actor.DonorProvidedDetails{ + donors := []DonorProvidedDetails{ {PK: dynamo.LpaKey("1"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("a")), LpaID: "1"}, {PK: dynamo.LpaKey("2"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("b")), LpaID: "2"}, {PK: dynamo.LpaKey("3"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("c")), LpaID: "3"}, @@ -339,7 +253,7 @@ func TestDonorStoreGetByKeysWhenDynamoErrors(t *testing.T) { } func TestDonorStorePut(t *testing.T) { - saved := &actor.DonorProvidedDetails{PK: dynamo.LpaKey("5"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, Donor: actor.Donor{FirstNames: "x", LastName: "y"}} + saved := &DonorProvidedDetails{PK: dynamo.LpaKey("5"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, Donor: Donor{FirstNames: "x", LastName: "y"}} saved.UpdateHash() dynamoClient := newMockDynamoClient(t) @@ -349,12 +263,12 @@ func TestDonorStorePut(t *testing.T) { donorStore := &donorStore{dynamoClient: dynamoClient, now: testNowFn} - err := donorStore.Put(ctx, &actor.DonorProvidedDetails{PK: dynamo.LpaKey("5"), Hash: 5, SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, Donor: actor.Donor{FirstNames: "x", LastName: "y"}}) + err := donorStore.Put(ctx, &DonorProvidedDetails{PK: dynamo.LpaKey("5"), Hash: 5, SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, Donor: Donor{FirstNames: "x", LastName: "y"}}) assert.Nil(t, err) } func TestDonorStorePutWhenUIDSet(t *testing.T) { - saved := &actor.DonorProvidedDetails{PK: dynamo.LpaKey("5"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, LpaUID: "M", UpdatedAt: testNow, Donor: actor.Donor{FirstNames: "x", LastName: "y"}} + saved := &DonorProvidedDetails{PK: dynamo.LpaKey("5"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, LpaUID: "M", UpdatedAt: testNow, Donor: Donor{FirstNames: "x", LastName: "y"}} saved.UpdateHash() dynamoClient := newMockDynamoClient(t) @@ -369,7 +283,7 @@ func TestDonorStorePutWhenUIDSet(t *testing.T) { donorStore := &donorStore{dynamoClient: dynamoClient, searchClient: searchClient, now: testNowFn} - err := donorStore.Put(ctx, &actor.DonorProvidedDetails{PK: dynamo.LpaKey("5"), Hash: 5, SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, LpaUID: "M", Donor: actor.Donor{FirstNames: "x", LastName: "y"}}) + err := donorStore.Put(ctx, &DonorProvidedDetails{PK: dynamo.LpaKey("5"), Hash: 5, SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, LpaUID: "M", Donor: Donor{FirstNames: "x", LastName: "y"}}) assert.Nil(t, err) } @@ -390,14 +304,14 @@ func TestDonorStorePutWhenUIDSetIndexErrors(t *testing.T) { donorStore := &donorStore{dynamoClient: dynamoClient, searchClient: searchClient, logger: logger, now: testNowFn} - err := donorStore.Put(ctx, &actor.DonorProvidedDetails{PK: dynamo.LpaKey("5"), Hash: 5, SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, LpaUID: "M", Donor: actor.Donor{FirstNames: "x", LastName: "y"}}) + err := donorStore.Put(ctx, &DonorProvidedDetails{PK: dynamo.LpaKey("5"), Hash: 5, SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, LpaUID: "M", Donor: Donor{FirstNames: "x", LastName: "y"}}) assert.Nil(t, err) } func TestDonorStorePutWhenNoChange(t *testing.T) { donorStore := &donorStore{} - donor := &actor.DonorProvidedDetails{LpaID: "an-id"} + donor := &DonorProvidedDetails{LpaID: "an-id"} donor.Hash, _ = hashstructure.Hash(donor, hashstructure.FormatV2, nil) err := donorStore.Put(ctx, donor) @@ -405,7 +319,7 @@ func TestDonorStorePutWhenNoChange(t *testing.T) { } func TestDonorStorePutWhenCheckChangeAndCheckCompleted(t *testing.T) { - saved := &actor.DonorProvidedDetails{PK: dynamo.LpaKey("5"), Hash: 5, CheckedHash: 5, SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, Donor: actor.Donor{FirstNames: "a", LastName: "b"}, Tasks: actor.DonorTasks{CheckYourLpa: actor.TaskInProgress}} + saved := &DonorProvidedDetails{PK: dynamo.LpaKey("5"), Hash: 5, CheckedHash: 5, SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, Donor: Donor{FirstNames: "a", LastName: "b"}, Tasks: DonorTasks{CheckYourLpa: task.StateInProgress}} _ = saved.UpdateHash() dynamoClient := newMockDynamoClient(t) @@ -415,7 +329,7 @@ func TestDonorStorePutWhenCheckChangeAndCheckCompleted(t *testing.T) { donorStore := &donorStore{dynamoClient: dynamoClient, now: testNowFn} - err := donorStore.Put(ctx, &actor.DonorProvidedDetails{PK: dynamo.LpaKey("5"), Hash: 5, CheckedHash: 5, SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, Donor: actor.Donor{FirstNames: "a", LastName: "b"}, Tasks: actor.DonorTasks{CheckYourLpa: actor.TaskCompleted}}) + err := donorStore.Put(ctx, &DonorProvidedDetails{PK: dynamo.LpaKey("5"), Hash: 5, CheckedHash: 5, SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", HasSentApplicationUpdatedEvent: true, Donor: Donor{FirstNames: "a", LastName: "b"}, Tasks: DonorTasks{CheckYourLpa: task.StateCompleted}}) assert.Nil(t, err) } @@ -425,7 +339,7 @@ func TestDonorStorePutWhenError(t *testing.T) { donorStore := &donorStore{dynamoClient: dynamoClient, now: time.Now} - err := donorStore.Put(ctx, &actor.DonorProvidedDetails{PK: dynamo.LpaKey("5"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5"}) + err := donorStore.Put(ctx, &DonorProvidedDetails{PK: dynamo.LpaKey("5"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5"}) assert.Equal(t, expectedError, err) } @@ -442,12 +356,12 @@ func TestDonorStorePutWhenApplicationUpdatedWhenError(t *testing.T) { donorStore := &donorStore{eventClient: eventClient, searchClient: searchClient, now: testNowFn} - err := donorStore.Put(ctx, &actor.DonorProvidedDetails{ + err := donorStore.Put(ctx, &DonorProvidedDetails{ PK: dynamo.LpaKey("5"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "5", LpaUID: "M-1111", - Donor: actor.Donor{ + Donor: Donor{ FirstNames: "John", LastName: "Smith", DateOfBirth: date.New("2000", "01", "01"), @@ -455,16 +369,16 @@ func TestDonorStorePutWhenApplicationUpdatedWhenError(t *testing.T) { Postcode: "F1 1FF", }, }, - Type: actor.LpaTypePersonalWelfare, + Type: LpaTypePersonalWelfare, }) assert.Equal(t, expectedError, err) } func TestDonorStoreCreate(t *testing.T) { - testCases := map[string]actor.DonorProvidedDetails{ + testCases := map[string]DonorProvidedDetails{ "with previous details": { - Donor: actor.Donor{ + Donor: Donor{ UID: actoruid.New(), FirstNames: "a", LastName: "b", @@ -478,21 +392,21 @@ func TestDonorStoreCreate(t *testing.T) { for name, previousDetails := range testCases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}) - donor := &actor.DonorProvidedDetails{ + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + donor := &DonorProvidedDetails{ PK: dynamo.LpaKey("10100000"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), LpaID: "10100000", CreatedAt: testNow, Version: 1, - Donor: actor.Donor{ + Donor: Donor{ UID: testUID, FirstNames: previousDetails.Donor.FirstNames, LastName: previousDetails.Donor.LastName, OtherNames: previousDetails.Donor.OtherNames, DateOfBirth: previousDetails.Donor.DateOfBirth, Address: previousDetails.Donor.Address, - Channel: actor.ChannelOnline, + Channel: ChannelOnline, }, } donor.UpdateHash() @@ -504,7 +418,7 @@ func TestDonorStoreCreate(t *testing.T) { Create(ctx, donor). Return(nil) dynamoClient.EXPECT(). - Create(ctx, lpaLink{PK: dynamo.LpaKey("10100000"), SK: dynamo.SubKey("an-id"), DonorKey: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), ActorType: actor.TypeDonor, UpdatedAt: testNow}). + Create(ctx, temporary.LpaLink{PK: dynamo.LpaKey("10100000"), SK: dynamo.SubKey("an-id"), DonorKey: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), ActorType: temporary.ActorTypeDonor, UpdatedAt: testNow}). Return(nil) donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }, now: testNowFn, newUID: testUIDFn} @@ -520,24 +434,24 @@ func TestDonorStoreCreateWithSessionMissing(t *testing.T) { donorStore := &donorStore{dynamoClient: nil, uuidString: func() string { return "10100000" }, now: func() time.Time { return time.Now() }} _, err := donorStore.Create(ctx) - assert.Equal(t, page.SessionMissingError{}, err) + assert.Equal(t, appcontext.SessionMissingError{}, err) } func TestDonorStoreCreateWhenError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) testcases := map[string]func(*testing.T) *mockDynamoClient{ "latest": func(t *testing.T) *mockDynamoClient { dynamoClient := newMockDynamoClient(t) dynamoClient. - ExpectLatestForActor(ctx, dynamo.DonorKey("an-id"), actor.DonorProvidedDetails{}, expectedError) + ExpectLatestForActor(ctx, dynamo.DonorKey("an-id"), DonorProvidedDetails{}, expectedError) return dynamoClient }, "donor record": func(t *testing.T) *mockDynamoClient { dynamoClient := newMockDynamoClient(t) dynamoClient. - ExpectLatestForActor(ctx, dynamo.DonorKey("an-id"), actor.DonorProvidedDetails{}, nil) + ExpectLatestForActor(ctx, dynamo.DonorKey("an-id"), DonorProvidedDetails{}, nil) dynamoClient.EXPECT(). Create(ctx, mock.Anything). Return(expectedError) @@ -547,7 +461,7 @@ func TestDonorStoreCreateWhenError(t *testing.T) { "link record": func(t *testing.T) *mockDynamoClient { dynamoClient := newMockDynamoClient(t) dynamoClient. - ExpectLatestForActor(ctx, dynamo.DonorKey("an-id"), actor.DonorProvidedDetails{}, nil) + ExpectLatestForActor(ctx, dynamo.DonorKey("an-id"), DonorProvidedDetails{}, nil) dynamoClient.EXPECT(). Create(ctx, mock.Anything). Return(nil). @@ -580,24 +494,24 @@ func TestDonorStoreCreateWhenError(t *testing.T) { func TestDonorStoreLink(t *testing.T) { testcases := map[string]struct { oneByPartialSKError error - link lpaLink + link temporary.LpaLink }{ "no link": { oneByPartialSKError: dynamo.NotFoundError{}, }, "not a donor link": { - link: lpaLink{ + link: temporary.LpaLink{ PK: dynamo.LpaKey(""), SK: dynamo.SubKey("a-sub"), - ActorType: actor.TypeCertificateProvider, + ActorType: temporary.ActorTypeCertificateProvider, }, }, } for name, tc := range testcases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "session-id"}) - shareCode := actor.ShareCodeData{ + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) + shareCode := sharecode.ShareCodeData{ LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), } @@ -609,16 +523,16 @@ func TestDonorStoreLink(t *testing.T) { SK: dynamo.DonorKey("session-id"), ReferencedSK: dynamo.OrganisationKey("org-id"), }, - lpaLink{ + temporary.LpaLink{ PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("session-id"), DonorKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), - ActorType: actor.TypeDonor, + ActorType: temporary.ActorTypeDonor, UpdatedAt: testNowFn(), }, }, Puts: []any{ - actor.ShareCodeData{ + sharecode.ShareCodeData{ LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), LpaLinkedTo: "a@example.com", @@ -645,37 +559,37 @@ func TestDonorStoreLink(t *testing.T) { func TestDonorStoreLinkWithDonor(t *testing.T) { donorStore := &donorStore{} - err := donorStore.Link(ctx, actor.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor"))}, "a@example.com") + err := donorStore.Link(ctx, sharecode.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor"))}, "a@example.com") assert.Error(t, err) } func TestDonorStoreLinkWithSessionMissing(t *testing.T) { donorStore := &donorStore{} - err := donorStore.Link(ctx, actor.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org"))}, "a@example.com") - assert.Equal(t, page.SessionMissingError{}, err) + err := donorStore.Link(ctx, sharecode.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org"))}, "a@example.com") + assert.Equal(t, appcontext.SessionMissingError{}, err) } func TestDonorStoreLinkWithSessionIDMissing(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{}) donorStore := &donorStore{} - err := donorStore.Link(ctx, actor.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org"))}, "a@example.com") + err := donorStore.Link(ctx, sharecode.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org"))}, "a@example.com") assert.Error(t, err) } func TestDonorStoreLinkWhenDonorLinkAlreadyExists(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient. - ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), lpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("a-sub"), ActorType: actor.TypeDonor}, nil) + ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), temporary.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("a-sub"), ActorType: temporary.ActorTypeDonor}, nil) donorStore := &donorStore{dynamoClient: dynamoClient} err := donorStore.Link( ctx, - actor.ShareCodeData{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org"))}, + sharecode.ShareCodeData{LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org"))}, "a@example.com", ) @@ -686,11 +600,11 @@ func TestDonorStoreLinkWhenError(t *testing.T) { testcases := map[string]func(*mockDynamoClient){ "OneByPartialSK errors": func(dynamoClient *mockDynamoClient) { dynamoClient. - ExpectOneByPartialSK(mock.Anything, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), lpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("a-sub"), ActorType: actor.TypeAttorney}, expectedError) + ExpectOneByPartialSK(mock.Anything, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), temporary.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("a-sub"), ActorType: temporary.ActorTypeAttorney}, expectedError) }, "WriteTransaction errors": func(dynamoClient *mockDynamoClient) { dynamoClient. - ExpectOneByPartialSK(mock.Anything, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), lpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("a-sub"), ActorType: actor.TypeAttorney}, nil) + ExpectOneByPartialSK(mock.Anything, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), temporary.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("a-sub"), ActorType: temporary.ActorTypeAttorney}, nil) dynamoClient.EXPECT(). WriteTransaction(mock.Anything, mock.Anything). Return(expectedError) @@ -699,8 +613,8 @@ func TestDonorStoreLinkWhenError(t *testing.T) { for name, setupDynamoClient := range testcases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}) - shareCode := actor.ShareCodeData{ + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + shareCode := sharecode.ShareCodeData{ LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), } @@ -717,7 +631,7 @@ func TestDonorStoreLinkWhenError(t *testing.T) { } func TestDonorStoreDelete(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id", LpaID: "123"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", LpaID: "123"}) keys := []dynamo.Keys{ {PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("sk1")}, @@ -740,7 +654,7 @@ func TestDonorStoreDelete(t *testing.T) { } func TestDonorStoreDeleteWhenOtherDonor(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id", LpaID: "123"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", LpaID: "123"}) keys := []dynamo.Keys{ {PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("sk1")}, @@ -760,7 +674,7 @@ func TestDonorStoreDeleteWhenOtherDonor(t *testing.T) { } func TestDonorStoreDeleteWhenAllKeysByPKErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id", LpaID: "123"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -774,7 +688,7 @@ func TestDonorStoreDeleteWhenAllKeysByPKErrors(t *testing.T) { } func TestDonorStoreDeleteWhenDeleteKeysErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id", LpaID: "123"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -793,8 +707,8 @@ func TestDonorStoreDeleteWhenDeleteKeysErrors(t *testing.T) { func TestDonorStoreDeleteWhenSessionMissing(t *testing.T) { testcases := map[string]context.Context{ "missing": context.Background(), - "no LpaID": page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}), - "no SessionID": page.ContextWithSessionData(context.Background(), &page.SessionData{LpaID: "123"}), + "no LpaID": appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}), + "no SessionID": appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}), } for name, ctx := range testcases { @@ -808,10 +722,10 @@ func TestDonorStoreDeleteWhenSessionMissing(t *testing.T) { } func TestDonorStoreDeleteDonorAccess(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id", OrganisationID: "org-id"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", OrganisationID: "org-id"}) - link := lpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("donor-sub")} - shareCodeData := actor.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")} + link := temporary.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("donor-sub")} + shareCodeData := sharecode.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")} dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), link, nil) @@ -834,58 +748,58 @@ func TestDonorStoreDeleteDonorAccess(t *testing.T) { func TestDonorStoreDeleteDonorAccessWhenDonor(t *testing.T) { donorStore := &donorStore{} - err := donorStore.DeleteDonorAccess(ctx, actor.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor"))}) + err := donorStore.DeleteDonorAccess(ctx, sharecode.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor"))}) assert.Error(t, err) } func TestDonorStoreDeleteDonorAccessWhenSessionMissing(t *testing.T) { testcases := map[string]context.Context{ "missing": context.Background(), - "no organisationID": page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}), + "no organisationID": appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}), } for name, ctx := range testcases { t.Run(name, func(t *testing.T) { donorStore := &donorStore{} - err := donorStore.DeleteDonorAccess(ctx, actor.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org"))}) + err := donorStore.DeleteDonorAccess(ctx, sharecode.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org"))}) assert.Error(t, err) }) } } func TestDonorStoreDeleteDonorAccessWhenDeleterInDifferentOrganisation(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id", OrganisationID: "a-different-org-id"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", OrganisationID: "a-different-org-id"}) donorStore := &donorStore{} - err := donorStore.DeleteDonorAccess(ctx, actor.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")}) + err := donorStore.DeleteDonorAccess(ctx, sharecode.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")}) assert.Error(t, err) } func TestDonorStoreDeleteDonorAccessWhenOneByPartialSKError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id", OrganisationID: "org-id"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", OrganisationID: "org-id"}) dynamoClient := newMockDynamoClient(t) - dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), lpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("donor-sub")}, expectedError) + dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), temporary.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("donor-sub")}, expectedError) donorStore := &donorStore{dynamoClient: dynamoClient} - err := donorStore.DeleteDonorAccess(ctx, actor.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")}) + err := donorStore.DeleteDonorAccess(ctx, sharecode.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")}) assert.Error(t, err) } func TestDonorStoreDeleteDonorAccessWhenWriteTransactionError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id", OrganisationID: "org-id"}) + ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", OrganisationID: "org-id"}) dynamoClient := newMockDynamoClient(t) - dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), lpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("donor-sub")}, nil) + dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), temporary.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("donor-sub")}, nil) dynamoClient.EXPECT(). WriteTransaction(mock.Anything, mock.Anything). Return(expectedError) donorStore := &donorStore{dynamoClient: dynamoClient} - err := donorStore.DeleteDonorAccess(ctx, actor.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")}) + err := donorStore.DeleteDonorAccess(ctx, sharecode.ShareCodeData{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")}) assert.Error(t, err) } diff --git a/internal/donor/donorpage/lpa_type.go b/internal/donor/donorpage/lpa_type.go index 66cbfd43aa..a91718bf48 100644 --- a/internal/donor/donorpage/lpa_type.go +++ b/internal/donor/donorpage/lpa_type.go @@ -5,6 +5,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -36,7 +37,7 @@ func LpaType(tmpl template.Template, donorStore DonorStore, eventClient EventCli data.Errors = data.Form.Validate(donor.Attorneys.TrustCorporation.Name != "" || donor.ReplacementAttorneys.TrustCorporation.Name != "") if data.Errors.None() { - session, err := page.SessionDataFromContext(r.Context()) + session, err := appcontext.SessionDataFromContext(r.Context()) if err != nil { return err } diff --git a/internal/donor/donorpage/lpa_type_test.go b/internal/donor/donorpage/lpa_type_test.go index d2f72d72f1..f45bb3cd36 100644 --- a/internal/donor/donorpage/lpa_type_test.go +++ b/internal/donor/donorpage/lpa_type_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" @@ -112,7 +113,7 @@ func TestPostLpaType(t *testing.T) { "lpa-type": {lpaType.String()}, } - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodPost, "/", strings.NewReader(form.Encode())) @@ -161,7 +162,7 @@ func TestPostLpaTypeWhenTrustCorporation(t *testing.T) { "lpa-type": {actor.LpaTypePersonalWelfare.String()}, } - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodPost, "/", strings.NewReader(form.Encode())) @@ -204,7 +205,7 @@ func TestPostLpaTypeWhenSessionErrors(t *testing.T) { LpaID: "lpa-id", }) - assert.Equal(t, page.SessionMissingError{}, err) + assert.Equal(t, appcontext.SessionMissingError{}, err) } func TestPostLpaTypeWhenEventErrors(t *testing.T) { @@ -212,7 +213,7 @@ func TestPostLpaTypeWhenEventErrors(t *testing.T) { "lpa-type": {actor.LpaTypePropertyAndAffairs.String()}, } - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodPost, "/", strings.NewReader(form.Encode())) @@ -240,7 +241,7 @@ func TestPostLpaTypeWhenStoreErrors(t *testing.T) { "lpa-type": {actor.LpaTypePropertyAndAffairs.String()}, } - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "an-id"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodPost, "/", strings.NewReader(form.Encode())) diff --git a/internal/donor/donorpage/mock_DocumentStore_test.go b/internal/donor/donorpage/mock_DocumentStore_test.go index 97dc9b9082..b4ab4ca0ee 100644 --- a/internal/donor/donorpage/mock_DocumentStore_test.go +++ b/internal/donor/donorpage/mock_DocumentStore_test.go @@ -5,8 +5,7 @@ package donorpage import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" mock "github.com/stretchr/testify/mock" page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -26,7 +25,7 @@ func (_m *mockDocumentStore) EXPECT() *mockDocumentStore_Expecter { } // Create provides a mock function with given fields: _a0, _a1, _a2, _a3 -func (_m *mockDocumentStore) Create(_a0 context.Context, _a1 *actor.DonorProvidedDetails, _a2 string, _a3 []byte) (page.Document, error) { +func (_m *mockDocumentStore) Create(_a0 context.Context, _a1 *donordata.DonorProvidedDetails, _a2 string, _a3 []byte) (page.Document, error) { ret := _m.Called(_a0, _a1, _a2, _a3) if len(ret) == 0 { @@ -35,16 +34,16 @@ func (_m *mockDocumentStore) Create(_a0 context.Context, _a1 *actor.DonorProvide var r0 page.Document var r1 error - if rf, ok := ret.Get(0).(func(context.Context, *actor.DonorProvidedDetails, string, []byte) (page.Document, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.DonorProvidedDetails, string, []byte) (page.Document, error)); ok { return rf(_a0, _a1, _a2, _a3) } - if rf, ok := ret.Get(0).(func(context.Context, *actor.DonorProvidedDetails, string, []byte) page.Document); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.DonorProvidedDetails, string, []byte) page.Document); ok { r0 = rf(_a0, _a1, _a2, _a3) } else { r0 = ret.Get(0).(page.Document) } - if rf, ok := ret.Get(1).(func(context.Context, *actor.DonorProvidedDetails, string, []byte) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, *donordata.DonorProvidedDetails, string, []byte) error); ok { r1 = rf(_a0, _a1, _a2, _a3) } else { r1 = ret.Error(1) @@ -60,16 +59,16 @@ type mockDocumentStore_Create_Call struct { // Create is a helper method to define mock.On call // - _a0 context.Context -// - _a1 *actor.DonorProvidedDetails +// - _a1 *donordata.DonorProvidedDetails // - _a2 string // - _a3 []byte func (_e *mockDocumentStore_Expecter) Create(_a0 interface{}, _a1 interface{}, _a2 interface{}, _a3 interface{}) *mockDocumentStore_Create_Call { return &mockDocumentStore_Create_Call{Call: _e.mock.On("Create", _a0, _a1, _a2, _a3)} } -func (_c *mockDocumentStore_Create_Call) Run(run func(_a0 context.Context, _a1 *actor.DonorProvidedDetails, _a2 string, _a3 []byte)) *mockDocumentStore_Create_Call { +func (_c *mockDocumentStore_Create_Call) Run(run func(_a0 context.Context, _a1 *donordata.DonorProvidedDetails, _a2 string, _a3 []byte)) *mockDocumentStore_Create_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*actor.DonorProvidedDetails), args[2].(string), args[3].([]byte)) + run(args[0].(context.Context), args[1].(*donordata.DonorProvidedDetails), args[2].(string), args[3].([]byte)) }) return _c } @@ -79,7 +78,7 @@ func (_c *mockDocumentStore_Create_Call) Return(_a0 page.Document, _a1 error) *m return _c } -func (_c *mockDocumentStore_Create_Call) RunAndReturn(run func(context.Context, *actor.DonorProvidedDetails, string, []byte) (page.Document, error)) *mockDocumentStore_Create_Call { +func (_c *mockDocumentStore_Create_Call) RunAndReturn(run func(context.Context, *donordata.DonorProvidedDetails, string, []byte) (page.Document, error)) *mockDocumentStore_Create_Call { _c.Call.Return(run) return _c } @@ -284,7 +283,7 @@ func (_c *mockDocumentStore_Put_Call) RunAndReturn(run func(context.Context, pag } // Submit provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockDocumentStore) Submit(_a0 context.Context, _a1 *actor.DonorProvidedDetails, _a2 page.Documents) error { +func (_m *mockDocumentStore) Submit(_a0 context.Context, _a1 *donordata.DonorProvidedDetails, _a2 page.Documents) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -292,7 +291,7 @@ func (_m *mockDocumentStore) Submit(_a0 context.Context, _a1 *actor.DonorProvide } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *actor.DonorProvidedDetails, page.Documents) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.DonorProvidedDetails, page.Documents) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -308,15 +307,15 @@ type mockDocumentStore_Submit_Call struct { // Submit is a helper method to define mock.On call // - _a0 context.Context -// - _a1 *actor.DonorProvidedDetails +// - _a1 *donordata.DonorProvidedDetails // - _a2 page.Documents func (_e *mockDocumentStore_Expecter) Submit(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockDocumentStore_Submit_Call { return &mockDocumentStore_Submit_Call{Call: _e.mock.On("Submit", _a0, _a1, _a2)} } -func (_c *mockDocumentStore_Submit_Call) Run(run func(_a0 context.Context, _a1 *actor.DonorProvidedDetails, _a2 page.Documents)) *mockDocumentStore_Submit_Call { +func (_c *mockDocumentStore_Submit_Call) Run(run func(_a0 context.Context, _a1 *donordata.DonorProvidedDetails, _a2 page.Documents)) *mockDocumentStore_Submit_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*actor.DonorProvidedDetails), args[2].(page.Documents)) + run(args[0].(context.Context), args[1].(*donordata.DonorProvidedDetails), args[2].(page.Documents)) }) return _c } @@ -326,7 +325,7 @@ func (_c *mockDocumentStore_Submit_Call) Return(_a0 error) *mockDocumentStore_Su return _c } -func (_c *mockDocumentStore_Submit_Call) RunAndReturn(run func(context.Context, *actor.DonorProvidedDetails, page.Documents) error) *mockDocumentStore_Submit_Call { +func (_c *mockDocumentStore_Submit_Call) RunAndReturn(run func(context.Context, *donordata.DonorProvidedDetails, page.Documents) error) *mockDocumentStore_Submit_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/mock_DonorStore_test.go b/internal/donor/donorpage/mock_DonorStore_test.go index fdc4d990bf..d5f47b8481 100644 --- a/internal/donor/donorpage/mock_DonorStore_test.go +++ b/internal/donor/donorpage/mock_DonorStore_test.go @@ -5,8 +5,7 @@ package donorpage import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" mock "github.com/stretchr/testify/mock" sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" @@ -72,23 +71,23 @@ func (_c *mockDonorStore_Delete_Call) RunAndReturn(run func(context.Context) err } // Get provides a mock function with given fields: ctx -func (_m *mockDonorStore) Get(ctx context.Context) (*actor.DonorProvidedDetails, error) { +func (_m *mockDonorStore) Get(ctx context.Context) (*donordata.DonorProvidedDetails, error) { ret := _m.Called(ctx) if len(ret) == 0 { panic("no return value specified for Get") } - var r0 *actor.DonorProvidedDetails + var r0 *donordata.DonorProvidedDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*actor.DonorProvidedDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (*donordata.DonorProvidedDetails, error)); ok { return rf(ctx) } - if rf, ok := ret.Get(0).(func(context.Context) *actor.DonorProvidedDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context) *donordata.DonorProvidedDetails); ok { r0 = rf(ctx) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*actor.DonorProvidedDetails) + r0 = ret.Get(0).(*donordata.DonorProvidedDetails) } } @@ -119,34 +118,34 @@ func (_c *mockDonorStore_Get_Call) Run(run func(ctx context.Context)) *mockDonor return _c } -func (_c *mockDonorStore_Get_Call) Return(_a0 *actor.DonorProvidedDetails, _a1 error) *mockDonorStore_Get_Call { +func (_c *mockDonorStore_Get_Call) Return(_a0 *donordata.DonorProvidedDetails, _a1 error) *mockDonorStore_Get_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockDonorStore_Get_Call) RunAndReturn(run func(context.Context) (*actor.DonorProvidedDetails, error)) *mockDonorStore_Get_Call { +func (_c *mockDonorStore_Get_Call) RunAndReturn(run func(context.Context) (*donordata.DonorProvidedDetails, error)) *mockDonorStore_Get_Call { _c.Call.Return(run) return _c } // Latest provides a mock function with given fields: ctx -func (_m *mockDonorStore) Latest(ctx context.Context) (*actor.DonorProvidedDetails, error) { +func (_m *mockDonorStore) Latest(ctx context.Context) (*donordata.DonorProvidedDetails, error) { ret := _m.Called(ctx) if len(ret) == 0 { panic("no return value specified for Latest") } - var r0 *actor.DonorProvidedDetails + var r0 *donordata.DonorProvidedDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*actor.DonorProvidedDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (*donordata.DonorProvidedDetails, error)); ok { return rf(ctx) } - if rf, ok := ret.Get(0).(func(context.Context) *actor.DonorProvidedDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context) *donordata.DonorProvidedDetails); ok { r0 = rf(ctx) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*actor.DonorProvidedDetails) + r0 = ret.Get(0).(*donordata.DonorProvidedDetails) } } @@ -177,12 +176,12 @@ func (_c *mockDonorStore_Latest_Call) Run(run func(ctx context.Context)) *mockDo return _c } -func (_c *mockDonorStore_Latest_Call) Return(_a0 *actor.DonorProvidedDetails, _a1 error) *mockDonorStore_Latest_Call { +func (_c *mockDonorStore_Latest_Call) Return(_a0 *donordata.DonorProvidedDetails, _a1 error) *mockDonorStore_Latest_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockDonorStore_Latest_Call) RunAndReturn(run func(context.Context) (*actor.DonorProvidedDetails, error)) *mockDonorStore_Latest_Call { +func (_c *mockDonorStore_Latest_Call) RunAndReturn(run func(context.Context) (*donordata.DonorProvidedDetails, error)) *mockDonorStore_Latest_Call { _c.Call.Return(run) return _c } @@ -236,7 +235,7 @@ func (_c *mockDonorStore_Link_Call) RunAndReturn(run func(context.Context, share } // Put provides a mock function with given fields: ctx, donor -func (_m *mockDonorStore) Put(ctx context.Context, donor *actor.DonorProvidedDetails) error { +func (_m *mockDonorStore) Put(ctx context.Context, donor *donordata.DonorProvidedDetails) error { ret := _m.Called(ctx, donor) if len(ret) == 0 { @@ -244,7 +243,7 @@ func (_m *mockDonorStore) Put(ctx context.Context, donor *actor.DonorProvidedDet } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *actor.DonorProvidedDetails) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.DonorProvidedDetails) error); ok { r0 = rf(ctx, donor) } else { r0 = ret.Error(0) @@ -260,14 +259,14 @@ type mockDonorStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - donor *actor.DonorProvidedDetails +// - donor *donordata.DonorProvidedDetails func (_e *mockDonorStore_Expecter) Put(ctx interface{}, donor interface{}) *mockDonorStore_Put_Call { return &mockDonorStore_Put_Call{Call: _e.mock.On("Put", ctx, donor)} } -func (_c *mockDonorStore_Put_Call) Run(run func(ctx context.Context, donor *actor.DonorProvidedDetails)) *mockDonorStore_Put_Call { +func (_c *mockDonorStore_Put_Call) Run(run func(ctx context.Context, donor *donordata.DonorProvidedDetails)) *mockDonorStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*actor.DonorProvidedDetails)) + run(args[0].(context.Context), args[1].(*donordata.DonorProvidedDetails)) }) return _c } @@ -277,7 +276,7 @@ func (_c *mockDonorStore_Put_Call) Return(_a0 error) *mockDonorStore_Put_Call { return _c } -func (_c *mockDonorStore_Put_Call) RunAndReturn(run func(context.Context, *actor.DonorProvidedDetails) error) *mockDonorStore_Put_Call { +func (_c *mockDonorStore_Put_Call) RunAndReturn(run func(context.Context, *donordata.DonorProvidedDetails) error) *mockDonorStore_Put_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/mock_GetDonorStore_test.go b/internal/donor/donorpage/mock_GetDonorStore_test.go index d54ac0ceff..153225bd55 100644 --- a/internal/donor/donorpage/mock_GetDonorStore_test.go +++ b/internal/donor/donorpage/mock_GetDonorStore_test.go @@ -5,8 +5,7 @@ package donorpage import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" mock "github.com/stretchr/testify/mock" ) @@ -24,23 +23,23 @@ func (_m *mockGetDonorStore) EXPECT() *mockGetDonorStore_Expecter { } // Get provides a mock function with given fields: _a0 -func (_m *mockGetDonorStore) Get(_a0 context.Context) (*actor.DonorProvidedDetails, error) { +func (_m *mockGetDonorStore) Get(_a0 context.Context) (*donordata.DonorProvidedDetails, error) { ret := _m.Called(_a0) if len(ret) == 0 { panic("no return value specified for Get") } - var r0 *actor.DonorProvidedDetails + var r0 *donordata.DonorProvidedDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*actor.DonorProvidedDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (*donordata.DonorProvidedDetails, error)); ok { return rf(_a0) } - if rf, ok := ret.Get(0).(func(context.Context) *actor.DonorProvidedDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context) *donordata.DonorProvidedDetails); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*actor.DonorProvidedDetails) + r0 = ret.Get(0).(*donordata.DonorProvidedDetails) } } @@ -71,12 +70,12 @@ func (_c *mockGetDonorStore_Get_Call) Run(run func(_a0 context.Context)) *mockGe return _c } -func (_c *mockGetDonorStore_Get_Call) Return(_a0 *actor.DonorProvidedDetails, _a1 error) *mockGetDonorStore_Get_Call { +func (_c *mockGetDonorStore_Get_Call) Return(_a0 *donordata.DonorProvidedDetails, _a1 error) *mockGetDonorStore_Get_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockGetDonorStore_Get_Call) RunAndReturn(run func(context.Context) (*actor.DonorProvidedDetails, error)) *mockGetDonorStore_Get_Call { +func (_c *mockGetDonorStore_Get_Call) RunAndReturn(run func(context.Context) (*donordata.DonorProvidedDetails, error)) *mockGetDonorStore_Get_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/mock_Handler_test.go b/internal/donor/donorpage/mock_Handler_test.go index fe4951dad6..0b6f2da8c1 100644 --- a/internal/donor/donorpage/mock_Handler_test.go +++ b/internal/donor/donorpage/mock_Handler_test.go @@ -5,7 +5,7 @@ package donorpage import ( http "net/http" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" mock "github.com/stretchr/testify/mock" @@ -26,7 +26,7 @@ func (_m *mockHandler) EXPECT() *mockHandler_Expecter { } // Execute provides a mock function with given fields: data, w, r, donor -func (_m *mockHandler) Execute(data page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails) error { +func (_m *mockHandler) Execute(data page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.DonorProvidedDetails) error { ret := _m.Called(data, w, r, donor) if len(ret) == 0 { @@ -34,7 +34,7 @@ func (_m *mockHandler) Execute(data page.AppData, w http.ResponseWriter, r *http } var r0 error - if rf, ok := ret.Get(0).(func(page.AppData, http.ResponseWriter, *http.Request, *actor.DonorProvidedDetails) error); ok { + if rf, ok := ret.Get(0).(func(page.AppData, http.ResponseWriter, *http.Request, *donordata.DonorProvidedDetails) error); ok { r0 = rf(data, w, r, donor) } else { r0 = ret.Error(0) @@ -52,14 +52,14 @@ type mockHandler_Execute_Call struct { // - data page.AppData // - w http.ResponseWriter // - r *http.Request -// - donor *actor.DonorProvidedDetails +// - donor *donordata.DonorProvidedDetails func (_e *mockHandler_Expecter) Execute(data interface{}, w interface{}, r interface{}, donor interface{}) *mockHandler_Execute_Call { return &mockHandler_Execute_Call{Call: _e.mock.On("Execute", data, w, r, donor)} } -func (_c *mockHandler_Execute_Call) Run(run func(data page.AppData, w http.ResponseWriter, r *http.Request, donor *actor.DonorProvidedDetails)) *mockHandler_Execute_Call { +func (_c *mockHandler_Execute_Call) Run(run func(data page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.DonorProvidedDetails)) *mockHandler_Execute_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(page.AppData), args[1].(http.ResponseWriter), args[2].(*http.Request), args[3].(*actor.DonorProvidedDetails)) + run(args[0].(page.AppData), args[1].(http.ResponseWriter), args[2].(*http.Request), args[3].(*donordata.DonorProvidedDetails)) }) return _c } @@ -69,7 +69,7 @@ func (_c *mockHandler_Execute_Call) Return(_a0 error) *mockHandler_Execute_Call return _c } -func (_c *mockHandler_Execute_Call) RunAndReturn(run func(page.AppData, http.ResponseWriter, *http.Request, *actor.DonorProvidedDetails) error) *mockHandler_Execute_Call { +func (_c *mockHandler_Execute_Call) RunAndReturn(run func(page.AppData, http.ResponseWriter, *http.Request, *donordata.DonorProvidedDetails) error) *mockHandler_Execute_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/mock_LpaStoreClient_test.go b/internal/donor/donorpage/mock_LpaStoreClient_test.go index 99af1efc84..8892594ddc 100644 --- a/internal/donor/donorpage/mock_LpaStoreClient_test.go +++ b/internal/donor/donorpage/mock_LpaStoreClient_test.go @@ -5,8 +5,7 @@ package donorpage import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" lpastore "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" mock "github.com/stretchr/testify/mock" @@ -85,7 +84,7 @@ func (_c *mockLpaStoreClient_Lpa_Call) RunAndReturn(run func(context.Context, st } // SendDonorConfirmIdentity provides a mock function with given fields: ctx, donor -func (_m *mockLpaStoreClient) SendDonorConfirmIdentity(ctx context.Context, donor *actor.DonorProvidedDetails) error { +func (_m *mockLpaStoreClient) SendDonorConfirmIdentity(ctx context.Context, donor *donordata.DonorProvidedDetails) error { ret := _m.Called(ctx, donor) if len(ret) == 0 { @@ -93,7 +92,7 @@ func (_m *mockLpaStoreClient) SendDonorConfirmIdentity(ctx context.Context, dono } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *actor.DonorProvidedDetails) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.DonorProvidedDetails) error); ok { r0 = rf(ctx, donor) } else { r0 = ret.Error(0) @@ -109,14 +108,14 @@ type mockLpaStoreClient_SendDonorConfirmIdentity_Call struct { // SendDonorConfirmIdentity is a helper method to define mock.On call // - ctx context.Context -// - donor *actor.DonorProvidedDetails +// - donor *donordata.DonorProvidedDetails func (_e *mockLpaStoreClient_Expecter) SendDonorConfirmIdentity(ctx interface{}, donor interface{}) *mockLpaStoreClient_SendDonorConfirmIdentity_Call { return &mockLpaStoreClient_SendDonorConfirmIdentity_Call{Call: _e.mock.On("SendDonorConfirmIdentity", ctx, donor)} } -func (_c *mockLpaStoreClient_SendDonorConfirmIdentity_Call) Run(run func(ctx context.Context, donor *actor.DonorProvidedDetails)) *mockLpaStoreClient_SendDonorConfirmIdentity_Call { +func (_c *mockLpaStoreClient_SendDonorConfirmIdentity_Call) Run(run func(ctx context.Context, donor *donordata.DonorProvidedDetails)) *mockLpaStoreClient_SendDonorConfirmIdentity_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*actor.DonorProvidedDetails)) + run(args[0].(context.Context), args[1].(*donordata.DonorProvidedDetails)) }) return _c } @@ -126,13 +125,13 @@ func (_c *mockLpaStoreClient_SendDonorConfirmIdentity_Call) Return(_a0 error) *m return _c } -func (_c *mockLpaStoreClient_SendDonorConfirmIdentity_Call) RunAndReturn(run func(context.Context, *actor.DonorProvidedDetails) error) *mockLpaStoreClient_SendDonorConfirmIdentity_Call { +func (_c *mockLpaStoreClient_SendDonorConfirmIdentity_Call) RunAndReturn(run func(context.Context, *donordata.DonorProvidedDetails) error) *mockLpaStoreClient_SendDonorConfirmIdentity_Call { _c.Call.Return(run) return _c } // SendLpa provides a mock function with given fields: ctx, details -func (_m *mockLpaStoreClient) SendLpa(ctx context.Context, details *actor.DonorProvidedDetails) error { +func (_m *mockLpaStoreClient) SendLpa(ctx context.Context, details *donordata.DonorProvidedDetails) error { ret := _m.Called(ctx, details) if len(ret) == 0 { @@ -140,7 +139,7 @@ func (_m *mockLpaStoreClient) SendLpa(ctx context.Context, details *actor.DonorP } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *actor.DonorProvidedDetails) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.DonorProvidedDetails) error); ok { r0 = rf(ctx, details) } else { r0 = ret.Error(0) @@ -156,14 +155,14 @@ type mockLpaStoreClient_SendLpa_Call struct { // SendLpa is a helper method to define mock.On call // - ctx context.Context -// - details *actor.DonorProvidedDetails +// - details *donordata.DonorProvidedDetails func (_e *mockLpaStoreClient_Expecter) SendLpa(ctx interface{}, details interface{}) *mockLpaStoreClient_SendLpa_Call { return &mockLpaStoreClient_SendLpa_Call{Call: _e.mock.On("SendLpa", ctx, details)} } -func (_c *mockLpaStoreClient_SendLpa_Call) Run(run func(ctx context.Context, details *actor.DonorProvidedDetails)) *mockLpaStoreClient_SendLpa_Call { +func (_c *mockLpaStoreClient_SendLpa_Call) Run(run func(ctx context.Context, details *donordata.DonorProvidedDetails)) *mockLpaStoreClient_SendLpa_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*actor.DonorProvidedDetails)) + run(args[0].(context.Context), args[1].(*donordata.DonorProvidedDetails)) }) return _c } @@ -173,7 +172,7 @@ func (_c *mockLpaStoreClient_SendLpa_Call) Return(_a0 error) *mockLpaStoreClient return _c } -func (_c *mockLpaStoreClient_SendLpa_Call) RunAndReturn(run func(context.Context, *actor.DonorProvidedDetails) error) *mockLpaStoreClient_SendLpa_Call { +func (_c *mockLpaStoreClient_SendLpa_Call) RunAndReturn(run func(context.Context, *donordata.DonorProvidedDetails) error) *mockLpaStoreClient_SendLpa_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/mock_ShareCodeSender_test.go b/internal/donor/donorpage/mock_ShareCodeSender_test.go index 05ee217776..71dfcfa59e 100644 --- a/internal/donor/donorpage/mock_ShareCodeSender_test.go +++ b/internal/donor/donorpage/mock_ShareCodeSender_test.go @@ -5,8 +5,7 @@ package donorpage import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" mock "github.com/stretchr/testify/mock" page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -74,7 +73,7 @@ func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) RunAndReturn(r } // SendCertificateProviderPrompt provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context, _a1 page.AppData, _a2 *actor.DonorProvidedDetails) error { +func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context, _a1 page.AppData, _a2 *donordata.DonorProvidedDetails) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -82,7 +81,7 @@ func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, page.AppData, *actor.DonorProvidedDetails) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, page.AppData, *donordata.DonorProvidedDetails) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -99,14 +98,14 @@ type mockShareCodeSender_SendCertificateProviderPrompt_Call struct { // SendCertificateProviderPrompt is a helper method to define mock.On call // - _a0 context.Context // - _a1 page.AppData -// - _a2 *actor.DonorProvidedDetails +// - _a2 *donordata.DonorProvidedDetails func (_e *mockShareCodeSender_Expecter) SendCertificateProviderPrompt(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockShareCodeSender_SendCertificateProviderPrompt_Call { return &mockShareCodeSender_SendCertificateProviderPrompt_Call{Call: _e.mock.On("SendCertificateProviderPrompt", _a0, _a1, _a2)} } -func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) Run(run func(_a0 context.Context, _a1 page.AppData, _a2 *actor.DonorProvidedDetails)) *mockShareCodeSender_SendCertificateProviderPrompt_Call { +func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) Run(run func(_a0 context.Context, _a1 page.AppData, _a2 *donordata.DonorProvidedDetails)) *mockShareCodeSender_SendCertificateProviderPrompt_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(page.AppData), args[2].(*actor.DonorProvidedDetails)) + run(args[0].(context.Context), args[1].(page.AppData), args[2].(*donordata.DonorProvidedDetails)) }) return _c } @@ -116,7 +115,7 @@ func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) Return(_a0 err return _c } -func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) RunAndReturn(run func(context.Context, page.AppData, *actor.DonorProvidedDetails) error) *mockShareCodeSender_SendCertificateProviderPrompt_Call { +func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) RunAndReturn(run func(context.Context, page.AppData, *donordata.DonorProvidedDetails) error) *mockShareCodeSender_SendCertificateProviderPrompt_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/mock_WitnessCodeSender_test.go b/internal/donor/donorpage/mock_WitnessCodeSender_test.go index d6784b3929..fd553c86c8 100644 --- a/internal/donor/donorpage/mock_WitnessCodeSender_test.go +++ b/internal/donor/donorpage/mock_WitnessCodeSender_test.go @@ -5,8 +5,7 @@ package donorpage import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" mock "github.com/stretchr/testify/mock" page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -26,7 +25,7 @@ func (_m *mockWitnessCodeSender) EXPECT() *mockWitnessCodeSender_Expecter { } // SendToCertificateProvider provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockWitnessCodeSender) SendToCertificateProvider(_a0 context.Context, _a1 *actor.DonorProvidedDetails, _a2 page.Localizer) error { +func (_m *mockWitnessCodeSender) SendToCertificateProvider(_a0 context.Context, _a1 *donordata.DonorProvidedDetails, _a2 page.Localizer) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -34,7 +33,7 @@ func (_m *mockWitnessCodeSender) SendToCertificateProvider(_a0 context.Context, } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *actor.DonorProvidedDetails, page.Localizer) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.DonorProvidedDetails, page.Localizer) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -50,15 +49,15 @@ type mockWitnessCodeSender_SendToCertificateProvider_Call struct { // SendToCertificateProvider is a helper method to define mock.On call // - _a0 context.Context -// - _a1 *actor.DonorProvidedDetails +// - _a1 *donordata.DonorProvidedDetails // - _a2 page.Localizer func (_e *mockWitnessCodeSender_Expecter) SendToCertificateProvider(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockWitnessCodeSender_SendToCertificateProvider_Call { return &mockWitnessCodeSender_SendToCertificateProvider_Call{Call: _e.mock.On("SendToCertificateProvider", _a0, _a1, _a2)} } -func (_c *mockWitnessCodeSender_SendToCertificateProvider_Call) Run(run func(_a0 context.Context, _a1 *actor.DonorProvidedDetails, _a2 page.Localizer)) *mockWitnessCodeSender_SendToCertificateProvider_Call { +func (_c *mockWitnessCodeSender_SendToCertificateProvider_Call) Run(run func(_a0 context.Context, _a1 *donordata.DonorProvidedDetails, _a2 page.Localizer)) *mockWitnessCodeSender_SendToCertificateProvider_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*actor.DonorProvidedDetails), args[2].(page.Localizer)) + run(args[0].(context.Context), args[1].(*donordata.DonorProvidedDetails), args[2].(page.Localizer)) }) return _c } @@ -68,13 +67,13 @@ func (_c *mockWitnessCodeSender_SendToCertificateProvider_Call) Return(_a0 error return _c } -func (_c *mockWitnessCodeSender_SendToCertificateProvider_Call) RunAndReturn(run func(context.Context, *actor.DonorProvidedDetails, page.Localizer) error) *mockWitnessCodeSender_SendToCertificateProvider_Call { +func (_c *mockWitnessCodeSender_SendToCertificateProvider_Call) RunAndReturn(run func(context.Context, *donordata.DonorProvidedDetails, page.Localizer) error) *mockWitnessCodeSender_SendToCertificateProvider_Call { _c.Call.Return(run) return _c } // SendToIndependentWitness provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockWitnessCodeSender) SendToIndependentWitness(_a0 context.Context, _a1 *actor.DonorProvidedDetails, _a2 page.Localizer) error { +func (_m *mockWitnessCodeSender) SendToIndependentWitness(_a0 context.Context, _a1 *donordata.DonorProvidedDetails, _a2 page.Localizer) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -82,7 +81,7 @@ func (_m *mockWitnessCodeSender) SendToIndependentWitness(_a0 context.Context, _ } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *actor.DonorProvidedDetails, page.Localizer) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.DonorProvidedDetails, page.Localizer) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -98,15 +97,15 @@ type mockWitnessCodeSender_SendToIndependentWitness_Call struct { // SendToIndependentWitness is a helper method to define mock.On call // - _a0 context.Context -// - _a1 *actor.DonorProvidedDetails +// - _a1 *donordata.DonorProvidedDetails // - _a2 page.Localizer func (_e *mockWitnessCodeSender_Expecter) SendToIndependentWitness(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockWitnessCodeSender_SendToIndependentWitness_Call { return &mockWitnessCodeSender_SendToIndependentWitness_Call{Call: _e.mock.On("SendToIndependentWitness", _a0, _a1, _a2)} } -func (_c *mockWitnessCodeSender_SendToIndependentWitness_Call) Run(run func(_a0 context.Context, _a1 *actor.DonorProvidedDetails, _a2 page.Localizer)) *mockWitnessCodeSender_SendToIndependentWitness_Call { +func (_c *mockWitnessCodeSender_SendToIndependentWitness_Call) Run(run func(_a0 context.Context, _a1 *donordata.DonorProvidedDetails, _a2 page.Localizer)) *mockWitnessCodeSender_SendToIndependentWitness_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*actor.DonorProvidedDetails), args[2].(page.Localizer)) + run(args[0].(context.Context), args[1].(*donordata.DonorProvidedDetails), args[2].(page.Localizer)) }) return _c } @@ -116,7 +115,7 @@ func (_c *mockWitnessCodeSender_SendToIndependentWitness_Call) Return(_a0 error) return _c } -func (_c *mockWitnessCodeSender_SendToIndependentWitness_Call) RunAndReturn(run func(context.Context, *actor.DonorProvidedDetails, page.Localizer) error) *mockWitnessCodeSender_SendToIndependentWitness_Call { +func (_c *mockWitnessCodeSender_SendToIndependentWitness_Call) RunAndReturn(run func(context.Context, *donordata.DonorProvidedDetails, page.Localizer) error) *mockWitnessCodeSender_SendToIndependentWitness_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/register.go b/internal/donor/donorpage/register.go index 5de727823d..c4198bc87d 100644 --- a/internal/donor/donorpage/register.go +++ b/internal/donor/donorpage/register.go @@ -9,6 +9,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" @@ -446,7 +447,7 @@ func makeHandle(mux *http.ServeMux, store SessionStore, errorHandler page.ErrorH appData.SessionID = session.SessionID() appData.LoginSessionEmail = session.Email - ctx = page.ContextWithSessionData(ctx, &page.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID, Email: appData.LoginSessionEmail}) + ctx = page.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID, Email: appData.LoginSessionEmail}) } if err := h(appData, w, r.WithContext(page.ContextWithAppData(ctx, appData))); err != nil { @@ -474,13 +475,13 @@ func makeLpaHandle(mux *http.ServeMux, store SessionStore, errorHandler page.Err appData.SessionID = loginSession.SessionID() appData.LoginSessionEmail = loginSession.Email - sessionData, err := page.SessionDataFromContext(ctx) + sessionData, err := appcontext.SessionDataFromContext(ctx) if err == nil { sessionData.SessionID = appData.SessionID sessionData.LpaID = appData.LpaID ctx = page.ContextWithSessionData(ctx, sessionData) } else { - sessionData = &page.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID} + sessionData = &appcontext.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID} ctx = page.ContextWithSessionData(ctx, sessionData) } diff --git a/internal/donor/donorpage/register_test.go b/internal/donor/donorpage/register_test.go index ac8a9aae5f..22158016e9 100644 --- a/internal/donor/donorpage/register_test.go +++ b/internal/donor/donorpage/register_test.go @@ -9,6 +9,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" lpastore "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" @@ -123,7 +124,7 @@ func TestMakeLpaHandleWhenDetailsProvidedAndUIDExists(t *testing.T) { testCases := map[string]struct { expectedAppData page.AppData loginSesh *sesh.LoginSession - expectedSessionData *page.SessionData + expectedSessionData *appcontext.SessionData }{ "donor": { expectedAppData: page.AppData{ @@ -133,7 +134,7 @@ func TestMakeLpaHandleWhenDetailsProvidedAndUIDExists(t *testing.T) { LpaID: "123", }, loginSesh: &sesh.LoginSession{Sub: "random"}, - expectedSessionData: &page.SessionData{SessionID: "cmFuZG9t", LpaID: "123"}, + expectedSessionData: &appcontext.SessionData{SessionID: "cmFuZG9t", LpaID: "123"}, }, "organisation": { expectedAppData: page.AppData{ @@ -147,7 +148,7 @@ func TestMakeLpaHandleWhenDetailsProvidedAndUIDExists(t *testing.T) { }, }, loginSesh: &sesh.LoginSession{Sub: "random", OrganisationID: "org-id"}, - expectedSessionData: &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", LpaID: "123"}, + expectedSessionData: &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", LpaID: "123"}, }, } @@ -184,7 +185,7 @@ func TestMakeLpaHandleWhenDetailsProvidedAndUIDExists(t *testing.T) { assert.Equal(t, w, hw) - sessionData, _ := page.SessionDataFromContext(hr.Context()) + sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) assert.Equal(t, tc.expectedSessionData, sessionData) hw.WriteHeader(http.StatusTeapot) @@ -353,7 +354,7 @@ func TestMakeLpaHandleWhenCannotGoToURL(t *testing.T) { } func TestMakeLpaHandleSessionExistingSessionData(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &page.SessionData{SessionID: "ignored"}) + ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/lpa/123/path?a=b", nil) @@ -379,9 +380,9 @@ func TestMakeLpaHandleSessionExistingSessionData(t *testing.T) { }, appData) assert.Equal(t, w, hw) - sessionData, _ := page.SessionDataFromContext(hr.Context()) + sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) - assert.Equal(t, &page.SessionData{LpaID: "123", SessionID: "cmFuZG9t"}, sessionData) + assert.Equal(t, &appcontext.SessionData{LpaID: "123", SessionID: "cmFuZG9t"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil }) diff --git a/internal/lpastore/mock_DonorStore_test.go b/internal/lpastore/mock_DonorStore_test.go index c0f277cd64..0e7346efb8 100644 --- a/internal/lpastore/mock_DonorStore_test.go +++ b/internal/lpastore/mock_DonorStore_test.go @@ -5,8 +5,7 @@ package lpastore import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" mock "github.com/stretchr/testify/mock" ) @@ -24,23 +23,23 @@ func (_m *mockDonorStore) EXPECT() *mockDonorStore_Expecter { } // GetAny provides a mock function with given fields: ctx -func (_m *mockDonorStore) GetAny(ctx context.Context) (*actor.DonorProvidedDetails, error) { +func (_m *mockDonorStore) GetAny(ctx context.Context) (*donordata.DonorProvidedDetails, error) { ret := _m.Called(ctx) if len(ret) == 0 { panic("no return value specified for GetAny") } - var r0 *actor.DonorProvidedDetails + var r0 *donordata.DonorProvidedDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*actor.DonorProvidedDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (*donordata.DonorProvidedDetails, error)); ok { return rf(ctx) } - if rf, ok := ret.Get(0).(func(context.Context) *actor.DonorProvidedDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context) *donordata.DonorProvidedDetails); ok { r0 = rf(ctx) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*actor.DonorProvidedDetails) + r0 = ret.Get(0).(*donordata.DonorProvidedDetails) } } @@ -71,12 +70,12 @@ func (_c *mockDonorStore_GetAny_Call) Run(run func(ctx context.Context)) *mockDo return _c } -func (_c *mockDonorStore_GetAny_Call) Return(_a0 *actor.DonorProvidedDetails, _a1 error) *mockDonorStore_GetAny_Call { +func (_c *mockDonorStore_GetAny_Call) Return(_a0 *donordata.DonorProvidedDetails, _a1 error) *mockDonorStore_GetAny_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockDonorStore_GetAny_Call) RunAndReturn(run func(context.Context) (*actor.DonorProvidedDetails, error)) *mockDonorStore_GetAny_Call { +func (_c *mockDonorStore_GetAny_Call) RunAndReturn(run func(context.Context) (*donordata.DonorProvidedDetails, error)) *mockDonorStore_GetAny_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/data.go b/internal/page/data.go index 1ec42d00fc..eb3367655d 100644 --- a/internal/page/data.go +++ b/internal/page/data.go @@ -17,9 +17,6 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/form" ) -type SessionData = appcontext.SessionData -type SessionMissingError = appcontext.SessionMissingError - var SessionDataFromContext = appcontext.SessionDataFromContext var ContextWithSessionData = appcontext.ContextWithSessionData diff --git a/internal/page/fixtures/attorney.go b/internal/page/fixtures/attorney.go index dad246727f..ed27333432 100644 --- a/internal/page/fixtures/attorney.go +++ b/internal/page/fixtures/attorney.go @@ -11,6 +11,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" @@ -105,11 +106,11 @@ func Attorney( } createFn := donorStore.Create - createSession := &page.SessionData{SessionID: donorSessionID} + createSession := &appcontext.SessionData{SessionID: donorSessionID} if isSupported { createFn = organisationStore.CreateLPA - supporterCtx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID, Email: testEmail}) + supporterCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, Email: testEmail}) member, err := memberStore.Create(supporterCtx, random.String(12), random.String(12)) if err != nil { @@ -138,9 +139,9 @@ func Attorney( } var ( - donorCtx = page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID, LpaID: donorDetails.LpaID}) - certificateProviderCtx = page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: certificateProviderSessionID, LpaID: donorDetails.LpaID}) - attorneyCtx = page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: attorneySessionID, LpaID: donorDetails.LpaID}) + donorCtx = page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, LpaID: donorDetails.LpaID}) + certificateProviderCtx = page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: certificateProviderSessionID, LpaID: donorDetails.LpaID}) + attorneyCtx = page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: attorneySessionID, LpaID: donorDetails.LpaID}) ) donorDetails.SignedAt = time.Now() @@ -266,7 +267,7 @@ func Attorney( if progress >= slices.Index(progressValues, "signedByAllAttorneys") { for isReplacement, list := range map[bool]actor.Attorneys{false: donorDetails.Attorneys, true: donorDetails.ReplacementAttorneys} { for _, a := range list.Attorneys { - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) attorney, err := createAttorney( ctx, @@ -297,7 +298,7 @@ func Attorney( } if list.TrustCorporation.Name != "" { - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) attorney, err := createAttorney( ctx, diff --git a/internal/page/fixtures/certificate_provider.go b/internal/page/fixtures/certificate_provider.go index 24ba87df80..1855ce3b11 100644 --- a/internal/page/fixtures/certificate_provider.go +++ b/internal/page/fixtures/certificate_provider.go @@ -8,6 +8,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" @@ -100,7 +101,7 @@ func CertificateProvider( return err } } else if isSupported { - supporterCtx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID, Email: testEmail}) + supporterCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, Email: testEmail}) member, err := memberStore.Create(supporterCtx, random.String(12), random.String(12)) if err != nil { @@ -112,7 +113,7 @@ func CertificateProvider( return err } - orgSession := &page.SessionData{SessionID: donorSessionID, OrganisationID: org.ID} + orgSession := &appcontext.SessionData{SessionID: donorSessionID, OrganisationID: org.ID} donorDetails, err = organisationStore.CreateLPA(page.ContextWithSessionData(r.Context(), orgSession)) if err != nil { return err @@ -125,15 +126,15 @@ func CertificateProvider( return err } } else { - donorDetails, err = donorStore.Create(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID})) + donorDetails, err = donorStore.Create(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID})) if err != nil { return err } } var ( - donorCtx = page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID, LpaID: donorDetails.LpaID}) - certificateProviderCtx = page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: certificateProviderSessionID, LpaID: donorDetails.LpaID}) + donorCtx = page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, LpaID: donorDetails.LpaID}) + certificateProviderCtx = page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: certificateProviderSessionID, LpaID: donorDetails.LpaID}) ) donorDetails.Donor = makeDonor(donorEmail) diff --git a/internal/page/fixtures/dashboard.go b/internal/page/fixtures/dashboard.go index 88f9a531e0..9df0cf4be5 100644 --- a/internal/page/fixtures/dashboard.go +++ b/internal/page/fixtures/dashboard.go @@ -6,6 +6,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/random" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" @@ -44,12 +45,12 @@ func Dashboard( } if asDonor { - donor, err := donorStore.Create(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: meSessionID})) + donor, err := donorStore.Create(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: meSessionID})) if err != nil { return err } - donorCtx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: meSessionID, LpaID: donor.LpaID}) + donorCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: meSessionID, LpaID: donor.LpaID}) donor.LpaUID = makeUID() donor.Donor = makeDonor(testEmail) @@ -65,18 +66,18 @@ func Dashboard( } if asCertificateProvider { - donor, err := donorStore.Create(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID})) + donor, err := donorStore.Create(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID})) if err != nil { return err } donor.Donor = makeDonor(testEmail) donor.LpaUID = makeUID() - if err := donorStore.Put(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID, LpaID: donor.LpaID}), donor); err != nil { + if err := donorStore.Put(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, LpaID: donor.LpaID}), donor); err != nil { return err } - certificateProviderCtx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: meSessionID, LpaID: donor.LpaID}) + certificateProviderCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: meSessionID, LpaID: donor.LpaID}) _, err = createCertificateProvider(certificateProviderCtx, shareCodeStore, certificateProviderStore, donor.CertificateProvider.UID, donor.SK, testEmail) if err != nil { @@ -85,7 +86,7 @@ func Dashboard( } if asAttorney { - donor, err := donorStore.Create(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID})) + donor, err := donorStore.Create(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID})) if err != nil { return err } @@ -95,11 +96,11 @@ func Dashboard( } donor.LpaUID = makeUID() - if err := donorStore.Put(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID, LpaID: donor.LpaID}), donor); err != nil { + if err := donorStore.Put(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, LpaID: donor.LpaID}), donor); err != nil { return err } - attorneyCtx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: meSessionID, LpaID: donor.LpaID}) + attorneyCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: meSessionID, LpaID: donor.LpaID}) attorney, err := createAttorney( attorneyCtx, diff --git a/internal/page/fixtures/donor.go b/internal/page/fixtures/donor.go index e0e7813a81..f79669e58a 100644 --- a/internal/page/fixtures/donor.go +++ b/internal/page/fixtures/donor.go @@ -12,6 +12,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" @@ -115,7 +116,7 @@ func Donor( return err } - donorDetails, err := donorStore.Create(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID})) + donorDetails, err := donorStore.Create(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID})) if err != nil { return err } @@ -126,7 +127,7 @@ func Donor( return err } - donorCtx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID, LpaID: donorDetails.LpaID}) + donorCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, LpaID: donorDetails.LpaID}) if data.Progress >= slices.Index(progressValues, "checkAndSendToYourCertificateProvider") { if err = donorDetails.UpdateCheckedHash(); err != nil { @@ -349,7 +350,7 @@ func updateLPAProgress( donorDetails.FeeType = feeType stagedForUpload, err := documentStore.Create( - page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID}), + page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID}), donorDetails, "supporting-evidence.png", make([]byte, 64), @@ -362,12 +363,12 @@ func updateLPAProgress( stagedForUpload.Scanned = true stagedForUpload.VirusDetected = data.WithVirus - if err := documentStore.Put(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID}), stagedForUpload); err != nil { + if err := documentStore.Put(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID}), stagedForUpload); err != nil { return nil, nil, err } previouslyUploaded, err := documentStore.Create( - page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID}), + page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID}), donorDetails, "previously-uploaded-evidence.png", make([]byte, 64), @@ -381,7 +382,7 @@ func updateLPAProgress( previouslyUploaded.VirusDetected = false previouslyUploaded.Sent = time.Now() - if err := documentStore.Put(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: donorSessionID}), previouslyUploaded); err != nil { + if err := documentStore.Put(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID}), previouslyUploaded); err != nil { return nil, nil, err } } else { @@ -447,7 +448,7 @@ func updateLPAProgress( var certificateProviderUID actoruid.UID if data.Progress >= slices.Index(progressValues, "signedByCertificateProvider") { - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) certificateProvider, err := createCertificateProvider(ctx, shareCodeStore, certificateProviderStore, donorDetails.CertificateProvider.UID, donorDetails.SK, donorDetails.CertificateProvider.Email) if err != nil { @@ -471,7 +472,7 @@ func updateLPAProgress( if data.Progress >= slices.Index(progressValues, "signedByAttorneys") { for isReplacement, list := range map[bool]actor.Attorneys{false: donorDetails.Attorneys, true: donorDetails.ReplacementAttorneys} { for _, a := range list.Attorneys { - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) attorney, err := createAttorney( ctx, @@ -504,7 +505,7 @@ func updateLPAProgress( } if list.TrustCorporation.Name != "" { - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) attorney, err := createAttorney( ctx, diff --git a/internal/page/fixtures/supporter.go b/internal/page/fixtures/supporter.go index 2a17d213a1..4c6ebdf408 100644 --- a/internal/page/fixtures/supporter.go +++ b/internal/page/fixtures/supporter.go @@ -11,6 +11,7 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" @@ -70,7 +71,7 @@ func Supporter( supporterSub = random.String(16) supporterSessionID = base64.StdEncoding.EncodeToString([]byte(supporterSub)) - supporterCtx = page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: supporterSessionID, Email: testEmail}) + supporterCtx = page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: supporterSessionID, Email: testEmail}) ) loginSession := &sesh.LoginSession{Sub: supporterSub, Email: testEmail} @@ -89,7 +90,7 @@ func Supporter( loginSession.OrganisationID = org.ID loginSession.OrganisationName = org.Name - organisationCtx := page.ContextWithSessionData(r.Context(), &page.SessionData{OrganisationID: org.ID}) + organisationCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{OrganisationID: org.ID}) if suspended { member.Status = actor.StatusSuspended @@ -104,7 +105,7 @@ func Supporter( if err != nil { return err } - donorCtx := page.ContextWithSessionData(r.Context(), &page.SessionData{OrganisationID: org.ID, LpaID: donor.LpaID, SessionID: random.String(12)}) + donorCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{OrganisationID: org.ID, LpaID: donor.LpaID, SessionID: random.String(12)}) donor.LpaUID = makeUID() donor.Donor = makeDonor(testEmail) @@ -157,7 +158,7 @@ func Supporter( if err != nil { return err } - donorCtx := page.ContextWithSessionData(r.Context(), &page.SessionData{OrganisationID: org.ID, LpaID: donor.LpaID}) + donorCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{OrganisationID: org.ID, LpaID: donor.LpaID}) donor.LpaUID = makeUID() donor.Donor = makeDonor(testEmail) @@ -230,7 +231,7 @@ func Supporter( ReferenceNumber: random.String(12), } - if err := dynamoClient.Create(page.ContextWithSessionData(r.Context(), &page.SessionData{OrganisationID: org.ID}), invite); err != nil { + if err := dynamoClient.Create(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{OrganisationID: org.ID}), invite); err != nil { return fmt.Errorf("error creating member invite: %w", err) } } @@ -256,7 +257,7 @@ func Supporter( email := strings.ToLower(fmt.Sprintf("%s-%s@example.org", member.Firstnames, member.Lastname)) sub := []byte(random.String(16)) - memberCtx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: base64.StdEncoding.EncodeToString(sub), Email: email}) + memberCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: base64.StdEncoding.EncodeToString(sub), Email: email}) if err = memberStore.CreateFromInvite( memberCtx, diff --git a/internal/page/mock_DonorStore_test.go b/internal/page/mock_DonorStore_test.go index 9e5ce7b288..f62b20241c 100644 --- a/internal/page/mock_DonorStore_test.go +++ b/internal/page/mock_DonorStore_test.go @@ -5,8 +5,7 @@ package page import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" mock "github.com/stretchr/testify/mock" ) @@ -24,23 +23,23 @@ func (_m *mockDonorStore) EXPECT() *mockDonorStore_Expecter { } // Create provides a mock function with given fields: _a0 -func (_m *mockDonorStore) Create(_a0 context.Context) (*actor.DonorProvidedDetails, error) { +func (_m *mockDonorStore) Create(_a0 context.Context) (*donordata.DonorProvidedDetails, error) { ret := _m.Called(_a0) if len(ret) == 0 { panic("no return value specified for Create") } - var r0 *actor.DonorProvidedDetails + var r0 *donordata.DonorProvidedDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*actor.DonorProvidedDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (*donordata.DonorProvidedDetails, error)); ok { return rf(_a0) } - if rf, ok := ret.Get(0).(func(context.Context) *actor.DonorProvidedDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context) *donordata.DonorProvidedDetails); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*actor.DonorProvidedDetails) + r0 = ret.Get(0).(*donordata.DonorProvidedDetails) } } @@ -71,18 +70,18 @@ func (_c *mockDonorStore_Create_Call) Run(run func(_a0 context.Context)) *mockDo return _c } -func (_c *mockDonorStore_Create_Call) Return(_a0 *actor.DonorProvidedDetails, _a1 error) *mockDonorStore_Create_Call { +func (_c *mockDonorStore_Create_Call) Return(_a0 *donordata.DonorProvidedDetails, _a1 error) *mockDonorStore_Create_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockDonorStore_Create_Call) RunAndReturn(run func(context.Context) (*actor.DonorProvidedDetails, error)) *mockDonorStore_Create_Call { +func (_c *mockDonorStore_Create_Call) RunAndReturn(run func(context.Context) (*donordata.DonorProvidedDetails, error)) *mockDonorStore_Create_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: _a0, _a1 -func (_m *mockDonorStore) Put(_a0 context.Context, _a1 *actor.DonorProvidedDetails) error { +func (_m *mockDonorStore) Put(_a0 context.Context, _a1 *donordata.DonorProvidedDetails) error { ret := _m.Called(_a0, _a1) if len(ret) == 0 { @@ -90,7 +89,7 @@ func (_m *mockDonorStore) Put(_a0 context.Context, _a1 *actor.DonorProvidedDetai } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *actor.DonorProvidedDetails) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.DonorProvidedDetails) error); ok { r0 = rf(_a0, _a1) } else { r0 = ret.Error(0) @@ -106,14 +105,14 @@ type mockDonorStore_Put_Call struct { // Put is a helper method to define mock.On call // - _a0 context.Context -// - _a1 *actor.DonorProvidedDetails +// - _a1 *donordata.DonorProvidedDetails func (_e *mockDonorStore_Expecter) Put(_a0 interface{}, _a1 interface{}) *mockDonorStore_Put_Call { return &mockDonorStore_Put_Call{Call: _e.mock.On("Put", _a0, _a1)} } -func (_c *mockDonorStore_Put_Call) Run(run func(_a0 context.Context, _a1 *actor.DonorProvidedDetails)) *mockDonorStore_Put_Call { +func (_c *mockDonorStore_Put_Call) Run(run func(_a0 context.Context, _a1 *donordata.DonorProvidedDetails)) *mockDonorStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*actor.DonorProvidedDetails)) + run(args[0].(context.Context), args[1].(*donordata.DonorProvidedDetails)) }) return _c } @@ -123,7 +122,7 @@ func (_c *mockDonorStore_Put_Call) Return(_a0 error) *mockDonorStore_Put_Call { return _c } -func (_c *mockDonorStore_Put_Call) RunAndReturn(run func(context.Context, *actor.DonorProvidedDetails) error) *mockDonorStore_Put_Call { +func (_c *mockDonorStore_Put_Call) RunAndReturn(run func(context.Context, *donordata.DonorProvidedDetails) error) *mockDonorStore_Put_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/supporter/login_callback.go b/internal/page/supporter/login_callback.go index 543855d6f9..ad71944366 100644 --- a/internal/page/supporter/login_callback.go +++ b/internal/page/supporter/login_callback.go @@ -7,6 +7,7 @@ import ( "net/http" "time" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -50,7 +51,7 @@ func LoginCallback(logger Logger, oneLoginClient LoginCallbackOneLoginClient, se logger.InfoContext(r.Context(), "login", slog.String("session_id", loginSession.SessionID())) - sessionData := &page.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email} + sessionData := &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email} ctx := page.ContextWithSessionData(r.Context(), sessionData) member, err := memberStore.GetAny(ctx) diff --git a/internal/page/supporter/login_callback_test.go b/internal/page/supporter/login_callback_test.go index de98e47e20..ca94a62e61 100644 --- a/internal/page/supporter/login_callback_test.go +++ b/internal/page/supporter/login_callback_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -211,12 +212,12 @@ func TestLoginCallbackHasMember(t *testing.T) { memberStore := newMockMemberStore(t) memberStore.EXPECT(). - GetAny(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email})). + GetAny(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email})). Return(&actor.Member{}, nil) organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email})). Return(nil, dynamo.NotFoundError{}) logger := newMockLogger(t) @@ -287,7 +288,7 @@ func TestLoginCallbackHasMemberWhenOrganisationGetErrors(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/?code=auth-code&state=my-state", nil) - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email}) + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email}) client := newMockOneLoginClient(t) client.EXPECT(). @@ -376,16 +377,16 @@ func TestLoginCallbackHasOrganisation(t *testing.T) { memberStore := newMockMemberStore(t) memberStore.EXPECT(). - GetAny(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email})). + GetAny(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email})). Return(&actor.Member{Email: tc.existingMemberEmail}, nil) memberStore.EXPECT(). - Put(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email, OrganisationID: "org-id"}), &actor.Member{Email: tc.loginSessionEmail, LastLoggedInAt: testNow}). + Put(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email, OrganisationID: "org-id"}), &actor.Member{Email: tc.loginSessionEmail, LastLoggedInAt: testNow}). Return(nil) organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email})). Return(&actor.Organisation{ID: "org-id", Name: "org name"}, nil) logger := newMockLogger(t) diff --git a/internal/page/supporter/mock_DonorStore_test.go b/internal/page/supporter/mock_DonorStore_test.go index 53dffd3255..04498589b4 100644 --- a/internal/page/supporter/mock_DonorStore_test.go +++ b/internal/page/supporter/mock_DonorStore_test.go @@ -5,8 +5,7 @@ package supporter import ( context "context" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" dynamo "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" mock "github.com/stretchr/testify/mock" @@ -75,23 +74,23 @@ func (_c *mockDonorStore_DeleteDonorAccess_Call) RunAndReturn(run func(context.C } // Get provides a mock function with given fields: ctx -func (_m *mockDonorStore) Get(ctx context.Context) (*actor.DonorProvidedDetails, error) { +func (_m *mockDonorStore) Get(ctx context.Context) (*donordata.DonorProvidedDetails, error) { ret := _m.Called(ctx) if len(ret) == 0 { panic("no return value specified for Get") } - var r0 *actor.DonorProvidedDetails + var r0 *donordata.DonorProvidedDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*actor.DonorProvidedDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (*donordata.DonorProvidedDetails, error)); ok { return rf(ctx) } - if rf, ok := ret.Get(0).(func(context.Context) *actor.DonorProvidedDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context) *donordata.DonorProvidedDetails); ok { r0 = rf(ctx) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*actor.DonorProvidedDetails) + r0 = ret.Get(0).(*donordata.DonorProvidedDetails) } } @@ -122,34 +121,34 @@ func (_c *mockDonorStore_Get_Call) Run(run func(ctx context.Context)) *mockDonor return _c } -func (_c *mockDonorStore_Get_Call) Return(_a0 *actor.DonorProvidedDetails, _a1 error) *mockDonorStore_Get_Call { +func (_c *mockDonorStore_Get_Call) Return(_a0 *donordata.DonorProvidedDetails, _a1 error) *mockDonorStore_Get_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockDonorStore_Get_Call) RunAndReturn(run func(context.Context) (*actor.DonorProvidedDetails, error)) *mockDonorStore_Get_Call { +func (_c *mockDonorStore_Get_Call) RunAndReturn(run func(context.Context) (*donordata.DonorProvidedDetails, error)) *mockDonorStore_Get_Call { _c.Call.Return(run) return _c } // GetByKeys provides a mock function with given fields: ctx, keys -func (_m *mockDonorStore) GetByKeys(ctx context.Context, keys []dynamo.Keys) ([]actor.DonorProvidedDetails, error) { +func (_m *mockDonorStore) GetByKeys(ctx context.Context, keys []dynamo.Keys) ([]donordata.DonorProvidedDetails, error) { ret := _m.Called(ctx, keys) if len(ret) == 0 { panic("no return value specified for GetByKeys") } - var r0 []actor.DonorProvidedDetails + var r0 []donordata.DonorProvidedDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) ([]actor.DonorProvidedDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) ([]donordata.DonorProvidedDetails, error)); ok { return rf(ctx, keys) } - if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) []actor.DonorProvidedDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context, []dynamo.Keys) []donordata.DonorProvidedDetails); ok { r0 = rf(ctx, keys) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]actor.DonorProvidedDetails) + r0 = ret.Get(0).([]donordata.DonorProvidedDetails) } } @@ -181,18 +180,18 @@ func (_c *mockDonorStore_GetByKeys_Call) Run(run func(ctx context.Context, keys return _c } -func (_c *mockDonorStore_GetByKeys_Call) Return(_a0 []actor.DonorProvidedDetails, _a1 error) *mockDonorStore_GetByKeys_Call { +func (_c *mockDonorStore_GetByKeys_Call) Return(_a0 []donordata.DonorProvidedDetails, _a1 error) *mockDonorStore_GetByKeys_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockDonorStore_GetByKeys_Call) RunAndReturn(run func(context.Context, []dynamo.Keys) ([]actor.DonorProvidedDetails, error)) *mockDonorStore_GetByKeys_Call { +func (_c *mockDonorStore_GetByKeys_Call) RunAndReturn(run func(context.Context, []dynamo.Keys) ([]donordata.DonorProvidedDetails, error)) *mockDonorStore_GetByKeys_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: ctx, donor -func (_m *mockDonorStore) Put(ctx context.Context, donor *actor.DonorProvidedDetails) error { +func (_m *mockDonorStore) Put(ctx context.Context, donor *donordata.DonorProvidedDetails) error { ret := _m.Called(ctx, donor) if len(ret) == 0 { @@ -200,7 +199,7 @@ func (_m *mockDonorStore) Put(ctx context.Context, donor *actor.DonorProvidedDet } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, *actor.DonorProvidedDetails) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, *donordata.DonorProvidedDetails) error); ok { r0 = rf(ctx, donor) } else { r0 = ret.Error(0) @@ -216,14 +215,14 @@ type mockDonorStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - donor *actor.DonorProvidedDetails +// - donor *donordata.DonorProvidedDetails func (_e *mockDonorStore_Expecter) Put(ctx interface{}, donor interface{}) *mockDonorStore_Put_Call { return &mockDonorStore_Put_Call{Call: _e.mock.On("Put", ctx, donor)} } -func (_c *mockDonorStore_Put_Call) Run(run func(ctx context.Context, donor *actor.DonorProvidedDetails)) *mockDonorStore_Put_Call { +func (_c *mockDonorStore_Put_Call) Run(run func(ctx context.Context, donor *donordata.DonorProvidedDetails)) *mockDonorStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*actor.DonorProvidedDetails)) + run(args[0].(context.Context), args[1].(*donordata.DonorProvidedDetails)) }) return _c } @@ -233,7 +232,7 @@ func (_c *mockDonorStore_Put_Call) Return(_a0 error) *mockDonorStore_Put_Call { return _c } -func (_c *mockDonorStore_Put_Call) RunAndReturn(run func(context.Context, *actor.DonorProvidedDetails) error) *mockDonorStore_Put_Call { +func (_c *mockDonorStore_Put_Call) RunAndReturn(run func(context.Context, *donordata.DonorProvidedDetails) error) *mockDonorStore_Put_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/supporter/mock_OrganisationStore_test.go b/internal/page/supporter/mock_OrganisationStore_test.go index 602889b0d8..f7d30efeed 100644 --- a/internal/page/supporter/mock_OrganisationStore_test.go +++ b/internal/page/supporter/mock_OrganisationStore_test.go @@ -7,6 +7,8 @@ import ( actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" + mock "github.com/stretchr/testify/mock" ) @@ -84,23 +86,23 @@ func (_c *mockOrganisationStore_Create_Call) RunAndReturn(run func(context.Conte } // CreateLPA provides a mock function with given fields: ctx -func (_m *mockOrganisationStore) CreateLPA(ctx context.Context) (*actor.DonorProvidedDetails, error) { +func (_m *mockOrganisationStore) CreateLPA(ctx context.Context) (*donordata.DonorProvidedDetails, error) { ret := _m.Called(ctx) if len(ret) == 0 { panic("no return value specified for CreateLPA") } - var r0 *actor.DonorProvidedDetails + var r0 *donordata.DonorProvidedDetails var r1 error - if rf, ok := ret.Get(0).(func(context.Context) (*actor.DonorProvidedDetails, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context) (*donordata.DonorProvidedDetails, error)); ok { return rf(ctx) } - if rf, ok := ret.Get(0).(func(context.Context) *actor.DonorProvidedDetails); ok { + if rf, ok := ret.Get(0).(func(context.Context) *donordata.DonorProvidedDetails); ok { r0 = rf(ctx) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*actor.DonorProvidedDetails) + r0 = ret.Get(0).(*donordata.DonorProvidedDetails) } } @@ -131,12 +133,12 @@ func (_c *mockOrganisationStore_CreateLPA_Call) Run(run func(ctx context.Context return _c } -func (_c *mockOrganisationStore_CreateLPA_Call) Return(_a0 *actor.DonorProvidedDetails, _a1 error) *mockOrganisationStore_CreateLPA_Call { +func (_c *mockOrganisationStore_CreateLPA_Call) Return(_a0 *donordata.DonorProvidedDetails, _a1 error) *mockOrganisationStore_CreateLPA_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockOrganisationStore_CreateLPA_Call) RunAndReturn(run func(context.Context) (*actor.DonorProvidedDetails, error)) *mockOrganisationStore_CreateLPA_Call { +func (_c *mockOrganisationStore_CreateLPA_Call) RunAndReturn(run func(context.Context) (*donordata.DonorProvidedDetails, error)) *mockOrganisationStore_CreateLPA_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/supporter/register.go b/internal/page/supporter/register.go index 841b9cb094..8cb0f93eb9 100644 --- a/internal/page/supporter/register.go +++ b/internal/page/supporter/register.go @@ -9,6 +9,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" @@ -198,7 +199,7 @@ func makeHandle(mux *http.ServeMux, store SessionStore, errorHandler page.ErrorH appData.SessionID = session.SessionID() - ctx = page.ContextWithSessionData(ctx, &page.SessionData{SessionID: appData.SessionID, Email: session.Email}) + ctx = page.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: appData.SessionID, Email: session.Email}) } if err := h(appData, w, r.WithContext(page.ContextWithAppData(ctx, appData))); err != nil { @@ -249,13 +250,13 @@ func makeSupporterHandle(mux *http.ServeMux, store SessionStore, errorHandler pa panic("non-supporter path registered") } - sessionData, err := page.SessionDataFromContext(r.Context()) + sessionData, err := appcontext.SessionDataFromContext(r.Context()) if err == nil { sessionData.SessionID = appData.SessionID sessionData.OrganisationID = loginSession.OrganisationID } else { - sessionData = &page.SessionData{ + sessionData = &appcontext.SessionData{ SessionID: appData.SessionID, Email: loginSession.Email, } @@ -271,7 +272,7 @@ func makeSupporterHandle(mux *http.ServeMux, store SessionStore, errorHandler pa return } - ctx := page.ContextWithSessionData(r.Context(), &page.SessionData{ + ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{ SessionID: appData.SessionID, Email: loginSession.Email, OrganisationID: organisation.ID, diff --git a/internal/page/supporter/register_test.go b/internal/page/supporter/register_test.go index 8ebafc153b..450321a462 100644 --- a/internal/page/supporter/register_test.go +++ b/internal/page/supporter/register_test.go @@ -8,6 +8,7 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" @@ -129,12 +130,12 @@ func TestMakeSupporterHandle(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Organisation{ID: "org-id"}, nil) memberStore := newMockMemberStore(t) memberStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Member{Permission: actor.PermissionAdmin, ID: "member-id"}, nil) handle := makeSupporterHandle(mux, sessionStore, nil, organisationStore, memberStore, nil) @@ -152,8 +153,8 @@ func TestMakeSupporterHandle(t *testing.T) { assert.Equal(t, w, hw) - sessionData, _ := page.SessionDataFromContext(hr.Context()) - assert.Equal(t, &page.SessionData{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id"}, sessionData) + sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) + assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil @@ -179,12 +180,12 @@ func TestMakeSupporterHandleWithLpaPath(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Organisation{ID: "org-id"}, nil) memberStore := newMockMemberStore(t) memberStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org", LpaID: "xyz"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org", LpaID: "xyz"})). Return(&actor.Member{Permission: actor.PermissionAdmin, ID: "member-id"}, nil) handle := makeSupporterHandle(mux, sessionStore, nil, organisationStore, memberStore, nil) @@ -203,8 +204,8 @@ func TestMakeSupporterHandleWithLpaPath(t *testing.T) { assert.Equal(t, w, hw) - sessionData, _ := page.SessionDataFromContext(hr.Context()) - assert.Equal(t, &page.SessionData{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id", LpaID: "xyz"}, sessionData) + sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) + assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id", LpaID: "xyz"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil @@ -230,12 +231,12 @@ func TestMakeSupporterHandleWhenRequireAdmin(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Organisation{ID: "org-id"}, nil) memberStore := newMockMemberStore(t) memberStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Member{Permission: actor.PermissionAdmin, ID: "member-id"}, nil) handle := makeSupporterHandle(mux, sessionStore, nil, organisationStore, memberStore, nil) @@ -252,8 +253,8 @@ func TestMakeSupporterHandleWhenRequireAdmin(t *testing.T) { assert.Equal(t, w, hw) - sessionData, _ := page.SessionDataFromContext(hr.Context()) - assert.Equal(t, &page.SessionData{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id"}, sessionData) + sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) + assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil @@ -279,12 +280,12 @@ func TestMakeSupporterHandleWhenRequireAdminAsNonAdmin(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Organisation{ID: "org-id"}, nil) memberStore := newMockMemberStore(t) memberStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Member{Permission: actor.PermissionNone, ID: "member-id"}, nil) errorHandler := newMockErrorHandler(t) @@ -311,12 +312,12 @@ func TestMakeSupporterHandleWhenSuspended(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Organisation{ID: "org-id", Name: "My Org"}, nil) memberStore := newMockMemberStore(t) memberStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Member{Permission: actor.PermissionAdmin, ID: "member-id", Status: actor.StatusSuspended}, nil) suspendedTmpl := newMockTemplate(t) @@ -355,12 +356,12 @@ func TestMakeSupporterHandleWhenSuspendedTemplateErrors(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Organisation{ID: "org-id", Name: "My Org"}, nil) memberStore := newMockMemberStore(t) memberStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Member{Permission: actor.PermissionAdmin, ID: "member-id", Status: actor.StatusSuspended}, nil) suspendedTmpl := newMockTemplate(t) @@ -393,7 +394,7 @@ func TestMakeSupporterHandleWithSessionData(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequestWithContext( page.ContextWithSessionData(context.Background(), - &page.SessionData{SessionID: "existing-sub", OrganisationID: "an-org-id"}), + &appcontext.SessionData{SessionID: "existing-sub", OrganisationID: "an-org-id"}), http.MethodGet, "/supporter/path", nil, @@ -408,12 +409,12 @@ func TestMakeSupporterHandleWithSessionData(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id"})). Return(&actor.Organisation{ID: "org-id"}, nil) memberStore := newMockMemberStore(t) memberStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Member{Permission: actor.PermissionAdmin, ID: "member-id"}, nil) handle := makeSupporterHandle(mux, sessionStore, nil, organisationStore, memberStore, nil) @@ -430,8 +431,8 @@ func TestMakeSupporterHandleWithSessionData(t *testing.T) { assert.Equal(t, w, hw) - sessionData, _ := page.SessionDataFromContext(hr.Context()) - assert.Equal(t, &page.SessionData{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id"}, sessionData) + sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) + assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil diff --git a/internal/search/client.go b/internal/search/client.go index 7964cede56..7a6c03de3d 100644 --- a/internal/search/client.go +++ b/internal/search/client.go @@ -8,8 +8,8 @@ import ( "strings" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/opensearch-project/opensearch-go/v4" "github.com/opensearch-project/opensearch-go/v4/opensearchapi" requestsigner "github.com/opensearch-project/opensearch-go/v4/signer/awsv2" @@ -230,7 +230,7 @@ func baseQuery(sk string) map[string]map[string]any { } func getSKFromContext(ctx context.Context) (string, error) { - session, err := page.SessionDataFromContext(ctx) + session, err := appcontext.SessionDataFromContext(ctx) if err != nil { return "", err } diff --git a/internal/search/client_test.go b/internal/search/client_test.go index 152cc576b3..d0b9966314 100644 --- a/internal/search/client_test.go +++ b/internal/search/client_test.go @@ -11,8 +11,8 @@ import ( "testing" "github.com/aws/aws-sdk-go-v2/aws" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/opensearch-project/opensearch-go/v4/opensearchapi" "github.com/stretchr/testify/assert" mock "github.com/stretchr/testify/mock" @@ -126,31 +126,31 @@ func TestClientIndexWhenIndexErrors(t *testing.T) { func TestClientQuery(t *testing.T) { testcases := map[string]struct { - session *page.SessionData + session *appcontext.SessionData sk dynamo.SK from int page int }{ "donor": { - session: &page.SessionData{SessionID: "abc"}, + session: &appcontext.SessionData{SessionID: "abc"}, sk: dynamo.DonorKey("abc"), from: 0, page: 1, }, "organisation": { - session: &page.SessionData{SessionID: "abc", OrganisationID: "xyz"}, + session: &appcontext.SessionData{SessionID: "abc", OrganisationID: "xyz"}, sk: dynamo.OrganisationKey("xyz"), from: 0, page: 1, }, "donor paged": { - session: &page.SessionData{SessionID: "abc"}, + session: &appcontext.SessionData{SessionID: "abc"}, sk: dynamo.DonorKey("abc"), from: 40, page: 5, }, "organisation paged": { - session: &page.SessionData{SessionID: "abc", OrganisationID: "xyz"}, + session: &appcontext.SessionData{SessionID: "abc", OrganisationID: "xyz"}, sk: dynamo.OrganisationKey("xyz"), from: 40, page: 5, @@ -159,7 +159,7 @@ func TestClientQuery(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(ctx, tc.session) + ctx := appcontext.ContextWithSessionData(ctx, tc.session) resp := &opensearchapi.SearchResp{} resp.Hits.Total.Value = 10 @@ -196,7 +196,7 @@ func TestClientQuery(t *testing.T) { } func TestClientQueryWhenResponseInvalid(t *testing.T) { - ctx := page.ContextWithSessionData(ctx, &page.SessionData{SessionID: "abc"}) + ctx := appcontext.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: "abc"}) resp := &opensearchapi.SearchResp{} resp.Hits.Total.Value = 10 @@ -215,7 +215,7 @@ func TestClientQueryWhenResponseInvalid(t *testing.T) { } func TestClientQueryWhenSearchErrors(t *testing.T) { - ctx := page.ContextWithSessionData(ctx, &page.SessionData{SessionID: "1"}) + ctx := appcontext.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: "1"}) svc := newMockOpensearchapiClient(t) svc.EXPECT(). @@ -230,40 +230,40 @@ func TestClientQueryWhenSearchErrors(t *testing.T) { func TestClientQueryWhenNoSession(t *testing.T) { client := &Client{} _, err := client.Query(ctx, QueryRequest{Page: 1, PageSize: 10}) - assert.ErrorIs(t, err, page.SessionMissingError{}) + assert.ErrorIs(t, err, appcontext.SessionMissingError{}) } func TestClientCountWithQuery(t *testing.T) { testcases := map[string]struct { query CountWithQueryReq body []byte - session *page.SessionData + session *appcontext.SessionData }{ "no query - donor": { query: CountWithQueryReq{}, body: []byte(`{"query":{"bool":{"must":[{"match":{"SK":"DONOR#1"}},{"prefix":{"PK":"LPA#"}}]}},"size":0,"track_total_hits":true}`), - session: &page.SessionData{SessionID: "1"}, + session: &appcontext.SessionData{SessionID: "1"}, }, "no query - organisation": { query: CountWithQueryReq{}, body: []byte(`{"query":{"bool":{"must":[{"match":{"SK":"ORGANISATION#1"}},{"prefix":{"PK":"LPA#"}}]}},"size":0,"track_total_hits":true}`), - session: &page.SessionData{OrganisationID: "1"}, + session: &appcontext.SessionData{OrganisationID: "1"}, }, "MustNotExist query - donor": { query: CountWithQueryReq{MustNotExist: "a-field"}, body: []byte(`{"query":{"bool":{"must":[{"match":{"SK":"DONOR#1"}},{"prefix":{"PK":"LPA#"}}],"must_not":{"exists":{"field":"a-field"}}}},"size":0,"track_total_hits":true}`), - session: &page.SessionData{SessionID: "1"}, + session: &appcontext.SessionData{SessionID: "1"}, }, "MustNotExist query - organisation": { query: CountWithQueryReq{MustNotExist: "a-field"}, body: []byte(`{"query":{"bool":{"must":[{"match":{"SK":"ORGANISATION#1"}},{"prefix":{"PK":"LPA#"}}],"must_not":{"exists":{"field":"a-field"}}}},"size":0,"track_total_hits":true}`), - session: &page.SessionData{OrganisationID: "1"}, + session: &appcontext.SessionData{OrganisationID: "1"}, }, } for name, tc := range testcases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(ctx, tc.session) + ctx := appcontext.ContextWithSessionData(ctx, tc.session) resp := &opensearchapi.SearchResp{} resp.Hits.Total.Value = 1 @@ -292,7 +292,7 @@ func TestClientCountWithQueryWhenNoSession(t *testing.T) { client := &Client{} _, err := client.CountWithQuery(ctx, CountWithQueryReq{}) - assert.ErrorIs(t, err, page.SessionMissingError{}) + assert.ErrorIs(t, err, appcontext.SessionMissingError{}) } func TestClientCountWithQueryWhenSearchError(t *testing.T) { @@ -305,7 +305,7 @@ func TestClientCountWithQueryWhenSearchError(t *testing.T) { svc: svc, } - ctx := page.ContextWithSessionData(ctx, &page.SessionData{SessionID: "1"}) + ctx := appcontext.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: "1"}) _, err := client.CountWithQuery(ctx, CountWithQueryReq{}) assert.Error(t, err) diff --git a/internal/telemetry/telemetry.go b/internal/telemetry/telemetry.go index 8b9b915f98..dac4549be6 100644 --- a/internal/telemetry/telemetry.go +++ b/internal/telemetry/telemetry.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/felixge/httpsnoop" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "go.opentelemetry.io/contrib/propagators/aws/xray" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" @@ -95,7 +95,7 @@ func (h *SlogHandler) Handle(ctx context.Context, record slog.Record) error { record.AddAttrs(slog.String("trace_id", traceID.String())) } - session, err := page.SessionDataFromContext(ctx) + session, err := appcontext.SessionDataFromContext(ctx) if err == nil { record.AddAttrs(slog.String("session_id", session.SessionID))