diff --git a/cmd/event-received/factory.go b/cmd/event-received/factory.go index 34c89437cd..3ba5f17014 100644 --- a/cmd/event-received/factory.go +++ b/cmd/event-received/factory.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" "github.com/ministryofjustice/opg-modernising-lpa/internal/app" + "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/lambda" @@ -37,9 +38,9 @@ type SecretsClient interface { } type ShareCodeSender interface { - SendCertificateProviderInvite(context.Context, page.AppData, page.CertificateProviderInvite) error - SendCertificateProviderPrompt(context.Context, page.AppData, *donordata.Provided) error - SendAttorneys(context.Context, page.AppData, *lpastore.Lpa) error + SendCertificateProviderInvite(context.Context, appcontext.Data, page.CertificateProviderInvite) error + SendCertificateProviderPrompt(context.Context, appcontext.Data, *donordata.Provided) error + SendAttorneys(context.Context, appcontext.Data, *lpastore.Lpa) error } type UidStore interface { @@ -68,7 +69,7 @@ type Factory struct { eventClient EventClient // previously constructed values - appData *page.AppData + appData *appcontext.Data lambdaClient LambdaClient secretsClient SecretsClient shareCodeSender ShareCodeSender @@ -89,15 +90,15 @@ func (f *Factory) UuidString() func() string { return f.uuidString } -func (f *Factory) AppData() (page.AppData, error) { +func (f *Factory) AppData() (appcontext.Data, error) { if f.appData == nil { bundle, err := localize.NewBundle("./lang/en.json", "./lang/cy.json") if err != nil { - return page.AppData{}, err + return appcontext.Data{}, err } //TODO do this in handleFeeApproved when/if we save lang preference in LPA - f.appData = &page.AppData{Localizer: bundle.For(localize.En)} + f.appData = &appcontext.Data{Localizer: bundle.For(localize.En)} } return *f.appData, nil diff --git a/cmd/event-received/factory_test.go b/cmd/event-received/factory_test.go index 6d72d7e8ad..5e0091be87 100644 --- a/cmd/event-received/factory_test.go +++ b/cmd/event-received/factory_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/secrets" "github.com/stretchr/testify/assert" ) @@ -33,11 +33,11 @@ func TestAppData(t *testing.T) { appData, err := factory.AppData() assert.Error(t, err) - assert.Equal(t, page.AppData{}, appData) + assert.Equal(t, appcontext.Data{}, appData) } func TestAppDataWhenSet(t *testing.T) { - expected := page.AppData{Page: "hi"} + expected := appcontext.Data{Page: "hi"} factory := &Factory{appData: &expected} appData, err := factory.AppData() diff --git a/cmd/event-received/main.go b/cmd/event-received/main.go index 32bd77ecc4..9f360d30e4 100644 --- a/cmd/event-received/main.go +++ b/cmd/event-received/main.go @@ -17,9 +17,9 @@ import ( dynamodbtypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" "github.com/aws/aws-sdk-go-v2/service/s3/types" "github.com/ministryofjustice/opg-modernising-lpa/internal/app" + "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/random" "github.com/ministryofjustice/opg-modernising-lpa/internal/s3" ) @@ -32,7 +32,7 @@ type factory interface { Now() func() time.Time DynamoClient() dynamodbClient UuidString() func() string - AppData() (page.AppData, error) + AppData() (appcontext.Data, error) ShareCodeSender(ctx context.Context) (ShareCodeSender, error) LpaStoreClient() (LpaStoreClient, error) UidStore() (UidStore, error) diff --git a/cmd/event-received/mock_factory_test.go b/cmd/event-received/mock_factory_test.go index 24ea437cc4..294d91f6ba 100644 --- a/cmd/event-received/mock_factory_test.go +++ b/cmd/event-received/mock_factory_test.go @@ -5,7 +5,8 @@ package main import ( context "context" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + appcontext "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + mock "github.com/stretchr/testify/mock" time "time" @@ -25,22 +26,22 @@ func (_m *mockFactory) EXPECT() *mockFactory_Expecter { } // AppData provides a mock function with given fields: -func (_m *mockFactory) AppData() (page.AppData, error) { +func (_m *mockFactory) AppData() (appcontext.Data, error) { ret := _m.Called() if len(ret) == 0 { panic("no return value specified for AppData") } - var r0 page.AppData + var r0 appcontext.Data var r1 error - if rf, ok := ret.Get(0).(func() (page.AppData, error)); ok { + if rf, ok := ret.Get(0).(func() (appcontext.Data, error)); ok { return rf() } - if rf, ok := ret.Get(0).(func() page.AppData); ok { + if rf, ok := ret.Get(0).(func() appcontext.Data); ok { r0 = rf() } else { - r0 = ret.Get(0).(page.AppData) + r0 = ret.Get(0).(appcontext.Data) } if rf, ok := ret.Get(1).(func() error); ok { @@ -69,12 +70,12 @@ func (_c *mockFactory_AppData_Call) Run(run func()) *mockFactory_AppData_Call { return _c } -func (_c *mockFactory_AppData_Call) Return(_a0 page.AppData, _a1 error) *mockFactory_AppData_Call { +func (_c *mockFactory_AppData_Call) Return(_a0 appcontext.Data, _a1 error) *mockFactory_AppData_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *mockFactory_AppData_Call) RunAndReturn(run func() (page.AppData, error)) *mockFactory_AppData_Call { +func (_c *mockFactory_AppData_Call) RunAndReturn(run func() (appcontext.Data, error)) *mockFactory_AppData_Call { _c.Call.Return(run) return _c } diff --git a/cmd/event-received/mock_lpaStoreClient_test.go b/cmd/event-received/mock_lpaStoreClient_test.go index 167fe1154b..e804d439e0 100644 --- a/cmd/event-received/mock_lpaStoreClient_test.go +++ b/cmd/event-received/mock_lpaStoreClient_test.go @@ -108,7 +108,7 @@ type mockLpaStoreClient_SendLpa_Call struct { // SendLpa is a helper method to define mock.On call // - ctx context.Context -// - donor *donordata.DonorProvidedDetails +// - donor *donordata.Provided func (_e *mockLpaStoreClient_Expecter) SendLpa(ctx interface{}, donor interface{}) *mockLpaStoreClient_SendLpa_Call { return &mockLpaStoreClient_SendLpa_Call{Call: _e.mock.On("SendLpa", ctx, donor)} } diff --git a/cmd/event-received/mock_shareCodeSender_test.go b/cmd/event-received/mock_shareCodeSender_test.go index 40a37b96c6..d12387e2bd 100644 --- a/cmd/event-received/mock_shareCodeSender_test.go +++ b/cmd/event-received/mock_shareCodeSender_test.go @@ -5,7 +5,10 @@ package main import ( context "context" + appcontext "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + 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" @@ -27,7 +30,7 @@ func (_m *mockShareCodeSender) EXPECT() *mockShareCodeSender_Expecter { } // SendAttorneys provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockShareCodeSender) SendAttorneys(_a0 context.Context, _a1 page.AppData, _a2 *lpastore.Lpa) error { +func (_m *mockShareCodeSender) SendAttorneys(_a0 context.Context, _a1 appcontext.Data, _a2 *lpastore.Lpa) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -35,7 +38,7 @@ func (_m *mockShareCodeSender) SendAttorneys(_a0 context.Context, _a1 page.AppDa } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, page.AppData, *lpastore.Lpa) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, appcontext.Data, *lpastore.Lpa) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -51,15 +54,15 @@ type mockShareCodeSender_SendAttorneys_Call struct { // SendAttorneys is a helper method to define mock.On call // - _a0 context.Context -// - _a1 page.AppData +// - _a1 appcontext.Data // - _a2 *lpastore.Lpa func (_e *mockShareCodeSender_Expecter) SendAttorneys(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockShareCodeSender_SendAttorneys_Call { return &mockShareCodeSender_SendAttorneys_Call{Call: _e.mock.On("SendAttorneys", _a0, _a1, _a2)} } -func (_c *mockShareCodeSender_SendAttorneys_Call) Run(run func(_a0 context.Context, _a1 page.AppData, _a2 *lpastore.Lpa)) *mockShareCodeSender_SendAttorneys_Call { +func (_c *mockShareCodeSender_SendAttorneys_Call) Run(run func(_a0 context.Context, _a1 appcontext.Data, _a2 *lpastore.Lpa)) *mockShareCodeSender_SendAttorneys_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(page.AppData), args[2].(*lpastore.Lpa)) + run(args[0].(context.Context), args[1].(appcontext.Data), args[2].(*lpastore.Lpa)) }) return _c } @@ -69,13 +72,13 @@ func (_c *mockShareCodeSender_SendAttorneys_Call) Return(_a0 error) *mockShareCo return _c } -func (_c *mockShareCodeSender_SendAttorneys_Call) RunAndReturn(run func(context.Context, page.AppData, *lpastore.Lpa) error) *mockShareCodeSender_SendAttorneys_Call { +func (_c *mockShareCodeSender_SendAttorneys_Call) RunAndReturn(run func(context.Context, appcontext.Data, *lpastore.Lpa) error) *mockShareCodeSender_SendAttorneys_Call { _c.Call.Return(run) return _c } // SendCertificateProviderInvite provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockShareCodeSender) SendCertificateProviderInvite(_a0 context.Context, _a1 page.AppData, _a2 page.CertificateProviderInvite) error { +func (_m *mockShareCodeSender) SendCertificateProviderInvite(_a0 context.Context, _a1 appcontext.Data, _a2 page.CertificateProviderInvite) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -83,7 +86,7 @@ func (_m *mockShareCodeSender) SendCertificateProviderInvite(_a0 context.Context } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, page.AppData, page.CertificateProviderInvite) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, appcontext.Data, page.CertificateProviderInvite) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -99,15 +102,15 @@ type mockShareCodeSender_SendCertificateProviderInvite_Call struct { // SendCertificateProviderInvite is a helper method to define mock.On call // - _a0 context.Context -// - _a1 page.AppData +// - _a1 appcontext.Data // - _a2 page.CertificateProviderInvite func (_e *mockShareCodeSender_Expecter) SendCertificateProviderInvite(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockShareCodeSender_SendCertificateProviderInvite_Call { return &mockShareCodeSender_SendCertificateProviderInvite_Call{Call: _e.mock.On("SendCertificateProviderInvite", _a0, _a1, _a2)} } -func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) Run(run func(_a0 context.Context, _a1 page.AppData, _a2 page.CertificateProviderInvite)) *mockShareCodeSender_SendCertificateProviderInvite_Call { +func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) Run(run func(_a0 context.Context, _a1 appcontext.Data, _a2 page.CertificateProviderInvite)) *mockShareCodeSender_SendCertificateProviderInvite_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(page.AppData), args[2].(page.CertificateProviderInvite)) + run(args[0].(context.Context), args[1].(appcontext.Data), args[2].(page.CertificateProviderInvite)) }) return _c } @@ -117,13 +120,13 @@ func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) Return(_a0 err return _c } -func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) RunAndReturn(run func(context.Context, page.AppData, page.CertificateProviderInvite) error) *mockShareCodeSender_SendCertificateProviderInvite_Call { +func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) RunAndReturn(run func(context.Context, appcontext.Data, page.CertificateProviderInvite) error) *mockShareCodeSender_SendCertificateProviderInvite_Call { _c.Call.Return(run) return _c } // SendCertificateProviderPrompt provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context, _a1 page.AppData, _a2 *donordata.Provided) error { +func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context, _a1 appcontext.Data, _a2 *donordata.Provided) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -131,7 +134,7 @@ func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, page.AppData, *donordata.Provided) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, appcontext.Data, *donordata.Provided) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -147,15 +150,15 @@ type mockShareCodeSender_SendCertificateProviderPrompt_Call struct { // SendCertificateProviderPrompt is a helper method to define mock.On call // - _a0 context.Context -// - _a1 page.AppData -// - _a2 *donordata.DonorProvidedDetails +// - _a1 appcontext.Data +// - _a2 *donordata.Provided 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 *donordata.Provided)) *mockShareCodeSender_SendCertificateProviderPrompt_Call { +func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) Run(run func(_a0 context.Context, _a1 appcontext.Data, _a2 *donordata.Provided)) *mockShareCodeSender_SendCertificateProviderPrompt_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(page.AppData), args[2].(*donordata.Provided)) + run(args[0].(context.Context), args[1].(appcontext.Data), args[2].(*donordata.Provided)) }) return _c } @@ -165,7 +168,7 @@ func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) Return(_a0 err return _c } -func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) RunAndReturn(run func(context.Context, page.AppData, *donordata.Provided) error) *mockShareCodeSender_SendCertificateProviderPrompt_Call { +func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) RunAndReturn(run func(context.Context, appcontext.Data, *donordata.Provided) error) *mockShareCodeSender_SendCertificateProviderPrompt_Call { _c.Call.Return(run) return _c } diff --git a/cmd/event-received/sirius_event_handler.go b/cmd/event-received/sirius_event_handler.go index 6f5f6f6c96..71fbe433f1 100644 --- a/cmd/event-received/sirius_event_handler.go +++ b/cmd/event-received/sirius_event_handler.go @@ -8,6 +8,7 @@ import ( "time" "github.com/aws/aws-lambda-go/events" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -94,7 +95,7 @@ func handleEvidenceReceived(ctx context.Context, client dynamodbClient, event ev return nil } -func handleFeeApproved(ctx context.Context, client dynamodbClient, event events.CloudWatchEvent, shareCodeSender ShareCodeSender, lpaStoreClient LpaStoreClient, appData page.AppData, now func() time.Time) error { +func handleFeeApproved(ctx context.Context, client dynamodbClient, event events.CloudWatchEvent, shareCodeSender ShareCodeSender, lpaStoreClient LpaStoreClient, appData appcontext.Data, now func() time.Time) error { var v uidEvent if err := json.Unmarshal(event.Detail, &v); err != nil { return fmt.Errorf("failed to unmarshal detail: %w", err) @@ -181,7 +182,7 @@ func handleFeeDenied(ctx context.Context, client dynamodbClient, event events.Cl return nil } -func handleDonorSubmissionCompleted(ctx context.Context, client dynamodbClient, event events.CloudWatchEvent, shareCodeSender ShareCodeSender, appData page.AppData, lpaStoreClient LpaStoreClient, uuidString func() string, now func() time.Time) error { +func handleDonorSubmissionCompleted(ctx context.Context, client dynamodbClient, event events.CloudWatchEvent, shareCodeSender ShareCodeSender, appData appcontext.Data, lpaStoreClient LpaStoreClient, uuidString func() string, now func() time.Time) error { var v uidEvent if err := json.Unmarshal(event.Detail, &v); err != nil { return fmt.Errorf("failed to unmarshal detail: %w", err) diff --git a/cmd/event-received/sirius_event_handler_test.go b/cmd/event-received/sirius_event_handler_test.go index f4cfba5390..1461dec92c 100644 --- a/cmd/event-received/sirius_event_handler_test.go +++ b/cmd/event-received/sirius_event_handler_test.go @@ -11,6 +11,7 @@ import ( "github.com/aws/aws-lambda-go/events" "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" @@ -142,7 +143,7 @@ func TestHandleFeeApproved(t *testing.T) { shareCodeSender := newMockShareCodeSender(t) shareCodeSender.EXPECT(). - SendCertificateProviderPrompt(ctx, page.AppData{}, &completedDonorProvided). + SendCertificateProviderPrompt(ctx, appcontext.Data{}, &completedDonorProvided). Return(nil) client := newMockDynamodbClient(t) @@ -177,7 +178,7 @@ func TestHandleFeeApproved(t *testing.T) { Return(client) factory.EXPECT(). AppData(). - Return(page.AppData{}, nil) + Return(appcontext.Data{}, nil) factory.EXPECT(). ShareCodeSender(ctx). Return(shareCodeSender, nil) @@ -245,7 +246,7 @@ func TestHandleFeeApprovedWhenNotPaid(t *testing.T) { Return(client) factory.EXPECT(). AppData(). - Return(page.AppData{}, nil) + Return(appcontext.Data{}, nil) factory.EXPECT(). ShareCodeSender(ctx). Return(nil, nil) @@ -305,7 +306,7 @@ func TestHandleFeeApprovedWhenNotSigned(t *testing.T) { Put(ctx, &updatedDonorProvided). Return(nil) - err := handleFeeApproved(ctx, client, event, nil, nil, page.AppData{}, func() time.Time { return now }) + err := handleFeeApproved(ctx, client, event, nil, nil, appcontext.Data{}, func() time.Time { return now }) assert.Nil(t, err) } @@ -343,7 +344,7 @@ func TestHandleFeeApprovedWhenAlreadyPaidOrApproved(t *testing.T) { return nil }) - err := handleFeeApproved(ctx, client, event, nil, nil, page.AppData{}, nil) + err := handleFeeApproved(ctx, client, event, nil, nil, appcontext.Data{}, nil) assert.Nil(t, err) }) } @@ -376,7 +377,7 @@ func TestHandleFeeApprovedWhenDynamoClientPutError(t *testing.T) { Put(ctx, mock.Anything). Return(expectedError) - err := handleFeeApproved(ctx, client, event, nil, nil, page.AppData{}, func() time.Time { return now }) + err := handleFeeApproved(ctx, client, event, nil, nil, appcontext.Data{}, func() time.Time { return now }) assert.Equal(t, fmt.Errorf("failed to update LPA task status: %w", expectedError), err) } @@ -416,10 +417,10 @@ func TestHandleFeeApprovedWhenShareCodeSenderError(t *testing.T) { shareCodeSender := newMockShareCodeSender(t) shareCodeSender.EXPECT(). - SendCertificateProviderPrompt(ctx, page.AppData{}, mock.Anything). + SendCertificateProviderPrompt(ctx, appcontext.Data{}, mock.Anything). Return(expectedError) - err := handleFeeApproved(ctx, client, event, shareCodeSender, lpaStoreClient, page.AppData{}, func() time.Time { return now }) + err := handleFeeApproved(ctx, client, event, shareCodeSender, lpaStoreClient, appcontext.Data{}, func() time.Time { return now }) assert.Equal(t, fmt.Errorf("failed to send share code to certificate provider: %w", expectedError), err) } @@ -457,7 +458,7 @@ func TestHandleFeeApprovedWhenLpaStoreError(t *testing.T) { SendLpa(ctx, mock.Anything). Return(expectedError) - err := handleFeeApproved(ctx, client, event, nil, lpaStoreClient, page.AppData{}, func() time.Time { return now }) + err := handleFeeApproved(ctx, client, event, nil, lpaStoreClient, appcontext.Data{}, func() time.Time { return now }) assert.Equal(t, fmt.Errorf("failed to send to lpastore: %w", expectedError), err) } @@ -679,7 +680,7 @@ var donorSubmissionCompletedEvent = events.CloudWatchEvent{ } func TestHandleDonorSubmissionCompleted(t *testing.T) { - appData := page.AppData{} + appData := appcontext.Data{} uid := actoruid.New() lpa := &lpastore.Lpa{ @@ -751,7 +752,7 @@ func TestHandleDonorSubmissionCompleted(t *testing.T) { } func TestHandleDonorSubmissionCompletedWhenPaperCertificateProvider(t *testing.T) { - appData := page.AppData{} + appData := appcontext.Data{} lpa := &lpastore.Lpa{ CertificateProvider: lpastore.CertificateProvider{ @@ -777,7 +778,7 @@ func TestHandleDonorSubmissionCompletedWhenPaperCertificateProvider(t *testing.T } func TestHandleDonorSubmissionCompletedWhenDynamoExists(t *testing.T) { - appData := page.AppData{} + appData := appcontext.Data{} client := newMockDynamodbClient(t) client.EXPECT(). @@ -789,7 +790,7 @@ func TestHandleDonorSubmissionCompletedWhenDynamoExists(t *testing.T) { } func TestHandleDonorSubmissionCompletedWhenDynamoOneByUIDError(t *testing.T) { - appData := page.AppData{} + appData := appcontext.Data{} client := newMockDynamodbClient(t) client.EXPECT(). @@ -801,7 +802,7 @@ func TestHandleDonorSubmissionCompletedWhenDynamoOneByUIDError(t *testing.T) { } func TestHandleDonorSubmissionCompletedWhenDynamoPutError(t *testing.T) { - appData := page.AppData{} + appData := appcontext.Data{} client := newMockDynamodbClient(t) client.EXPECT(). @@ -816,7 +817,7 @@ func TestHandleDonorSubmissionCompletedWhenDynamoPutError(t *testing.T) { } func TestHandleDonorSubmissionCompletedWhenLpaStoreError(t *testing.T) { - appData := page.AppData{} + appData := appcontext.Data{} lpa := &lpastore.Lpa{ CertificateProvider: lpastore.CertificateProvider{ @@ -842,7 +843,7 @@ func TestHandleDonorSubmissionCompletedWhenLpaStoreError(t *testing.T) { } func TestHandleDonorSubmissionCompletedWhenShareCodeSenderError(t *testing.T) { - appData := page.AppData{} + appData := appcontext.Data{} lpa := &lpastore.Lpa{ CertificateProvider: lpastore.CertificateProvider{ @@ -878,7 +879,7 @@ var certificateProviderSubmissionCompletedEvent = events.CloudWatchEvent{ } func TestHandleCertificateProviderSubmissionCompleted(t *testing.T) { - appData := page.AppData{} + appData := appcontext.Data{} lpa := &lpastore.Lpa{ CertificateProvider: lpastore.CertificateProvider{ @@ -986,7 +987,7 @@ func TestHandleCertificateProviderSubmissionCompletedWhenShareCodeSenderErrors(t Return(shareCodeSender, nil) factory.EXPECT(). AppData(). - Return(page.AppData{}, nil) + Return(appcontext.Data{}, nil) handler := &siriusEventHandler{} err := handler.Handle(ctx, factory, certificateProviderSubmissionCompletedEvent) @@ -1035,7 +1036,7 @@ func TestHandleCertificateProviderSubmissionCompletedWhenAppDataFactoryErrors(t Return(nil, nil) factory.EXPECT(). AppData(). - Return(page.AppData{}, expectedError) + Return(appcontext.Data{}, expectedError) handler := &siriusEventHandler{} err := handler.Handle(ctx, factory, certificateProviderSubmissionCompletedEvent) diff --git a/internal/temporary/lpa_link.go b/internal/actor/lpa_link.go similarity index 94% rename from internal/temporary/lpa_link.go rename to internal/actor/lpa_link.go index 7295396fcf..5e92f4e6b8 100644 --- a/internal/temporary/lpa_link.go +++ b/internal/actor/lpa_link.go @@ -1,4 +1,4 @@ -package temporary +package actor import ( "strings" @@ -16,7 +16,7 @@ type LpaLink struct { // DonorKey is the donorKey for the donor DonorKey dynamo.LpaOwnerKeyType // ActorType is the type for the current user - ActorType ActorType + ActorType Type // UpdatedAt is set to allow this data to be queried from SKUpdatedAtIndex UpdatedAt time.Time } diff --git a/internal/actor/type.go b/internal/actor/type.go index c1b03fd7d2..35b9449e21 100644 --- a/internal/actor/type.go +++ b/internal/actor/type.go @@ -1,23 +1,72 @@ package actor -import "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" - -type Type = temporary.ActorType +type Type uint8 const ( - TypeNone = temporary.ActorTypeNone - TypeDonor = temporary.ActorTypeDonor - TypeAttorney = temporary.ActorTypeAttorney - TypeReplacementAttorney = temporary.ActorTypeReplacementAttorney - TypeCertificateProvider = temporary.ActorTypeCertificateProvider - TypePersonToNotify = temporary.ActorTypePersonToNotify - TypeAuthorisedSignatory = temporary.ActorTypeAuthorisedSignatory - TypeIndependentWitness = temporary.ActorTypeIndependentWitness - TypeTrustCorporation = temporary.ActorTypeTrustCorporation - TypeReplacementTrustCorporation = temporary.ActorTypeReplacementTrustCorporation - TypeVoucher = temporary.ActorTypeVoucher + TypeNone Type = iota + TypeDonor + TypeAttorney + TypeReplacementAttorney + TypeCertificateProvider + TypePersonToNotify + TypeAuthorisedSignatory + TypeIndependentWitness + TypeTrustCorporation + TypeReplacementTrustCorporation + TypeVoucher ) -type Types = temporary.Types +func (t Type) String() string { + switch t { + case TypeDonor: + return "donor" + case TypeAttorney: + return "attorney" + case TypeReplacementAttorney: + return "replacementAttorney" + case TypeCertificateProvider: + return "certificateProvider" + case TypePersonToNotify: + return "personToNotify" + case TypeAuthorisedSignatory: + return "signatory" + case TypeIndependentWitness: + return "independentWitness" + case TypeTrustCorporation: + return "trustCorporation" + case TypeReplacementTrustCorporation: + return "replacementTrustCorporation" + case TypeVoucher: + return "voucher" + default: + return "" + } +} + +type Types struct { + None Type + Donor Type + Attorney Type + ReplacementAttorney Type + TrustCorporation Type + ReplacementTrustCorporation Type + CertificateProvider Type + PersonToNotify Type + AuthorisedSignatory Type + IndependentWitness Type + Voucher Type +} -var ActorTypes = temporary.ActorTypes +var ActorTypes = Types{ + None: TypeNone, + Donor: TypeDonor, + Attorney: TypeAttorney, + ReplacementAttorney: TypeReplacementAttorney, + TrustCorporation: TypeTrustCorporation, + ReplacementTrustCorporation: TypeReplacementTrustCorporation, + CertificateProvider: TypeCertificateProvider, + PersonToNotify: TypePersonToNotify, + AuthorisedSignatory: TypeAuthorisedSignatory, + IndependentWitness: TypeIndependentWitness, + Voucher: TypeVoucher, +} diff --git a/internal/app/app.go b/internal/app/app.go index 7b26745d3e..fa0bce0558 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -234,7 +234,7 @@ func withAppData(next http.Handler, localizer page.Localizer, lang localize.Lang localizer.SetShowTranslationKeys(r.FormValue("showTranslationKeys") == "1") } - appData := page.AppDataFromContext(ctx) + appData := appcontext.DataFromContext(ctx) appData.Path = r.URL.Path appData.Query = r.URL.Query() appData.Localizer = localizer @@ -244,7 +244,7 @@ func withAppData(next http.Handler, localizer page.Localizer, lang localize.Lang _, cookieErr := r.Cookie("cookies-consent") appData.CookieConsentSet = cookieErr != http.ErrNoCookie - next.ServeHTTP(w, r.WithContext(page.ContextWithAppData(ctx, appData))) + next.ServeHTTP(w, r.WithContext(appcontext.ContextWithData(ctx, appData))) } } @@ -260,7 +260,7 @@ func makeHandle(mux *http.ServeMux, errorHandler page.ErrorHandler, sessionStore mux.HandleFunc(path.String(), func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - appData := page.AppDataFromContext(ctx) + appData := appcontext.DataFromContext(ctx) appData.Page = path.Format() if opt&RequireSession != 0 { @@ -271,10 +271,10 @@ func makeHandle(mux *http.ServeMux, errorHandler page.ErrorHandler, sessionStore } appData.SessionID = loginSession.SessionID() - ctx = page.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: appData.SessionID}) + ctx = appcontext.ContextWithSession(ctx, &appcontext.Session{SessionID: appData.SessionID}) } - if err := h(appData, w, r.WithContext(page.ContextWithAppData(ctx, appData))); err != nil { + if err := h(appData, w, r.WithContext(appcontext.ContextWithData(ctx, appData))); err != nil { errorHandler(w, r, err) } }) diff --git a/internal/app/app_test.go b/internal/app/app_test.go index 46b3ababe8..82b0d3df64 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -108,8 +108,8 @@ func TestMakeHandle(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, nil, nil) - handle("/path", None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { - assert.Equal(t, page.AppData{ + handle("/path", None, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { + assert.Equal(t, appcontext.Data{ Page: "/path", }, appData) assert.Equal(t, w, hw) @@ -135,15 +135,15 @@ func TestMakeHandleRequireSession(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, nil, sessionStore) - handle("/path", RequireSession, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { - assert.Equal(t, page.AppData{ + handle("/path", RequireSession, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { + assert.Equal(t, appcontext.Data{ Page: "/path", SessionID: "cmFuZG9t", }, appData) assert.Equal(t, w, hw) - sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) - assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t"}, sessionData) + sessionData, _ := appcontext.SessionFromContext(hr.Context()) + assert.Equal(t, &appcontext.Session{SessionID: "cmFuZG9t"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil @@ -166,7 +166,7 @@ func TestMakeHandleRequireSessionError(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, nil, sessionStore) - handle("/path", RequireSession, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request) error { return nil }) + handle("/path", RequireSession, func(_ appcontext.Data, _ http.ResponseWriter, _ *http.Request) error { return nil }) mux.ServeHTTP(w, r) resp := w.Result() @@ -185,7 +185,7 @@ func TestMakeHandleWhenError(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, errorHandler.Execute, nil) - handle("/path", None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { + handle("/path", None, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { return expectedError }) @@ -242,14 +242,14 @@ func TestWithAppData(t *testing.T) { } handler := http.HandlerFunc(func(hw http.ResponseWriter, hr *http.Request) { - assert.Equal(t, page.AppData{ + assert.Equal(t, appcontext.Data{ Path: "/path", Query: query, Localizer: localizer, Lang: localize.En, CookieConsentSet: tc.cookieConsentSet, CanToggleWelsh: true, - }, page.AppDataFromContext(hr.Context())) + }, appcontext.DataFromContext(hr.Context())) assert.Equal(t, w, hw) }) diff --git a/internal/app/attorney_store.go b/internal/app/attorney_store.go deleted file mode 100644 index 15973460d7..0000000000 --- a/internal/app/attorney_store.go +++ /dev/null @@ -1,5 +0,0 @@ -package app - -import "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" - -type attorneyStore = attorneydata.Store diff --git a/internal/app/dashboard_store.go b/internal/app/dashboard_store.go index 3a04fcbe7e..94c85419c7 100644 --- a/internal/app/dashboard_store.go +++ b/internal/app/dashboard_store.go @@ -15,7 +15,6 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" - "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" ) type LpaStoreResolvingService interface { @@ -23,7 +22,7 @@ type LpaStoreResolvingService interface { } // An lpaLink is used to join an actor to an LPA. -type lpaLink = temporary.LpaLink +type lpaLink = actor.LpaLink type dashboardStore struct { dynamoClient DynamoClient @@ -63,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 := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(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 874ee5ea15..e455fa8d0a 100644 --- a/internal/app/dashboard_store_test.go +++ b/internal/app/dashboard_store_test.go @@ -126,7 +126,7 @@ func TestDashboardStoreGetAll(t *testing.T) { for name, attributeValues := range testCases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: sessionID}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: sessionID}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), @@ -206,7 +206,7 @@ func TestDashboardStoreGetAllSubmittedForAttorneys(t *testing.T) { IsReplacement: true, } - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: sessionID}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: sessionID}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), @@ -252,7 +252,7 @@ func TestDashboardStoreGetAllWhenResolveErrors(t *testing.T) { donor := &donordata.Provided{LpaID: "0", LpaUID: "M", UpdatedAt: aTime, SK: dynamo.LpaOwnerKey(dynamo.DonorKey(sessionID)), PK: dynamo.LpaKey("0")} - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: sessionID}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: sessionID}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), @@ -275,7 +275,7 @@ func TestDashboardStoreGetAllWhenResolveErrors(t *testing.T) { } func TestDashboardStoreGetAllWhenNone(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), @@ -291,7 +291,7 @@ func TestDashboardStoreGetAllWhenNone(t *testing.T) { } func TestDashboardStoreGetAllWhenAllForActorErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), @@ -304,7 +304,7 @@ func TestDashboardStoreGetAllWhenAllForActorErrors(t *testing.T) { } func TestDashboardStoreGetAllWhenAllByKeysErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.SubKey("an-id"), @@ -320,7 +320,7 @@ func TestDashboardStoreGetAllWhenAllByKeysErrors(t *testing.T) { } func TestDashboardStoreGetAllWhenReferenceGetErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{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 e611cc70c9..8753807c09 100644 --- a/internal/app/document_store.go +++ b/internal/app/document_store.go @@ -61,7 +61,7 @@ func (s *documentStore) Create(ctx context.Context, donor *donordata.Provided, f } func (s *documentStore) GetAll(ctx context.Context) (page.Documents, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } diff --git a/internal/app/document_store_test.go b/internal/app/document_store_test.go index 9d90f87b51..b79b3b2d9d 100644 --- a/internal/app/document_store_test.go +++ b/internal/app/document_store_test.go @@ -28,7 +28,7 @@ func TestNewDocumentStore(t *testing.T) { } func TestDocumentStoreGetAll(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -47,7 +47,7 @@ func TestDocumentStoreGetAll(t *testing.T) { assert.Equal(t, page.Documents{{PK: dynamo.LpaKey("123")}}, documents) } -func TestDocumentStoreGetAllMissingSessionData(t *testing.T) { +func TestDocumentStoreGetAllMissingSession(t *testing.T) { documentStore := documentStore{} _, err := documentStore.GetAll(context.Background()) @@ -55,7 +55,7 @@ func TestDocumentStoreGetAllMissingSessionData(t *testing.T) { } func TestDocumentStoreGetAllMissingLpaIdInSession(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{}) documentStore := documentStore{} _, err := documentStore.GetAll(ctx) @@ -64,7 +64,7 @@ func TestDocumentStoreGetAllMissingLpaIdInSession(t *testing.T) { } func TestDocumentStoreGetAllWhenDynamoClientAllByPartialSKError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -82,7 +82,7 @@ func TestDocumentStoreGetAllWhenDynamoClientAllByPartialSKError(t *testing.T) { } func TestDocumentStoreGetAllWhenNoResults(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -101,7 +101,7 @@ func TestDocumentStoreGetAllWhenNoResults(t *testing.T) { } func TestDocumentStoreUpdateScanResults(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). Update( @@ -122,7 +122,7 @@ func TestDocumentStoreUpdateScanResults(t *testing.T) { } func TestDocumentStoreUpdateScanResultsWhenUpdateError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). Update( @@ -143,7 +143,7 @@ func TestDocumentStoreUpdateScanResultsWhenUpdateError(t *testing.T) { } func TestDocumentStorePut(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -158,7 +158,7 @@ func TestDocumentStorePut(t *testing.T) { } func TestDocumentStorePutWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -173,7 +173,7 @@ func TestDocumentStorePutWhenDynamoClientError(t *testing.T) { } func TestDeleteInfectedDocuments(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -194,7 +194,7 @@ func TestDeleteInfectedDocuments(t *testing.T) { } func TestDeleteInfectedDocumentsWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -215,7 +215,7 @@ func TestDeleteInfectedDocumentsWhenDynamoClientError(t *testing.T) { } func TestDeleteInfectedDocumentsNonInfectedDocumentsAreNotDeleted(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) documentStore := documentStore{} @@ -228,7 +228,7 @@ func TestDeleteInfectedDocumentsNonInfectedDocumentsAreNotDeleted(t *testing.T) } func TestDelete(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) s3Client := newMockS3Client(t) s3Client.EXPECT(). @@ -248,7 +248,7 @@ func TestDelete(t *testing.T) { } func TestDeleteWhenS3ClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) s3Client := newMockS3Client(t) s3Client.EXPECT(). @@ -263,7 +263,7 @@ func TestDeleteWhenS3ClientError(t *testing.T) { } func TestDeleteWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) s3Client := newMockS3Client(t) s3Client.EXPECT(). diff --git a/internal/app/evidence_received_store.go b/internal/app/evidence_received_store.go index d7bc59ee6c..4384b48038 100644 --- a/internal/app/evidence_received_store.go +++ b/internal/app/evidence_received_store.go @@ -13,7 +13,7 @@ type evidenceReceivedStore struct { } func (s *evidenceReceivedStore) Get(ctx context.Context) (bool, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(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 dbfb86a435..939783048a 100644 --- a/internal/app/evidence_received_store_test.go +++ b/internal/app/evidence_received_store_test.go @@ -7,12 +7,11 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "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(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.EvidenceReceivedKey(), nil, nil) @@ -25,7 +24,7 @@ func TestEvidenceReceivedStoreGet(t *testing.T) { } func TestEvidenceReceivedStoreGetWhenFalse(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.EvidenceReceivedKey(), nil, dynamo.NotFoundError{}) @@ -47,7 +46,7 @@ func TestEvidenceReceivedStoreGetWithSessionMissing(t *testing.T) { } func TestEvidenceReceivedStoreGetWhenDataStoreError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.EvidenceReceivedKey(), &donordata.Provided{LpaID: "an-id"}, expectedError) diff --git a/internal/app/member_store.go b/internal/app/member_store.go index eefbf9c0e4..3afbbdfdfd 100644 --- a/internal/app/member_store.go +++ b/internal/app/member_store.go @@ -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 := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(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 := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(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 := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(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 := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(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 := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(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 := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(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 := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(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 := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(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 := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(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 := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } diff --git a/internal/app/member_store_test.go b/internal/app/member_store_test.go index f2023cf33d..c76be17a1b 100644 --- a/internal/app/member_store_test.go +++ b/internal/app/member_store_test.go @@ -7,13 +7,12 @@ import ( "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" "github.com/stretchr/testify/mock" ) func TestMemberStoreCreateMemberInvite(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -40,7 +39,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(), &appcontext.SessionData{}), + "missing OrganisationID": appcontext.ContextWithSession(context.Background(), &appcontext.Session{}), } memberStore := &memberStore{now: testNowFn} @@ -56,7 +55,7 @@ func TestMemberStoreCreateMemberInviteWithSessionMissing(t *testing.T) { } func TestMemberStoreInvitedMember(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{Email: "a@example.org"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{Email: "a@example.org"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOneBySK(ctx, dynamo.MemberInviteKey("a@example.org"), &actor.MemberInvite{OrganisationID: "an-id"}, nil) @@ -70,7 +69,7 @@ func TestMemberStoreInvitedMember(t *testing.T) { } func TestMemberStoreInvitedMemberWhenDynamoError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{Email: "a@example.org"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{Email: "a@example.org"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOneBySK(ctx, mock.Anything, mock.Anything, expectedError) @@ -84,7 +83,7 @@ func TestMemberStoreInvitedMemberWhenDynamoError(t *testing.T) { func TestMemberStoreInvitedMemberWhenSessionMissing(t *testing.T) { testcases := map[string]context.Context{ - "no email": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), + "no email": appcontext.ContextWithSession(context.Background(), &appcontext.Session{}), "no session data": context.Background(), } @@ -100,7 +99,7 @@ func TestMemberStoreInvitedMemberWhenSessionMissing(t *testing.T) { } func TestMemberStoreCreateMemberInviteWhenErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -114,7 +113,7 @@ func TestMemberStoreCreateMemberInviteWhenErrors(t *testing.T) { } func TestMemberStoreInvitedMembers(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllByPartialSK(ctx, dynamo.OrganisationKey("an-id"), @@ -130,7 +129,7 @@ func TestMemberStoreInvitedMembers(t *testing.T) { func TestMemberStoreInvitedMembersWhenSessionMissing(t *testing.T) { testcases := map[string]context.Context{ - "no organisation id": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), + "no organisation id": appcontext.ContextWithSession(context.Background(), &appcontext.Session{}), "no session data": context.Background(), } @@ -146,7 +145,7 @@ func TestMemberStoreInvitedMembersWhenSessionMissing(t *testing.T) { } func TestMemberStoreInvitedMembersWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllByPartialSK(ctx, dynamo.OrganisationKey("an-id"), @@ -160,7 +159,7 @@ func TestMemberStoreInvitedMembersWhenDynamoClientError(t *testing.T) { } func TestMemberStoreInvitedMembersByEmail(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{Email: "a@example.org"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{Email: "a@example.org"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, dynamo.MemberInviteKey("a@example.org"), []*actor.MemberInvite{ @@ -180,7 +179,7 @@ func TestMemberStoreInvitedMembersByEmail(t *testing.T) { } func TestMemberStoreInvitedMembersByEmailWhenDynamoError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{Email: "a@example.org"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{Email: "a@example.org"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllBySK(ctx, mock.Anything, mock.Anything, expectedError) @@ -194,7 +193,7 @@ func TestMemberStoreInvitedMembersByEmailWhenDynamoError(t *testing.T) { func TestMemberStoreInvitedMembersByEmailWhenSessionMissing(t *testing.T) { testcases := map[string]context.Context{ - "no email": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), + "no email": appcontext.ContextWithSession(context.Background(), &appcontext.Session{}), "no session data": context.Background(), } @@ -244,7 +243,7 @@ func TestPutWhenDynamoError(t *testing.T) { } func TestMemberStoreGetAll(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllByPartialSK(ctx, dynamo.OrganisationKey("an-id"), @@ -260,7 +259,7 @@ func TestMemberStoreGetAll(t *testing.T) { func TestMemberStoreGetAllWhenSessionMissing(t *testing.T) { testcases := map[string]context.Context{ - "no organisation ID": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), + "no organisation ID": appcontext.ContextWithSession(context.Background(), &appcontext.Session{}), "no session data": context.Background(), } @@ -276,7 +275,7 @@ func TestMemberStoreGetAllWhenSessionMissing(t *testing.T) { } func TestMemberStoreGetAllWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectAllByPartialSK(ctx, dynamo.OrganisationKey("an-id"), @@ -290,7 +289,7 @@ func TestMemberStoreGetAllWhenDynamoClientError(t *testing.T) { } func TestMemberStoreGet(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{ + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{ OrganisationID: "a-uuid", SessionID: "session-id", }) @@ -310,8 +309,8 @@ func TestMemberStoreGet(t *testing.T) { func TestMemberStoreGetWithSessionMissing(t *testing.T) { testcases := map[string]context.Context{ - "no session id": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "id"}), - "no organisation id": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{}), + "no session id": appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "id"}), + "no organisation id": appcontext.ContextWithSession(context.Background(), &appcontext.Session{}), "no session data": context.Background(), } @@ -326,7 +325,7 @@ func TestMemberStoreGetWithSessionMissing(t *testing.T) { } func TestMemberStoreGetWhenErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "a-uuid", SessionID: "session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{OrganisationID: "a-uuid", SessionID: "session-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -339,7 +338,7 @@ func TestMemberStoreGetWhenErrors(t *testing.T) { } func TestMemberStoreCreate(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id", Email: "email@example.com"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "session-id", Email: "email@example.com"}) expectedMember := &actor.Member{ PK: dynamo.OrganisationKey("a-uuid"), SK: dynamo.MemberKey("session-id"), @@ -379,8 +378,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(), &appcontext.SessionData{SessionID: "a"}), - "missing session ID": page.ContextWithSessionData(context.Background(), &appcontext.SessionData{Email: "a"}), + "missing email": appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "a"}), + "missing session ID": appcontext.ContextWithSession(context.Background(), &appcontext.Session{Email: "a"}), } for name, ctx := range testCases { @@ -394,7 +393,7 @@ func TestMemberStoreCreateWhenSessionMissing(t *testing.T) { } func TestMemberStoreCreateWhenDynamoErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id", Email: "a"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "session-id", Email: "a"}) testcases := map[string]struct { dynamoClientSetup func(*mockDynamoClient) @@ -435,7 +434,7 @@ func TestMemberStoreCreateWhenDynamoErrors(t *testing.T) { } func TestMemberStoreCreateFromInvite(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "session-id"}) invite := &actor.MemberInvite{ PK: "pk", @@ -486,7 +485,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(), &appcontext.SessionData{}), + "missing session ID": appcontext.ContextWithSession(context.Background(), &appcontext.Session{}), } for name, ctx := range testCases { @@ -518,7 +517,7 @@ func TestMemberStoreCreateFromInviteWhenDynamoErrors(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "session-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -547,7 +546,7 @@ func TestMemberStoreCreateFromInviteWhenDynamoErrors(t *testing.T) { } func TestMemberStoreGetByID(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "org-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{OrganisationID: "org-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -579,7 +578,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(), &appcontext.SessionData{}), + "missing organisation ID": appcontext.ContextWithSession(context.Background(), &appcontext.Session{}), } for name, ctx := range testCases { @@ -608,7 +607,7 @@ func TestMemberStoreGetByIDWhenDynamoClientErrors(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "org-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{OrganisationID: "org-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -631,7 +630,7 @@ func TestMemberStoreGetByIDWhenDynamoClientErrors(t *testing.T) { } func TestMemberStoreGetAny(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "session-id"}) expectedMember := &actor.Member{ID: "a"} @@ -650,7 +649,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(), &appcontext.SessionData{}), + "missing session ID": appcontext.ContextWithSession(context.Background(), &appcontext.Session{}), } for name, ctx := range testCases { @@ -665,7 +664,7 @@ func TestMemberStoreGetAnyWhenMissingSession(t *testing.T) { } func TestMemberStoreGetAnyWhenDynamoClientErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "session-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient. diff --git a/internal/app/mock_LpaStoreResolvingService_test.go b/internal/app/mock_LpaStoreResolvingService_test.go index 980a0b9cb9..c0fa94d2df 100644 --- a/internal/app/mock_LpaStoreResolvingService_test.go +++ b/internal/app/mock_LpaStoreResolvingService_test.go @@ -61,7 +61,7 @@ type mockLpaStoreResolvingService_ResolveList_Call struct { // ResolveList is a helper method to define mock.On call // - ctx context.Context -// - donors []*donordata.DonorProvidedDetails +// - donors []*donordata.Provided func (_e *mockLpaStoreResolvingService_Expecter) ResolveList(ctx interface{}, donors interface{}) *mockLpaStoreResolvingService_ResolveList_Call { return &mockLpaStoreResolvingService_ResolveList_Call{Call: _e.mock.On("ResolveList", ctx, donors)} } diff --git a/internal/app/organisation_store.go b/internal/app/organisation_store.go index 5d82ed505e..89489c3413 100644 --- a/internal/app/organisation_store.go +++ b/internal/app/organisation_store.go @@ -31,7 +31,7 @@ type organisationLink struct { } func (s *organisationStore) Create(ctx context.Context, member *actor.Member, name string) (*actor.Organisation, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } @@ -56,7 +56,7 @@ func (s *organisationStore) Create(ctx context.Context, member *actor.Member, na } func (s *organisationStore) Get(ctx context.Context) (*actor.Organisation, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } @@ -88,7 +88,7 @@ func (s *organisationStore) Put(ctx context.Context, organisation *actor.Organis } func (s *organisationStore) CreateLPA(ctx context.Context) (*donordata.Provided, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } diff --git a/internal/app/organisation_store_test.go b/internal/app/organisation_store_test.go index aea6e65640..62133a6180 100644 --- a/internal/app/organisation_store_test.go +++ b/internal/app/organisation_store_test.go @@ -8,13 +8,12 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/stretchr/testify/assert" mock "github.com/stretchr/testify/mock" ) func TestOrganisationStoreCreate(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", Email: "a@example.org"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id", Email: "a@example.org"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -42,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(), &appcontext.SessionData{Email: "a@example.org"}), + "no session id": appcontext.ContextWithSession(context.Background(), &appcontext.Session{Email: "a@example.org"}), "no session data": context.Background(), } @@ -58,7 +57,7 @@ func TestOrganisationStoreCreateWithSessionMissing(t *testing.T) { } func TestOrganisationStoreCreateWhenErrors(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", Email: "a@example.org"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id", Email: "a@example.org"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -73,7 +72,7 @@ func TestOrganisationStoreCreateWhenErrors(t *testing.T) { } func TestOrganisationStoreGet(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "session-id"}) organisation := &actor.Organisation{Name: "A name"} member := actor.Member{PK: dynamo.OrganisationKey("a-uuid")} @@ -91,7 +90,7 @@ func TestOrganisationStoreGet(t *testing.T) { } func TestOrganisationStoreGetWhenOrganisationDeleted(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "session-id"}) organisation := &actor.Organisation{Name: "A name", DeletedAt: testNow} member := actor.Member{PK: dynamo.OrganisationKey("a-uuid")} @@ -112,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(), &appcontext.SessionData{}), + "missing SessionID": appcontext.ContextWithSession(context.Background(), &appcontext.Session{}), } for name, ctx := range testcases { @@ -138,7 +137,7 @@ func TestOrganisationStoreGetWhenErrors(t *testing.T) { }, } - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "session-id"}) member := actor.Member{PK: dynamo.OrganisationKey("a-uuid")} for name, tc := range testcases { @@ -178,7 +177,7 @@ func TestOrganisationStorePut(t *testing.T) { } func TestOrganisationStoreCreateLPA(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{OrganisationID: "an-id"}) expectedDonor := &donordata.Provided{ PK: dynamo.LpaKey("a-uuid"), SK: dynamo.LpaOwnerKey(dynamo.OrganisationKey("an-id")), @@ -212,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(), &appcontext.SessionData{}), + "missing organisation ID": appcontext.ContextWithSession(context.Background(), &appcontext.Session{}), } for name, ctx := range testCases { @@ -226,7 +225,7 @@ func TestOrganisationStoreCreateLPAWithSessionMissing(t *testing.T) { } func TestOrganisationStoreCreateLPAWhenDynamoError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{OrganisationID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -246,7 +245,7 @@ func TestOrganisationStoreCreateLPAWhenDynamoError(t *testing.T) { } func TestOrganisationStoreSoftDelete(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id", SessionID: "session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{OrganisationID: "an-id", SessionID: "session-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -260,7 +259,7 @@ func TestOrganisationStoreSoftDelete(t *testing.T) { } func TestOrganisationStoreSoftDeleteWhenDynamoClientError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{OrganisationID: "an-id", SessionID: "session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{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 695c131b83..202f339803 100644 --- a/internal/app/share_code_store.go +++ b/internal/app/share_code_store.go @@ -76,7 +76,7 @@ func (s *shareCodeStore) PutDonor(ctx context.Context, shareCode string, data sh func (s *shareCodeStore) GetDonor(ctx context.Context) (sharecode.Data, error) { var data sharecode.Data - sessionData, err := appcontext.SessionDataFromContext(ctx) + sessionData, err := appcontext.SessionFromContext(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 1b4b4c0cca..56929cb1d5 100644 --- a/internal/app/share_code_store_test.go +++ b/internal/app/share_code_store_test.go @@ -8,7 +8,6 @@ import ( "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/sharecode" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -158,7 +157,7 @@ func TestNewShareCodeStore(t *testing.T) { } func TestShareCodeStoreGetDonor(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{ + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{ OrganisationID: "org-id", LpaID: "lpa-id", }) diff --git a/internal/appcontext/data.go b/internal/appcontext/data.go new file mode 100644 index 0000000000..051af429e2 --- /dev/null +++ b/internal/appcontext/data.go @@ -0,0 +1,107 @@ +package appcontext + +import ( + "context" + "net/http" + "net/url" + "time" + + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/date" + "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" + "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" +) + +type Localizer interface { + Concat(list []string, joiner string) string + Count(messageID string, count int) string + Format(messageID string, data map[string]interface{}) string + FormatCount(messageID string, count int, data map[string]any) string + FormatDate(t date.TimeOrDate) string + FormatTime(t time.Time) string + FormatDateTime(t time.Time) string + Possessive(s string) string + SetShowTranslationKeys(s bool) + ShowTranslationKeys() bool + T(messageID string) string +} + +type Data struct { + Page string + Path string + Query url.Values + Localizer Localizer + Lang localize.Lang + CookieConsentSet bool + CanGoBack bool + CanToggleWelsh bool + SessionID string + LpaID string + CsrfToken string + ActorType actor.Type + AttorneyUID actoruid.UID + LoginSessionEmail string + SupporterData *SupporterData +} + +type SupporterData struct { + LpaType lpadata.LpaType + DonorFullName string + OrganisationName string + IsManageOrganisation bool + Permission actor.Permission + LoggedInSupporterID string +} + +func ContextWithData(ctx context.Context, appData Data) context.Context { + return context.WithValue(ctx, (*Data)(nil), appData) +} + +func DataFromContext(ctx context.Context) Data { + appData, _ := ctx.Value((*Data)(nil)).(Data) + + return appData +} + +func (d Data) Redirect(w http.ResponseWriter, r *http.Request, url string) error { + http.Redirect(w, r, d.Lang.URL(url), http.StatusFound) + return nil +} + +func (d Data) IsDonor() bool { + return d.ActorType == actor.TypeDonor +} + +func (d Data) IsCertificateProvider() bool { + return d.ActorType == actor.TypeCertificateProvider +} + +func (d Data) IsAttorneyType() bool { + return d.ActorType == actor.TypeAttorney || + d.ActorType == actor.TypeReplacementAttorney || + d.ActorType == actor.TypeTrustCorporation || + d.ActorType == actor.TypeReplacementTrustCorporation +} + +func (d Data) IsReplacementAttorney() bool { + return d.ActorType == actor.TypeReplacementAttorney || d.ActorType == actor.TypeReplacementTrustCorporation +} + +func (d Data) IsTrustCorporation() bool { + return d.ActorType == actor.TypeTrustCorporation || d.ActorType == actor.TypeReplacementTrustCorporation +} + +func (d Data) IsAdmin() bool { + return d.SupporterData != nil && d.SupporterData.Permission.IsAdmin() +} + +func (d Data) EncodeQuery() string { + query := "" + + if d.Query.Encode() != "" { + query = "?" + d.Query.Encode() + } + + return query +} diff --git a/internal/page/app_data_test.go b/internal/appcontext/data_test.go similarity index 66% rename from internal/page/app_data_test.go rename to internal/appcontext/data_test.go index d89652c255..0f89586156 100644 --- a/internal/page/app_data_test.go +++ b/internal/appcontext/data_test.go @@ -1,4 +1,4 @@ -package page +package appcontext import ( "context" @@ -24,7 +24,7 @@ func TestAppDataRedirect(t *testing.T) { r, _ := http.NewRequest(http.MethodGet, "/", nil) w := httptest.NewRecorder() - AppData{Lang: lang, LpaID: "lpa-id"}.Redirect(w, r, "/dashboard") + Data{Lang: lang, LpaID: "lpa-id"}.Redirect(w, r, "/dashboard") resp := w.Result() assert.Equal(t, http.StatusFound, resp.StatusCode) @@ -34,15 +34,15 @@ func TestAppDataRedirect(t *testing.T) { } func TestAppDataContext(t *testing.T) { - appData := AppData{LpaID: "me"} + appData := Data{LpaID: "me"} ctx := context.Background() - assert.Equal(t, AppData{}, AppDataFromContext(ctx)) - assert.Equal(t, appData, AppDataFromContext(ContextWithAppData(ctx, appData))) + assert.Equal(t, Data{}, DataFromContext(ctx)) + assert.Equal(t, appData, DataFromContext(ContextWithData(ctx, appData))) } func TestIsDonor(t *testing.T) { - appData := AppData{ActorType: actor.TypeDonor} + appData := Data{ActorType: actor.TypeDonor} assert.True(t, appData.IsDonor()) appData.ActorType = actor.TypeAttorney @@ -50,7 +50,7 @@ func TestIsDonor(t *testing.T) { } func TestIsCertificateProvider(t *testing.T) { - appData := AppData{ActorType: actor.TypeCertificateProvider} + appData := Data{ActorType: actor.TypeCertificateProvider} assert.True(t, appData.IsCertificateProvider()) appData.ActorType = actor.TypeAttorney @@ -58,7 +58,7 @@ func TestIsCertificateProvider(t *testing.T) { } func TestIsAttorneyType(t *testing.T) { - appData := AppData{ActorType: actor.TypeReplacementAttorney} + appData := Data{ActorType: actor.TypeReplacementAttorney} assert.True(t, appData.IsAttorneyType()) appData.ActorType = actor.TypeAttorney @@ -75,7 +75,7 @@ func TestIsAttorneyType(t *testing.T) { } func TestIsReplacementAttorney(t *testing.T) { - appData := AppData{ActorType: actor.TypeReplacementAttorney} + appData := Data{ActorType: actor.TypeReplacementAttorney} assert.True(t, appData.IsReplacementAttorney()) appData.ActorType = actor.TypeAttorney @@ -83,16 +83,16 @@ func TestIsReplacementAttorney(t *testing.T) { } func TestIsTrustCorporation(t *testing.T) { - assert.True(t, AppData{ActorType: actor.TypeTrustCorporation, AttorneyUID: actoruid.New()}.IsTrustCorporation()) - assert.True(t, AppData{ActorType: actor.TypeReplacementTrustCorporation, AttorneyUID: actoruid.New()}.IsTrustCorporation()) + assert.True(t, Data{ActorType: actor.TypeTrustCorporation, AttorneyUID: actoruid.New()}.IsTrustCorporation()) + assert.True(t, Data{ActorType: actor.TypeReplacementTrustCorporation, AttorneyUID: actoruid.New()}.IsTrustCorporation()) - assert.False(t, AppData{ActorType: actor.TypeAttorney, AttorneyUID: actoruid.New()}.IsTrustCorporation()) - assert.False(t, AppData{ActorType: actor.TypeReplacementAttorney, AttorneyUID: actoruid.New()}.IsTrustCorporation()) + assert.False(t, Data{ActorType: actor.TypeAttorney, AttorneyUID: actoruid.New()}.IsTrustCorporation()) + assert.False(t, Data{ActorType: actor.TypeReplacementAttorney, AttorneyUID: actoruid.New()}.IsTrustCorporation()) } func TestAppDataIsAdmin(t *testing.T) { - assert.True(t, AppData{SupporterData: &SupporterData{Permission: actor.PermissionAdmin}}.IsAdmin()) - assert.False(t, AppData{}.IsAdmin()) + assert.True(t, Data{SupporterData: &SupporterData{Permission: actor.PermissionAdmin}}.IsAdmin()) + assert.False(t, Data{}.IsAdmin()) } func TestAppDataEncodeQuery(t *testing.T) { @@ -111,7 +111,7 @@ func TestAppDataEncodeQuery(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { - assert.Equal(t, tc.expectedQueryString, AppData{Query: tc.query}.EncodeQuery()) + assert.Equal(t, tc.expectedQueryString, Data{Query: tc.query}.EncodeQuery()) }) } } diff --git a/internal/appcontext/session.go b/internal/appcontext/session.go new file mode 100644 index 0000000000..099f8f0f8f --- /dev/null +++ b/internal/appcontext/session.go @@ -0,0 +1,32 @@ +package appcontext + +import "context" + +type Session struct { + SessionID string + LpaID string + + // if a supporter + Email string + OrganisationID string +} + +type SessionMissingError struct{} + +func (s SessionMissingError) Error() string { + return "session not set in context" +} + +func SessionFromContext(ctx context.Context) (*Session, error) { + data, ok := ctx.Value((*Session)(nil)).(*Session) + + if !ok { + return nil, SessionMissingError{} + } + + return data, nil +} + +func ContextWithSession(ctx context.Context, data *Session) context.Context { + return context.WithValue(ctx, (*Session)(nil), data) +} diff --git a/internal/appcontext/session_data.go b/internal/appcontext/session_data.go deleted file mode 100644 index 86f86d7ed8..0000000000 --- a/internal/appcontext/session_data.go +++ /dev/null @@ -1,32 +0,0 @@ -package appcontext - -import "context" - -type SessionData struct { - SessionID string - LpaID string - - // if a supporter - Email string - OrganisationID string -} - -type SessionMissingError struct{} - -func (s SessionMissingError) Error() string { - return "Session data not set" -} - -func SessionDataFromContext(ctx context.Context) (*SessionData, error) { - data, ok := ctx.Value((*SessionData)(nil)).(*SessionData) - - if !ok { - return nil, SessionMissingError{} - } - - return data, nil -} - -func ContextWithSessionData(ctx context.Context, data *SessionData) context.Context { - return context.WithValue(ctx, (*SessionData)(nil), data) -} diff --git a/internal/attorney/attorneydata/store.go b/internal/attorney/attorneydata/store.go index 3263c7b8fa..a6f432dd38 100644 --- a/internal/attorney/attorneydata/store.go +++ b/internal/attorney/attorneydata/store.go @@ -7,10 +7,10 @@ import ( "time" dynamodbtypes "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/sharecode" - "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" ) type DynamoClient interface { @@ -43,7 +43,7 @@ func NewStore(dynamoClient DynamoClient, now func() time.Time) *Store { } func (s *Store) Create(ctx context.Context, shareCode sharecode.Data, email string) (*Provided, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } @@ -65,11 +65,11 @@ func (s *Store) Create(ctx context.Context, shareCode sharecode.Data, email stri transaction := dynamo.NewTransaction(). Create(attorney). - Create(temporary.LpaLink{ + Create(actor.LpaLink{ PK: dynamo.LpaKey(data.LpaID), SK: dynamo.SubKey(data.SessionID), DonorKey: shareCode.LpaOwnerKey, - ActorType: temporary.ActorTypeAttorney, + ActorType: actor.TypeAttorney, UpdatedAt: s.now(), }). Delete(dynamo.Keys{PK: shareCode.PK, SK: shareCode.SK}) @@ -82,7 +82,7 @@ func (s *Store) Create(ctx context.Context, shareCode sharecode.Data, email stri } func (s *Store) Get(ctx context.Context) (*Provided, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } @@ -103,7 +103,7 @@ func (s *Store) Put(ctx context.Context, attorney *Provided) error { } func (s *Store) Delete(ctx context.Context) error { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return err } diff --git a/internal/attorney/attorneydata/store_test.go b/internal/attorney/attorneydata/store_test.go index c4f9744aa0..b47a1b0ec7 100644 --- a/internal/attorney/attorneydata/store_test.go +++ b/internal/attorney/attorneydata/store_test.go @@ -7,11 +7,11 @@ import ( "testing" "time" + "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/sharecode" - "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) @@ -29,7 +29,7 @@ func TestAttorneyStoreCreate(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}) now := time.Now() uid := actoruid.New() details := &Provided{ @@ -56,11 +56,11 @@ func TestAttorneyStoreCreate(t *testing.T) { expectedTransaction := &dynamo.Transaction{ Creates: []any{ details, - temporary.LpaLink{ + actor.LpaLink{ PK: dynamo.LpaKey("123"), SK: dynamo.SubKey("456"), DonorKey: dynamo.LpaOwnerKey(dynamo.DonorKey("donor")), - ActorType: temporary.ActorTypeAttorney, + ActorType: actor.TypeAttorney, UpdatedAt: now, }, }, @@ -95,15 +95,15 @@ func TestAttorneyStoreCreateWhenSessionMissing(t *testing.T) { assert.Equal(t, appcontext.SessionMissingError{}, err) } -func TestAttorneyStoreCreateWhenSessionDataMissing(t *testing.T) { - testcases := map[string]*appcontext.SessionData{ +func TestAttorneyStoreCreateWhenSessionMissingRequiredData(t *testing.T) { + testcases := map[string]*appcontext.Session{ "LpaID": {SessionID: "456"}, "SessionID": {LpaID: "123"}, } for name, sessionData := range testcases { t.Run(name, func(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), sessionData) + ctx := appcontext.ContextWithSession(context.Background(), sessionData) attorneyStore := &Store{} @@ -114,7 +114,7 @@ func TestAttorneyStoreCreateWhenSessionDataMissing(t *testing.T) { } func TestAttorneyStoreCreateWhenWriteTransactionError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}) now := time.Now() dynamoClient := newMockDynamoClient(t) @@ -132,7 +132,7 @@ func TestAttorneyStoreCreateWhenWriteTransactionError(t *testing.T) { } func TestAttorneyStoreGet(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -155,8 +155,8 @@ func TestAttorneyStoreGetWhenSessionMissing(t *testing.T) { assert.Equal(t, appcontext.SessionMissingError{}, err) } -func TestAttorneyStoreGetMissingLpaIDInSessionData(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "456"}) +func TestAttorneyStoreGetMissingLpaIDInSession(t *testing.T) { + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "456"}) attorneyStore := &Store{} @@ -164,8 +164,8 @@ func TestAttorneyStoreGetMissingLpaIDInSessionData(t *testing.T) { assert.Equal(t, errors.New("attorneyStore.Get requires LpaID and SessionID"), err) } -func TestAttorneyStoreGetMissingSessionIDInSessionData(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) +func TestAttorneyStoreGetMissingSessionIDInSession(t *testing.T) { + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) attorneyStore := &Store{} @@ -174,7 +174,7 @@ func TestAttorneyStoreGetMissingSessionIDInSessionData(t *testing.T) { } func TestAttorneyStoreGetOnError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -224,7 +224,7 @@ func TestAttorneyStorePutOnError(t *testing.T) { } func TestAttorneyStoreDelete(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -237,7 +237,7 @@ func TestAttorneyStoreDelete(t *testing.T) { assert.Nil(t, err) } -func TestAttorneyStoreDeleteWhenSessionDataErrors(t *testing.T) { +func TestAttorneyStoreDeleteWhenSessionErrors(t *testing.T) { attorneyStore := &Store{} err := attorneyStore.Delete(ctx) @@ -259,7 +259,7 @@ func TestAttorneyStoreDeleteWhenMissingSessionValues(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: tc.lpaID, SessionID: tc.sessionID}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: tc.lpaID, SessionID: tc.sessionID}) attorneyStore := &Store{} @@ -270,7 +270,7 @@ func TestAttorneyStoreDeleteWhenMissingSessionValues(t *testing.T) { } func TestAttorneyStoreDeleteWhenDynamoClientError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). diff --git a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney.go b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney.go index 5b4ec77bf4..92a253accd 100644 --- a/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney.go +++ b/internal/attorney/attorneypage/confirm_dont_want_to_be_attorney.go @@ -5,6 +5,7 @@ import ( "net/url" "github.com/ministryofjustice/opg-go-common/template" + "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" @@ -13,13 +14,13 @@ import ( ) type confirmDontWantToBeAttorneyData struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa } func ConfirmDontWantToBeAttorney(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, attorneyStore AttorneyStore, notifyClient NotifyClient, appPublicURL string) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err 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 aa3190030f..212232eb76 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 @@ -16,19 +16,19 @@ import ( ) type confirmDontWantToBeAttorneyDataLoggedOut struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa } func ConfirmDontWantToBeAttorneyLoggedOut(tmpl template.Template, shareCodeStore ShareCodeStore, lpaStoreResolvingService LpaStoreResolvingService, sessionStore SessionStore, notifyClient NotifyClient, appPublicURL string) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { session, err := sessionStore.LpaData(r) if err != nil { return err } - ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: session.LpaID}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{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 c382a809c3..3c80262a3b 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 @@ -33,7 +33,7 @@ func TestGetConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) { lpaStoreResolvingService := newMockLpaStoreResolvingService(t) lpaStoreResolvingService.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: "lpa-id"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"})). Return(&lpa, nil) template := newMockTemplate(t) @@ -146,7 +146,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(), &appcontext.SessionData{LpaID: "lpa-id"}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"}) sessionStore := newMockSessionStore(t) sessionStore.EXPECT(). @@ -223,7 +223,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(), &appcontext.SessionData{LpaID: "lpa-id"}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"}) sessionStore := newMockSessionStore(t) sessionStore.EXPECT(). @@ -259,7 +259,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOutWhenAttorneyNotFound(t *testing func TestPostConfirmDontWantToBeAttorneyLoggedOutErrors(t *testing.T) { r, _ := http.NewRequest(http.MethodPost, "/?referenceNumber=123", nil) - ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: "lpa-id"}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"}) shareCodeData := sharecode.Data{ 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 d78ed29b9a..0939bd4e74 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 @@ -82,7 +82,7 @@ func TestGetConfirmDontWantToBeAttorneyWhenTemplateErrors(t *testing.T) { } func TestPostConfirmDontWantToBeAttorney(t *testing.T) { - r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) + r, _ := http.NewRequestWithContext(appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) w := httptest.NewRecorder() uid := actoruid.New() @@ -138,7 +138,7 @@ func TestPostConfirmDontWantToBeAttorney(t *testing.T) { } func TestPostConfirmDontWantToBeAttorneyWhenAttorneyNotFound(t *testing.T) { - r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) + r, _ := http.NewRequestWithContext(appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) w := httptest.NewRecorder() uid := actoruid.New() diff --git a/internal/attorney/attorneypage/confirm_your_details.go b/internal/attorney/attorneypage/confirm_your_details.go index 6126761bfb..1f815a38e4 100644 --- a/internal/attorney/attorneypage/confirm_your_details.go +++ b/internal/attorney/attorneypage/confirm_your_details.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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" @@ -12,7 +13,7 @@ import ( ) type confirmYourDetailsData struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa Attorney lpastore.Attorney @@ -21,7 +22,7 @@ type confirmYourDetailsData struct { } func ConfirmYourDetails(tmpl template.Template, attorneyStore AttorneyStore, lpaStoreResolvingService LpaStoreResolvingService) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { if r.Method == http.MethodPost { attorneyProvidedDetails.Tasks.ConfirmYourDetails = task.StateCompleted diff --git a/internal/attorney/attorneypage/confirm_your_details_test.go b/internal/attorney/attorneypage/confirm_your_details_test.go index 9026466b70..3fb940e41b 100644 --- a/internal/attorney/attorneypage/confirm_your_details_test.go +++ b/internal/attorney/attorneypage/confirm_your_details_test.go @@ -6,6 +6,7 @@ import ( "testing" "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" @@ -19,7 +20,7 @@ func TestGetConfirmYourDetails(t *testing.T) { attorneyProvidedDetails := &attorneydata.Provided{UID: uid} testcases := map[string]struct { - appData page.AppData + appData appcontext.Data donor *lpastore.Lpa data *confirmYourDetailsData }{ diff --git a/internal/attorney/attorneypage/enter_reference_number.go b/internal/attorney/attorneypage/enter_reference_number.go index 2142eab3eb..70cf910ec1 100644 --- a/internal/attorney/attorneypage/enter_reference_number.go +++ b/internal/attorney/attorneypage/enter_reference_number.go @@ -13,13 +13,13 @@ import ( ) type enterReferenceNumberData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *enterReferenceNumberForm } func EnterReferenceNumber(tmpl template.Template, shareCodeStore ShareCodeStore, sessionStore SessionStore, attorneyStore AttorneyStore) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { data := enterReferenceNumberData{ App: appData, Form: &enterReferenceNumberForm{}, @@ -47,7 +47,7 @@ func EnterReferenceNumber(tmpl template.Template, shareCodeStore ShareCodeStore, return err } - ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{ + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{ SessionID: session.SessionID(), LpaID: shareCode.LpaKey.ID(), }) diff --git a/internal/attorney/attorneypage/enter_reference_number_opt_out.go b/internal/attorney/attorneypage/enter_reference_number_opt_out.go index eeeda25554..b3af69aa75 100644 --- a/internal/attorney/attorneypage/enter_reference_number_opt_out.go +++ b/internal/attorney/attorneypage/enter_reference_number_opt_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/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" @@ -14,7 +15,7 @@ import ( ) func EnterReferenceNumberOptOut(tmpl template.Template, shareCodeStore ShareCodeStore, sessionStore SessionStore) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { data := enterReferenceNumberData{ App: appData, Form: &enterReferenceNumberForm{}, diff --git a/internal/attorney/attorneypage/enter_reference_number_test.go b/internal/attorney/attorneypage/enter_reference_number_test.go index 744dd9ed98..8c40f842d4 100644 --- a/internal/attorney/attorneypage/enter_reference_number_test.go +++ b/internal/attorney/attorneypage/enter_reference_number_test.go @@ -117,9 +117,9 @@ func TestPostEnterReferenceNumber(t *testing.T) { attorneyStore := newMockAttorneyStore(t) attorneyStore.EXPECT(). Create(mock.MatchedBy(func(ctx context.Context) bool { - session, _ := appcontext.SessionDataFromContext(ctx) + session, _ := appcontext.SessionFromContext(ctx) - return assert.Equal(t, &appcontext.SessionData{SessionID: "aGV5", LpaID: "lpa-id"}, session) + return assert.Equal(t, &appcontext.Session{SessionID: "aGV5", LpaID: "lpa-id"}, session) }), tc.shareCode, "a@example.com"). Return(&attorneydata.Provided{}, nil) diff --git a/internal/attorney/attorneypage/guidance.go b/internal/attorney/attorneypage/guidance.go index 6f97096a28..1706165a55 100644 --- a/internal/attorney/attorneypage/guidance.go +++ b/internal/attorney/attorneypage/guidance.go @@ -4,20 +4,20 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type guidanceData struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa } func Guidance(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, _ *attorneydata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, _ *attorneydata.Provided) error { data := &guidanceData{ App: appData, } diff --git a/internal/attorney/attorneypage/mobile_number.go b/internal/attorney/attorneypage/mobile_number.go index 448b2a29d7..44466b7117 100644 --- a/internal/attorney/attorneypage/mobile_number.go +++ b/internal/attorney/attorneypage/mobile_number.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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" @@ -12,7 +13,7 @@ import ( ) type mobileNumberData struct { - App page.AppData + App appcontext.Data Donor *lpastore.Lpa Form *mobileNumberForm Errors validation.List @@ -23,7 +24,7 @@ type mobileNumberForm struct { } func MobileNumber(tmpl template.Template, attorneyStore AttorneyStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { data := &mobileNumberData{ App: appData, Form: &mobileNumberForm{ diff --git a/internal/attorney/attorneypage/mobile_number_test.go b/internal/attorney/attorneypage/mobile_number_test.go index bbf0b247cc..eacde3bcf0 100644 --- a/internal/attorney/attorneypage/mobile_number_test.go +++ b/internal/attorney/attorneypage/mobile_number_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -17,7 +18,7 @@ import ( func TestGetMobileNumber(t *testing.T) { testcases := map[string]struct { - appData page.AppData + appData appcontext.Data }{ "attorney": { appData: testAppData, @@ -51,7 +52,7 @@ func TestGetMobileNumber(t *testing.T) { func TestGetMobileNumberFromStore(t *testing.T) { testcases := map[string]struct { - appData page.AppData + appData appcontext.Data attorney *attorneydata.Provided }{ "attorney": { @@ -107,7 +108,7 @@ func TestPostMobileNumber(t *testing.T) { form url.Values attorney *attorneydata.Provided updatedAttorney *attorneydata.Provided - appData page.AppData + appData appcontext.Data }{ "attorney": { form: url.Values{ diff --git a/internal/attorney/attorneypage/mock_DashboardStore_test.go b/internal/attorney/attorneypage/mock_DashboardStore_test.go index c06c23dce8..795aa37504 100644 --- a/internal/attorney/attorneypage/mock_DashboardStore_test.go +++ b/internal/attorney/attorneypage/mock_DashboardStore_test.go @@ -5,10 +5,11 @@ package attorneypage import ( context "context" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + mock "github.com/stretchr/testify/mock" - temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" + page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) // mockDashboardStore is an autogenerated mock type for the DashboardStore type @@ -101,7 +102,7 @@ func (_c *mockDashboardStore_GetAll_Call) RunAndReturn(run func(context.Context) } // SubExistsForActorType provides a mock function with given fields: ctx, sub, actorType -func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType temporary.ActorType) (bool, error) { +func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType actor.Type) (bool, error) { ret := _m.Called(ctx, sub, actorType) if len(ret) == 0 { @@ -110,16 +111,16 @@ func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub str var r0 bool var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) (bool, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) (bool, error)); ok { return rf(ctx, sub, actorType) } - if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) bool); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) bool); ok { r0 = rf(ctx, sub, actorType) } else { r0 = ret.Get(0).(bool) } - if rf, ok := ret.Get(1).(func(context.Context, string, temporary.ActorType) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, actor.Type) error); ok { r1 = rf(ctx, sub, actorType) } else { r1 = ret.Error(1) @@ -136,14 +137,14 @@ type mockDashboardStore_SubExistsForActorType_Call struct { // SubExistsForActorType is a helper method to define mock.On call // - ctx context.Context // - sub string -// - actorType temporary.ActorType +// - actorType actor.Type func (_e *mockDashboardStore_Expecter) SubExistsForActorType(ctx interface{}, sub interface{}, actorType interface{}) *mockDashboardStore_SubExistsForActorType_Call { return &mockDashboardStore_SubExistsForActorType_Call{Call: _e.mock.On("SubExistsForActorType", ctx, sub, actorType)} } -func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType temporary.ActorType)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType actor.Type)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(temporary.ActorType)) + run(args[0].(context.Context), args[1].(string), args[2].(actor.Type)) }) return _c } @@ -153,7 +154,7 @@ func (_c *mockDashboardStore_SubExistsForActorType_Call) Return(_a0 bool, _a1 er return _c } -func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, temporary.ActorType) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, actor.Type) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Return(run) return _c } diff --git a/internal/attorney/attorneypage/mock_Handler_test.go b/internal/attorney/attorneypage/mock_Handler_test.go index ebbea22527..c8558a58ae 100644 --- a/internal/attorney/attorneypage/mock_Handler_test.go +++ b/internal/attorney/attorneypage/mock_Handler_test.go @@ -3,13 +3,12 @@ package attorneypage import ( - http "net/http" - + appcontext "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" attorneydata "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" - mock "github.com/stretchr/testify/mock" + http "net/http" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + mock "github.com/stretchr/testify/mock" ) // mockHandler is an autogenerated mock type for the Handler type @@ -26,7 +25,7 @@ func (_m *mockHandler) EXPECT() *mockHandler_Expecter { } // Execute provides a mock function with given fields: data, w, r, details -func (_m *mockHandler) Execute(data page.AppData, w http.ResponseWriter, r *http.Request, details *attorneydata.Provided) error { +func (_m *mockHandler) Execute(data appcontext.Data, w http.ResponseWriter, r *http.Request, details *attorneydata.Provided) error { ret := _m.Called(data, w, r, details) if len(ret) == 0 { @@ -34,7 +33,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, *attorneydata.Provided) error); ok { + if rf, ok := ret.Get(0).(func(appcontext.Data, http.ResponseWriter, *http.Request, *attorneydata.Provided) error); ok { r0 = rf(data, w, r, details) } else { r0 = ret.Error(0) @@ -49,7 +48,7 @@ type mockHandler_Execute_Call struct { } // Execute is a helper method to define mock.On call -// - data page.AppData +// - data appcontext.Data // - w http.ResponseWriter // - r *http.Request // - details *attorneydata.Provided @@ -57,9 +56,9 @@ func (_e *mockHandler_Expecter) Execute(data interface{}, w interface{}, r inter return &mockHandler_Execute_Call{Call: _e.mock.On("Execute", data, w, r, details)} } -func (_c *mockHandler_Execute_Call) Run(run func(data page.AppData, w http.ResponseWriter, r *http.Request, details *attorneydata.Provided)) *mockHandler_Execute_Call { +func (_c *mockHandler_Execute_Call) Run(run func(data appcontext.Data, w http.ResponseWriter, r *http.Request, details *attorneydata.Provided)) *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].(*attorneydata.Provided)) + run(args[0].(appcontext.Data), args[1].(http.ResponseWriter), args[2].(*http.Request), args[3].(*attorneydata.Provided)) }) return _c } @@ -69,7 +68,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, *attorneydata.Provided) error) *mockHandler_Execute_Call { +func (_c *mockHandler_Execute_Call) RunAndReturn(run func(appcontext.Data, http.ResponseWriter, *http.Request, *attorneydata.Provided) error) *mockHandler_Execute_Call { _c.Call.Return(run) return _c } diff --git a/internal/attorney/attorneypage/mock_ShareCodeStore_test.go b/internal/attorney/attorneypage/mock_ShareCodeStore_test.go index 93f17a10fa..6da566168a 100644 --- a/internal/attorney/attorneypage/mock_ShareCodeStore_test.go +++ b/internal/attorney/attorneypage/mock_ShareCodeStore_test.go @@ -5,10 +5,11 @@ package attorneypage import ( context "context" - sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" + actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + mock "github.com/stretchr/testify/mock" - temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) // mockShareCodeStore is an autogenerated mock type for the ShareCodeStore type @@ -72,7 +73,7 @@ func (_c *mockShareCodeStore_Delete_Call) RunAndReturn(run func(context.Context, } // Get provides a mock function with given fields: ctx, actorType, shareCode -func (_m *mockShareCodeStore) Get(ctx context.Context, actorType temporary.ActorType, shareCode string) (sharecode.Data, error) { +func (_m *mockShareCodeStore) Get(ctx context.Context, actorType actor.Type, shareCode string) (sharecode.Data, error) { ret := _m.Called(ctx, actorType, shareCode) if len(ret) == 0 { @@ -81,16 +82,16 @@ func (_m *mockShareCodeStore) Get(ctx context.Context, actorType temporary.Actor var r0 sharecode.Data var r1 error - if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) (sharecode.Data, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) (sharecode.Data, error)); ok { return rf(ctx, actorType, shareCode) } - if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) sharecode.Data); ok { + if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) sharecode.Data); ok { r0 = rf(ctx, actorType, shareCode) } else { r0 = ret.Get(0).(sharecode.Data) } - if rf, ok := ret.Get(1).(func(context.Context, temporary.ActorType, string) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, actor.Type, string) error); ok { r1 = rf(ctx, actorType, shareCode) } else { r1 = ret.Error(1) @@ -106,15 +107,15 @@ type mockShareCodeStore_Get_Call struct { // Get is a helper method to define mock.On call // - ctx context.Context -// - actorType temporary.ActorType +// - actorType actor.Type // - shareCode string func (_e *mockShareCodeStore_Expecter) Get(ctx interface{}, actorType interface{}, shareCode interface{}) *mockShareCodeStore_Get_Call { return &mockShareCodeStore_Get_Call{Call: _e.mock.On("Get", ctx, actorType, shareCode)} } -func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, shareCode string)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType actor.Type, shareCode string)) *mockShareCodeStore_Get_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string)) + run(args[0].(context.Context), args[1].(actor.Type), args[2].(string)) }) return _c } @@ -124,13 +125,13 @@ func (_c *mockShareCodeStore_Get_Call) Return(_a0 sharecode.Data, _a1 error) *mo return _c } -func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string) (sharecode.Data, error)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, actor.Type, string) (sharecode.Data, error)) *mockShareCodeStore_Get_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: ctx, actorType, shareCode, data -func (_m *mockShareCodeStore) Put(ctx context.Context, actorType temporary.ActorType, shareCode string, data sharecode.Data) error { +func (_m *mockShareCodeStore) Put(ctx context.Context, actorType actor.Type, shareCode string, data sharecode.Data) error { ret := _m.Called(ctx, actorType, shareCode, data) if len(ret) == 0 { @@ -138,7 +139,7 @@ func (_m *mockShareCodeStore) Put(ctx context.Context, actorType temporary.Actor } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string, sharecode.Data) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string, sharecode.Data) error); ok { r0 = rf(ctx, actorType, shareCode, data) } else { r0 = ret.Error(0) @@ -154,16 +155,16 @@ type mockShareCodeStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - actorType temporary.ActorType +// - actorType actor.Type // - shareCode string // - data sharecode.Data func (_e *mockShareCodeStore_Expecter) Put(ctx interface{}, actorType interface{}, shareCode interface{}, data interface{}) *mockShareCodeStore_Put_Call { return &mockShareCodeStore_Put_Call{Call: _e.mock.On("Put", ctx, actorType, shareCode, data)} } -func (_c *mockShareCodeStore_Put_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, shareCode string, data sharecode.Data)) *mockShareCodeStore_Put_Call { +func (_c *mockShareCodeStore_Put_Call) Run(run func(ctx context.Context, actorType actor.Type, shareCode string, data sharecode.Data)) *mockShareCodeStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string), args[3].(sharecode.Data)) + run(args[0].(context.Context), args[1].(actor.Type), args[2].(string), args[3].(sharecode.Data)) }) return _c } @@ -173,7 +174,7 @@ func (_c *mockShareCodeStore_Put_Call) Return(_a0 error) *mockShareCodeStore_Put return _c } -func (_c *mockShareCodeStore_Put_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string, sharecode.Data) error) *mockShareCodeStore_Put_Call { +func (_c *mockShareCodeStore_Put_Call) RunAndReturn(run func(context.Context, actor.Type, string, sharecode.Data) error) *mockShareCodeStore_Put_Call { _c.Call.Return(run) return _c } diff --git a/internal/attorney/attorneypage/mock_test.go b/internal/attorney/attorneypage/mock_test.go index 476962eef2..d485bf761f 100644 --- a/internal/attorney/attorneypage/mock_test.go +++ b/internal/attorney/attorneypage/mock_test.go @@ -6,35 +6,35 @@ 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/localize" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) var ( testUID = actoruid.New() expectedError = errors.New("err") - testAppData = page.AppData{ + testAppData = appcontext.Data{ SessionID: "session-id", LpaID: "lpa-id", AttorneyUID: testUID, Lang: localize.En, ActorType: actor.TypeAttorney, } - testReplacementAppData = page.AppData{ + testReplacementAppData = appcontext.Data{ SessionID: "session-id", LpaID: "lpa-id", AttorneyUID: testUID, Lang: localize.En, ActorType: actor.TypeReplacementAttorney, } - testTrustCorporationAppData = page.AppData{ + testTrustCorporationAppData = appcontext.Data{ SessionID: "session-id", LpaID: "lpa-id", AttorneyUID: testUID, Lang: localize.En, ActorType: actor.TypeTrustCorporation, } - testReplacementTrustCorporationAppData = page.AppData{ + testReplacementTrustCorporationAppData = appcontext.Data{ SessionID: "session-id", LpaID: "lpa-id", AttorneyUID: testUID, diff --git a/internal/attorney/attorneypage/progress.go b/internal/attorney/attorneypage/progress.go index ffc3359e63..01815481f3 100644 --- a/internal/attorney/attorneypage/progress.go +++ b/internal/attorney/attorneypage/progress.go @@ -4,14 +4,14 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type progressData struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa Signed bool @@ -19,7 +19,7 @@ type progressData struct { } func Progress(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err diff --git a/internal/attorney/attorneypage/read_the_lpa.go b/internal/attorney/attorneypage/read_the_lpa.go index deed0c82f5..1d2d690942 100644 --- a/internal/attorney/attorneypage/read_the_lpa.go +++ b/internal/attorney/attorneypage/read_the_lpa.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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" @@ -12,13 +13,13 @@ import ( ) type readTheLpaData struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa } func ReadTheLpa(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, attorneyStore AttorneyStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { if r.Method == http.MethodPost { attorneyProvidedDetails.Tasks.ReadTheLpa = task.StateCompleted diff --git a/internal/attorney/attorneypage/register.go b/internal/attorney/attorneypage/register.go index f8a23bedf3..37e1d6e917 100644 --- a/internal/attorney/attorneypage/register.go +++ b/internal/attorney/attorneypage/register.go @@ -28,7 +28,7 @@ type LpaStoreResolvingService interface { Get(ctx context.Context) (*lpastore.Lpa, error) } -type Handler func(data page.AppData, w http.ResponseWriter, r *http.Request, details *attorneydata.Provided) error +type Handler func(data appcontext.Data, w http.ResponseWriter, r *http.Request, details *attorneydata.Provided) error type Template func(io.Writer, interface{}) error @@ -159,7 +159,7 @@ func makeHandle(mux *http.ServeMux, store SessionStore, errorHandler page.ErrorH mux.HandleFunc(path.String(), func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - appData := page.AppDataFromContext(ctx) + appData := appcontext.DataFromContext(ctx) appData.Page = path.Format() appData.CanGoBack = opt&CanGoBack != 0 @@ -171,10 +171,10 @@ func makeHandle(mux *http.ServeMux, store SessionStore, errorHandler page.ErrorH } appData.SessionID = session.SessionID() - ctx = page.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID}) + ctx = appcontext.ContextWithSession(ctx, &appcontext.Session{SessionID: appData.SessionID, LpaID: appData.LpaID}) } - if err := h(appData, w, r.WithContext(page.ContextWithAppData(ctx, appData))); err != nil { + if err := h(appData, w, r.WithContext(appcontext.ContextWithData(ctx, appData))); err != nil { errorHandler(w, r, err) } }) @@ -186,7 +186,7 @@ func makeAttorneyHandle(mux *http.ServeMux, store SessionStore, errorHandler pag mux.HandleFunc(path.String(), func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - appData := page.AppDataFromContext(ctx) + appData := appcontext.DataFromContext(ctx) appData.CanGoBack = opt&CanGoBack != 0 appData.LpaID = r.PathValue("id") @@ -198,13 +198,13 @@ func makeAttorneyHandle(mux *http.ServeMux, store SessionStore, errorHandler pag appData.SessionID = session.SessionID() - sessionData, err := appcontext.SessionDataFromContext(ctx) + sessionData, err := appcontext.SessionFromContext(ctx) if err == nil { sessionData.SessionID = appData.SessionID sessionData.LpaID = appData.LpaID - ctx = page.ContextWithSessionData(ctx, sessionData) + ctx = appcontext.ContextWithSession(ctx, sessionData) } else { - ctx = page.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID}) + ctx = appcontext.ContextWithSession(ctx, &appcontext.Session{SessionID: appData.SessionID, LpaID: appData.LpaID}) } attorney, err := attorneyStore.Get(ctx) @@ -230,7 +230,7 @@ func makeAttorneyHandle(mux *http.ServeMux, store SessionStore, errorHandler pag appData.ActorType = actor.TypeAttorney } - if err := h(appData, w, r.WithContext(page.ContextWithAppData(ctx, appData)), attorney); err != nil { + if err := h(appData, w, r.WithContext(appcontext.ContextWithData(ctx, appData)), attorney); err != nil { errorHandler(w, r, err) } }) diff --git a/internal/attorney/attorneypage/register_test.go b/internal/attorney/attorneypage/register_test.go index d6d6d093f7..bc41e8b844 100644 --- a/internal/attorney/attorneypage/register_test.go +++ b/internal/attorney/attorneypage/register_test.go @@ -36,8 +36,8 @@ func TestMakeHandle(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, sessionStore, nil) - handle("/path", RequireSession, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { - assert.Equal(t, page.AppData{ + handle("/path", RequireSession, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { + assert.Equal(t, appcontext.Data{ Page: "/path", CanGoBack: false, SessionID: "cmFuZG9t", @@ -54,8 +54,8 @@ func TestMakeHandle(t *testing.T) { assert.Equal(t, http.StatusTeapot, resp.StatusCode) } -func TestMakeHandleRequireSessionExistingSessionData(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored-session-id"}) +func TestMakeHandleRequireSessionExistingSession(t *testing.T) { + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "ignored-session-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/path?a=b", nil) @@ -66,17 +66,17 @@ func TestMakeHandleRequireSessionExistingSessionData(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, sessionStore, nil) - handle("/path", RequireSession|CanGoBack, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { - assert.Equal(t, page.AppData{ + handle("/path", RequireSession|CanGoBack, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { + assert.Equal(t, appcontext.Data{ Page: "/path", CanGoBack: true, SessionID: "cmFuZG9t", }, appData) assert.Equal(t, w, hw) - sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) + sessionData, _ := appcontext.SessionFromContext(hr.Context()) - assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t"}, sessionData) + assert.Equal(t, &appcontext.Session{SessionID: "cmFuZG9t"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil }) @@ -97,7 +97,7 @@ func TestMakeHandleErrors(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, nil, errorHandler.Execute) - handle("/path", None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { + handle("/path", None, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { return expectedError }) @@ -115,7 +115,7 @@ func TestMakeHandleSessionError(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, sessionStore, nil) - handle("/path", RequireSession, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { return nil }) + handle("/path", RequireSession, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { return nil }) mux.ServeHTTP(w, r) resp := w.Result() @@ -130,12 +130,12 @@ func TestMakeHandleNoSessionRequired(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, nil, nil) - handle("/path", None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { - assert.Equal(t, page.AppData{ + handle("/path", None, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { + assert.Equal(t, appcontext.Data{ Page: "/path", }, appData) assert.Equal(t, w, hw) - assert.Equal(t, r.WithContext(page.ContextWithAppData(r.Context(), page.AppData{Page: "/path"})), hr) + assert.Equal(t, r.WithContext(appcontext.ContextWithData(r.Context(), appcontext.Data{Page: "/path"})), hr) hw.WriteHeader(http.StatusTeapot) return nil }) @@ -146,8 +146,8 @@ func TestMakeHandleNoSessionRequired(t *testing.T) { assert.Equal(t, http.StatusTeapot, resp.StatusCode) } -func TestMakeAttorneyHandleExistingSessionData(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored-session-id"}) +func TestMakeAttorneyHandleExistingSession(t *testing.T) { + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "ignored-session-id"}) uid := actoruid.New() w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/attorney/lpa-id/path?a=b", nil) @@ -165,10 +165,10 @@ func TestMakeAttorneyHandleExistingSessionData(t *testing.T) { mux := http.NewServeMux() handle := makeAttorneyHandle(mux, sessionStore, nil, attorneyStore) - handle("/path", CanGoBack, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, details *attorneydata.Provided) error { + handle("/path", CanGoBack, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request, details *attorneydata.Provided) error { assert.Equal(t, expectedDetails, details) - assert.Equal(t, page.AppData{ + assert.Equal(t, appcontext.Data{ Page: "/attorney/lpa-id/path", CanGoBack: true, SessionID: "cmFuZG9t", @@ -178,9 +178,9 @@ func TestMakeAttorneyHandleExistingSessionData(t *testing.T) { }, appData) assert.Equal(t, w, hw) - sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) + sessionData, _ := appcontext.SessionFromContext(hr.Context()) - assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t", LpaID: "lpa-id"}, sessionData) + assert.Equal(t, &appcontext.Session{SessionID: "cmFuZG9t", LpaID: "lpa-id"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil }) @@ -233,9 +233,9 @@ func TestMakeAttorneyHandleExistingLpaData(t *testing.T) { mux := http.NewServeMux() handle := makeAttorneyHandle(mux, sessionStore, nil, attorneyStore) - handle("/path", CanGoBack, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, details *attorneydata.Provided) error { + handle("/path", CanGoBack, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request, details *attorneydata.Provided) error { assert.Equal(t, tc.details, details) - assert.Equal(t, page.AppData{ + assert.Equal(t, appcontext.Data{ Page: "/attorney/lpa-id/path", CanGoBack: true, LpaID: "lpa-id", @@ -245,9 +245,9 @@ func TestMakeAttorneyHandleExistingLpaData(t *testing.T) { }, appData) assert.Equal(t, w, hw) - sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) + sessionData, _ := appcontext.SessionFromContext(hr.Context()) - assert.Equal(t, &appcontext.SessionData{LpaID: "lpa-id", SessionID: "cmFuZG9t"}, sessionData) + assert.Equal(t, &appcontext.Session{LpaID: "lpa-id", SessionID: "cmFuZG9t"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil }) @@ -260,10 +260,10 @@ func TestMakeAttorneyHandleExistingLpaData(t *testing.T) { } } -func TestMakeAttorneyHandleExistingSessionDataWhenCannotGoToURL(t *testing.T) { +func TestMakeAttorneyHandleExistingSessionWhenCannotGoToURL(t *testing.T) { path := page.Paths.Attorney.Sign - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored-session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "ignored-session-id"}) uid := actoruid.New() w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, path.Format("123"), nil) @@ -281,7 +281,7 @@ func TestMakeAttorneyHandleExistingSessionDataWhenCannotGoToURL(t *testing.T) { mux := http.NewServeMux() handle := makeAttorneyHandle(mux, sessionStore, nil, attorneyStore) - handle(path, CanGoBack, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, details *attorneydata.Provided) error { + handle(path, CanGoBack, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request, details *attorneydata.Provided) error { return nil }) @@ -312,7 +312,7 @@ func TestMakeAttorneyHandleErrors(t *testing.T) { mux := http.NewServeMux() handle := makeAttorneyHandle(mux, sessionStore, errorHandler.Execute, attorneyStore) - handle("/path", None, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *attorneydata.Provided) error { + handle("/path", None, func(_ appcontext.Data, _ http.ResponseWriter, _ *http.Request, _ *attorneydata.Provided) error { return expectedError }) @@ -339,7 +339,7 @@ func TestMakeAttorneyHandleAttorneyStoreErrors(t *testing.T) { mux := http.NewServeMux() handle := makeAttorneyHandle(mux, sessionStore, errorHandler.Execute, attorneyStore) - handle("/path", None, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *attorneydata.Provided) error { + handle("/path", None, func(_ appcontext.Data, _ http.ResponseWriter, _ *http.Request, _ *attorneydata.Provided) error { return nil }) @@ -357,7 +357,7 @@ func TestMakeAttorneyHandleSessionError(t *testing.T) { mux := http.NewServeMux() handle := makeAttorneyHandle(mux, sessionStore, nil, nil) - handle("/path", RequireSession, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *attorneydata.Provided) error { + handle("/path", RequireSession, func(_ appcontext.Data, _ http.ResponseWriter, _ *http.Request, _ *attorneydata.Provided) error { return nil }) diff --git a/internal/attorney/attorneypage/sign.go b/internal/attorney/attorneypage/sign.go index 898f4ace42..24ec18e6a9 100644 --- a/internal/attorney/attorneypage/sign.go +++ b/internal/attorney/attorneypage/sign.go @@ -5,6 +5,7 @@ import ( "time" "github.com/ministryofjustice/opg-go-common/template" + "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" @@ -13,7 +14,7 @@ import ( ) type signData struct { - App page.AppData + App appcontext.Data Errors validation.List LpaID string Attorney lpastore.Attorney @@ -31,7 +32,7 @@ func Sign( lpaStoreClient LpaStoreClient, now func() time.Time, ) Handler { - signAttorney := func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided, lpa *lpastore.Lpa) error { + signAttorney := func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided, lpa *lpastore.Lpa) error { data := &signData{ App: appData, LpaID: lpa.LpaID, @@ -79,7 +80,7 @@ func Sign( return tmpl(w, data) } - signTrustCorporation := func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided, lpa *lpastore.Lpa) error { + signTrustCorporation := func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided, lpa *lpastore.Lpa) error { signatoryIndex := 0 if r.URL.Query().Has("second") { signatoryIndex = 1 @@ -149,7 +150,7 @@ func Sign( return tmpl(w, data) } - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { if attorneyProvidedDetails.Signed() { return page.Paths.Attorney.WhatHappensNext.Redirect(w, r, appData, attorneyProvidedDetails.LpaID) } diff --git a/internal/attorney/attorneypage/sign_test.go b/internal/attorney/attorneypage/sign_test.go index f3b8c00da7..5f42ff8c3e 100644 --- a/internal/attorney/attorneypage/sign_test.go +++ b/internal/attorney/attorneypage/sign_test.go @@ -9,6 +9,7 @@ import ( "time" "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" @@ -22,7 +23,7 @@ import ( func TestGetSign(t *testing.T) { testcases := map[string]struct { - appData page.AppData + appData appcontext.Data lpa *lpastore.Lpa data *signData }{ @@ -186,7 +187,7 @@ func TestGetSignCantSignYet(t *testing.T) { uid := actoruid.New() testcases := map[string]struct { - appData page.AppData + appData appcontext.Data lpa *lpastore.Lpa }{ "submitted but not certified": { @@ -238,7 +239,7 @@ func TestGetSignWhenAttorneyDoesNotExist(t *testing.T) { uid := actoruid.New() testcases := map[string]struct { - appData page.AppData + appData appcontext.Data lpa *lpastore.Lpa }{ "attorney": { @@ -336,7 +337,7 @@ func TestPostSign(t *testing.T) { testcases := map[string]struct { url string - appData page.AppData + appData appcontext.Data form url.Values lpa *lpastore.Lpa updatedAttorney *attorneydata.Provided @@ -460,7 +461,7 @@ func TestPostSignWhenSignedInLpaStore(t *testing.T) { testcases := map[string]struct { url string - appData page.AppData + appData appcontext.Data form url.Values lpa *lpastore.Lpa updatedAttorney *attorneydata.Provided @@ -578,7 +579,7 @@ func TestPostSignWhenWantSecondSignatory(t *testing.T) { testcases := map[string]struct { url string - appData page.AppData + appData appcontext.Data form url.Values lpa *lpastore.Lpa updatedAttorney *attorneydata.Provided diff --git a/internal/attorney/attorneypage/task_list.go b/internal/attorney/attorneypage/task_list.go index 2dec72b6a8..8e23b603f3 100644 --- a/internal/attorney/attorneypage/task_list.go +++ b/internal/attorney/attorneypage/task_list.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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" @@ -12,7 +13,7 @@ import ( ) type taskListData struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa Items []taskListItem @@ -26,7 +27,7 @@ type taskListItem struct { } func TaskList(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorney *attorneydata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorney *attorneydata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err diff --git a/internal/attorney/attorneypage/task_list_test.go b/internal/attorney/attorneypage/task_list_test.go index fc06e18891..b1ae9b9dcb 100644 --- a/internal/attorney/attorneypage/task_list_test.go +++ b/internal/attorney/attorneypage/task_list_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" @@ -19,7 +20,7 @@ func TestGetTaskList(t *testing.T) { testCases := map[string]struct { lpa *lpastore.Lpa attorney *attorneydata.Provided - appData page.AppData + appData appcontext.Data expected func([]taskListItem) []taskListItem }{ "empty": { diff --git a/internal/attorney/attorneypage/would_like_second_signatory.go b/internal/attorney/attorneypage/would_like_second_signatory.go index 94832bf67a..0bae368390 100644 --- a/internal/attorney/attorneypage/would_like_second_signatory.go +++ b/internal/attorney/attorneypage/would_like_second_signatory.go @@ -5,6 +5,7 @@ import ( "net/url" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,13 +13,13 @@ import ( ) type wouldLikeSecondSignatoryData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm } func WouldLikeSecondSignatory(tmpl template.Template, attorneyStore AttorneyStore, lpaStoreResolvingService LpaStoreResolvingService, lpaStoreClient LpaStoreClient) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { if attorneyProvidedDetails.Signed() { return page.Paths.Attorney.WhatHappensNext.Redirect(w, r, appData, attorneyProvidedDetails.LpaID) } diff --git a/internal/attorney/attorneypage/would_like_second_signatory_test.go b/internal/attorney/attorneypage/would_like_second_signatory_test.go index bacf45b436..804e073158 100644 --- a/internal/attorney/attorneypage/would_like_second_signatory_test.go +++ b/internal/attorney/attorneypage/would_like_second_signatory_test.go @@ -8,6 +8,7 @@ import ( "testing" "time" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" @@ -139,7 +140,7 @@ func TestPostWouldLikeSecondSignatoryWhenNo(t *testing.T) { func TestPostWouldLikeSecondSignatoryWhenNoAndSignedInLpaStore(t *testing.T) { testcases := map[string]struct { - appData page.AppData + appData appcontext.Data lpa *lpastore.Lpa }{ "trust corporation": { diff --git a/internal/attorney/attorneypage/your_preferred_language.go b/internal/attorney/attorneypage/your_preferred_language.go index ec18ae0602..561b262284 100644 --- a/internal/attorney/attorneypage/your_preferred_language.go +++ b/internal/attorney/attorneypage/your_preferred_language.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -13,7 +14,7 @@ import ( ) type yourPreferredLanguageData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.LanguagePreferenceForm Options localize.LangOptions @@ -22,7 +23,7 @@ type yourPreferredLanguageData struct { } func YourPreferredLanguage(tmpl template.Template, attorneyStore AttorneyStore, lpaStoreResolvingService LpaStoreResolvingService) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err diff --git a/internal/certificateprovider/certificateproviderdata/store.go b/internal/certificateprovider/certificateproviderdata/store.go index 0b354ea1e1..8754adc6fe 100644 --- a/internal/certificateprovider/certificateproviderdata/store.go +++ b/internal/certificateprovider/certificateproviderdata/store.go @@ -11,7 +11,6 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" - "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" ) type DynamoClient interface { @@ -44,7 +43,7 @@ type Store struct { } func (s *Store) Create(ctx context.Context, shareCode sharecode.Data, email string) (*Provided, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } @@ -64,7 +63,7 @@ func (s *Store) Create(ctx context.Context, shareCode sharecode.Data, email stri transaction := dynamo.NewTransaction(). Create(certificateProvider). - Create(temporary.LpaLink{ + Create(actor.LpaLink{ PK: dynamo.LpaKey(data.LpaID), SK: dynamo.SubKey(data.SessionID), DonorKey: shareCode.LpaOwnerKey, @@ -81,7 +80,7 @@ func (s *Store) Create(ctx context.Context, shareCode sharecode.Data, email stri } func (s *Store) GetAny(ctx context.Context) (*Provided, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } @@ -97,7 +96,7 @@ func (s *Store) GetAny(ctx context.Context) (*Provided, error) { } func (s *Store) Get(ctx context.Context) (*Provided, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } @@ -118,7 +117,7 @@ func (s *Store) Put(ctx context.Context, certificateProvider *Provided) error { } func (s *Store) Delete(ctx context.Context) error { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return err } diff --git a/internal/certificateprovider/certificateproviderdata/store_test.go b/internal/certificateprovider/certificateproviderdata/store_test.go index 10ca4771be..b6e3304d47 100644 --- a/internal/certificateprovider/certificateproviderdata/store_test.go +++ b/internal/certificateprovider/certificateproviderdata/store_test.go @@ -6,17 +6,17 @@ import ( "fmt" "testing" + "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/sharecode" - "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) func TestCertificateProviderStoreCreate(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "lpa-id", SessionID: "session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "lpa-id", SessionID: "session-id"}) uid := actoruid.New() details := &Provided{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.CertificateProviderKey("session-id"), LpaID: "lpa-id", UpdatedAt: testNow, UID: uid, Email: "a@b.com"} @@ -31,11 +31,11 @@ func TestCertificateProviderStoreCreate(t *testing.T) { expectedTransaction := &dynamo.Transaction{ Creates: []any{ details, - temporary.LpaLink{ + actor.LpaLink{ PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("session-id"), DonorKey: shareCode.LpaOwnerKey, - ActorType: temporary.ActorTypeCertificateProvider, + ActorType: actor.TypeCertificateProvider, UpdatedAt: testNow, }, }, @@ -61,15 +61,15 @@ func TestCertificateProviderStoreCreateWhenSessionMissing(t *testing.T) { assert.Equal(t, appcontext.SessionMissingError{}, err) } -func TestCertificateProviderStoreCreateWhenSessionDataMissing(t *testing.T) { - testcases := map[string]*appcontext.SessionData{ +func TestCertificateProviderStoreCreateWhenSessionMissingRequiredData(t *testing.T) { + testcases := map[string]*appcontext.Session{ "LpaID": {SessionID: "456"}, "SessionID": {LpaID: "123"}, } for name, sessionData := range testcases { t.Run(name, func(t *testing.T) { - ctx := appcontext.ContextWithSessionData(ctx, sessionData) + ctx := appcontext.ContextWithSession(ctx, sessionData) certificateProviderStore := &Store{} @@ -80,7 +80,7 @@ func TestCertificateProviderStoreCreateWhenSessionDataMissing(t *testing.T) { } func TestCertificateProviderStoreCreateWhenWriteTransactionError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -97,7 +97,7 @@ func TestCertificateProviderStoreCreateWhenWriteTransactionError(t *testing.T) { } func TestCertificateProviderStoreGetAny(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -117,8 +117,8 @@ func TestCertificateProviderStoreGetAnyWhenSessionMissing(t *testing.T) { assert.Equal(t, appcontext.SessionMissingError{}, err) } -func TestCertificateProviderStoreGetAnyMissingLpaIDInSessionData(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{}) +func TestCertificateProviderStoreGetAnyMissingLpaIDInSession(t *testing.T) { + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{}) certificateProviderStore := &Store{} @@ -127,7 +127,7 @@ func TestCertificateProviderStoreGetAnyMissingLpaIDInSessionData(t *testing.T) { } func TestCertificateProviderStoreGetAnyOnError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -140,7 +140,7 @@ func TestCertificateProviderStoreGetAnyOnError(t *testing.T) { } func TestCertificateProviderStoreGet(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -160,8 +160,8 @@ func TestCertificateProviderStoreGetWhenSessionMissing(t *testing.T) { assert.Equal(t, appcontext.SessionMissingError{}, err) } -func TestCertificateProviderStoreGetMissingLpaIDInSessionData(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "456"}) +func TestCertificateProviderStoreGetMissingLpaIDInSession(t *testing.T) { + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "456"}) certificateProviderStore := &Store{} @@ -169,8 +169,8 @@ func TestCertificateProviderStoreGetMissingLpaIDInSessionData(t *testing.T) { assert.Equal(t, errors.New("certificateProviderStore.Get requires LpaID and SessionID"), err) } -func TestCertificateProviderStoreGetMissingSessionIDInSessionData(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}) +func TestCertificateProviderStoreGetMissingSessionIDInSession(t *testing.T) { + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}) certificateProviderStore := &Store{} @@ -179,7 +179,7 @@ func TestCertificateProviderStoreGetMissingSessionIDInSessionData(t *testing.T) } func TestCertificateProviderStoreGetOnError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient. @@ -222,7 +222,7 @@ func TestCertificateProviderStorePutOnError(t *testing.T) { } func TestCertificateProviderStoreDelete(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -250,7 +250,7 @@ func TestCertificateProviderStoreDeleteWhenMissingSessionValues(t *testing.T) { for name, tc := range testcases { t.Run(name, func(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: tc.lpaID, SessionID: tc.sessionID}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: tc.lpaID, SessionID: tc.sessionID}) certificateProviderStore := &Store{} @@ -261,7 +261,7 @@ func TestCertificateProviderStoreDeleteWhenMissingSessionValues(t *testing.T) { } func TestCertificateProviderStoreDeleteWhenDynamoClientError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). diff --git a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider.go b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider.go index 5c2b7b82ab..b125138f4b 100644 --- a/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider.go +++ b/internal/certificateprovider/certificateproviderpage/confirm_dont_want_to_be_certificate_provider.go @@ -5,6 +5,7 @@ import ( "net/url" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" @@ -15,13 +16,13 @@ import ( ) type confirmDontWantToBeCertificateProviderData struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa } func ConfirmDontWantToBeCertificateProvider(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, lpaStoreClient LpaStoreClient, donorStore DonorStore, certificateProviderStore CertificateProviderStore, notifyClient NotifyClient, appPublicURL string) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err 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 5fb580d751..2562ea442c 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 @@ -17,19 +17,19 @@ import ( ) type confirmDontWantToBeCertificateProviderDataLoggedOut struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa } func ConfirmDontWantToBeCertificateProviderLoggedOut(tmpl template.Template, shareCodeStore ShareCodeStore, lpaStoreResolvingService LpaStoreResolvingService, lpaStoreClient LpaStoreClient, donorStore DonorStore, sessionStore SessionStore, notifyClient NotifyClient, appPublicURL string) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { session, err := sessionStore.LpaData(r) if err != nil { return err } - ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: session.LpaID}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{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 808fd1a4e1..fd32529b1a 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 @@ -34,7 +34,7 @@ func TestGetConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { lpaStoreResolvingService := newMockLpaStoreResolvingService(t) lpaStoreResolvingService.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: "lpa-id"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"})). Return(&lpa, nil) template := newMockTemplate(t) @@ -134,7 +134,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(), &appcontext.SessionData{LpaID: "lpa-id"}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"}) testcases := map[string]struct { lpa lpastore.Lpa @@ -298,7 +298,7 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) { func TestPostConfirmDontWantToBeCertificateProviderLoggedOutErrors(t *testing.T) { r, _ := http.NewRequest(http.MethodPost, "/?referenceNumber=123", nil) - ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{LpaID: "lpa-id"}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{LpaID: "lpa-id"}) shareCodeData := sharecode.Data{ 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 69dbb48150..8356c6fd58 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 @@ -96,7 +96,7 @@ func TestGetConfirmDontWantToBeCertificateProviderErrors(t *testing.T) { } func TestPostConfirmDontWantToBeCertificateProvider(t *testing.T) { - r, _ := http.NewRequestWithContext(page.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) + r, _ := http.NewRequestWithContext(appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123", SessionID: "456"}), http.MethodPost, "/?referenceNumber=123", nil) w := httptest.NewRecorder() uid := actoruid.New() diff --git a/internal/certificateprovider/certificateproviderpage/confirm_your_details.go b/internal/certificateprovider/certificateproviderpage/confirm_your_details.go index 43c96e0544..44ad99e1a3 100644 --- a/internal/certificateprovider/certificateproviderpage/confirm_your_details.go +++ b/internal/certificateprovider/certificateproviderpage/confirm_your_details.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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/page" @@ -12,7 +13,7 @@ import ( ) type confirmYourDetailsData struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa CertificateProvider *certificateproviderdata.Provided @@ -22,7 +23,7 @@ type confirmYourDetailsData struct { } func ConfirmYourDetails(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, certificateProviderStore CertificateProviderStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err diff --git a/internal/certificateprovider/certificateproviderpage/enter_date_of_birth.go b/internal/certificateprovider/certificateproviderpage/enter_date_of_birth.go index 716b5ec5ad..e6a659eac9 100644 --- a/internal/certificateprovider/certificateproviderpage/enter_date_of_birth.go +++ b/internal/certificateprovider/certificateproviderpage/enter_date_of_birth.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" @@ -13,7 +14,7 @@ import ( ) type dateOfBirthData struct { - App page.AppData + App appcontext.Data Lpa *lpastore.Lpa Form *dateOfBirthForm Errors validation.List @@ -26,7 +27,7 @@ type dateOfBirthForm struct { } func EnterDateOfBirth(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, certificateProviderStore CertificateProviderStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err diff --git a/internal/certificateprovider/certificateproviderpage/enter_reference_number.go b/internal/certificateprovider/certificateproviderpage/enter_reference_number.go index 7eb2545a7e..5d78770452 100644 --- a/internal/certificateprovider/certificateproviderpage/enter_reference_number.go +++ b/internal/certificateprovider/certificateproviderpage/enter_reference_number.go @@ -13,13 +13,13 @@ import ( ) type enterReferenceNumberData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *enterReferenceNumberForm } func EnterReferenceNumber(tmpl template.Template, shareCodeStore ShareCodeStore, sessionStore SessionStore, certificateProviderStore CertificateProviderStore) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { data := enterReferenceNumberData{ App: appData, Form: &enterReferenceNumberForm{}, @@ -47,7 +47,7 @@ func EnterReferenceNumber(tmpl template.Template, shareCodeStore ShareCodeStore, return err } - ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{ + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{ SessionID: session.SessionID(), LpaID: shareCode.LpaKey.ID(), }) diff --git a/internal/certificateprovider/certificateproviderpage/enter_reference_number_opt_out.go b/internal/certificateprovider/certificateproviderpage/enter_reference_number_opt_out.go index b6e799e1dd..9cd0c69877 100644 --- a/internal/certificateprovider/certificateproviderpage/enter_reference_number_opt_out.go +++ b/internal/certificateprovider/certificateproviderpage/enter_reference_number_opt_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/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" @@ -14,7 +15,7 @@ import ( ) func EnterReferenceNumberOptOut(tmpl template.Template, shareCodeStore ShareCodeStore, sessionStore SessionStore) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { data := enterReferenceNumberData{ App: appData, Form: &enterReferenceNumberForm{}, diff --git a/internal/certificateprovider/certificateproviderpage/enter_reference_number_test.go b/internal/certificateprovider/certificateproviderpage/enter_reference_number_test.go index 75ec22de2b..f621eaff6a 100644 --- a/internal/certificateprovider/certificateproviderpage/enter_reference_number_test.go +++ b/internal/certificateprovider/certificateproviderpage/enter_reference_number_test.go @@ -89,9 +89,9 @@ func TestPostEnterReferenceNumber(t *testing.T) { certificateProviderStore := newMockCertificateProviderStore(t) certificateProviderStore.EXPECT(). Create(mock.MatchedBy(func(ctx context.Context) bool { - session, _ := appcontext.SessionDataFromContext(ctx) + session, _ := appcontext.SessionFromContext(ctx) - return assert.Equal(t, &appcontext.SessionData{SessionID: "aGV5", LpaID: "lpa-id"}, session) + return assert.Equal(t, &appcontext.Session{SessionID: "aGV5", LpaID: "lpa-id"}, session) }), shareCodeData, "a@b.com"). Return(&certificateproviderdata.Provided{}, nil) diff --git a/internal/certificateprovider/certificateproviderpage/guidance.go b/internal/certificateprovider/certificateproviderpage/guidance.go index 1655205fb6..c9349934e9 100644 --- a/internal/certificateprovider/certificateproviderpage/guidance.go +++ b/internal/certificateprovider/certificateproviderpage/guidance.go @@ -4,21 +4,21 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type guidanceData struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa CertificateProvider *certificateproviderdata.Provided } func Guidance(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { data := &guidanceData{ App: appData, CertificateProvider: certificateProvider, diff --git a/internal/certificateprovider/certificateproviderpage/identity_with_one_login.go b/internal/certificateprovider/certificateproviderpage/identity_with_one_login.go index 457d433e7d..9263259e32 100644 --- a/internal/certificateprovider/certificateproviderpage/identity_with_one_login.go +++ b/internal/certificateprovider/certificateproviderpage/identity_with_one_login.go @@ -3,6 +3,7 @@ package certificateproviderpage import ( "net/http" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -10,7 +11,7 @@ import ( ) func IdentityWithOneLogin(oneLoginClient OneLoginClient, sessionStore SessionStore, randomString func(int) string) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, _ *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, _ *certificateproviderdata.Provided) error { locale := "" if appData.Lang == localize.Cy { locale = "cy" diff --git a/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback.go b/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback.go index dc362df52f..0287b6f140 100644 --- a/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback.go +++ b/internal/certificateprovider/certificateproviderpage/identity_with_one_login_callback.go @@ -4,6 +4,7 @@ import ( "errors" "net/http" + "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/notify" @@ -11,7 +12,7 @@ import ( ) func IdentityWithOneLoginCallback(oneLoginClient OneLoginClient, sessionStore SessionStore, certificateProviderStore CertificateProviderStore, lpaStoreResolvingService LpaStoreResolvingService, notifyClient NotifyClient, lpaStoreClient LpaStoreClient, appPublicURL string) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err diff --git a/internal/certificateprovider/certificateproviderpage/identity_with_one_login_test.go b/internal/certificateprovider/certificateproviderpage/identity_with_one_login_test.go index f00389e16c..440406a73f 100644 --- a/internal/certificateprovider/certificateproviderpage/identity_with_one_login_test.go +++ b/internal/certificateprovider/certificateproviderpage/identity_with_one_login_test.go @@ -5,6 +5,7 @@ import ( "net/http/httptest" "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" @@ -26,7 +27,7 @@ func TestIdentityWithOneLogin(t *testing.T) { SetOneLogin(r, w, &sesh.OneLoginSession{State: "i am random", Nonce: "i am random", Locale: "cy", Redirect: page.Paths.CertificateProvider.IdentityWithOneLoginCallback.Format("lpa-id")}). Return(nil) - err := IdentityWithOneLogin(client, sessionStore, func(int) string { return "i am random" })(page.AppData{LpaID: "lpa-id", Lang: localize.Cy}, w, r, nil) + err := IdentityWithOneLogin(client, sessionStore, func(int) string { return "i am random" })(appcontext.Data{LpaID: "lpa-id", Lang: localize.Cy}, w, r, nil) resp := w.Result() assert.Nil(t, err) diff --git a/internal/certificateprovider/certificateproviderpage/mock_DashboardStore_test.go b/internal/certificateprovider/certificateproviderpage/mock_DashboardStore_test.go index 498bdee3c1..febcf4062f 100644 --- a/internal/certificateprovider/certificateproviderpage/mock_DashboardStore_test.go +++ b/internal/certificateprovider/certificateproviderpage/mock_DashboardStore_test.go @@ -5,10 +5,11 @@ package certificateproviderpage import ( context "context" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + mock "github.com/stretchr/testify/mock" - temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" + page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) // mockDashboardStore is an autogenerated mock type for the DashboardStore type @@ -101,7 +102,7 @@ func (_c *mockDashboardStore_GetAll_Call) RunAndReturn(run func(context.Context) } // SubExistsForActorType provides a mock function with given fields: ctx, sub, actorType -func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType temporary.ActorType) (bool, error) { +func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType actor.Type) (bool, error) { ret := _m.Called(ctx, sub, actorType) if len(ret) == 0 { @@ -110,16 +111,16 @@ func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub str var r0 bool var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) (bool, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) (bool, error)); ok { return rf(ctx, sub, actorType) } - if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) bool); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) bool); ok { r0 = rf(ctx, sub, actorType) } else { r0 = ret.Get(0).(bool) } - if rf, ok := ret.Get(1).(func(context.Context, string, temporary.ActorType) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, actor.Type) error); ok { r1 = rf(ctx, sub, actorType) } else { r1 = ret.Error(1) @@ -136,14 +137,14 @@ type mockDashboardStore_SubExistsForActorType_Call struct { // SubExistsForActorType is a helper method to define mock.On call // - ctx context.Context // - sub string -// - actorType temporary.ActorType +// - actorType actor.Type func (_e *mockDashboardStore_Expecter) SubExistsForActorType(ctx interface{}, sub interface{}, actorType interface{}) *mockDashboardStore_SubExistsForActorType_Call { return &mockDashboardStore_SubExistsForActorType_Call{Call: _e.mock.On("SubExistsForActorType", ctx, sub, actorType)} } -func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType temporary.ActorType)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType actor.Type)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(temporary.ActorType)) + run(args[0].(context.Context), args[1].(string), args[2].(actor.Type)) }) return _c } @@ -153,7 +154,7 @@ func (_c *mockDashboardStore_SubExistsForActorType_Call) Return(_a0 bool, _a1 er return _c } -func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, temporary.ActorType) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, actor.Type) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Return(run) return _c } diff --git a/internal/certificateprovider/certificateproviderpage/mock_DonorStore_test.go b/internal/certificateprovider/certificateproviderpage/mock_DonorStore_test.go index 3950a93c78..a840bdfecf 100644 --- a/internal/certificateprovider/certificateproviderpage/mock_DonorStore_test.go +++ b/internal/certificateprovider/certificateproviderpage/mock_DonorStore_test.go @@ -105,7 +105,7 @@ type mockDonorStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - donor *donordata.DonorProvidedDetails +// - donor *donordata.Provided func (_e *mockDonorStore_Expecter) Put(ctx interface{}, donor interface{}) *mockDonorStore_Put_Call { return &mockDonorStore_Put_Call{Call: _e.mock.On("Put", ctx, donor)} } diff --git a/internal/certificateprovider/certificateproviderpage/mock_Handler_test.go b/internal/certificateprovider/certificateproviderpage/mock_Handler_test.go index 0b0ce695bb..1ec06553cb 100644 --- a/internal/certificateprovider/certificateproviderpage/mock_Handler_test.go +++ b/internal/certificateprovider/certificateproviderpage/mock_Handler_test.go @@ -5,11 +5,10 @@ package certificateproviderpage import ( http "net/http" + appcontext "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" certificateproviderdata "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" mock "github.com/stretchr/testify/mock" - - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) // mockHandler is an autogenerated mock type for the Handler type @@ -26,7 +25,7 @@ func (_m *mockHandler) EXPECT() *mockHandler_Expecter { } // Execute provides a mock function with given fields: data, w, r, details -func (_m *mockHandler) Execute(data page.AppData, w http.ResponseWriter, r *http.Request, details *certificateproviderdata.Provided) error { +func (_m *mockHandler) Execute(data appcontext.Data, w http.ResponseWriter, r *http.Request, details *certificateproviderdata.Provided) error { ret := _m.Called(data, w, r, details) if len(ret) == 0 { @@ -34,7 +33,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, *certificateproviderdata.Provided) error); ok { + if rf, ok := ret.Get(0).(func(appcontext.Data, http.ResponseWriter, *http.Request, *certificateproviderdata.Provided) error); ok { r0 = rf(data, w, r, details) } else { r0 = ret.Error(0) @@ -49,7 +48,7 @@ type mockHandler_Execute_Call struct { } // Execute is a helper method to define mock.On call -// - data page.AppData +// - data appcontext.Data // - w http.ResponseWriter // - r *http.Request // - details *certificateproviderdata.Provided @@ -57,9 +56,9 @@ func (_e *mockHandler_Expecter) Execute(data interface{}, w interface{}, r inter return &mockHandler_Execute_Call{Call: _e.mock.On("Execute", data, w, r, details)} } -func (_c *mockHandler_Execute_Call) Run(run func(data page.AppData, w http.ResponseWriter, r *http.Request, details *certificateproviderdata.Provided)) *mockHandler_Execute_Call { +func (_c *mockHandler_Execute_Call) Run(run func(data appcontext.Data, w http.ResponseWriter, r *http.Request, details *certificateproviderdata.Provided)) *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].(*certificateproviderdata.Provided)) + run(args[0].(appcontext.Data), args[1].(http.ResponseWriter), args[2].(*http.Request), args[3].(*certificateproviderdata.Provided)) }) return _c } @@ -69,7 +68,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, *certificateproviderdata.Provided) error) *mockHandler_Execute_Call { +func (_c *mockHandler_Execute_Call) RunAndReturn(run func(appcontext.Data, http.ResponseWriter, *http.Request, *certificateproviderdata.Provided) error) *mockHandler_Execute_Call { _c.Call.Return(run) return _c } diff --git a/internal/certificateprovider/certificateproviderpage/mock_ShareCodeSender_test.go b/internal/certificateprovider/certificateproviderpage/mock_ShareCodeSender_test.go index 03af5ac1c5..1876a1ed7c 100644 --- a/internal/certificateprovider/certificateproviderpage/mock_ShareCodeSender_test.go +++ b/internal/certificateprovider/certificateproviderpage/mock_ShareCodeSender_test.go @@ -5,10 +5,11 @@ package certificateproviderpage import ( context "context" + appcontext "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + lpastore "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" - mock "github.com/stretchr/testify/mock" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + mock "github.com/stretchr/testify/mock" ) // mockShareCodeSender is an autogenerated mock type for the ShareCodeSender type @@ -25,7 +26,7 @@ func (_m *mockShareCodeSender) EXPECT() *mockShareCodeSender_Expecter { } // SendAttorneys provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockShareCodeSender) SendAttorneys(_a0 context.Context, _a1 page.AppData, _a2 *lpastore.Lpa) error { +func (_m *mockShareCodeSender) SendAttorneys(_a0 context.Context, _a1 appcontext.Data, _a2 *lpastore.Lpa) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -33,7 +34,7 @@ func (_m *mockShareCodeSender) SendAttorneys(_a0 context.Context, _a1 page.AppDa } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, page.AppData, *lpastore.Lpa) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, appcontext.Data, *lpastore.Lpa) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -49,15 +50,15 @@ type mockShareCodeSender_SendAttorneys_Call struct { // SendAttorneys is a helper method to define mock.On call // - _a0 context.Context -// - _a1 page.AppData +// - _a1 appcontext.Data // - _a2 *lpastore.Lpa func (_e *mockShareCodeSender_Expecter) SendAttorneys(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockShareCodeSender_SendAttorneys_Call { return &mockShareCodeSender_SendAttorneys_Call{Call: _e.mock.On("SendAttorneys", _a0, _a1, _a2)} } -func (_c *mockShareCodeSender_SendAttorneys_Call) Run(run func(_a0 context.Context, _a1 page.AppData, _a2 *lpastore.Lpa)) *mockShareCodeSender_SendAttorneys_Call { +func (_c *mockShareCodeSender_SendAttorneys_Call) Run(run func(_a0 context.Context, _a1 appcontext.Data, _a2 *lpastore.Lpa)) *mockShareCodeSender_SendAttorneys_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(page.AppData), args[2].(*lpastore.Lpa)) + run(args[0].(context.Context), args[1].(appcontext.Data), args[2].(*lpastore.Lpa)) }) return _c } @@ -67,7 +68,7 @@ func (_c *mockShareCodeSender_SendAttorneys_Call) Return(_a0 error) *mockShareCo return _c } -func (_c *mockShareCodeSender_SendAttorneys_Call) RunAndReturn(run func(context.Context, page.AppData, *lpastore.Lpa) error) *mockShareCodeSender_SendAttorneys_Call { +func (_c *mockShareCodeSender_SendAttorneys_Call) RunAndReturn(run func(context.Context, appcontext.Data, *lpastore.Lpa) error) *mockShareCodeSender_SendAttorneys_Call { _c.Call.Return(run) return _c } diff --git a/internal/certificateprovider/certificateproviderpage/mock_ShareCodeStore_test.go b/internal/certificateprovider/certificateproviderpage/mock_ShareCodeStore_test.go index 1c2adf2c49..3aab1f0eb8 100644 --- a/internal/certificateprovider/certificateproviderpage/mock_ShareCodeStore_test.go +++ b/internal/certificateprovider/certificateproviderpage/mock_ShareCodeStore_test.go @@ -5,10 +5,11 @@ package certificateproviderpage import ( context "context" - sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" + actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + mock "github.com/stretchr/testify/mock" - temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) // mockShareCodeStore is an autogenerated mock type for the ShareCodeStore type @@ -72,7 +73,7 @@ func (_c *mockShareCodeStore_Delete_Call) RunAndReturn(run func(context.Context, } // Get provides a mock function with given fields: ctx, actorType, shareCode -func (_m *mockShareCodeStore) Get(ctx context.Context, actorType temporary.ActorType, shareCode string) (sharecode.Data, error) { +func (_m *mockShareCodeStore) Get(ctx context.Context, actorType actor.Type, shareCode string) (sharecode.Data, error) { ret := _m.Called(ctx, actorType, shareCode) if len(ret) == 0 { @@ -81,16 +82,16 @@ func (_m *mockShareCodeStore) Get(ctx context.Context, actorType temporary.Actor var r0 sharecode.Data var r1 error - if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) (sharecode.Data, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) (sharecode.Data, error)); ok { return rf(ctx, actorType, shareCode) } - if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) sharecode.Data); ok { + if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) sharecode.Data); ok { r0 = rf(ctx, actorType, shareCode) } else { r0 = ret.Get(0).(sharecode.Data) } - if rf, ok := ret.Get(1).(func(context.Context, temporary.ActorType, string) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, actor.Type, string) error); ok { r1 = rf(ctx, actorType, shareCode) } else { r1 = ret.Error(1) @@ -106,15 +107,15 @@ type mockShareCodeStore_Get_Call struct { // Get is a helper method to define mock.On call // - ctx context.Context -// - actorType temporary.ActorType +// - actorType actor.Type // - shareCode string func (_e *mockShareCodeStore_Expecter) Get(ctx interface{}, actorType interface{}, shareCode interface{}) *mockShareCodeStore_Get_Call { return &mockShareCodeStore_Get_Call{Call: _e.mock.On("Get", ctx, actorType, shareCode)} } -func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, shareCode string)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType actor.Type, shareCode string)) *mockShareCodeStore_Get_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string)) + run(args[0].(context.Context), args[1].(actor.Type), args[2].(string)) }) return _c } @@ -124,13 +125,13 @@ func (_c *mockShareCodeStore_Get_Call) Return(_a0 sharecode.Data, _a1 error) *mo return _c } -func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string) (sharecode.Data, error)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, actor.Type, string) (sharecode.Data, error)) *mockShareCodeStore_Get_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: ctx, actorType, shareCode, shareCodeData -func (_m *mockShareCodeStore) Put(ctx context.Context, actorType temporary.ActorType, shareCode string, shareCodeData sharecode.Data) error { +func (_m *mockShareCodeStore) Put(ctx context.Context, actorType actor.Type, shareCode string, shareCodeData sharecode.Data) error { ret := _m.Called(ctx, actorType, shareCode, shareCodeData) if len(ret) == 0 { @@ -138,7 +139,7 @@ func (_m *mockShareCodeStore) Put(ctx context.Context, actorType temporary.Actor } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string, sharecode.Data) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string, sharecode.Data) error); ok { r0 = rf(ctx, actorType, shareCode, shareCodeData) } else { r0 = ret.Error(0) @@ -154,16 +155,16 @@ type mockShareCodeStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - actorType temporary.ActorType +// - actorType actor.Type // - shareCode string // - shareCodeData sharecode.Data func (_e *mockShareCodeStore_Expecter) Put(ctx interface{}, actorType interface{}, shareCode interface{}, shareCodeData interface{}) *mockShareCodeStore_Put_Call { return &mockShareCodeStore_Put_Call{Call: _e.mock.On("Put", ctx, actorType, shareCode, shareCodeData)} } -func (_c *mockShareCodeStore_Put_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, shareCode string, shareCodeData sharecode.Data)) *mockShareCodeStore_Put_Call { +func (_c *mockShareCodeStore_Put_Call) Run(run func(ctx context.Context, actorType actor.Type, shareCode string, shareCodeData sharecode.Data)) *mockShareCodeStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string), args[3].(sharecode.Data)) + run(args[0].(context.Context), args[1].(actor.Type), args[2].(string), args[3].(sharecode.Data)) }) return _c } @@ -173,7 +174,7 @@ func (_c *mockShareCodeStore_Put_Call) Return(_a0 error) *mockShareCodeStore_Put return _c } -func (_c *mockShareCodeStore_Put_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string, sharecode.Data) error) *mockShareCodeStore_Put_Call { +func (_c *mockShareCodeStore_Put_Call) RunAndReturn(run func(context.Context, actor.Type, string, sharecode.Data) error) *mockShareCodeStore_Put_Call { _c.Call.Return(run) return _c } diff --git a/internal/certificateprovider/certificateproviderpage/mock_test.go b/internal/certificateprovider/certificateproviderpage/mock_test.go index 648003843a..3348869335 100644 --- a/internal/certificateprovider/certificateproviderpage/mock_test.go +++ b/internal/certificateprovider/certificateproviderpage/mock_test.go @@ -3,8 +3,8 @@ package certificateproviderpage import ( "errors" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" ) @@ -17,7 +17,7 @@ var ( Postcode: "e", } expectedError = errors.New("err") - testAppData = page.AppData{ + testAppData = appcontext.Data{ SessionID: "session-id", LpaID: "lpa-id", Lang: localize.En, diff --git a/internal/certificateprovider/certificateproviderpage/one_login_identity_details.go b/internal/certificateprovider/certificateproviderpage/one_login_identity_details.go index 35406a3fa2..a6f0d79095 100644 --- a/internal/certificateprovider/certificateproviderpage/one_login_identity_details.go +++ b/internal/certificateprovider/certificateproviderpage/one_login_identity_details.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -11,13 +12,13 @@ import ( ) type oneLoginIdentityDetailsData struct { - App page.AppData + App appcontext.Data Errors validation.List CertificateProvider *certificateproviderdata.Provided } func OneLoginIdentityDetails(tmpl template.Template, certificateProviderStore CertificateProviderStore, lpaStoreResolvingService LpaStoreResolvingService) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { data := &oneLoginIdentityDetailsData{ App: appData, CertificateProvider: certificateProvider, diff --git a/internal/certificateprovider/certificateproviderpage/provide_certificate.go b/internal/certificateprovider/certificateproviderpage/provide_certificate.go index 0549e3491c..8d7590b621 100644 --- a/internal/certificateprovider/certificateproviderpage/provide_certificate.go +++ b/internal/certificateprovider/certificateproviderpage/provide_certificate.go @@ -6,6 +6,7 @@ import ( "time" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" @@ -16,7 +17,7 @@ import ( ) type provideCertificateData struct { - App page.AppData + App appcontext.Data Errors validation.List CertificateProvider *certificateproviderdata.Provided Lpa *lpastore.Lpa @@ -32,7 +33,7 @@ func ProvideCertificate( lpaStoreClient LpaStoreClient, now func() time.Time, ) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err diff --git a/internal/certificateprovider/certificateproviderpage/read_the_lpa.go b/internal/certificateprovider/certificateproviderpage/read_the_lpa.go index 2b228324a1..f6d8b1c22c 100644 --- a/internal/certificateprovider/certificateproviderpage/read_the_lpa.go +++ b/internal/certificateprovider/certificateproviderpage/read_the_lpa.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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/page" @@ -12,13 +13,13 @@ import ( ) type readTheLpaData struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa } func ReadTheLpa(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, certificateProviderStore CertificateProviderStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err diff --git a/internal/certificateprovider/certificateproviderpage/register.go b/internal/certificateprovider/certificateproviderpage/register.go index c3b9fb2cda..155954bdb2 100644 --- a/internal/certificateprovider/certificateproviderpage/register.go +++ b/internal/certificateprovider/certificateproviderpage/register.go @@ -23,7 +23,7 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) -type Handler func(data page.AppData, w http.ResponseWriter, r *http.Request, details *certificateproviderdata.Provided) error +type Handler func(data appcontext.Data, w http.ResponseWriter, r *http.Request, details *certificateproviderdata.Provided) error type LpaStoreResolvingService interface { Get(ctx context.Context) (*lpastore.Lpa, error) @@ -72,7 +72,7 @@ type NotifyClient interface { } type ShareCodeSender interface { - SendAttorneys(context.Context, page.AppData, *lpastore.Lpa) error + SendAttorneys(context.Context, appcontext.Data, *lpastore.Lpa) error } type AddressClient interface { @@ -179,11 +179,11 @@ func makeHandle(mux *http.ServeMux, errorHandler page.ErrorHandler) func(page.Pa mux.HandleFunc(path.String(), func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - appData := page.AppDataFromContext(ctx) + appData := appcontext.DataFromContext(ctx) appData.ActorType = actor.TypeCertificateProvider appData.Page = path.Format() - if err := h(appData, w, r.WithContext(page.ContextWithAppData(ctx, appData))); err != nil { + if err := h(appData, w, r.WithContext(appcontext.ContextWithData(ctx, appData))); err != nil { errorHandler(w, r, err) } }) @@ -195,7 +195,7 @@ func makeCertificateProviderHandle(mux *http.ServeMux, sessionStore SessionStore mux.HandleFunc(path.String(), func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - appData := page.AppDataFromContext(ctx) + appData := appcontext.DataFromContext(ctx) appData.ActorType = actor.TypeCertificateProvider appData.CanGoBack = opt&page.CanGoBack != 0 appData.LpaID = r.PathValue("id") @@ -208,13 +208,13 @@ func makeCertificateProviderHandle(mux *http.ServeMux, sessionStore SessionStore appData.SessionID = session.SessionID() - sessionData, err := appcontext.SessionDataFromContext(ctx) + sessionData, err := appcontext.SessionFromContext(ctx) if err == nil { sessionData.SessionID = appData.SessionID sessionData.LpaID = appData.LpaID - ctx = page.ContextWithSessionData(ctx, sessionData) + ctx = appcontext.ContextWithSession(ctx, sessionData) } else { - ctx = page.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID}) + ctx = appcontext.ContextWithSession(ctx, &appcontext.Session{SessionID: appData.SessionID, LpaID: appData.LpaID}) } certificateProvider, err := certificateProviderStore.Get(ctx) @@ -230,7 +230,7 @@ func makeCertificateProviderHandle(mux *http.ServeMux, sessionStore SessionStore appData.Page = path.Format(appData.LpaID) - if err := h(appData, w, r.WithContext(page.ContextWithAppData(ctx, appData)), certificateProvider); err != nil { + if err := h(appData, w, r.WithContext(appcontext.ContextWithData(ctx, appData)), certificateProvider); err != nil { errorHandler(w, r, err) } }) diff --git a/internal/certificateprovider/certificateproviderpage/register_test.go b/internal/certificateprovider/certificateproviderpage/register_test.go index 027a133415..d2e1d49979 100644 --- a/internal/certificateprovider/certificateproviderpage/register_test.go +++ b/internal/certificateprovider/certificateproviderpage/register_test.go @@ -34,14 +34,14 @@ func TestMakeHandle(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, nil) - handle("/path", func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { - assert.Equal(t, page.AppData{ + handle("/path", func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { + assert.Equal(t, appcontext.Data{ Page: "/path", ActorType: actor.TypeCertificateProvider, }, appData) assert.Equal(t, w, hw) - sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) + sessionData, _ := appcontext.SessionFromContext(hr.Context()) assert.Nil(t, sessionData) hw.WriteHeader(http.StatusTeapot) @@ -64,7 +64,7 @@ func TestMakeHandleErrors(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, errorHandler.Execute) - handle("/path", func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { + handle("/path", func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { return expectedError }) @@ -72,7 +72,7 @@ func TestMakeHandleErrors(t *testing.T) { } func TestMakeCertificateProviderHandle(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored-session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "ignored-session-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/certificate-provider/123/path?a=b", nil) @@ -88,8 +88,8 @@ func TestMakeCertificateProviderHandle(t *testing.T) { mux := http.NewServeMux() handle := makeCertificateProviderHandle(mux, sessionStore, nil, certificateProviderStore) - handle("/path", page.None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, certificateProvider *certificateproviderdata.Provided) error { - assert.Equal(t, page.AppData{ + handle("/path", page.None, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request, certificateProvider *certificateproviderdata.Provided) error { + assert.Equal(t, appcontext.Data{ Page: "/certificate-provider/123/path", SessionID: "cmFuZG9t", LpaID: "123", @@ -99,8 +99,8 @@ func TestMakeCertificateProviderHandle(t *testing.T) { assert.Equal(t, &certificateproviderdata.Provided{LpaID: "123"}, certificateProvider) - sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) - assert.Equal(t, &appcontext.SessionData{LpaID: "123", SessionID: "cmFuZG9t"}, sessionData) + sessionData, _ := appcontext.SessionFromContext(hr.Context()) + assert.Equal(t, &appcontext.Session{LpaID: "123", SessionID: "cmFuZG9t"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil @@ -115,7 +115,7 @@ func TestMakeCertificateProviderHandle(t *testing.T) { func TestMakeCertificateProviderHandleWhenCannotGoToURL(t *testing.T) { path := page.Paths.CertificateProvider.ProvideCertificate - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored-session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "ignored-session-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, path.Format("123"), nil) @@ -131,7 +131,7 @@ func TestMakeCertificateProviderHandleWhenCannotGoToURL(t *testing.T) { mux := http.NewServeMux() handle := makeCertificateProviderHandle(mux, sessionStore, nil, certificateProviderStore) - handle(path, page.None, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *certificateproviderdata.Provided) error { + handle(path, page.None, func(_ appcontext.Data, _ http.ResponseWriter, _ *http.Request, _ *certificateproviderdata.Provided) error { return nil }) @@ -153,7 +153,7 @@ func TestMakeCertificateProviderHandleSessionError(t *testing.T) { mux := http.NewServeMux() handle := makeCertificateProviderHandle(mux, sessionStore, nil, nil) - handle("/path", page.None, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *certificateproviderdata.Provided) error { + handle("/path", page.None, func(_ appcontext.Data, _ http.ResponseWriter, _ *http.Request, _ *certificateproviderdata.Provided) error { return nil }) @@ -165,7 +165,7 @@ func TestMakeCertificateProviderHandleSessionError(t *testing.T) { } func TestMakeCertificateProviderHandleWhenAttorneyStoreError(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored-session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "ignored-session-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/certificate-provider/id/path", nil) @@ -185,7 +185,7 @@ func TestMakeCertificateProviderHandleWhenAttorneyStoreError(t *testing.T) { mux := http.NewServeMux() handle := makeCertificateProviderHandle(mux, sessionStore, errorHandler.Execute, certificateProviderStore) - handle("/path", page.None, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *certificateproviderdata.Provided) error { + handle("/path", page.None, func(_ appcontext.Data, _ http.ResponseWriter, _ *http.Request, _ *certificateproviderdata.Provided) error { return nil }) diff --git a/internal/certificateprovider/certificateproviderpage/task_list.go b/internal/certificateprovider/certificateproviderpage/task_list.go index 014d168a2e..30501b3870 100644 --- a/internal/certificateprovider/certificateproviderpage/task_list.go +++ b/internal/certificateprovider/certificateproviderpage/task_list.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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/page" @@ -12,7 +13,7 @@ import ( ) type taskListData struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa Items []taskListItem @@ -26,7 +27,7 @@ type taskListItem struct { } func TaskList(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err diff --git a/internal/certificateprovider/certificateproviderpage/task_list_test.go b/internal/certificateprovider/certificateproviderpage/task_list_test.go index b794c36a7a..e79a508978 100644 --- a/internal/certificateprovider/certificateproviderpage/task_list_test.go +++ b/internal/certificateprovider/certificateproviderpage/task_list_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "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" @@ -19,7 +20,7 @@ func TestGetTaskList(t *testing.T) { testCases := map[string]struct { donor *lpastore.Lpa certificateProvider *certificateproviderdata.Provided - appData page.AppData + appData appcontext.Data expected func([]taskListItem) []taskListItem }{ "empty": { diff --git a/internal/certificateprovider/certificateproviderpage/unable_to_confirm_identity.go b/internal/certificateprovider/certificateproviderpage/unable_to_confirm_identity.go index 3204fd444c..8a77a4344b 100644 --- a/internal/certificateprovider/certificateproviderpage/unable_to_confirm_identity.go +++ b/internal/certificateprovider/certificateproviderpage/unable_to_confirm_identity.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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/page" @@ -12,13 +13,13 @@ import ( ) type unableToConfirmIdentityData struct { - App page.AppData + App appcontext.Data Donor lpastore.Donor Errors validation.List } func UnableToConfirmIdentity(tmpl template.Template, certificateProviderStore CertificateProviderStore, lpaStoreResolvingService LpaStoreResolvingService) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { if r.Method == http.MethodPost { certificateProvider.Tasks.ConfirmYourIdentity = task.StateCompleted diff --git a/internal/certificateprovider/certificateproviderpage/what_is_your_home_address.go b/internal/certificateprovider/certificateproviderpage/what_is_your_home_address.go index c7762f923e..3e70596a3d 100644 --- a/internal/certificateprovider/certificateproviderpage/what_is_your_home_address.go +++ b/internal/certificateprovider/certificateproviderpage/what_is_your_home_address.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -15,14 +16,14 @@ import ( ) type whatIsYourHomeAddressData struct { - App page.AppData + App appcontext.Data Addresses []place.Address Form *form.AddressForm Errors validation.List } func WhatIsYourHomeAddress(logger Logger, tmpl template.Template, addressClient AddressClient, certificateProviderStore CertificateProviderStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { f := form.NewAddressForm() f.Action = "postcode" diff --git a/internal/certificateprovider/certificateproviderpage/your_preferred_language.go b/internal/certificateprovider/certificateproviderpage/your_preferred_language.go index fe4827910f..262bce5307 100644 --- a/internal/certificateprovider/certificateproviderpage/your_preferred_language.go +++ b/internal/certificateprovider/certificateproviderpage/your_preferred_language.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -13,7 +14,7 @@ import ( ) type yourPreferredLanguageData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.LanguagePreferenceForm Options localize.LangOptions @@ -22,7 +23,7 @@ type yourPreferredLanguageData struct { } func YourPreferredLanguage(tmpl template.Template, certificateProviderStore CertificateProviderStore, lpaStoreResolvingService LpaStoreResolvingService) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, certificateProvider *certificateproviderdata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err diff --git a/internal/donor/donordata/donor_provided_test.go b/internal/donor/donordata/donor_provided_test.go index 7857dd5650..0deeba3696 100644 --- a/internal/donor/donordata/donor_provided_test.go +++ b/internal/donor/donordata/donor_provided_test.go @@ -5,11 +5,11 @@ import ( "testing" "time" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" - "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" "github.com/stretchr/testify/assert" ) @@ -239,8 +239,8 @@ func TestUnder18ActorDetails(t *testing.T) { actors := donor.Under18ActorDetails() assert.Equal(t, []Under18ActorDetails{ - {FullName: "a b", DateOfBirth: under18, UID: uid1, Type: temporary.ActorTypeAttorney}, - {FullName: "e f", DateOfBirth: under18, UID: uid3, Type: temporary.ActorTypeReplacementAttorney}, + {FullName: "a b", DateOfBirth: under18, UID: uid1, Type: actor.TypeAttorney}, + {FullName: "e f", DateOfBirth: under18, UID: uid3, Type: actor.TypeReplacementAttorney}, }, actors) } diff --git a/internal/donor/donordata/lpa_type.go b/internal/donor/donordata/lpa_type.go index 67b92630f8..4601bfdb36 100644 --- a/internal/donor/donordata/lpa_type.go +++ b/internal/donor/donordata/lpa_type.go @@ -1,19 +1,10 @@ package donordata -//go:generate enumerator -type LpaType -linecomment -trimprefix -empty -type LpaType uint8 +import "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" + +type LpaType = lpadata.LpaType const ( - LpaTypePersonalWelfare LpaType = iota + 1 // personal-welfare - LpaTypePropertyAndAffairs // property-and-affairs + LpaTypePersonalWelfare = lpadata.LpaTypePersonalWelfare + LpaTypePropertyAndAffairs = lpadata.LpaTypePropertyAndAffairs ) - -func (e LpaType) WhatLPACoversTransKey() string { - switch e { - case LpaTypePropertyAndAffairs: - return "whatPropertyAndAffairsCovers" - case LpaTypePersonalWelfare: - return "whatPersonalWelfareCovers" - } - return "" -} diff --git a/internal/donor/donordata/provided.go b/internal/donor/donordata/provided.go index f07427e1c2..7e6b54bcd0 100644 --- a/internal/donor/donordata/provided.go +++ b/internal/donor/donordata/provided.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" @@ -14,7 +15,6 @@ import ( "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" - "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" "github.com/mitchellh/hashstructure/v2" ) @@ -256,7 +256,7 @@ type Under18ActorDetails struct { FullName string DateOfBirth date.Date UID actoruid.UID - Type temporary.ActorType + Type actor.Type } func (l *Provided) Under18ActorDetails() []Under18ActorDetails { @@ -269,7 +269,7 @@ func (l *Provided) Under18ActorDetails() []Under18ActorDetails { FullName: a.FullName(), DateOfBirth: a.DateOfBirth, UID: a.UID, - Type: temporary.ActorTypeAttorney, + Type: actor.TypeAttorney, }) } } @@ -280,7 +280,7 @@ func (l *Provided) Under18ActorDetails() []Under18ActorDetails { FullName: ra.FullName(), DateOfBirth: ra.DateOfBirth, UID: ra.UID, - Type: temporary.ActorTypeReplacementAttorney, + Type: actor.TypeReplacementAttorney, }) } } diff --git a/internal/donor/donordata/store.go b/internal/donor/donordata/store.go index 73697d85c6..c5a876eb34 100644 --- a/internal/donor/donordata/store.go +++ b/internal/donor/donordata/store.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" dynamodbtypes "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" "github.com/google/uuid" + "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" @@ -16,7 +17,6 @@ import ( "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" ) @@ -84,7 +84,7 @@ func NewStore(dynamoClient DynamoClient, eventClient EventClient, logger Logger, } func (s *donorStore) Create(ctx context.Context) (*Provided, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } @@ -129,11 +129,11 @@ func (s *donorStore) Create(ctx context.Context) (*Provided, error) { return nil, err } - if err := s.dynamoClient.Create(ctx, temporary.LpaLink{ + if err := s.dynamoClient.Create(ctx, actor.LpaLink{ PK: dynamo.LpaKey(lpaID), SK: dynamo.SubKey(data.SessionID), DonorKey: dynamo.LpaOwnerKey(dynamo.DonorKey(data.SessionID)), - ActorType: temporary.ActorTypeDonor, + ActorType: actor.TypeDonor, UpdatedAt: s.now(), }); err != nil { return nil, err @@ -164,7 +164,7 @@ func (s *donorStore) Link(ctx context.Context, shareCode sharecode.Data, donorEm return errors.New("donorStore.Link can only be used with organisations") } - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return err } @@ -173,10 +173,10 @@ func (s *donorStore) Link(ctx context.Context, shareCode sharecode.Data, donorEm return errors.New("donorStore.Link requires SessionID") } - var link temporary.LpaLink + var link actor.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 == temporary.ActorTypeDonor { + } else if link.ActorType == actor.TypeDonor { return errors.New("a donor link already exists for " + shareCode.LpaKey.ID()) } @@ -189,11 +189,11 @@ func (s *donorStore) Link(ctx context.Context, shareCode sharecode.Data, donorEm SK: dynamo.DonorKey(data.SessionID), ReferencedSK: organisationKey, }). - Create(temporary.LpaLink{ + Create(actor.LpaLink{ PK: shareCode.LpaKey, SK: dynamo.SubKey(data.SessionID), DonorKey: shareCode.LpaOwnerKey, - ActorType: temporary.ActorTypeDonor, + ActorType: actor.TypeDonor, UpdatedAt: s.now(), }). Put(shareCode) @@ -202,7 +202,7 @@ func (s *donorStore) Link(ctx context.Context, shareCode sharecode.Data, donorEm } func (s *donorStore) GetAny(ctx context.Context) (*Provided, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } @@ -232,7 +232,7 @@ func (s *donorStore) GetAny(ctx context.Context) (*Provided, error) { } func (s *donorStore) Get(ctx context.Context) (*Provided, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } @@ -262,7 +262,7 @@ func (s *donorStore) Get(ctx context.Context) (*Provided, error) { } func (s *donorStore) Latest(ctx context.Context) (*Provided, error) { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return nil, err } @@ -358,7 +358,7 @@ func (s *donorStore) Put(ctx context.Context, donor *Provided) error { } func (s *donorStore) Delete(ctx context.Context) error { - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return err } @@ -393,7 +393,7 @@ func (s *donorStore) DeleteDonorAccess(ctx context.Context, shareCodeData sharec return errors.New("donorStore.DeleteDonorAccess can only be used with organisations") } - data, err := appcontext.SessionDataFromContext(ctx) + data, err := appcontext.SessionFromContext(ctx) if err != nil { return err } @@ -406,7 +406,7 @@ func (s *donorStore) DeleteDonorAccess(ctx context.Context, shareCodeData sharec return errors.New("cannot remove access to another organisations LPA") } - var link temporary.LpaLink + var link actor.LpaLink if err := s.dynamoClient.OneByPartialSK(ctx, shareCodeData.LpaKey, dynamo.SubKey(""), &link); err != nil { return err } diff --git a/internal/donor/donordata/store_test.go b/internal/donor/donordata/store_test.go index 660f82da9d..6f16a4a2a3 100644 --- a/internal/donor/donordata/store_test.go +++ b/internal/donor/donordata/store_test.go @@ -9,6 +9,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/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" @@ -17,14 +18,13 @@ import ( "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" ) func TestDonorStoreGetAny(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey(""), &Provided{LpaID: "an-id"}, nil) @@ -37,7 +37,7 @@ func TestDonorStoreGetAny(t *testing.T) { } func TestDonorStoreGetAnyWhenOrganisation(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", OrganisationID: "x"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "an-id", OrganisationID: "x"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.OrganisationKey(""), &Provided{LpaID: "an-id"}, nil) @@ -50,7 +50,7 @@ func TestDonorStoreGetAnyWhenOrganisation(t *testing.T) { } func TestDonorStoreGetAnyWhenReference(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey(""), @@ -77,7 +77,7 @@ func TestDonorStoreGetAnyWithSessionMissing(t *testing.T) { } func TestDonorStoreGetAnyWhenDataStoreError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey(""), &Provided{LpaID: "an-id"}, expectedError) @@ -89,7 +89,7 @@ func TestDonorStoreGetAnyWhenDataStoreError(t *testing.T) { } func TestDonorStoreGetAnyWhenReferenceErrors(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey(""), @@ -109,22 +109,22 @@ func TestDonorStoreGetAnyWhenReferenceErrors(t *testing.T) { func TestDonorStoreGet(t *testing.T) { testCases := map[string]struct { - sessionData *appcontext.SessionData + sessionData *appcontext.Session expectedSK dynamo.SK }{ "donor": { - sessionData: &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}, + sessionData: &appcontext.Session{LpaID: "an-id", SessionID: "456"}, expectedSK: dynamo.DonorKey("456"), }, "organisation": { - sessionData: &appcontext.SessionData{LpaID: "an-id", SessionID: "456", OrganisationID: "789"}, + sessionData: &appcontext.Session{LpaID: "an-id", SessionID: "456", OrganisationID: "789"}, expectedSK: dynamo.OrganisationKey("789"), }, } for name, tc := range testCases { t.Run(name, func(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), tc.sessionData) + ctx := appcontext.ContextWithSession(context.Background(), tc.sessionData) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), tc.expectedSK, &Provided{LpaID: "an-id"}, nil) @@ -139,7 +139,7 @@ func TestDonorStoreGet(t *testing.T) { } func TestDonorStoreGetWhenReferenced(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey("456"), lpaReference{ReferencedSK: dynamo.OrganisationKey("789")}, nil) @@ -160,7 +160,7 @@ func TestDonorStoreGetWithSessionMissing(t *testing.T) { } func TestDonorStoreGetWhenDataStoreError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectOne(ctx, dynamo.LpaKey("an-id"), dynamo.DonorKey("456"), lpaReference{ReferencedSK: "ref"}, expectedError) @@ -172,7 +172,7 @@ func TestDonorStoreGetWhenDataStoreError(t *testing.T) { } func TestDonorStoreLatest(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectLatestForActor(ctx, dynamo.DonorKey("456"), &Provided{LpaID: "an-id"}, nil) @@ -192,7 +192,7 @@ func TestDonorStoreLatestWithSessionMissing(t *testing.T) { } func TestDonorStoreLatestWhenDataStoreError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "an-id", SessionID: "456"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "an-id", SessionID: "456"}) dynamoClient := newMockDynamoClient(t) dynamoClient.ExpectLatestForActor(ctx, dynamo.DonorKey("456"), &Provided{LpaID: "an-id"}, expectedError) @@ -392,7 +392,7 @@ func TestDonorStoreCreate(t *testing.T) { for name, previousDetails := range testCases { t.Run(name, func(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}) donor := &Provided{ PK: dynamo.LpaKey("10100000"), SK: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), @@ -418,7 +418,7 @@ func TestDonorStoreCreate(t *testing.T) { Create(ctx, donor). Return(nil) dynamoClient.EXPECT(). - 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}). + Create(ctx, actor.LpaLink{PK: dynamo.LpaKey("10100000"), SK: dynamo.SubKey("an-id"), DonorKey: dynamo.LpaOwnerKey(dynamo.DonorKey("an-id")), ActorType: actor.TypeDonor, UpdatedAt: testNow}). Return(nil) donorStore := &donorStore{dynamoClient: dynamoClient, uuidString: func() string { return "10100000" }, now: testNowFn, newUID: testUIDFn} @@ -438,7 +438,7 @@ func TestDonorStoreCreateWithSessionMissing(t *testing.T) { } func TestDonorStoreCreateWhenError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}) testcases := map[string]func(*testing.T) *mockDynamoClient{ "latest": func(t *testing.T) *mockDynamoClient { @@ -494,23 +494,23 @@ func TestDonorStoreCreateWhenError(t *testing.T) { func TestDonorStoreLink(t *testing.T) { testcases := map[string]struct { oneByPartialSKError error - link temporary.LpaLink + link actor.LpaLink }{ "no link": { oneByPartialSKError: dynamo.NotFoundError{}, }, "not a donor link": { - link: temporary.LpaLink{ + link: actor.LpaLink{ PK: dynamo.LpaKey(""), SK: dynamo.SubKey("a-sub"), - ActorType: temporary.ActorTypeCertificateProvider, + ActorType: actor.TypeCertificateProvider, }, }, } for name, tc := range testcases { t.Run(name, func(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "session-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "session-id"}) shareCode := sharecode.Data{ LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), @@ -523,11 +523,11 @@ func TestDonorStoreLink(t *testing.T) { SK: dynamo.DonorKey("session-id"), ReferencedSK: dynamo.OrganisationKey("org-id"), }, - temporary.LpaLink{ + actor.LpaLink{ PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("session-id"), DonorKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), - ActorType: temporary.ActorTypeDonor, + ActorType: actor.TypeDonor, UpdatedAt: testNowFn(), }, }, @@ -571,7 +571,7 @@ func TestDonorStoreLinkWithSessionMissing(t *testing.T) { } func TestDonorStoreLinkWithSessionIDMissing(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{}) donorStore := &donorStore{} err := donorStore.Link(ctx, sharecode.Data{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org"))}, "a@example.com") @@ -579,11 +579,11 @@ func TestDonorStoreLinkWithSessionIDMissing(t *testing.T) { } func TestDonorStoreLinkWhenDonorLinkAlreadyExists(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}) dynamoClient := newMockDynamoClient(t) dynamoClient. - ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), temporary.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("a-sub"), ActorType: temporary.ActorTypeDonor}, nil) + ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), actor.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("a-sub"), ActorType: actor.TypeDonor}, nil) donorStore := &donorStore{dynamoClient: dynamoClient} @@ -600,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(""), temporary.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("a-sub"), ActorType: temporary.ActorTypeAttorney}, expectedError) + ExpectOneByPartialSK(mock.Anything, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), actor.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("a-sub"), ActorType: actor.TypeAttorney}, expectedError) }, "WriteTransaction errors": func(dynamoClient *mockDynamoClient) { dynamoClient. - 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) + ExpectOneByPartialSK(mock.Anything, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), actor.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("a-sub"), ActorType: actor.TypeAttorney}, nil) dynamoClient.EXPECT(). WriteTransaction(mock.Anything, mock.Anything). Return(expectedError) @@ -613,7 +613,7 @@ func TestDonorStoreLinkWhenError(t *testing.T) { for name, setupDynamoClient := range testcases { t.Run(name, func(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}) shareCode := sharecode.Data{ LpaKey: dynamo.LpaKey("lpa-id"), LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), @@ -631,7 +631,7 @@ func TestDonorStoreLinkWhenError(t *testing.T) { } func TestDonorStoreDelete(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id", LpaID: "123"}) keys := []dynamo.Keys{ {PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("sk1")}, @@ -654,7 +654,7 @@ func TestDonorStoreDelete(t *testing.T) { } func TestDonorStoreDeleteWhenOtherDonor(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id", LpaID: "123"}) keys := []dynamo.Keys{ {PK: dynamo.LpaKey("123"), SK: dynamo.DonorKey("sk1")}, @@ -674,7 +674,7 @@ func TestDonorStoreDeleteWhenOtherDonor(t *testing.T) { } func TestDonorStoreDeleteWhenAllKeysByPKErrors(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id", LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -688,7 +688,7 @@ func TestDonorStoreDeleteWhenAllKeysByPKErrors(t *testing.T) { } func TestDonorStoreDeleteWhenDeleteKeysErrors(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", LpaID: "123"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id", LpaID: "123"}) dynamoClient := newMockDynamoClient(t) dynamoClient.EXPECT(). @@ -707,8 +707,8 @@ func TestDonorStoreDeleteWhenDeleteKeysErrors(t *testing.T) { func TestDonorStoreDeleteWhenSessionMissing(t *testing.T) { testcases := map[string]context.Context{ "missing": context.Background(), - "no LpaID": appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}), - "no SessionID": appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{LpaID: "123"}), + "no LpaID": appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}), + "no SessionID": appcontext.ContextWithSession(context.Background(), &appcontext.Session{LpaID: "123"}), } for name, ctx := range testcases { @@ -722,9 +722,9 @@ func TestDonorStoreDeleteWhenSessionMissing(t *testing.T) { } func TestDonorStoreDeleteDonorAccess(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", OrganisationID: "org-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id", OrganisationID: "org-id"}) - link := temporary.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("donor-sub")} + link := actor.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("donor-sub")} shareCodeData := sharecode.Data{LpaOwnerKey: dynamo.LpaOwnerKey(dynamo.OrganisationKey("org-id")), LpaKey: dynamo.LpaKey("lpa-id")} dynamoClient := newMockDynamoClient(t) @@ -755,7 +755,7 @@ func TestDonorStoreDeleteDonorAccessWhenDonor(t *testing.T) { func TestDonorStoreDeleteDonorAccessWhenSessionMissing(t *testing.T) { testcases := map[string]context.Context{ "missing": context.Background(), - "no organisationID": appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}), + "no organisationID": appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}), } for name, ctx := range testcases { @@ -769,7 +769,7 @@ func TestDonorStoreDeleteDonorAccessWhenSessionMissing(t *testing.T) { } func TestDonorStoreDeleteDonorAccessWhenDeleterInDifferentOrganisation(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", OrganisationID: "a-different-org-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id", OrganisationID: "a-different-org-id"}) donorStore := &donorStore{} @@ -778,10 +778,10 @@ func TestDonorStoreDeleteDonorAccessWhenDeleterInDifferentOrganisation(t *testin } func TestDonorStoreDeleteDonorAccessWhenOneByPartialSKError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", OrganisationID: "org-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id", OrganisationID: "org-id"}) dynamoClient := newMockDynamoClient(t) - dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), temporary.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("donor-sub")}, expectedError) + dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), actor.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("donor-sub")}, expectedError) donorStore := &donorStore{dynamoClient: dynamoClient} @@ -790,10 +790,10 @@ func TestDonorStoreDeleteDonorAccessWhenOneByPartialSKError(t *testing.T) { } func TestDonorStoreDeleteDonorAccessWhenWriteTransactionError(t *testing.T) { - ctx := appcontext.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id", OrganisationID: "org-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id", OrganisationID: "org-id"}) dynamoClient := newMockDynamoClient(t) - dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), temporary.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("donor-sub")}, nil) + dynamoClient.ExpectOneByPartialSK(ctx, dynamo.LpaKey("lpa-id"), dynamo.SubKey(""), actor.LpaLink{PK: dynamo.LpaKey("lpa-id"), SK: dynamo.SubKey("donor-sub")}, nil) dynamoClient.EXPECT(). WriteTransaction(mock.Anything, mock.Anything). Return(expectedError) diff --git a/internal/donor/donordata/voucher.go b/internal/donor/donordata/voucher.go index d280abe763..f7caaaac57 100644 --- a/internal/donor/donordata/voucher.go +++ b/internal/donor/donordata/voucher.go @@ -3,7 +3,7 @@ package donordata import ( "strings" - "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" ) type Voucher struct { @@ -17,43 +17,43 @@ func (v Voucher) FullName() string { return v.FirstNames + " " + v.LastName } -func (v Voucher) Matches(donor *Provided) (match []temporary.ActorType) { +func (v Voucher) Matches(donor *Provided) (match []actor.Type) { if v.FirstNames == "" && v.LastName == "" { return nil } if strings.EqualFold(donor.Donor.FirstNames, v.FirstNames) && strings.EqualFold(donor.Donor.LastName, v.LastName) { - match = append(match, temporary.ActorTypeDonor) + match = append(match, actor.TypeDonor) } for _, attorney := range donor.Attorneys.Attorneys { if strings.EqualFold(attorney.FirstNames, v.FirstNames) && strings.EqualFold(attorney.LastName, v.LastName) { - match = append(match, temporary.ActorTypeAttorney) + match = append(match, actor.TypeAttorney) } } for _, attorney := range donor.ReplacementAttorneys.Attorneys { if strings.EqualFold(attorney.FirstNames, v.FirstNames) && strings.EqualFold(attorney.LastName, v.LastName) { - match = append(match, temporary.ActorTypeReplacementAttorney) + match = append(match, actor.TypeReplacementAttorney) } } if strings.EqualFold(donor.CertificateProvider.FirstNames, v.FirstNames) && strings.EqualFold(donor.CertificateProvider.LastName, v.LastName) { - match = append(match, temporary.ActorTypeCertificateProvider) + match = append(match, actor.TypeCertificateProvider) } for _, person := range donor.PeopleToNotify { if strings.EqualFold(person.FirstNames, v.FirstNames) && strings.EqualFold(person.LastName, v.LastName) { - match = append(match, temporary.ActorTypePersonToNotify) + match = append(match, actor.TypePersonToNotify) } } if strings.EqualFold(donor.AuthorisedSignatory.FirstNames, v.FirstNames) && strings.EqualFold(donor.AuthorisedSignatory.LastName, v.LastName) { - match = append(match, temporary.ActorTypeAuthorisedSignatory) + match = append(match, actor.TypeAuthorisedSignatory) } if strings.EqualFold(donor.IndependentWitness.FirstNames, v.FirstNames) && strings.EqualFold(donor.IndependentWitness.LastName, v.LastName) { - match = append(match, temporary.ActorTypeIndependentWitness) + match = append(match, actor.TypeIndependentWitness) } return match diff --git a/internal/donor/donordata/voucher_test.go b/internal/donor/donordata/voucher_test.go index a64eb67c14..0f04359c1d 100644 --- a/internal/donor/donordata/voucher_test.go +++ b/internal/donor/donordata/voucher_test.go @@ -3,7 +3,7 @@ package donordata import ( "testing" - "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/stretchr/testify/assert" ) @@ -32,16 +32,16 @@ func TestVoucherMatches(t *testing.T) { } assert.Nil(t, Voucher{FirstNames: "x", LastName: "y"}.Matches(donor)) - assert.Equal(t, []temporary.ActorType{temporary.ActorTypeDonor}, Voucher{FirstNames: "a", LastName: "b"}.Matches(donor)) - assert.Equal(t, []temporary.ActorType{temporary.ActorTypeAttorney}, Voucher{FirstNames: "C", LastName: "D"}.Matches(donor)) - assert.Equal(t, []temporary.ActorType{temporary.ActorTypeAttorney}, Voucher{FirstNames: "e", LastName: "f"}.Matches(donor)) - assert.Equal(t, []temporary.ActorType{temporary.ActorTypeReplacementAttorney}, Voucher{FirstNames: "G", LastName: "H"}.Matches(donor)) - assert.Equal(t, []temporary.ActorType{temporary.ActorTypeReplacementAttorney}, Voucher{FirstNames: "i", LastName: "j"}.Matches(donor)) - assert.Equal(t, []temporary.ActorType{temporary.ActorTypeCertificateProvider}, Voucher{FirstNames: "k", LastName: "l"}.Matches(donor)) - assert.Equal(t, []temporary.ActorType{temporary.ActorTypePersonToNotify}, Voucher{FirstNames: "m", LastName: "n"}.Matches(donor)) - assert.Equal(t, []temporary.ActorType{temporary.ActorTypePersonToNotify}, Voucher{FirstNames: "O", LastName: "P"}.Matches(donor)) - assert.Equal(t, []temporary.ActorType{temporary.ActorTypeAuthorisedSignatory}, Voucher{FirstNames: "a", LastName: "s"}.Matches(donor)) - assert.Equal(t, []temporary.ActorType{temporary.ActorTypeIndependentWitness}, Voucher{FirstNames: "i", LastName: "w"}.Matches(donor)) + assert.Equal(t, []actor.Type{actor.TypeDonor}, Voucher{FirstNames: "a", LastName: "b"}.Matches(donor)) + assert.Equal(t, []actor.Type{actor.TypeAttorney}, Voucher{FirstNames: "C", LastName: "D"}.Matches(donor)) + assert.Equal(t, []actor.Type{actor.TypeAttorney}, Voucher{FirstNames: "e", LastName: "f"}.Matches(donor)) + assert.Equal(t, []actor.Type{actor.TypeReplacementAttorney}, Voucher{FirstNames: "G", LastName: "H"}.Matches(donor)) + assert.Equal(t, []actor.Type{actor.TypeReplacementAttorney}, Voucher{FirstNames: "i", LastName: "j"}.Matches(donor)) + assert.Equal(t, []actor.Type{actor.TypeCertificateProvider}, Voucher{FirstNames: "k", LastName: "l"}.Matches(donor)) + assert.Equal(t, []actor.Type{actor.TypePersonToNotify}, Voucher{FirstNames: "m", LastName: "n"}.Matches(donor)) + assert.Equal(t, []actor.Type{actor.TypePersonToNotify}, Voucher{FirstNames: "O", LastName: "P"}.Matches(donor)) + assert.Equal(t, []actor.Type{actor.TypeAuthorisedSignatory}, Voucher{FirstNames: "a", LastName: "s"}.Matches(donor)) + assert.Equal(t, []actor.Type{actor.TypeIndependentWitness}, Voucher{FirstNames: "i", LastName: "w"}.Matches(donor)) } func TestVoucherMatchesMultiple(t *testing.T) { @@ -64,8 +64,8 @@ func TestVoucherMatchesMultiple(t *testing.T) { IndependentWitness: IndependentWitness{FirstNames: "a", LastName: "b"}, } - assert.Equal(t, []temporary.ActorType{temporary.ActorTypeDonor, temporary.ActorTypeAttorney, temporary.ActorTypeAttorney, temporary.ActorTypeReplacementAttorney, temporary.ActorTypeReplacementAttorney, - temporary.ActorTypeCertificateProvider, temporary.ActorTypePersonToNotify, temporary.ActorTypePersonToNotify, temporary.ActorTypeAuthorisedSignatory, temporary.ActorTypeIndependentWitness}, + assert.Equal(t, []actor.Type{actor.TypeDonor, actor.TypeAttorney, actor.TypeAttorney, actor.TypeReplacementAttorney, actor.TypeReplacementAttorney, + actor.TypeCertificateProvider, actor.TypePersonToNotify, actor.TypePersonToNotify, actor.TypeAuthorisedSignatory, actor.TypeIndependentWitness}, Voucher{FirstNames: "a", LastName: "b"}.Matches(donor)) } diff --git a/internal/donor/donorpage/add_correspondent.go b/internal/donor/donorpage/add_correspondent.go index ab55e19458..cc2b8a1250 100644 --- a/internal/donor/donorpage/add_correspondent.go +++ b/internal/donor/donorpage/add_correspondent.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,14 +13,14 @@ import ( ) type addCorrespondentData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm Donor *donordata.Provided } func AddCorrespondent(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &addCorrespondentData{ App: appData, Donor: donor, diff --git a/internal/donor/donorpage/are_you_applying_for_fee_discount_or_exemption.go b/internal/donor/donorpage/are_you_applying_for_fee_discount_or_exemption.go index 11fdcc5c60..04e499b0e1 100644 --- a/internal/donor/donorpage/are_you_applying_for_fee_discount_or_exemption.go +++ b/internal/donor/donorpage/are_you_applying_for_fee_discount_or_exemption.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,14 +13,14 @@ import ( ) type areYouApplyingForFeeDiscountOrExemptionData struct { - App page.AppData + App appcontext.Data Errors validation.List CertificateProvider donordata.CertificateProvider Form *form.YesNoForm } func AreYouApplyingForFeeDiscountOrExemption(tmpl template.Template, payer Handler, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &areYouApplyingForFeeDiscountOrExemptionData{ App: appData, CertificateProvider: donor.CertificateProvider, diff --git a/internal/donor/donorpage/can_you_sign_your_lpa.go b/internal/donor/donorpage/can_you_sign_your_lpa.go index 24b2876590..62dd9d6753 100644 --- a/internal/donor/donorpage/can_you_sign_your_lpa.go +++ b/internal/donor/donorpage/can_you_sign_your_lpa.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -11,7 +12,7 @@ import ( ) type canYouSignYourLpaData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *canYouSignYourLpaForm YesNoMaybeOptions donordata.YesNoMaybeOptions @@ -19,7 +20,7 @@ type canYouSignYourLpaData struct { } func CanYouSignYourLpa(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &canYouSignYourLpaData{ App: appData, Form: &canYouSignYourLpaForm{ diff --git a/internal/donor/donorpage/certificate_provider_address.go b/internal/donor/donorpage/certificate_provider_address.go index e176383606..b8059b45fd 100644 --- a/internal/donor/donorpage/certificate_provider_address.go +++ b/internal/donor/donorpage/certificate_provider_address.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,7 +13,7 @@ import ( ) func CertificateProviderAddress(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := newChooseAddressData( appData, "certificateProvider", diff --git a/internal/donor/donorpage/certificate_provider_details.go b/internal/donor/donorpage/certificate_provider_details.go index db7dfbc357..62087cab20 100644 --- a/internal/donor/donorpage/certificate_provider_details.go +++ b/internal/donor/donorpage/certificate_provider_details.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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -14,14 +15,14 @@ import ( ) type certificateProviderDetailsData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *certificateProviderDetailsForm NameWarning *actor.SameNameWarning } func CertificateProviderDetails(tmpl template.Template, donorStore DonorStore, newUID func() actoruid.UID) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &certificateProviderDetailsData{ App: appData, Form: &certificateProviderDetailsForm{ diff --git a/internal/donor/donorpage/change_mobile_number.go b/internal/donor/donorpage/change_mobile_number.go index 9cce2526a6..232da18e42 100644 --- a/internal/donor/donorpage/change_mobile_number.go +++ b/internal/donor/donorpage/change_mobile_number.go @@ -7,13 +7,14 @@ 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/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type changeMobileNumberData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *changeMobileNumberForm ActorType actor.Type @@ -34,7 +35,7 @@ func ChangeMobileNumber(tmpl template.Template, witnessCodeSender WitnessCodeSen panic("ChangeMobileNumber only supports IndependentWitness or CertificateProvider actors") } - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &changeMobileNumberData{ App: appData, Form: &changeMobileNumberForm{}, diff --git a/internal/donor/donorpage/check_you_can_sign.go b/internal/donor/donorpage/check_you_can_sign.go index 5c28b3832e..18967bc143 100644 --- a/internal/donor/donorpage/check_you_can_sign.go +++ b/internal/donor/donorpage/check_you_can_sign.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -11,13 +12,13 @@ import ( ) type checkYouCanSignData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm } func CheckYouCanSign(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &checkYouCanSignData{ App: appData, Form: form.NewYesNoForm(donor.Donor.CanSign), diff --git a/internal/donor/donorpage/check_your_details.go b/internal/donor/donorpage/check_your_details.go index cdb2449f85..b754a2201e 100644 --- a/internal/donor/donorpage/check_your_details.go +++ b/internal/donor/donorpage/check_your_details.go @@ -4,19 +4,20 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type checkYourDetailsData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided } func CheckYourDetails(tmpl template.Template) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if r.Method == http.MethodPost { if !donor.Tasks.PayForLpa.IsCompleted() { return page.Paths.WeHaveReceivedVoucherDetails.Redirect(w, r, appData, donor) diff --git a/internal/donor/donorpage/check_your_lpa.go b/internal/donor/donorpage/check_your_lpa.go index 1e4b3d8ea5..1aa6c16554 100644 --- a/internal/donor/donorpage/check_your_lpa.go +++ b/internal/donor/donorpage/check_your_lpa.go @@ -8,6 +8,7 @@ import ( "time" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -18,7 +19,7 @@ import ( ) type checkYourLpaData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided Form *checkYourLpaForm @@ -33,7 +34,7 @@ type checkYourLpaNotifier struct { appPublicURL string } -func (n *checkYourLpaNotifier) Notify(ctx context.Context, appData page.AppData, donor *donordata.Provided, wasCompleted bool) error { +func (n *checkYourLpaNotifier) Notify(ctx context.Context, appData appcontext.Data, donor *donordata.Provided, wasCompleted bool) error { if donor.CertificateProvider.CarryOutBy.IsPaper() { return n.sendPaperNotification(ctx, appData, donor, wasCompleted) } @@ -41,7 +42,7 @@ func (n *checkYourLpaNotifier) Notify(ctx context.Context, appData page.AppData, return n.sendOnlineNotification(ctx, appData, donor, wasCompleted) } -func (n *checkYourLpaNotifier) sendPaperNotification(ctx context.Context, appData page.AppData, donor *donordata.Provided, wasCompleted bool) error { +func (n *checkYourLpaNotifier) sendPaperNotification(ctx context.Context, appData appcontext.Data, donor *donordata.Provided, wasCompleted bool) error { var sms notify.SMS if wasCompleted { sms = notify.CertificateProviderActingOnPaperDetailsChangedSMS{ @@ -61,7 +62,7 @@ func (n *checkYourLpaNotifier) sendPaperNotification(ctx context.Context, appDat return n.notifyClient.SendActorSMS(ctx, donor.CertificateProvider.Mobile, donor.LpaUID, sms) } -func (n *checkYourLpaNotifier) sendOnlineNotification(ctx context.Context, appData page.AppData, donor *donordata.Provided, wasCompleted bool) error { +func (n *checkYourLpaNotifier) sendOnlineNotification(ctx context.Context, appData appcontext.Data, donor *donordata.Provided, wasCompleted bool) error { if !wasCompleted { return n.shareCodeSender.SendCertificateProviderInvite(ctx, appData, page.CertificateProviderInvite{ LpaKey: donor.PK, @@ -107,7 +108,7 @@ func CheckYourLpa(tmpl template.Template, donorStore DonorStore, shareCodeSender appPublicURL: appPublicURL, } - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &checkYourLpaData{ App: appData, Donor: donor, diff --git a/internal/donor/donorpage/choose_a_new_certificate_provider.go b/internal/donor/donorpage/choose_a_new_certificate_provider.go index 8cf3e87e94..bed10b58d0 100644 --- a/internal/donor/donorpage/choose_a_new_certificate_provider.go +++ b/internal/donor/donorpage/choose_a_new_certificate_provider.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" @@ -12,11 +13,11 @@ import ( type chooseNewCertificateProviderData struct { Donor *donordata.Provided Errors validation.List - App page.AppData + App appcontext.Data } func ChooseNewCertificateProvider(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &chooseNewCertificateProviderData{Donor: donor, App: appData} if r.Method == http.MethodPost { diff --git a/internal/donor/donorpage/choose_address.go b/internal/donor/donorpage/choose_address.go index 2363afaaa9..0367aeb2ab 100644 --- a/internal/donor/donorpage/choose_address.go +++ b/internal/donor/donorpage/choose_address.go @@ -6,13 +6,13 @@ import ( "log/slog" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) -func newChooseAddressData(appData page.AppData, actorLabel, fullName string, UID actoruid.UID) *chooseAddressData { +func newChooseAddressData(appData appcontext.Data, actorLabel, fullName string, UID actoruid.UID) *chooseAddressData { return &chooseAddressData{ App: appData, ActorLabel: actorLabel, @@ -30,7 +30,7 @@ func newChooseAddressData(appData page.AppData, actorLabel, fullName string, UID } type chooseAddressData struct { - App page.AppData + App appcontext.Data Errors validation.List ActorLabel string FullName string diff --git a/internal/donor/donorpage/choose_attorneys.go b/internal/donor/donorpage/choose_attorneys.go index a901225835..b85fc2a171 100644 --- a/internal/donor/donorpage/choose_attorneys.go +++ b/internal/donor/donorpage/choose_attorneys.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/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -15,7 +16,7 @@ import ( ) type chooseAttorneysData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided Form *chooseAttorneysForm @@ -26,7 +27,7 @@ type chooseAttorneysData struct { } func ChooseAttorneys(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { uid := actoruid.FromRequest(r) if uid.IsZero() { diff --git a/internal/donor/donorpage/choose_attorneys_address.go b/internal/donor/donorpage/choose_attorneys_address.go index e094720c6c..cf4914c1e3 100644 --- a/internal/donor/donorpage/choose_attorneys_address.go +++ b/internal/donor/donorpage/choose_attorneys_address.go @@ -5,6 +5,7 @@ import ( "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,7 +13,7 @@ import ( ) func ChooseAttorneysAddress(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { attorney, found := donor.Attorneys.Get(actoruid.FromRequest(r)) if found == false { diff --git a/internal/donor/donorpage/choose_attorneys_guidance.go b/internal/donor/donorpage/choose_attorneys_guidance.go index 94ba602c8d..30ba547017 100644 --- a/internal/donor/donorpage/choose_attorneys_guidance.go +++ b/internal/donor/donorpage/choose_attorneys_guidance.go @@ -6,19 +6,20 @@ import ( "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type chooseAttorneysGuidanceData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided } func ChooseAttorneysGuidance(tmpl template.Template, newUID func() actoruid.UID) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &chooseAttorneysGuidanceData{ App: appData, Donor: donor, diff --git a/internal/donor/donorpage/choose_attorneys_summary.go b/internal/donor/donorpage/choose_attorneys_summary.go index b0dbe5fd99..48720c6980 100644 --- a/internal/donor/donorpage/choose_attorneys_summary.go +++ b/internal/donor/donorpage/choose_attorneys_summary.go @@ -6,6 +6,7 @@ import ( "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -13,14 +14,14 @@ import ( ) type chooseAttorneysSummaryData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm Donor *donordata.Provided } func ChooseAttorneysSummary(tmpl template.Template, newUID func() actoruid.UID) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if donor.Attorneys.Len() == 0 { return page.Paths.ChooseAttorneys.RedirectQuery(w, r, appData, donor, url.Values{"id": {newUID().String()}}) } diff --git a/internal/donor/donorpage/choose_people_to_notify.go b/internal/donor/donorpage/choose_people_to_notify.go index b75e37b826..95ab7b5794 100644 --- a/internal/donor/donorpage/choose_people_to_notify.go +++ b/internal/donor/donorpage/choose_people_to_notify.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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -15,14 +16,14 @@ import ( ) type choosePeopleToNotifyData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *choosePeopleToNotifyForm NameWarning *actor.SameNameWarning } func ChoosePeopleToNotify(tmpl template.Template, donorStore DonorStore, newUID func() actoruid.UID) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if len(donor.PeopleToNotify) > 4 { return page.Paths.ChoosePeopleToNotifySummary.Redirect(w, r, appData, donor) } diff --git a/internal/donor/donorpage/choose_people_to_notify_address.go b/internal/donor/donorpage/choose_people_to_notify_address.go index 8f2ca52018..0044fc67cf 100644 --- a/internal/donor/donorpage/choose_people_to_notify_address.go +++ b/internal/donor/donorpage/choose_people_to_notify_address.go @@ -5,6 +5,7 @@ import ( "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -13,7 +14,7 @@ import ( ) func ChoosePeopleToNotifyAddress(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { personToNotify, found := donor.PeopleToNotify.Get(actoruid.FromRequest(r)) if found == false { diff --git a/internal/donor/donorpage/choose_people_to_notify_summary.go b/internal/donor/donorpage/choose_people_to_notify_summary.go index 84440ebe8b..cf23b70869 100644 --- a/internal/donor/donorpage/choose_people_to_notify_summary.go +++ b/internal/donor/donorpage/choose_people_to_notify_summary.go @@ -5,6 +5,7 @@ import ( "net/url" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,14 +13,14 @@ import ( ) type choosePeopleToNotifySummaryData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm Donor *donordata.Provided } func ChoosePeopleToNotifySummary(tmpl template.Template) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if len(donor.PeopleToNotify) == 0 { return page.Paths.DoYouWantToNotifyPeople.Redirect(w, r, appData, donor) } diff --git a/internal/donor/donorpage/choose_replacement_attorneys.go b/internal/donor/donorpage/choose_replacement_attorneys.go index 929d6667dc..24b15c9bdd 100644 --- a/internal/donor/donorpage/choose_replacement_attorneys.go +++ b/internal/donor/donorpage/choose_replacement_attorneys.go @@ -8,13 +8,14 @@ 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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type chooseReplacementAttorneysData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided Form *chooseAttorneysForm @@ -24,7 +25,7 @@ type chooseReplacementAttorneysData struct { } func ChooseReplacementAttorneys(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { uid := actoruid.FromRequest(r) if uid.IsZero() { diff --git a/internal/donor/donorpage/choose_replacement_attorneys_address.go b/internal/donor/donorpage/choose_replacement_attorneys_address.go index 93c934acb7..217a2593e0 100644 --- a/internal/donor/donorpage/choose_replacement_attorneys_address.go +++ b/internal/donor/donorpage/choose_replacement_attorneys_address.go @@ -5,6 +5,7 @@ import ( "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,7 +13,7 @@ import ( ) func ChooseReplacementAttorneysAddress(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { attorney, _ := donor.ReplacementAttorneys.Get(actoruid.FromRequest(r)) data := newChooseAddressData( diff --git a/internal/donor/donorpage/choose_replacement_attorneys_summary.go b/internal/donor/donorpage/choose_replacement_attorneys_summary.go index d4420a372c..fb76b47ebf 100644 --- a/internal/donor/donorpage/choose_replacement_attorneys_summary.go +++ b/internal/donor/donorpage/choose_replacement_attorneys_summary.go @@ -6,6 +6,7 @@ import ( "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -13,14 +14,14 @@ import ( ) type chooseReplacementAttorneysSummaryData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm Donor *donordata.Provided } func ChooseReplacementAttorneysSummary(tmpl template.Template, newUID func() actoruid.UID) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if donor.ReplacementAttorneys.Len() == 0 { return page.Paths.DoYouWantReplacementAttorneys.Redirect(w, r, appData, donor) } diff --git a/internal/donor/donorpage/confirm_person_allowed_to_vouch.go b/internal/donor/donorpage/confirm_person_allowed_to_vouch.go index 71342f348b..20a632ed15 100644 --- a/internal/donor/donorpage/confirm_person_allowed_to_vouch.go +++ b/internal/donor/donorpage/confirm_person_allowed_to_vouch.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/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -14,7 +15,7 @@ import ( ) type confirmPersonAllowedToVouchData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm Matches []actor.Type @@ -32,7 +33,7 @@ func (d confirmPersonAllowedToVouchData) MultipleMatches() bool { } func ConfirmPersonAllowedToVouch(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { matches := donor.Voucher.Matches(donor) data := &confirmPersonAllowedToVouchData{ diff --git a/internal/donor/donorpage/confirm_your_certificate_provider_is_not_related.go b/internal/donor/donorpage/confirm_your_certificate_provider_is_not_related.go index e7ccf6d4f5..622660568b 100644 --- a/internal/donor/donorpage/confirm_your_certificate_provider_is_not_related.go +++ b/internal/donor/donorpage/confirm_your_certificate_provider_is_not_related.go @@ -5,6 +5,7 @@ import ( "time" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -13,14 +14,14 @@ import ( ) type confirmYourCertificateProviderIsNotRelatedData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm Donor *donordata.Provided } func ConfirmYourCertificateProviderIsNotRelated(tmpl template.Template, donorStore DonorStore, now func() time.Time) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &confirmYourCertificateProviderIsNotRelatedData{ App: appData, Form: form.NewYesNoForm(form.YesNoUnknown), diff --git a/internal/donor/donorpage/delete_lpa.go b/internal/donor/donorpage/delete_lpa.go index 943f2a04bb..37c525f345 100644 --- a/internal/donor/donorpage/delete_lpa.go +++ b/internal/donor/donorpage/delete_lpa.go @@ -5,20 +5,21 @@ import ( "net/url" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type deleteLpaData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided } func DeleteLpa(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if r.Method == http.MethodPost { if err := donorStore.Delete(r.Context()); err != nil { return err diff --git a/internal/donor/donorpage/do_you_want_to_notify_people.go b/internal/donor/donorpage/do_you_want_to_notify_people.go index 05674cb1d0..02afdb5592 100644 --- a/internal/donor/donorpage/do_you_want_to_notify_people.go +++ b/internal/donor/donorpage/do_you_want_to_notify_people.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,7 +13,7 @@ import ( ) type doYouWantToNotifyPeopleData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm Donor *donordata.Provided @@ -20,7 +21,7 @@ type doYouWantToNotifyPeopleData struct { } func DoYouWantToNotifyPeople(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if len(donor.PeopleToNotify) > 0 { return page.Paths.ChoosePeopleToNotifySummary.Redirect(w, r, appData, donor) } diff --git a/internal/donor/donorpage/enter_access_code.go b/internal/donor/donorpage/enter_access_code.go index 57ee3b4ec2..cd3399f4b5 100644 --- a/internal/donor/donorpage/enter_access_code.go +++ b/internal/donor/donorpage/enter_access_code.go @@ -7,19 +7,20 @@ 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" ) type enterAccessCodeData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *enterAccessCodeForm } func EnterAccessCode(logger Logger, tmpl template.Template, shareCodeStore ShareCodeStore, donorStore DonorStore) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { data := enterAccessCodeData{ App: appData, Form: &enterAccessCodeForm{}, diff --git a/internal/donor/donorpage/enter_correspondent_address.go b/internal/donor/donorpage/enter_correspondent_address.go index a531eed9ef..9ab2421706 100644 --- a/internal/donor/donorpage/enter_correspondent_address.go +++ b/internal/donor/donorpage/enter_correspondent_address.go @@ -5,6 +5,7 @@ import ( "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -13,7 +14,7 @@ import ( ) func EnterCorrespondentAddress(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := newChooseAddressData( appData, "correspondent", diff --git a/internal/donor/donorpage/enter_correspondent_details.go b/internal/donor/donorpage/enter_correspondent_details.go index 06838c66b8..a10dafdd83 100644 --- a/internal/donor/donorpage/enter_correspondent_details.go +++ b/internal/donor/donorpage/enter_correspondent_details.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/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -14,14 +15,14 @@ import ( ) type enterCorrespondentDetailsData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *enterCorrespondentDetailsForm NameWarning *actor.SameNameWarning } func EnterCorrespondentDetails(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &enterCorrespondentDetailsData{ App: appData, Form: &enterCorrespondentDetailsForm{ diff --git a/internal/donor/donorpage/enter_replacement_trust_corporation.go b/internal/donor/donorpage/enter_replacement_trust_corporation.go index 9783258363..d89e763064 100644 --- a/internal/donor/donorpage/enter_replacement_trust_corporation.go +++ b/internal/donor/donorpage/enter_replacement_trust_corporation.go @@ -4,20 +4,21 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type enterReplacementTrustCorporationData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *enterTrustCorporationForm LpaID string } func EnterReplacementTrustCorporation(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { trustCorporation := donor.ReplacementAttorneys.TrustCorporation data := &enterReplacementTrustCorporationData{ diff --git a/internal/donor/donorpage/enter_replacement_trust_corporation_address.go b/internal/donor/donorpage/enter_replacement_trust_corporation_address.go index 754b2c1269..1fe54395be 100644 --- a/internal/donor/donorpage/enter_replacement_trust_corporation_address.go +++ b/internal/donor/donorpage/enter_replacement_trust_corporation_address.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -11,7 +12,7 @@ import ( ) func EnterReplacementTrustCorporationAddress(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { trustCorporation := donor.ReplacementAttorneys.TrustCorporation data := newChooseAddressData( diff --git a/internal/donor/donorpage/enter_trust_corporation.go b/internal/donor/donorpage/enter_trust_corporation.go index 44e0f6f04a..73bac0f15a 100644 --- a/internal/donor/donorpage/enter_trust_corporation.go +++ b/internal/donor/donorpage/enter_trust_corporation.go @@ -4,20 +4,21 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type enterTrustCorporationData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *enterTrustCorporationForm LpaID string } func EnterTrustCorporation(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { trustCorporation := donor.Attorneys.TrustCorporation data := &enterTrustCorporationData{ diff --git a/internal/donor/donorpage/enter_trust_corporation_address.go b/internal/donor/donorpage/enter_trust_corporation_address.go index 946eb195b7..9da7ca43f8 100644 --- a/internal/donor/donorpage/enter_trust_corporation_address.go +++ b/internal/donor/donorpage/enter_trust_corporation_address.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -11,7 +12,7 @@ import ( ) func EnterTrustCorporationAddress(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { trustCorporation := donor.Attorneys.TrustCorporation data := newChooseAddressData( diff --git a/internal/donor/donorpage/enter_voucher.go b/internal/donor/donorpage/enter_voucher.go index 5689c7197b..b18740722d 100644 --- a/internal/donor/donorpage/enter_voucher.go +++ b/internal/donor/donorpage/enter_voucher.go @@ -5,19 +5,20 @@ import ( "strings" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type enterVoucherData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *enterVoucherForm } func EnterVoucher(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &enterVoucherData{ App: appData, Form: &enterVoucherForm{ diff --git a/internal/donor/donorpage/fee_denied.go b/internal/donor/donorpage/fee_denied.go index ed7a774ca7..d40530b3ce 100644 --- a/internal/donor/donorpage/fee_denied.go +++ b/internal/donor/donorpage/fee_denied.go @@ -4,19 +4,19 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type feeDeniedData struct { Donor *donordata.Provided Errors validation.List - App page.AppData + App appcontext.Data } func FeeDenied(tmpl template.Template, payer Handler) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if r.Method == http.MethodPost { return payer(appData, w, r, donor) } diff --git a/internal/donor/donorpage/guidance.go b/internal/donor/donorpage/guidance.go index 1e0fea6ae6..dd3c966a36 100644 --- a/internal/donor/donorpage/guidance.go +++ b/internal/donor/donorpage/guidance.go @@ -4,19 +4,19 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type guidanceData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided } func Guidance(tmpl template.Template) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &guidanceData{ App: appData, Donor: donor, diff --git a/internal/donor/donorpage/how_do_you_know_your_certificate_provider.go b/internal/donor/donorpage/how_do_you_know_your_certificate_provider.go index 6121a5f0bc..ad749a1072 100644 --- a/internal/donor/donorpage/how_do_you_know_your_certificate_provider.go +++ b/internal/donor/donorpage/how_do_you_know_your_certificate_provider.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" @@ -12,7 +13,7 @@ import ( ) type howDoYouKnowYourCertificateProviderData struct { - App page.AppData + App appcontext.Data Errors validation.List CertificateProvider donordata.CertificateProvider Form *howDoYouKnowYourCertificateProviderForm @@ -20,7 +21,7 @@ type howDoYouKnowYourCertificateProviderData struct { } func HowDoYouKnowYourCertificateProvider(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &howDoYouKnowYourCertificateProviderData{ App: appData, CertificateProvider: donor.CertificateProvider, diff --git a/internal/donor/donorpage/how_long_have_you_known_certificate_provider.go b/internal/donor/donorpage/how_long_have_you_known_certificate_provider.go index 234c4ce1d6..7b8642356c 100644 --- a/internal/donor/donorpage/how_long_have_you_known_certificate_provider.go +++ b/internal/donor/donorpage/how_long_have_you_known_certificate_provider.go @@ -4,13 +4,14 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type howLongHaveYouKnownCertificateProviderData struct { - App page.AppData + App appcontext.Data Errors validation.List CertificateProvider donordata.CertificateProvider RelationshipLength donordata.CertificateProviderRelationshipLength @@ -18,7 +19,7 @@ type howLongHaveYouKnownCertificateProviderData struct { } func HowLongHaveYouKnownCertificateProvider(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &howLongHaveYouKnownCertificateProviderData{ App: appData, CertificateProvider: donor.CertificateProvider, diff --git a/internal/donor/donorpage/how_should_attorneys_make_decisions.go b/internal/donor/donorpage/how_should_attorneys_make_decisions.go index bb6ef75e68..db7516c57c 100644 --- a/internal/donor/donorpage/how_should_attorneys_make_decisions.go +++ b/internal/donor/donorpage/how_should_attorneys_make_decisions.go @@ -4,13 +4,14 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type howShouldAttorneysMakeDecisionsData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *howShouldAttorneysMakeDecisionsForm Donor *donordata.Provided @@ -18,7 +19,7 @@ type howShouldAttorneysMakeDecisionsData struct { } func HowShouldAttorneysMakeDecisions(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &howShouldAttorneysMakeDecisionsData{ App: appData, Form: &howShouldAttorneysMakeDecisionsForm{ diff --git a/internal/donor/donorpage/how_should_replacement_attorneys_make_decisions.go b/internal/donor/donorpage/how_should_replacement_attorneys_make_decisions.go index 4b308066e2..e59e685952 100644 --- a/internal/donor/donorpage/how_should_replacement_attorneys_make_decisions.go +++ b/internal/donor/donorpage/how_should_replacement_attorneys_make_decisions.go @@ -4,13 +4,14 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type howShouldReplacementAttorneysMakeDecisionsData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *howShouldAttorneysMakeDecisionsForm Options donordata.AttorneysActOptions @@ -18,7 +19,7 @@ type howShouldReplacementAttorneysMakeDecisionsData struct { } func HowShouldReplacementAttorneysMakeDecisions(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &howShouldReplacementAttorneysMakeDecisionsData{ App: appData, Form: &howShouldAttorneysMakeDecisionsForm{ diff --git a/internal/donor/donorpage/how_should_replacement_attorneys_step_in.go b/internal/donor/donorpage/how_should_replacement_attorneys_step_in.go index 2d589cf2b7..0875613bfe 100644 --- a/internal/donor/donorpage/how_should_replacement_attorneys_step_in.go +++ b/internal/donor/donorpage/how_should_replacement_attorneys_step_in.go @@ -4,20 +4,21 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type howShouldReplacementAttorneysStepInData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *howShouldReplacementAttorneysStepInForm Options donordata.ReplacementAttorneysStepInOptions } func HowShouldReplacementAttorneysStepIn(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &howShouldReplacementAttorneysStepInData{ App: appData, Form: &howShouldReplacementAttorneysStepInForm{ diff --git a/internal/donor/donorpage/how_would_certificate_provider_prefer_to_carry_out_their_role.go b/internal/donor/donorpage/how_would_certificate_provider_prefer_to_carry_out_their_role.go index 5522252d32..4a3c903269 100644 --- a/internal/donor/donorpage/how_would_certificate_provider_prefer_to_carry_out_their_role.go +++ b/internal/donor/donorpage/how_would_certificate_provider_prefer_to_carry_out_their_role.go @@ -4,13 +4,14 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type howWouldCertificateProviderPreferToCarryOutTheirRoleData struct { - App page.AppData + App appcontext.Data Errors validation.List CertificateProvider donordata.CertificateProvider Form *howWouldCertificateProviderPreferToCarryOutTheirRoleForm @@ -18,7 +19,7 @@ type howWouldCertificateProviderPreferToCarryOutTheirRoleData struct { } func HowWouldCertificateProviderPreferToCarryOutTheirRole(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &howWouldCertificateProviderPreferToCarryOutTheirRoleData{ App: appData, CertificateProvider: donor.CertificateProvider, diff --git a/internal/donor/donorpage/how_would_you_like_to_send_evidence.go b/internal/donor/donorpage/how_would_you_like_to_send_evidence.go index 068fe40cff..972d6b7d24 100644 --- a/internal/donor/donorpage/how_would_you_like_to_send_evidence.go +++ b/internal/donor/donorpage/how_would_you_like_to_send_evidence.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,13 +13,13 @@ import ( ) type howWouldYouLikeToSendEvidenceData struct { - App page.AppData + App appcontext.Data Errors validation.List Options pay.EvidenceDeliveryOptions } func HowWouldYouLikeToSendEvidence(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &howWouldYouLikeToSendEvidenceData{ App: appData, Options: pay.EvidenceDeliveryValues, diff --git a/internal/donor/donorpage/identity_with_one_login.go b/internal/donor/donorpage/identity_with_one_login.go index 8679cd5d9a..55536547f3 100644 --- a/internal/donor/donorpage/identity_with_one_login.go +++ b/internal/donor/donorpage/identity_with_one_login.go @@ -3,6 +3,7 @@ package donorpage import ( "net/http" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -10,7 +11,7 @@ import ( ) func IdentityWithOneLogin(oneLoginClient OneLoginClient, sessionStore SessionStore, randomString func(int) string) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { locale := "" if appData.Lang == localize.Cy { locale = "cy" diff --git a/internal/donor/donorpage/identity_with_one_login_callback.go b/internal/donor/donorpage/identity_with_one_login_callback.go index b44ec24dda..65f85823ff 100644 --- a/internal/donor/donorpage/identity_with_one_login_callback.go +++ b/internal/donor/donorpage/identity_with_one_login_callback.go @@ -4,6 +4,7 @@ import ( "errors" "net/http" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -11,7 +12,7 @@ import ( ) func IdentityWithOneLoginCallback(oneLoginClient OneLoginClient, sessionStore SessionStore, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if donor.DonorIdentityConfirmed() { return page.Paths.OneLoginIdentityDetails.Redirect(w, r, appData, donor) } diff --git a/internal/donor/donorpage/identity_with_one_login_test.go b/internal/donor/donorpage/identity_with_one_login_test.go index 8570118656..7bc623f2ba 100644 --- a/internal/donor/donorpage/identity_with_one_login_test.go +++ b/internal/donor/donorpage/identity_with_one_login_test.go @@ -5,6 +5,7 @@ import ( "net/http/httptest" "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -27,7 +28,7 @@ func TestIdentityWithOneLogin(t *testing.T) { SetOneLogin(r, w, &sesh.OneLoginSession{State: "i am random", Nonce: "i am random", Locale: "cy", Redirect: page.Paths.IdentityWithOneLoginCallback.Format("lpa-id"), LpaID: "lpa-id"}). Return(nil) - err := IdentityWithOneLogin(client, sessionStore, func(int) string { return "i am random" })(page.AppData{Lang: localize.Cy}, w, r, &donordata.Provided{LpaID: "lpa-id"}) + err := IdentityWithOneLogin(client, sessionStore, func(int) string { return "i am random" })(appcontext.Data{Lang: localize.Cy}, w, r, &donordata.Provided{LpaID: "lpa-id"}) resp := w.Result() assert.Nil(t, err) diff --git a/internal/donor/donorpage/life_sustaining_treatment.go b/internal/donor/donorpage/life_sustaining_treatment.go index 874d4ad84a..4decd8d694 100644 --- a/internal/donor/donorpage/life_sustaining_treatment.go +++ b/internal/donor/donorpage/life_sustaining_treatment.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -11,14 +12,14 @@ import ( ) type lifeSustainingTreatmentData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *lifeSustainingTreatmentForm Options donordata.LifeSustainingTreatmentOptions } func LifeSustainingTreatment(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &lifeSustainingTreatmentData{ App: appData, Form: &lifeSustainingTreatmentForm{ diff --git a/internal/donor/donorpage/lpa_details_saved.go b/internal/donor/donorpage/lpa_details_saved.go index a75c127fbe..5ca2e66d5c 100644 --- a/internal/donor/donorpage/lpa_details_saved.go +++ b/internal/donor/donorpage/lpa_details_saved.go @@ -4,20 +4,20 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type LpaDetailsSavedData struct { - App page.AppData + App appcontext.Data Donor *donordata.Provided IsFirstCheck bool Errors validation.List } func LpaDetailsSaved(tmpl template.Template) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { return tmpl(w, LpaDetailsSavedData{ App: appData, IsFirstCheck: r.URL.Query().Has("firstCheck"), diff --git a/internal/donor/donorpage/lpa_progress.go b/internal/donor/donorpage/lpa_progress.go index 7e4ef73b21..d5d6836484 100644 --- a/internal/donor/donorpage/lpa_progress.go +++ b/internal/donor/donorpage/lpa_progress.go @@ -4,20 +4,21 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type lpaProgressData struct { - App page.AppData + App appcontext.Data Donor *donordata.Provided Progress page.Progress Errors validation.List } func LpaProgress(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, progressTracker ProgressTracker) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err diff --git a/internal/donor/donorpage/lpa_type.go b/internal/donor/donorpage/lpa_type.go index 96f879360f..3785987d14 100644 --- a/internal/donor/donorpage/lpa_type.go +++ b/internal/donor/donorpage/lpa_type.go @@ -7,6 +7,7 @@ import ( "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/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" "github.com/ministryofjustice/opg-modernising-lpa/internal/uid" @@ -14,21 +15,21 @@ import ( ) type lpaTypeData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *lpaTypeForm - Options donordata.LpaTypeOptions + Options lpadata.LpaTypeOptions CanTaskList bool } func LpaType(tmpl template.Template, donorStore DonorStore, eventClient EventClient) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &lpaTypeData{ App: appData, Form: &lpaTypeForm{ LpaType: donor.Type, }, - Options: donordata.LpaTypeValues, + Options: lpadata.LpaTypeValues, CanTaskList: !donor.Type.Empty(), } @@ -37,7 +38,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 := appcontext.SessionDataFromContext(r.Context()) + session, err := appcontext.SessionFromContext(r.Context()) if err != nil { return err } @@ -81,7 +82,7 @@ type lpaTypeForm struct { } func readLpaTypeForm(r *http.Request) *lpaTypeForm { - lpaType, err := donordata.ParseLpaType(page.PostFormString(r, "lpa-type")) + lpaType, err := lpadata.ParseLpaType(page.PostFormString(r, "lpa-type")) return &lpaTypeForm{ LpaType: lpaType, diff --git a/internal/donor/donorpage/lpa_type_test.go b/internal/donor/donorpage/lpa_type_test.go index 5084bc0f53..ef5289d46f 100644 --- a/internal/donor/donorpage/lpa_type_test.go +++ b/internal/donor/donorpage/lpa_type_test.go @@ -12,6 +12,7 @@ import ( "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" + "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -30,7 +31,7 @@ func TestGetLpaType(t *testing.T) { Execute(w, &lpaTypeData{ App: testAppData, Form: &lpaTypeForm{}, - Options: donordata.LpaTypeValues, + Options: lpadata.LpaTypeValues, }). Return(nil) @@ -52,7 +53,7 @@ func TestGetLpaTypeFromStore(t *testing.T) { Form: &lpaTypeForm{ LpaType: donordata.LpaTypePropertyAndAffairs, }, - Options: donordata.LpaTypeValues, + Options: lpadata.LpaTypeValues, CanTaskList: true, }). Return(nil) @@ -113,7 +114,7 @@ func TestPostLpaType(t *testing.T) { "lpa-type": {lpaType.String()}, } - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodPost, "/", strings.NewReader(form.Encode())) @@ -162,7 +163,7 @@ func TestPostLpaTypeWhenTrustCorporation(t *testing.T) { "lpa-type": {donordata.LpaTypePersonalWelfare.String()}, } - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodPost, "/", strings.NewReader(form.Encode())) @@ -213,7 +214,7 @@ func TestPostLpaTypeWhenEventErrors(t *testing.T) { "lpa-type": {donordata.LpaTypePropertyAndAffairs.String()}, } - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodPost, "/", strings.NewReader(form.Encode())) @@ -241,7 +242,7 @@ func TestPostLpaTypeWhenStoreErrors(t *testing.T) { "lpa-type": {donordata.LpaTypePropertyAndAffairs.String()}, } - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "an-id"}) + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "an-id"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodPost, "/", strings.NewReader(form.Encode())) diff --git a/internal/donor/donorpage/mock_DashboardStore_test.go b/internal/donor/donorpage/mock_DashboardStore_test.go index fe4cc8ed71..c0a61f7efb 100644 --- a/internal/donor/donorpage/mock_DashboardStore_test.go +++ b/internal/donor/donorpage/mock_DashboardStore_test.go @@ -5,10 +5,11 @@ package donorpage import ( context "context" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + mock "github.com/stretchr/testify/mock" - temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" + page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) // mockDashboardStore is an autogenerated mock type for the DashboardStore type @@ -101,7 +102,7 @@ func (_c *mockDashboardStore_GetAll_Call) RunAndReturn(run func(context.Context) } // SubExistsForActorType provides a mock function with given fields: ctx, sub, actorType -func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType temporary.ActorType) (bool, error) { +func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType actor.Type) (bool, error) { ret := _m.Called(ctx, sub, actorType) if len(ret) == 0 { @@ -110,16 +111,16 @@ func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub str var r0 bool var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) (bool, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) (bool, error)); ok { return rf(ctx, sub, actorType) } - if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) bool); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) bool); ok { r0 = rf(ctx, sub, actorType) } else { r0 = ret.Get(0).(bool) } - if rf, ok := ret.Get(1).(func(context.Context, string, temporary.ActorType) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, actor.Type) error); ok { r1 = rf(ctx, sub, actorType) } else { r1 = ret.Error(1) @@ -136,14 +137,14 @@ type mockDashboardStore_SubExistsForActorType_Call struct { // SubExistsForActorType is a helper method to define mock.On call // - ctx context.Context // - sub string -// - actorType temporary.ActorType +// - actorType actor.Type func (_e *mockDashboardStore_Expecter) SubExistsForActorType(ctx interface{}, sub interface{}, actorType interface{}) *mockDashboardStore_SubExistsForActorType_Call { return &mockDashboardStore_SubExistsForActorType_Call{Call: _e.mock.On("SubExistsForActorType", ctx, sub, actorType)} } -func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType temporary.ActorType)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType actor.Type)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(temporary.ActorType)) + run(args[0].(context.Context), args[1].(string), args[2].(actor.Type)) }) return _c } @@ -153,7 +154,7 @@ func (_c *mockDashboardStore_SubExistsForActorType_Call) Return(_a0 bool, _a1 er return _c } -func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, temporary.ActorType) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, actor.Type) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/mock_DocumentStore_test.go b/internal/donor/donorpage/mock_DocumentStore_test.go index a06487fc8c..2fb562147e 100644 --- a/internal/donor/donorpage/mock_DocumentStore_test.go +++ b/internal/donor/donorpage/mock_DocumentStore_test.go @@ -59,7 +59,7 @@ type mockDocumentStore_Create_Call struct { // Create is a helper method to define mock.On call // - _a0 context.Context -// - _a1 *donordata.DonorProvidedDetails +// - _a1 *donordata.Provided // - _a2 string // - _a3 []byte func (_e *mockDocumentStore_Expecter) Create(_a0 interface{}, _a1 interface{}, _a2 interface{}, _a3 interface{}) *mockDocumentStore_Create_Call { @@ -307,7 +307,7 @@ type mockDocumentStore_Submit_Call struct { // Submit is a helper method to define mock.On call // - _a0 context.Context -// - _a1 *donordata.DonorProvidedDetails +// - _a1 *donordata.Provided // - _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)} diff --git a/internal/donor/donorpage/mock_DonorStore_test.go b/internal/donor/donorpage/mock_DonorStore_test.go index a165b2ba9d..34a1b59ed4 100644 --- a/internal/donor/donorpage/mock_DonorStore_test.go +++ b/internal/donor/donorpage/mock_DonorStore_test.go @@ -259,7 +259,7 @@ type mockDonorStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - donor *donordata.DonorProvidedDetails +// - donor *donordata.Provided func (_e *mockDonorStore_Expecter) Put(ctx interface{}, donor interface{}) *mockDonorStore_Put_Call { return &mockDonorStore_Put_Call{Call: _e.mock.On("Put", ctx, donor)} } diff --git a/internal/donor/donorpage/mock_Handler_test.go b/internal/donor/donorpage/mock_Handler_test.go index e7830fa1eb..80faebfade 100644 --- a/internal/donor/donorpage/mock_Handler_test.go +++ b/internal/donor/donorpage/mock_Handler_test.go @@ -3,13 +3,12 @@ package donorpage import ( - http "net/http" - + appcontext "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" donordata "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" - mock "github.com/stretchr/testify/mock" + http "net/http" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + mock "github.com/stretchr/testify/mock" ) // mockHandler is an autogenerated mock type for the Handler type @@ -26,7 +25,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 *donordata.Provided) error { +func (_m *mockHandler) Execute(data appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { ret := _m.Called(data, w, r, donor) if len(ret) == 0 { @@ -34,7 +33,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, *donordata.Provided) error); ok { + if rf, ok := ret.Get(0).(func(appcontext.Data, http.ResponseWriter, *http.Request, *donordata.Provided) error); ok { r0 = rf(data, w, r, donor) } else { r0 = ret.Error(0) @@ -49,17 +48,17 @@ type mockHandler_Execute_Call struct { } // Execute is a helper method to define mock.On call -// - data page.AppData +// - data appcontext.Data // - w http.ResponseWriter // - r *http.Request -// - donor *donordata.DonorProvidedDetails +// - donor *donordata.Provided 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 *donordata.Provided)) *mockHandler_Execute_Call { +func (_c *mockHandler_Execute_Call) Run(run func(data appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided)) *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].(*donordata.Provided)) + run(args[0].(appcontext.Data), args[1].(http.ResponseWriter), args[2].(*http.Request), args[3].(*donordata.Provided)) }) return _c } @@ -69,7 +68,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, *donordata.Provided) error) *mockHandler_Execute_Call { +func (_c *mockHandler_Execute_Call) RunAndReturn(run func(appcontext.Data, http.ResponseWriter, *http.Request, *donordata.Provided) 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 8088b5af60..25b6f8e2f7 100644 --- a/internal/donor/donorpage/mock_LpaStoreClient_test.go +++ b/internal/donor/donorpage/mock_LpaStoreClient_test.go @@ -108,7 +108,7 @@ type mockLpaStoreClient_SendDonorConfirmIdentity_Call struct { // SendDonorConfirmIdentity is a helper method to define mock.On call // - ctx context.Context -// - donor *donordata.DonorProvidedDetails +// - donor *donordata.Provided func (_e *mockLpaStoreClient_Expecter) SendDonorConfirmIdentity(ctx interface{}, donor interface{}) *mockLpaStoreClient_SendDonorConfirmIdentity_Call { return &mockLpaStoreClient_SendDonorConfirmIdentity_Call{Call: _e.mock.On("SendDonorConfirmIdentity", ctx, donor)} } @@ -155,7 +155,7 @@ type mockLpaStoreClient_SendLpa_Call struct { // SendLpa is a helper method to define mock.On call // - ctx context.Context -// - details *donordata.DonorProvidedDetails +// - details *donordata.Provided func (_e *mockLpaStoreClient_Expecter) SendLpa(ctx interface{}, details interface{}) *mockLpaStoreClient_SendLpa_Call { return &mockLpaStoreClient_SendLpa_Call{Call: _e.mock.On("SendLpa", ctx, details)} } diff --git a/internal/donor/donorpage/mock_ShareCodeSender_test.go b/internal/donor/donorpage/mock_ShareCodeSender_test.go index 34f9829ae4..10a7431b4d 100644 --- a/internal/donor/donorpage/mock_ShareCodeSender_test.go +++ b/internal/donor/donorpage/mock_ShareCodeSender_test.go @@ -5,7 +5,10 @@ package donorpage import ( context "context" + appcontext "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + 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" @@ -25,7 +28,7 @@ func (_m *mockShareCodeSender) EXPECT() *mockShareCodeSender_Expecter { } // SendCertificateProviderInvite provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockShareCodeSender) SendCertificateProviderInvite(_a0 context.Context, _a1 page.AppData, _a2 page.CertificateProviderInvite) error { +func (_m *mockShareCodeSender) SendCertificateProviderInvite(_a0 context.Context, _a1 appcontext.Data, _a2 page.CertificateProviderInvite) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -33,7 +36,7 @@ func (_m *mockShareCodeSender) SendCertificateProviderInvite(_a0 context.Context } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, page.AppData, page.CertificateProviderInvite) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, appcontext.Data, page.CertificateProviderInvite) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -49,15 +52,15 @@ type mockShareCodeSender_SendCertificateProviderInvite_Call struct { // SendCertificateProviderInvite is a helper method to define mock.On call // - _a0 context.Context -// - _a1 page.AppData +// - _a1 appcontext.Data // - _a2 page.CertificateProviderInvite func (_e *mockShareCodeSender_Expecter) SendCertificateProviderInvite(_a0 interface{}, _a1 interface{}, _a2 interface{}) *mockShareCodeSender_SendCertificateProviderInvite_Call { return &mockShareCodeSender_SendCertificateProviderInvite_Call{Call: _e.mock.On("SendCertificateProviderInvite", _a0, _a1, _a2)} } -func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) Run(run func(_a0 context.Context, _a1 page.AppData, _a2 page.CertificateProviderInvite)) *mockShareCodeSender_SendCertificateProviderInvite_Call { +func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) Run(run func(_a0 context.Context, _a1 appcontext.Data, _a2 page.CertificateProviderInvite)) *mockShareCodeSender_SendCertificateProviderInvite_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(page.AppData), args[2].(page.CertificateProviderInvite)) + run(args[0].(context.Context), args[1].(appcontext.Data), args[2].(page.CertificateProviderInvite)) }) return _c } @@ -67,13 +70,13 @@ func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) Return(_a0 err return _c } -func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) RunAndReturn(run func(context.Context, page.AppData, page.CertificateProviderInvite) error) *mockShareCodeSender_SendCertificateProviderInvite_Call { +func (_c *mockShareCodeSender_SendCertificateProviderInvite_Call) RunAndReturn(run func(context.Context, appcontext.Data, page.CertificateProviderInvite) error) *mockShareCodeSender_SendCertificateProviderInvite_Call { _c.Call.Return(run) return _c } // SendCertificateProviderPrompt provides a mock function with given fields: _a0, _a1, _a2 -func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context, _a1 page.AppData, _a2 *donordata.Provided) error { +func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context, _a1 appcontext.Data, _a2 *donordata.Provided) error { ret := _m.Called(_a0, _a1, _a2) if len(ret) == 0 { @@ -81,7 +84,7 @@ func (_m *mockShareCodeSender) SendCertificateProviderPrompt(_a0 context.Context } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, page.AppData, *donordata.Provided) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, appcontext.Data, *donordata.Provided) error); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Error(0) @@ -97,15 +100,15 @@ type mockShareCodeSender_SendCertificateProviderPrompt_Call struct { // SendCertificateProviderPrompt is a helper method to define mock.On call // - _a0 context.Context -// - _a1 page.AppData -// - _a2 *donordata.DonorProvidedDetails +// - _a1 appcontext.Data +// - _a2 *donordata.Provided 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 *donordata.Provided)) *mockShareCodeSender_SendCertificateProviderPrompt_Call { +func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) Run(run func(_a0 context.Context, _a1 appcontext.Data, _a2 *donordata.Provided)) *mockShareCodeSender_SendCertificateProviderPrompt_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(page.AppData), args[2].(*donordata.Provided)) + run(args[0].(context.Context), args[1].(appcontext.Data), args[2].(*donordata.Provided)) }) return _c } @@ -115,7 +118,7 @@ func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) Return(_a0 err return _c } -func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) RunAndReturn(run func(context.Context, page.AppData, *donordata.Provided) error) *mockShareCodeSender_SendCertificateProviderPrompt_Call { +func (_c *mockShareCodeSender_SendCertificateProviderPrompt_Call) RunAndReturn(run func(context.Context, appcontext.Data, *donordata.Provided) error) *mockShareCodeSender_SendCertificateProviderPrompt_Call { _c.Call.Return(run) return _c } diff --git a/internal/donor/donorpage/mock_ShareCodeStore_test.go b/internal/donor/donorpage/mock_ShareCodeStore_test.go index 42326c72fc..331a5f1907 100644 --- a/internal/donor/donorpage/mock_ShareCodeStore_test.go +++ b/internal/donor/donorpage/mock_ShareCodeStore_test.go @@ -5,10 +5,11 @@ package donorpage import ( context "context" - sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" + actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + mock "github.com/stretchr/testify/mock" - temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) // mockShareCodeStore is an autogenerated mock type for the ShareCodeStore type @@ -25,7 +26,7 @@ func (_m *mockShareCodeStore) EXPECT() *mockShareCodeStore_Expecter { } // Get provides a mock function with given fields: ctx, actorType, code -func (_m *mockShareCodeStore) Get(ctx context.Context, actorType temporary.ActorType, code string) (sharecode.Data, error) { +func (_m *mockShareCodeStore) Get(ctx context.Context, actorType actor.Type, code string) (sharecode.Data, error) { ret := _m.Called(ctx, actorType, code) if len(ret) == 0 { @@ -34,16 +35,16 @@ func (_m *mockShareCodeStore) Get(ctx context.Context, actorType temporary.Actor var r0 sharecode.Data var r1 error - if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) (sharecode.Data, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) (sharecode.Data, error)); ok { return rf(ctx, actorType, code) } - if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) sharecode.Data); ok { + if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) sharecode.Data); ok { r0 = rf(ctx, actorType, code) } else { r0 = ret.Get(0).(sharecode.Data) } - if rf, ok := ret.Get(1).(func(context.Context, temporary.ActorType, string) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, actor.Type, string) error); ok { r1 = rf(ctx, actorType, code) } else { r1 = ret.Error(1) @@ -59,15 +60,15 @@ type mockShareCodeStore_Get_Call struct { // Get is a helper method to define mock.On call // - ctx context.Context -// - actorType temporary.ActorType +// - actorType actor.Type // - code string func (_e *mockShareCodeStore_Expecter) Get(ctx interface{}, actorType interface{}, code interface{}) *mockShareCodeStore_Get_Call { return &mockShareCodeStore_Get_Call{Call: _e.mock.On("Get", ctx, actorType, code)} } -func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, code string)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType actor.Type, code string)) *mockShareCodeStore_Get_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string)) + run(args[0].(context.Context), args[1].(actor.Type), args[2].(string)) }) return _c } @@ -77,7 +78,7 @@ func (_c *mockShareCodeStore_Get_Call) Return(_a0 sharecode.Data, _a1 error) *mo return _c } -func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string) (sharecode.Data, error)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, actor.Type, string) (sharecode.Data, error)) *mockShareCodeStore_Get_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 0942cea102..edcb8e8a74 100644 --- a/internal/donor/donorpage/mock_WitnessCodeSender_test.go +++ b/internal/donor/donorpage/mock_WitnessCodeSender_test.go @@ -49,7 +49,7 @@ type mockWitnessCodeSender_SendToCertificateProvider_Call struct { // SendToCertificateProvider is a helper method to define mock.On call // - _a0 context.Context -// - _a1 *donordata.DonorProvidedDetails +// - _a1 *donordata.Provided // - _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)} @@ -97,7 +97,7 @@ type mockWitnessCodeSender_SendToIndependentWitness_Call struct { // SendToIndependentWitness is a helper method to define mock.On call // - _a0 context.Context -// - _a1 *donordata.DonorProvidedDetails +// - _a1 *donordata.Provided // - _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)} diff --git a/internal/donor/donorpage/mock_test.go b/internal/donor/donorpage/mock_test.go index e1d215a0b2..8965d3058c 100644 --- a/internal/donor/donorpage/mock_test.go +++ b/internal/donor/donorpage/mock_test.go @@ -7,8 +7,8 @@ import ( "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" ) @@ -25,16 +25,16 @@ var ( Country: "GB", } expectedError = errors.New("err") - testAppData = page.AppData{ + testAppData = appcontext.Data{ SessionID: "session-id", LpaID: "lpa-id", Lang: localize.En, LoginSessionEmail: "logged-in@example.com", } - testSupporterAppData = page.AppData{ + testSupporterAppData = appcontext.Data{ SessionID: "session-id", LpaID: "lpa-id", - SupporterData: &page.SupporterData{}, + SupporterData: &appcontext.SupporterData{}, Lang: localize.En, } testNow = time.Date(2023, time.July, 3, 4, 5, 6, 1, time.UTC) diff --git a/internal/donor/donorpage/one_login_identity_details.go b/internal/donor/donorpage/one_login_identity_details.go index f51f8cfc98..9b7b62bc68 100644 --- a/internal/donor/donorpage/one_login_identity_details.go +++ b/internal/donor/donorpage/one_login_identity_details.go @@ -5,6 +5,7 @@ import ( "net/url" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,7 +13,7 @@ import ( ) type oneLoginIdentityDetailsData struct { - App page.AppData + App appcontext.Data Errors validation.List DonorProvided *donordata.Provided DetailsMatch bool @@ -21,7 +22,7 @@ type oneLoginIdentityDetailsData struct { } func OneLoginIdentityDetails(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &oneLoginIdentityDetailsData{ App: appData, Form: form.NewYesNoForm(form.YesNoUnknown), diff --git a/internal/donor/donorpage/pay.go b/internal/donor/donorpage/pay.go index 55d533b591..d93b470d57 100644 --- a/internal/donor/donorpage/pay.go +++ b/internal/donor/donorpage/pay.go @@ -5,6 +5,7 @@ import ( "log/slog" "net/http" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" @@ -20,7 +21,7 @@ func Pay( randomString func(int) string, appPublicURL string, ) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if donor.FeeType.IsNoFee() || donor.FeeType.IsHardshipFee() || donor.Tasks.PayForLpa.IsMoreEvidenceRequired() { donor.Tasks.PayForLpa = task.PaymentStatePending if err := donorStore.Put(r.Context(), donor); err != nil { diff --git a/internal/donor/donorpage/payment_confirmation.go b/internal/donor/donorpage/payment_confirmation.go index 9fb63f9c2c..a91449ad30 100644 --- a/internal/donor/donorpage/payment_confirmation.go +++ b/internal/donor/donorpage/payment_confirmation.go @@ -8,6 +8,7 @@ import ( "slices" "github.com/ministryofjustice/opg-go-common/template" + "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/notify" @@ -18,7 +19,7 @@ import ( ) type paymentConfirmationData struct { - App page.AppData + App appcontext.Data Errors validation.List PaymentReference string FeeType pay.FeeType @@ -28,7 +29,7 @@ type paymentConfirmationData struct { } func PaymentConfirmation(logger Logger, tmpl template.Template, payClient PayClient, donorStore DonorStore, sessionStore SessionStore, shareCodeSender ShareCodeSender, lpaStoreClient LpaStoreClient, eventClient EventClient, notifyClient NotifyClient) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { paymentSession, err := sessionStore.Payment(r) if err != nil { return err diff --git a/internal/donor/donorpage/previous_application_number.go b/internal/donor/donorpage/previous_application_number.go index 4df2428d35..706a84c23a 100644 --- a/internal/donor/donorpage/previous_application_number.go +++ b/internal/donor/donorpage/previous_application_number.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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" @@ -11,13 +12,13 @@ import ( ) type previousApplicationNumberData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *previousApplicationNumberForm } func PreviousApplicationNumber(tmpl template.Template, donorStore DonorStore, eventClient EventClient) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &previousApplicationNumberData{ App: appData, Form: &previousApplicationNumberForm{ diff --git a/internal/donor/donorpage/previous_fee.go b/internal/donor/donorpage/previous_fee.go index 62df36c303..e4e066a8d8 100644 --- a/internal/donor/donorpage/previous_fee.go +++ b/internal/donor/donorpage/previous_fee.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" @@ -11,14 +12,14 @@ import ( ) type previousFeeData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *previousFeeForm Options pay.PreviousFeeOptions } func PreviousFee(tmpl template.Template, payer Handler, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &previousFeeData{ App: appData, Form: &previousFeeForm{ diff --git a/internal/donor/donorpage/register.go b/internal/donor/donorpage/register.go index 15b42411b4..8062c126a2 100644 --- a/internal/donor/donorpage/register.go +++ b/internal/donor/donorpage/register.go @@ -30,7 +30,7 @@ type LpaStoreResolvingService interface { Get(ctx context.Context) (*lpastore.Lpa, error) } -type Handler func(data page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error +type Handler func(data appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error type Template func(io.Writer, interface{}) error @@ -76,8 +76,8 @@ type AddressClient interface { } type ShareCodeSender interface { - SendCertificateProviderInvite(context.Context, page.AppData, page.CertificateProviderInvite) error - SendCertificateProviderPrompt(context.Context, page.AppData, *donordata.Provided) error + SendCertificateProviderInvite(context.Context, appcontext.Data, page.CertificateProviderInvite) error + SendCertificateProviderPrompt(context.Context, appcontext.Data, *donordata.Provided) error } type OneLoginClient interface { @@ -434,7 +434,7 @@ func makeHandle(mux *http.ServeMux, store SessionStore, errorHandler page.ErrorH mux.HandleFunc(path.String(), func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - appData := page.AppDataFromContext(ctx) + appData := appcontext.DataFromContext(ctx) appData.Page = path.Format() appData.ActorType = actor.TypeDonor @@ -447,10 +447,10 @@ func makeHandle(mux *http.ServeMux, store SessionStore, errorHandler page.ErrorH appData.SessionID = session.SessionID() appData.LoginSessionEmail = session.Email - ctx = page.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID, Email: appData.LoginSessionEmail}) + ctx = appcontext.ContextWithSession(ctx, &appcontext.Session{SessionID: appData.SessionID, LpaID: appData.LpaID, Email: appData.LoginSessionEmail}) } - if err := h(appData, w, r.WithContext(page.ContextWithAppData(ctx, appData))); err != nil { + if err := h(appData, w, r.WithContext(appcontext.ContextWithData(ctx, appData))); err != nil { errorHandler(w, r, err) } }) @@ -468,21 +468,21 @@ func makeLpaHandle(mux *http.ServeMux, store SessionStore, errorHandler page.Err return } - appData := page.AppDataFromContext(ctx) + appData := appcontext.DataFromContext(ctx) appData.CanGoBack = opt&page.CanGoBack != 0 appData.ActorType = actor.TypeDonor appData.LpaID = r.PathValue("id") appData.SessionID = loginSession.SessionID() appData.LoginSessionEmail = loginSession.Email - sessionData, err := appcontext.SessionDataFromContext(ctx) + sessionData, err := appcontext.SessionFromContext(ctx) if err == nil { sessionData.SessionID = appData.SessionID sessionData.LpaID = appData.LpaID - ctx = page.ContextWithSessionData(ctx, sessionData) + ctx = appcontext.ContextWithSession(ctx, sessionData) } else { - sessionData = &appcontext.SessionData{SessionID: appData.SessionID, LpaID: appData.LpaID} - ctx = page.ContextWithSessionData(ctx, sessionData) + sessionData = &appcontext.Session{SessionID: appData.SessionID, LpaID: appData.LpaID} + ctx = appcontext.ContextWithSession(ctx, sessionData) } if loginSession.OrganisationID != "" { @@ -513,14 +513,14 @@ func makeLpaHandle(mux *http.ServeMux, store SessionStore, errorHandler page.Err } if loginSession.OrganisationID != "" { - appData.SupporterData = &page.SupporterData{ + appData.SupporterData = &appcontext.SupporterData{ LpaType: lpa.Type, DonorFullName: lpa.Donor.FullName(), OrganisationName: loginSession.OrganisationName, } } - if err := h(appData, w, r.WithContext(page.ContextWithAppData(ctx, appData)), lpa); err != nil { + if err := h(appData, w, r.WithContext(appcontext.ContextWithData(ctx, appData)), lpa); err != nil { errorHandler(w, r, err) } }) diff --git a/internal/donor/donorpage/register_test.go b/internal/donor/donorpage/register_test.go index 8af93a5ad5..871450901a 100644 --- a/internal/donor/donorpage/register_test.go +++ b/internal/donor/donorpage/register_test.go @@ -36,8 +36,8 @@ func TestMakeHandle(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, nil, nil) - handle("/path", page.None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { - assert.Equal(t, page.AppData{ + handle("/path", page.None, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { + assert.Equal(t, appcontext.Data{ Page: "/path", ActorType: actor.TypeDonor, }, appData) @@ -66,8 +66,8 @@ func TestMakeHandleWhenRequireSession(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, sessionStore, nil) - handle("/path", page.RequireSession, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { - assert.Equal(t, page.AppData{ + handle("/path", page.RequireSession, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { + assert.Equal(t, appcontext.Data{ Page: "/path", ActorType: actor.TypeDonor, SessionID: loginSession.SessionID(), @@ -115,7 +115,7 @@ func TestMakeHandleErrors(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, nil, errorHandler.Execute) - handle("/path", page.None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { + handle("/path", page.None, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { return expectedError }) @@ -124,33 +124,33 @@ func TestMakeHandleErrors(t *testing.T) { func TestMakeLpaHandleWhenDetailsProvidedAndUIDExists(t *testing.T) { testCases := map[string]struct { - expectedAppData page.AppData - loginSesh *sesh.LoginSession - expectedSessionData *appcontext.SessionData + expectedAppData appcontext.Data + loginSesh *sesh.LoginSession + expectedSession *appcontext.Session }{ "donor": { - expectedAppData: page.AppData{ + expectedAppData: appcontext.Data{ Page: "/lpa/123/path", ActorType: actor.TypeDonor, SessionID: "cmFuZG9t", LpaID: "123", }, - loginSesh: &sesh.LoginSession{Sub: "random"}, - expectedSessionData: &appcontext.SessionData{SessionID: "cmFuZG9t", LpaID: "123"}, + loginSesh: &sesh.LoginSession{Sub: "random"}, + expectedSession: &appcontext.Session{SessionID: "cmFuZG9t", LpaID: "123"}, }, "organisation": { - expectedAppData: page.AppData{ + expectedAppData: appcontext.Data{ Page: "/lpa/123/path", ActorType: actor.TypeDonor, SessionID: "cmFuZG9t", LpaID: "123", - SupporterData: &page.SupporterData{ + SupporterData: &appcontext.SupporterData{ DonorFullName: "Jane Smith", LpaType: donordata.LpaTypePropertyAndAffairs, }, }, - loginSesh: &sesh.LoginSession{Sub: "random", OrganisationID: "org-id"}, - expectedSessionData: &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", LpaID: "123"}, + loginSesh: &sesh.LoginSession{Sub: "random", OrganisationID: "org-id"}, + expectedSession: &appcontext.Session{SessionID: "cmFuZG9t", OrganisationID: "org-id", LpaID: "123"}, }, } @@ -182,13 +182,13 @@ func TestMakeLpaHandleWhenDetailsProvidedAndUIDExists(t *testing.T) { }, nil) handle := makeLpaHandle(mux, sessionStore, nil, donorStore) - handle("/path", page.None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, _ *donordata.Provided) error { + handle("/path", page.None, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request, _ *donordata.Provided) error { assert.Equal(t, tc.expectedAppData, appData) assert.Equal(t, w, hw) - sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) - assert.Equal(t, tc.expectedSessionData, sessionData) + sessionData, _ := appcontext.SessionFromContext(hr.Context()) + assert.Equal(t, tc.expectedSession, sessionData) hw.WriteHeader(http.StatusTeapot) return nil @@ -241,7 +241,7 @@ func TestMakeHandleLpaWhenDonorEmailNotSet(t *testing.T) { Return(nil) handle := makeLpaHandle(mux, sessionStore, nil, donorStore) - handle("/path", page.None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, _ *donordata.Provided) error { + handle("/path", page.None, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request, _ *donordata.Provided) error { hw.WriteHeader(http.StatusTeapot) return nil }) @@ -264,7 +264,7 @@ func TestMakeLpaHandleWhenSessionStoreError(t *testing.T) { Return(nil, expectedError) handle := makeLpaHandle(mux, sessionStore, nil, nil) - handle("/path", page.None, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *donordata.Provided) error { + handle("/path", page.None, func(_ appcontext.Data, _ http.ResponseWriter, _ *http.Request, _ *donordata.Provided) error { return expectedError }) @@ -313,7 +313,7 @@ func TestMakeLpaHandleWhenDonorStoreError(t *testing.T) { Execute(w, r, expectedError) handle := makeLpaHandle(mux, sessionStore, errorHandler.Execute, donorStore()) - handle("/path", page.None, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *donordata.Provided) error { + handle("/path", page.None, func(_ appcontext.Data, _ http.ResponseWriter, _ *http.Request, _ *donordata.Provided) error { return expectedError }) @@ -344,7 +344,7 @@ func TestMakeLpaHandleWhenCannotGoToURL(t *testing.T) { Return(&donordata.Provided{LpaID: "123", Donor: donordata.Donor{Email: "a@example.com"}}, nil) handle := makeLpaHandle(mux, sessionStore, nil, donorStore) - handle(path, page.None, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *donordata.Provided) error { + handle(path, page.None, func(_ appcontext.Data, _ http.ResponseWriter, _ *http.Request, _ *donordata.Provided) error { return nil }) @@ -355,8 +355,8 @@ func TestMakeLpaHandleWhenCannotGoToURL(t *testing.T) { assert.Equal(t, page.Paths.TaskList.Format("123"), resp.Header.Get("Location")) } -func TestMakeLpaHandleSessionExistingSessionData(t *testing.T) { - ctx := page.ContextWithSessionData(context.Background(), &appcontext.SessionData{SessionID: "ignored"}) +func TestMakeLpaHandleSessionExistingSession(t *testing.T) { + ctx := appcontext.ContextWithSession(context.Background(), &appcontext.Session{SessionID: "ignored"}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/lpa/123/path?a=b", nil) @@ -372,8 +372,8 @@ func TestMakeLpaHandleSessionExistingSessionData(t *testing.T) { mux := http.NewServeMux() handle := makeLpaHandle(mux, sessionStore, nil, donorStore) - handle("/path", page.RequireSession|page.CanGoBack, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, _ *donordata.Provided) error { - assert.Equal(t, page.AppData{ + handle("/path", page.RequireSession|page.CanGoBack, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request, _ *donordata.Provided) error { + assert.Equal(t, appcontext.Data{ Page: "/lpa/123/path", SessionID: "cmFuZG9t", CanGoBack: true, @@ -382,9 +382,9 @@ func TestMakeLpaHandleSessionExistingSessionData(t *testing.T) { }, appData) assert.Equal(t, w, hw) - sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) + sessionData, _ := appcontext.SessionFromContext(hr.Context()) - assert.Equal(t, &appcontext.SessionData{LpaID: "123", SessionID: "cmFuZG9t"}, sessionData) + assert.Equal(t, &appcontext.Session{LpaID: "123", SessionID: "cmFuZG9t"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil }) @@ -415,7 +415,7 @@ func TestMakeLpaHandleErrors(t *testing.T) { mux := http.NewServeMux() handle := makeLpaHandle(mux, sessionStore, errorHandler.Execute, donorStore) - handle("/path", page.RequireSession, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *donordata.Provided) error { + handle("/path", page.RequireSession, func(_ appcontext.Data, _ http.ResponseWriter, _ *http.Request, _ *donordata.Provided) error { return expectedError }) diff --git a/internal/donor/donorpage/register_with_court_of_protection.go b/internal/donor/donorpage/register_with_court_of_protection.go index fb54b8f05c..82ec018e13 100644 --- a/internal/donor/donorpage/register_with_court_of_protection.go +++ b/internal/donor/donorpage/register_with_court_of_protection.go @@ -5,6 +5,7 @@ import ( "time" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,13 +13,13 @@ import ( ) type registerWithCourtOfProtectionData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm } func RegisterWithCourtOfProtection(tmpl template.Template, donorStore DonorStore, now func() time.Time) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := ®isterWithCourtOfProtectionData{ App: appData, Form: form.NewYesNoForm(form.YesNoUnknown), diff --git a/internal/donor/donorpage/remove_attorney.go b/internal/donor/donorpage/remove_attorney.go index 850d4dff76..f9d48c3977 100644 --- a/internal/donor/donorpage/remove_attorney.go +++ b/internal/donor/donorpage/remove_attorney.go @@ -6,6 +6,7 @@ import ( "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -13,7 +14,7 @@ import ( ) type removeAttorneyData struct { - App page.AppData + App appcontext.Data TitleLabel string Name string Errors validation.List @@ -21,7 +22,7 @@ type removeAttorneyData struct { } func RemoveAttorney(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { attorney, found := donor.Attorneys.Get(actoruid.FromRequest(r)) if found == false { diff --git a/internal/donor/donorpage/remove_person_to_notify.go b/internal/donor/donorpage/remove_person_to_notify.go index 4e3735e50f..9d03d12319 100644 --- a/internal/donor/donorpage/remove_person_to_notify.go +++ b/internal/donor/donorpage/remove_person_to_notify.go @@ -6,6 +6,7 @@ import ( "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -14,14 +15,14 @@ import ( ) type removePersonToNotifyData struct { - App page.AppData + App appcontext.Data PersonToNotify donordata.PersonToNotify Errors validation.List Form *form.YesNoForm } func RemovePersonToNotify(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { person, found := donor.PeopleToNotify.Get(actoruid.FromRequest(r)) if found == false { diff --git a/internal/donor/donorpage/remove_replacement_attorney.go b/internal/donor/donorpage/remove_replacement_attorney.go index b66c94e51f..5b13a3d04f 100644 --- a/internal/donor/donorpage/remove_replacement_attorney.go +++ b/internal/donor/donorpage/remove_replacement_attorney.go @@ -6,13 +6,14 @@ import ( "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) func RemoveReplacementAttorney(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { attorney, found := donor.ReplacementAttorneys.Get(actoruid.FromRequest(r)) if found == false { diff --git a/internal/donor/donorpage/remove_trust_corporation.go b/internal/donor/donorpage/remove_trust_corporation.go index 503fb0e2a8..9f9c0ef2a0 100644 --- a/internal/donor/donorpage/remove_trust_corporation.go +++ b/internal/donor/donorpage/remove_trust_corporation.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -33,7 +34,7 @@ func RemoveTrustCorporation(tmpl template.Template, donorStore DonorStore, isRep } } - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { name := donor.Attorneys.TrustCorporation.Name if isReplacement { name = donor.ReplacementAttorneys.TrustCorporation.Name diff --git a/internal/donor/donorpage/resend_witness_code.go b/internal/donor/donorpage/resend_witness_code.go index dd478cfdb6..c47bd2e6f3 100644 --- a/internal/donor/donorpage/resend_witness_code.go +++ b/internal/donor/donorpage/resend_witness_code.go @@ -6,13 +6,14 @@ 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/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type resendWitnessCodeData struct { - App page.AppData + App appcontext.Data Errors validation.List } @@ -25,7 +26,7 @@ func ResendWitnessCode(tmpl template.Template, witnessCodeSender WitnessCodeSend redirect = page.Paths.WitnessingAsIndependentWitness } - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &resendWitnessCodeData{ App: appData, } diff --git a/internal/donor/donorpage/restrictions.go b/internal/donor/donorpage/restrictions.go index 4f6bdd0f72..aa56c37e77 100644 --- a/internal/donor/donorpage/restrictions.go +++ b/internal/donor/donorpage/restrictions.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -11,13 +12,13 @@ import ( ) type restrictionsData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided } func Restrictions(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &restrictionsData{ App: appData, Donor: donor, diff --git a/internal/donor/donorpage/send_us_your_evidence_by_post.go b/internal/donor/donorpage/send_us_your_evidence_by_post.go index e7de1c2bf0..d2e2a72cf3 100644 --- a/internal/donor/donorpage/send_us_your_evidence_by_post.go +++ b/internal/donor/donorpage/send_us_your_evidence_by_post.go @@ -4,21 +4,21 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "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" "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type sendUsYourEvidenceByPostData struct { - App page.AppData + App appcontext.Data Errors validation.List FeeType pay.FeeType } func SendUsYourEvidenceByPost(tmpl template.Template, payer Handler, eventClient EventClient) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &sendUsYourEvidenceByPostData{ App: appData, FeeType: donor.FeeType, diff --git a/internal/donor/donorpage/sign_your_lpa.go b/internal/donor/donorpage/sign_your_lpa.go index aa45b9d71c..f764c7b061 100644 --- a/internal/donor/donorpage/sign_your_lpa.go +++ b/internal/donor/donorpage/sign_your_lpa.go @@ -5,13 +5,14 @@ import ( "time" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type signYourLpaData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided Form *signYourLpaForm @@ -25,7 +26,7 @@ const ( ) func SignYourLpa(tmpl template.Template, donorStore DonorStore, now func() time.Time) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if !donor.SignedAt.IsZero() { return page.Paths.WitnessingYourSignature.Redirect(w, r, appData, donor) } diff --git a/internal/donor/donorpage/task_list.go b/internal/donor/donorpage/task_list.go index f3618be7d8..70d76e2f65 100644 --- a/internal/donor/donorpage/task_list.go +++ b/internal/donor/donorpage/task_list.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,7 +13,7 @@ import ( ) type taskListData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided Sections []taskListSection @@ -35,7 +36,7 @@ type taskListSection struct { } func TaskList(tmpl template.Template, evidenceReceivedStore EvidenceReceivedStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { evidenceReceived, err := evidenceReceivedStore.Get(r.Context()) if err != nil { return err diff --git a/internal/donor/donorpage/task_list_test.go b/internal/donor/donorpage/task_list_test.go index 998364ad23..b254d19435 100644 --- a/internal/donor/donorpage/task_list_test.go +++ b/internal/donor/donorpage/task_list_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + "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/form" @@ -20,7 +21,7 @@ import ( func TestGetTaskList(t *testing.T) { testCases := map[string]struct { - appData page.AppData + appData appcontext.Data donor *donordata.Provided evidenceReceived bool expected func([]taskListSection) []taskListSection @@ -374,11 +375,11 @@ func TestGetTaskList(t *testing.T) { }, }, "supporter": { - appData: page.AppData{ + appData: appcontext.Data{ SessionID: "session-id", LpaID: "lpa-id", Lang: localize.En, - SupporterData: &page.SupporterData{}, + SupporterData: &appcontext.SupporterData{}, }, donor: &donordata.Provided{ LpaID: "lpa-id", diff --git a/internal/donor/donorpage/upload_evidence.go b/internal/donor/donorpage/upload_evidence.go index 77ee9d9fec..3d8d287313 100644 --- a/internal/donor/donorpage/upload_evidence.go +++ b/internal/donor/donorpage/upload_evidence.go @@ -12,6 +12,7 @@ import ( "github.com/gabriel-vasile/mimetype" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" @@ -50,7 +51,7 @@ func acceptedMimeTypes() []string { } type uploadEvidenceData struct { - App page.AppData + App appcontext.Data Errors validation.List NumberOfAllowedFiles int FeeType pay.FeeType @@ -61,7 +62,7 @@ type uploadEvidenceData struct { } func UploadEvidence(tmpl template.Template, logger Logger, payer Handler, documentStore DocumentStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if donor.Tasks.PayForLpa.IsPending() { return page.Paths.TaskList.Redirect(w, r, appData, donor) } diff --git a/internal/donor/donorpage/upload_evidence_sse.go b/internal/donor/donorpage/upload_evidence_sse.go index 3fab58ad7e..2f9f39e22c 100644 --- a/internal/donor/donorpage/upload_evidence_sse.go +++ b/internal/donor/donorpage/upload_evidence_sse.go @@ -6,12 +6,12 @@ import ( "net/http" "time" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) func UploadEvidenceSSE(documentStore DocumentStore, ttl time.Duration, flushFrequency time.Duration, now func() time.Time) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { w.Header().Set("Cache-Control", "no-cache") w.Header().Set("Connection", "keep-alive") w.Header().Set("Content-Type", "text/event-stream") diff --git a/internal/donor/donorpage/want_replacement_attorneys.go b/internal/donor/donorpage/want_replacement_attorneys.go index 67d980549f..78a13736e7 100644 --- a/internal/donor/donorpage/want_replacement_attorneys.go +++ b/internal/donor/donorpage/want_replacement_attorneys.go @@ -6,6 +6,7 @@ import ( "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -13,14 +14,14 @@ import ( ) type wantReplacementAttorneysData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm Donor *donordata.Provided } func WantReplacementAttorneys(tmpl template.Template, donorStore DonorStore, newUID func() actoruid.UID) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &wantReplacementAttorneysData{ App: appData, Donor: donor, diff --git a/internal/donor/donorpage/what_is_vouching.go b/internal/donor/donorpage/what_is_vouching.go index 259dfc47d7..50d011b4f9 100644 --- a/internal/donor/donorpage/what_is_vouching.go +++ b/internal/donor/donorpage/what_is_vouching.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -11,13 +12,13 @@ import ( ) type whatIsVouchingData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm } func WhatIsVouching(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &whatIsVouchingData{ App: appData, Form: form.NewYesNoForm(donor.WantVoucher), diff --git a/internal/donor/donorpage/what_you_can_do_now.go b/internal/donor/donorpage/what_you_can_do_now.go index 400578fe4f..455d740ec8 100644 --- a/internal/donor/donorpage/what_you_can_do_now.go +++ b/internal/donor/donorpage/what_you_can_do_now.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/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" @@ -13,13 +14,13 @@ import ( ) type whatYouCanDoNowData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *whatYouCanDoNowForm } func WhatYouCanDoNow(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &whatYouCanDoNowData{ App: appData, Form: &whatYouCanDoNowForm{ diff --git a/internal/donor/donorpage/when_can_the_lpa_be_used.go b/internal/donor/donorpage/when_can_the_lpa_be_used.go index b48213e7dc..c7f9d5a6ec 100644 --- a/internal/donor/donorpage/when_can_the_lpa_be_used.go +++ b/internal/donor/donorpage/when_can_the_lpa_be_used.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -11,7 +12,7 @@ import ( ) type whenCanTheLpaBeUsedData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided Form *whenCanTheLpaBeUsedForm @@ -19,7 +20,7 @@ type whenCanTheLpaBeUsedData struct { } func WhenCanTheLpaBeUsed(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &whenCanTheLpaBeUsedData{ App: appData, Donor: donor, diff --git a/internal/donor/donorpage/which_fee_type_are_you_applying_for.go b/internal/donor/donorpage/which_fee_type_are_you_applying_for.go index 6b71ea1c97..c694ec7b92 100644 --- a/internal/donor/donorpage/which_fee_type_are_you_applying_for.go +++ b/internal/donor/donorpage/which_fee_type_are_you_applying_for.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/pay" @@ -11,14 +12,14 @@ import ( ) type whichFeeTypeAreYouApplyingForData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *whichFeeTypeAreYouApplyingForForm Options pay.FeeTypeOptions } func WhichFeeTypeAreYouApplyingFor(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &whichFeeTypeAreYouApplyingForData{ App: appData, Form: &whichFeeTypeAreYouApplyingForForm{ diff --git a/internal/donor/donorpage/withdraw_lpa.go b/internal/donor/donorpage/withdraw_lpa.go index d45708fcfc..8e30f71494 100644 --- a/internal/donor/donorpage/withdraw_lpa.go +++ b/internal/donor/donorpage/withdraw_lpa.go @@ -6,19 +6,20 @@ import ( "time" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type withdrawLpaData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided } func WithdrawLpa(tmpl template.Template, donorStore DonorStore, now func() time.Time) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if r.Method == http.MethodPost { donor.WithdrawnAt = now() if err := donorStore.Put(r.Context(), donor); err != nil { diff --git a/internal/donor/donorpage/witnessing_as_certificate_provider.go b/internal/donor/donorpage/witnessing_as_certificate_provider.go index 00009364f3..4331764844 100644 --- a/internal/donor/donorpage/witnessing_as_certificate_provider.go +++ b/internal/donor/donorpage/witnessing_as_certificate_provider.go @@ -5,6 +5,7 @@ import ( "time" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -12,7 +13,7 @@ import ( ) type witnessingAsCertificateProviderData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *witnessingAsCertificateProviderForm Donor *donordata.Provided @@ -25,7 +26,7 @@ func WitnessingAsCertificateProvider( lpaStoreClient LpaStoreClient, now func() time.Time, ) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &witnessingAsCertificateProviderData{ App: appData, Donor: donor, diff --git a/internal/donor/donorpage/witnessing_as_independent_witness.go b/internal/donor/donorpage/witnessing_as_independent_witness.go index 9145f6508e..46eeab25d9 100644 --- a/internal/donor/donorpage/witnessing_as_independent_witness.go +++ b/internal/donor/donorpage/witnessing_as_independent_witness.go @@ -5,20 +5,21 @@ import ( "time" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type witnessingAsIndependentWitnessData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *witnessingAsIndependentWitnessForm Donor *donordata.Provided } func WitnessingAsIndependentWitness(tmpl template.Template, donorStore DonorStore, now func() time.Time) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &witnessingAsIndependentWitnessData{ App: appData, Donor: donor, diff --git a/internal/donor/donorpage/witnessing_your_signature.go b/internal/donor/donorpage/witnessing_your_signature.go index 75fbcd53af..1d7c03b0f4 100644 --- a/internal/donor/donorpage/witnessing_your_signature.go +++ b/internal/donor/donorpage/witnessing_your_signature.go @@ -4,19 +4,20 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type witnessingYourSignatureData struct { - App page.AppData + App appcontext.Data Errors validation.List Donor *donordata.Provided } func WitnessingYourSignature(tmpl template.Template, witnessCodeSender WitnessCodeSender, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if r.Method == http.MethodPost { if err := witnessCodeSender.SendToCertificateProvider(r.Context(), donor, appData.Localizer); err != nil { return err diff --git a/internal/donor/donorpage/you_cannot_sign_your_lpa_yet.go b/internal/donor/donorpage/you_cannot_sign_your_lpa_yet.go index d6a13876ba..76d11973f7 100644 --- a/internal/donor/donorpage/you_cannot_sign_your_lpa_yet.go +++ b/internal/donor/donorpage/you_cannot_sign_your_lpa_yet.go @@ -4,12 +4,13 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) func YouCannotSignYourLpaYet(tmpl template.Template) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { if len(donor.Under18ActorDetails()) == 0 { return appData.Redirect(w, r, page.Paths.TaskList.Format(donor.LpaID)) } diff --git a/internal/donor/donorpage/your_address.go b/internal/donor/donorpage/your_address.go index bdf1391eff..1347eb1d03 100644 --- a/internal/donor/donorpage/your_address.go +++ b/internal/donor/donorpage/your_address.go @@ -5,6 +5,7 @@ import ( "net/url" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -12,7 +13,7 @@ import ( ) func YourAddress(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := newChooseAddressData( appData, "", diff --git a/internal/donor/donorpage/your_address_test.go b/internal/donor/donorpage/your_address_test.go index a372ef541b..574ca476ce 100644 --- a/internal/donor/donorpage/your_address_test.go +++ b/internal/donor/donorpage/your_address_test.go @@ -8,6 +8,7 @@ import ( "strings" "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -136,7 +137,7 @@ func TestGetYourAddressWhenTemplateErrors(t *testing.T) { func TestPostYourAddressManual(t *testing.T) { testCases := map[string]struct { url string - appData page.AppData + appData appcontext.Data expectedRedirect string }{ "making first LPA": { diff --git a/internal/donor/donorpage/your_authorised_signatory.go b/internal/donor/donorpage/your_authorised_signatory.go index 7e025ca63a..caa64d55f5 100644 --- a/internal/donor/donorpage/your_authorised_signatory.go +++ b/internal/donor/donorpage/your_authorised_signatory.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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -13,14 +14,14 @@ import ( ) type yourAuthorisedSignatoryData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *yourAuthorisedSignatoryForm NameWarning *actor.SameNameWarning } func YourAuthorisedSignatory(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &yourAuthorisedSignatoryData{ App: appData, Form: &yourAuthorisedSignatoryForm{ diff --git a/internal/donor/donorpage/your_date_of_birth.go b/internal/donor/donorpage/your_date_of_birth.go index 482c52c84f..9ccdcd5fe8 100644 --- a/internal/donor/donorpage/your_date_of_birth.go +++ b/internal/donor/donorpage/your_date_of_birth.go @@ -5,6 +5,7 @@ import ( "net/url" "github.com/ministryofjustice/opg-go-common/template" + "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/page" @@ -12,7 +13,7 @@ import ( ) type yourDateOfBirthData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *yourDateOfBirthForm DobWarning string @@ -21,7 +22,7 @@ type yourDateOfBirthData struct { } func YourDateOfBirth(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &yourDateOfBirthData{ App: appData, Form: &yourDateOfBirthForm{ diff --git a/internal/donor/donorpage/your_email.go b/internal/donor/donorpage/your_email.go index 3aeb90a875..e09327680f 100644 --- a/internal/donor/donorpage/your_email.go +++ b/internal/donor/donorpage/your_email.go @@ -4,20 +4,21 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type yourEmailData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *yourEmailForm CanTaskList bool } func YourEmail(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &yourEmailData{ App: appData, Form: &yourEmailForm{ diff --git a/internal/donor/donorpage/your_independent_witness.go b/internal/donor/donorpage/your_independent_witness.go index 645648c2d9..e689239d3c 100644 --- a/internal/donor/donorpage/your_independent_witness.go +++ b/internal/donor/donorpage/your_independent_witness.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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" @@ -13,14 +14,14 @@ import ( ) type yourIndependentWitnessData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *yourIndependentWitnessForm NameWarning *actor.SameNameWarning } func YourIndependentWitness(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &yourIndependentWitnessData{ App: appData, Form: &yourIndependentWitnessForm{ diff --git a/internal/donor/donorpage/your_independent_witness_address.go b/internal/donor/donorpage/your_independent_witness_address.go index 8623108bd4..b7562cc12a 100644 --- a/internal/donor/donorpage/your_independent_witness_address.go +++ b/internal/donor/donorpage/your_independent_witness_address.go @@ -5,6 +5,7 @@ import ( "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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" @@ -13,7 +14,7 @@ import ( ) func YourIndependentWitnessAddress(logger Logger, tmpl template.Template, addressClient AddressClient, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := newChooseAddressData( appData, "independentWitness", diff --git a/internal/donor/donorpage/your_independent_witness_mobile.go b/internal/donor/donorpage/your_independent_witness_mobile.go index cf7fcd824e..0570b369b3 100644 --- a/internal/donor/donorpage/your_independent_witness_mobile.go +++ b/internal/donor/donorpage/your_independent_witness_mobile.go @@ -4,20 +4,21 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type yourIndependentWitnessMobileData struct { - App page.AppData + App appcontext.Data Errors validation.List AuthorisedSignatory donordata.AuthorisedSignatory Form *yourIndependentWitnessMobileForm } func YourIndependentWitnessMobile(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &yourIndependentWitnessMobileData{ App: appData, AuthorisedSignatory: donor.AuthorisedSignatory, diff --git a/internal/donor/donorpage/your_lpa_language.go b/internal/donor/donorpage/your_lpa_language.go index 8f21e14c6d..d66263c53a 100644 --- a/internal/donor/donorpage/your_lpa_language.go +++ b/internal/donor/donorpage/your_lpa_language.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -12,7 +13,7 @@ import ( ) type yourLpaLanguageData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm SelectedLanguage localize.Lang @@ -20,7 +21,7 @@ type yourLpaLanguageData struct { } func YourLpaLanguage(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &yourLpaLanguageData{ App: appData, Form: form.NewYesNoForm(form.YesNoUnknown), diff --git a/internal/donor/donorpage/your_name.go b/internal/donor/donorpage/your_name.go index 1bd69c256a..c39b7e6a25 100644 --- a/internal/donor/donorpage/your_name.go +++ b/internal/donor/donorpage/your_name.go @@ -8,13 +8,14 @@ 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/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type yourNameData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *yourNameForm NameWarning *actor.SameNameWarning @@ -23,7 +24,7 @@ type yourNameData struct { } func YourName(tmpl template.Template, donorStore DonorStore, sessionStore SessionStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &yourNameData{ App: appData, Form: &yourNameForm{ diff --git a/internal/donor/donorpage/your_preferred_language.go b/internal/donor/donorpage/your_preferred_language.go index caa764e18b..dc21d6bb8e 100644 --- a/internal/donor/donorpage/your_preferred_language.go +++ b/internal/donor/donorpage/your_preferred_language.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -12,7 +13,7 @@ import ( ) type yourPreferredLanguageData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *yourPreferredLanguageForm Options localize.LangOptions @@ -20,7 +21,7 @@ type yourPreferredLanguageData struct { } func YourPreferredLanguage(tmpl template.Template, donorStore DonorStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, donor *donordata.Provided) error { data := &yourPreferredLanguageData{ App: appData, Form: &yourPreferredLanguageForm{ diff --git a/internal/donor/donordata/enum_lpatype.go b/internal/lpastore/lpadata/enum_lpatype.go similarity index 98% rename from internal/donor/donordata/enum_lpatype.go rename to internal/lpastore/lpadata/enum_lpatype.go index 03d17f8bb3..6cff648a7b 100644 --- a/internal/donor/donordata/enum_lpatype.go +++ b/internal/lpastore/lpadata/enum_lpatype.go @@ -1,5 +1,5 @@ // Code generated by "enumerator -type LpaType -linecomment -trimprefix -empty"; DO NOT EDIT. -package donordata +package lpadata import ( "fmt" diff --git a/internal/lpastore/lpadata/lpa_type.go b/internal/lpastore/lpadata/lpa_type.go new file mode 100644 index 0000000000..eccc963b2e --- /dev/null +++ b/internal/lpastore/lpadata/lpa_type.go @@ -0,0 +1,20 @@ +package lpadata + +//go:generate enumerator -type LpaType -linecomment -trimprefix -empty +type LpaType uint8 + +const ( + LpaTypePersonalWelfare LpaType = iota + 1 // personal-welfare + LpaTypePropertyAndAffairs // property-and-affairs +) + +// TODO: move this somewhere else +func (e LpaType) WhatLPACoversTransKey() string { + switch e { + case LpaTypePropertyAndAffairs: + return "whatPropertyAndAffairsCovers" + case LpaTypePersonalWelfare: + return "whatPersonalWelfareCovers" + } + return "" +} diff --git a/internal/donor/donordata/lpa_type_test.go b/internal/lpastore/lpadata/lpa_type_test.go similarity index 98% rename from internal/donor/donordata/lpa_type_test.go rename to internal/lpastore/lpadata/lpa_type_test.go index e59fe009ea..880a8016c4 100644 --- a/internal/donor/donordata/lpa_type_test.go +++ b/internal/lpastore/lpadata/lpa_type_test.go @@ -1,4 +1,4 @@ -package donordata +package lpadata import ( "fmt" diff --git a/internal/page/app_data.go b/internal/page/app_data.go index de5bbe692f..52aa8377d3 100644 --- a/internal/page/app_data.go +++ b/internal/page/app_data.go @@ -1,91 +1 @@ package page - -import ( - "context" - "net/http" - "net/url" - - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" - "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" - "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" -) - -type AppData struct { - Page string - Path string - Query url.Values - Localizer Localizer - Lang localize.Lang - CookieConsentSet bool - CanGoBack bool - CanToggleWelsh bool - SessionID string - LpaID string - CsrfToken string - ActorType actor.Type - AttorneyUID actoruid.UID - LoginSessionEmail string - SupporterData *SupporterData -} - -type SupporterData struct { - LpaType donordata.LpaType - DonorFullName string - OrganisationName string - IsManageOrganisation bool - Permission actor.Permission - LoggedInSupporterID string -} - -func (d AppData) Redirect(w http.ResponseWriter, r *http.Request, url string) error { - http.Redirect(w, r, d.Lang.URL(url), http.StatusFound) - return nil -} - -func ContextWithAppData(ctx context.Context, appData AppData) context.Context { - return context.WithValue(ctx, contextKey("appData"), appData) -} - -func AppDataFromContext(ctx context.Context) AppData { - appData, _ := ctx.Value(contextKey("appData")).(AppData) - - return appData -} - -func (d AppData) IsDonor() bool { - return d.ActorType == actor.TypeDonor -} - -func (d AppData) IsCertificateProvider() bool { - return d.ActorType == actor.TypeCertificateProvider -} - -func (d AppData) IsAttorneyType() bool { - return d.ActorType == actor.TypeAttorney || - d.ActorType == actor.TypeReplacementAttorney || - d.ActorType == actor.TypeTrustCorporation || - d.ActorType == actor.TypeReplacementTrustCorporation -} - -func (d AppData) IsReplacementAttorney() bool { - return d.ActorType == actor.TypeReplacementAttorney || d.ActorType == actor.TypeReplacementTrustCorporation -} - -func (d AppData) IsTrustCorporation() bool { - return d.ActorType == actor.TypeTrustCorporation || d.ActorType == actor.TypeReplacementTrustCorporation -} - -func (d AppData) IsAdmin() bool { - return d.SupporterData != nil && d.SupporterData.Permission.IsAdmin() -} - -func (d AppData) EncodeQuery() string { - query := "" - - if d.Query.Encode() != "" { - query = "?" + d.Query.Encode() - } - - return query -} diff --git a/internal/page/auth_redirect.go b/internal/page/auth_redirect.go index 70b221ee02..3ba55263cb 100644 --- a/internal/page/auth_redirect.go +++ b/internal/page/auth_redirect.go @@ -4,6 +4,7 @@ import ( "log/slog" "net/http" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" ) @@ -25,7 +26,7 @@ func AuthRedirect(logger Logger, sessionStore SessionStore) http.HandlerFunc { lang = localize.Cy } - appData := AppData{Lang: lang, LpaID: oneLoginSession.LpaID} + appData := appcontext.Data{Lang: lang, LpaID: oneLoginSession.LpaID} appData.Redirect(w, r, oneLoginSession.Redirect+"?"+r.URL.RawQuery) } diff --git a/internal/page/common.go b/internal/page/common.go index 19afd2b4fa..210fb9dd7f 100644 --- a/internal/page/common.go +++ b/internal/page/common.go @@ -8,6 +8,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/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" @@ -75,7 +76,7 @@ func PostFormReferenceNumber(r *http.Request, name string) string { return strings.ReplaceAll(strings.ReplaceAll(r.PostFormValue(name), " ", ""), "-", "") } -type Handler func(data AppData, w http.ResponseWriter, r *http.Request) error +type Handler func(data appcontext.Data, w http.ResponseWriter, r *http.Request) error type EventClient interface { SendNotificationSent(ctx context.Context, notificationSentEvent event.NotificationSent) error diff --git a/internal/page/csrf.go b/internal/page/csrf.go index addcdc05df..21e7f7b3ce 100644 --- a/internal/page/csrf.go +++ b/internal/page/csrf.go @@ -8,6 +8,7 @@ import ( "mime/multipart" "net/http" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" ) @@ -39,10 +40,10 @@ func ValidateCsrf(next http.Handler, store SessionStore, randomString func(int) _ = store.SetCsrf(r, w, csrfSession) } - appData := AppDataFromContext(ctx) + appData := appcontext.DataFromContext(ctx) appData.CsrfToken = csrfSession.Token - next.ServeHTTP(w, r.WithContext(ContextWithAppData(ctx, appData))) + next.ServeHTTP(w, r.WithContext(appcontext.ContextWithData(ctx, appData))) } } diff --git a/internal/page/dashboard.go b/internal/page/dashboard.go index 376cb1935b..b33e3269ed 100644 --- a/internal/page/dashboard.go +++ b/internal/page/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/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" @@ -28,7 +29,7 @@ type dashboardForm struct { } type dashboardData struct { - App AppData + App appcontext.Data Errors validation.List UseTabs bool DonorLpas []LpaAndActorTasks @@ -37,7 +38,7 @@ type dashboardData struct { } func Dashboard(tmpl template.Template, donorStore DonorStore, dashboardStore DashboardStore) Handler { - return func(appData AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { if r.Method == http.MethodPost { form := readDashboardForm(r) diff --git a/internal/page/dashboard_test.go b/internal/page/dashboard_test.go index 8755c5be70..90c5dd709e 100644 --- a/internal/page/dashboard_test.go +++ b/internal/page/dashboard_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore" "github.com/stretchr/testify/assert" @@ -33,7 +34,7 @@ func TestGetDashboard(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). Execute(w, &dashboardData{ - App: AppData{}, + App: appcontext.Data{}, UseTabs: true, DonorLpas: donorLpas, AttorneyLpas: attorneyLpas, @@ -41,7 +42,7 @@ func TestGetDashboard(t *testing.T) { }). Return(nil) - err := Dashboard(template.Execute, nil, dashboardStore)(AppData{}, w, r) + err := Dashboard(template.Execute, nil, dashboardStore)(appcontext.Data{}, w, r) resp := w.Result() assert.Nil(t, err) @@ -65,12 +66,12 @@ func TestGetDashboardOnlyDonor(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). Execute(w, &dashboardData{ - App: AppData{}, + App: appcontext.Data{}, DonorLpas: donorLpas, }). Return(nil) - err := Dashboard(template.Execute, nil, dashboardStore)(AppData{}, w, r) + err := Dashboard(template.Execute, nil, dashboardStore)(appcontext.Data{}, w, r) resp := w.Result() assert.Nil(t, err) @@ -86,7 +87,7 @@ func TestGetDashboardWhenDashboardStoreErrors(t *testing.T) { GetAll(r.Context()). Return(nil, nil, nil, expectedError) - err := Dashboard(nil, nil, dashboardStore)(AppData{}, w, r) + err := Dashboard(nil, nil, dashboardStore)(appcontext.Data{}, w, r) resp := w.Result() assert.Equal(t, expectedError, err) @@ -107,7 +108,7 @@ func TestGetDashboardWhenTemplateErrors(t *testing.T) { Execute(w, mock.Anything). Return(expectedError) - err := Dashboard(template.Execute, nil, dashboardStore)(AppData{}, w, r) + err := Dashboard(template.Execute, nil, dashboardStore)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } @@ -136,7 +137,7 @@ func TestPostDashboard(t *testing.T) { Create(r.Context()). Return(&donordata.Provided{LpaID: "lpa-id"}, nil) - err := Dashboard(nil, donorStore, nil)(AppData{}, w, r) + err := Dashboard(nil, donorStore, nil)(appcontext.Data{}, w, r) resp := w.Result() assert.Nil(t, err) @@ -155,7 +156,7 @@ func TestPostDashboardWhenDonorStoreError(t *testing.T) { Create(r.Context()). Return(&donordata.Provided{LpaID: "123"}, expectedError) - err := Dashboard(nil, donorStore, nil)(AppData{}, w, r) + err := Dashboard(nil, donorStore, nil)(appcontext.Data{}, w, r) resp := w.Result() assert.Equal(t, expectedError, err) diff --git a/internal/page/data.go b/internal/page/data.go index 2952dfdb4e..439fd5a831 100644 --- a/internal/page/data.go +++ b/internal/page/data.go @@ -12,15 +12,11 @@ package page import ( - "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/task" ) -var SessionDataFromContext = appcontext.SessionDataFromContext -var ContextWithSessionData = appcontext.ContextWithSessionData - func ChooseAttorneysState(attorneys donordata.Attorneys, decisions donordata.AttorneyDecisions) task.State { if attorneys.Len() == 0 { return task.StateNotStarted diff --git a/internal/page/error.go b/internal/page/error.go index a6236a6384..0ef9f5e7e4 100644 --- a/internal/page/error.go +++ b/internal/page/error.go @@ -5,13 +5,14 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type ErrorHandler func(http.ResponseWriter, *http.Request, error) type errorData struct { - App AppData + App appcontext.Data Errors validation.List Err error } @@ -25,7 +26,7 @@ func Error(tmpl template.Template, logger Logger, showError bool) ErrorHandler { w.WriteHeader(http.StatusInternalServerError) } - data := &errorData{App: AppDataFromContext(r.Context())} + data := &errorData{App: appcontext.DataFromContext(r.Context())} if showError { data.Err = err } diff --git a/internal/page/error_test.go b/internal/page/error_test.go index 88385fe7e3..e6db01ec35 100644 --- a/internal/page/error_test.go +++ b/internal/page/error_test.go @@ -9,6 +9,7 @@ import ( "net/http/httptest" "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/stretchr/testify/assert" ) @@ -21,7 +22,7 @@ func TestError(t *testing.T) { for showErrors, data := range testcases { t.Run(fmt.Sprint(showErrors), func(t *testing.T) { w := httptest.NewRecorder() - r, _ := http.NewRequestWithContext(ContextWithAppData(context.Background(), TestAppData), http.MethodGet, "/", nil) + r, _ := http.NewRequestWithContext(appcontext.ContextWithData(context.Background(), TestAppData), http.MethodGet, "/", nil) logger := newMockLogger(t) logger.EXPECT(). @@ -42,7 +43,7 @@ func TestError(t *testing.T) { func TestErrorWithErrCsrfInvalid(t *testing.T) { w := httptest.NewRecorder() - r, _ := http.NewRequestWithContext(ContextWithAppData(context.Background(), TestAppData), http.MethodGet, "/", nil) + r, _ := http.NewRequestWithContext(appcontext.ContextWithData(context.Background(), TestAppData), http.MethodGet, "/", nil) logger := newMockLogger(t) logger.EXPECT(). @@ -61,7 +62,7 @@ func TestErrorWithErrCsrfInvalid(t *testing.T) { func TestErrorWhenTemplateErrors(t *testing.T) { w := httptest.NewRecorder() - r, _ := http.NewRequestWithContext(ContextWithAppData(context.Background(), TestAppData), http.MethodGet, "/", nil) + r, _ := http.NewRequestWithContext(appcontext.ContextWithData(context.Background(), TestAppData), http.MethodGet, "/", nil) templateError := errors.New("template error") diff --git a/internal/page/fixtures/attorney.go b/internal/page/fixtures/attorney.go index 3d98c6c9c1..a2c57b8e5d 100644 --- a/internal/page/fixtures/attorney.go +++ b/internal/page/fixtures/attorney.go @@ -67,7 +67,7 @@ func Attorney( "registered", } - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { acceptCookiesConsent(w) var ( @@ -108,11 +108,11 @@ func Attorney( } createFn := donorStore.Create - createSession := &appcontext.SessionData{SessionID: donorSessionID} + createSession := &appcontext.Session{SessionID: donorSessionID} if isSupported { createFn = organisationStore.CreateLPA - supporterCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, Email: testEmail}) + supporterCtx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID, Email: testEmail}) member, err := memberStore.Create(supporterCtx, random.String(12), random.String(12)) if err != nil { @@ -126,13 +126,13 @@ func Attorney( createSession.OrganisationID = org.ID } - donorDetails, err := createFn(page.ContextWithSessionData(r.Context(), createSession)) + donorDetails, err := createFn(appcontext.ContextWithSession(r.Context(), createSession)) if err != nil { return err } if isSupported { - if err := donorStore.Link(page.ContextWithSessionData(r.Context(), createSession), sharecode.Data{ + if err := donorStore.Link(appcontext.ContextWithSession(r.Context(), createSession), sharecode.Data{ LpaKey: donorDetails.PK, LpaOwnerKey: donorDetails.SK, }, donorDetails.Donor.Email); err != nil { @@ -141,9 +141,9 @@ func Attorney( } var ( - 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}) + donorCtx = appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID, LpaID: donorDetails.LpaID}) + certificateProviderCtx = appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: certificateProviderSessionID, LpaID: donorDetails.LpaID}) + attorneyCtx = appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: attorneySessionID, LpaID: donorDetails.LpaID}) ) donorDetails.SignedAt = time.Now() @@ -269,7 +269,7 @@ func Attorney( if progress >= slices.Index(progressValues, "signedByAllAttorneys") { for isReplacement, list := range map[bool]donordata.Attorneys{false: donorDetails.Attorneys, true: donorDetails.ReplacementAttorneys} { for _, a := range list.Attorneys { - ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: random.String(16), LpaID: donorDetails.LpaID}) attorney, err := createAttorney( ctx, @@ -300,7 +300,7 @@ func Attorney( } if list.TrustCorporation.Name != "" { - ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: random.String(16), LpaID: donorDetails.LpaID}) attorney, err := createAttorney( ctx, @@ -402,7 +402,7 @@ func Attorney( lpa.LpaKey = donorDetails.PK lpa.LpaOwnerKey = donorDetails.SK - shareCodeSender.SendAttorneys(donorCtx, page.AppData{ + shareCodeSender.SendAttorneys(donorCtx, appcontext.Data{ SessionID: donorSessionID, LpaID: donorDetails.LpaID, Localizer: appData.Localizer, diff --git a/internal/page/fixtures/certificate_provider.go b/internal/page/fixtures/certificate_provider.go index 38a5acc638..3a18a1e9de 100644 --- a/internal/page/fixtures/certificate_provider.go +++ b/internal/page/fixtures/certificate_provider.go @@ -44,7 +44,7 @@ func CertificateProvider( "confirmYourIdentity", } - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { acceptCookiesConsent(w) var ( @@ -103,7 +103,7 @@ func CertificateProvider( return err } } else if isSupported { - supporterCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, Email: testEmail}) + supporterCtx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID, Email: testEmail}) member, err := memberStore.Create(supporterCtx, random.String(12), random.String(12)) if err != nil { @@ -115,28 +115,28 @@ func CertificateProvider( return err } - orgSession := &appcontext.SessionData{SessionID: donorSessionID, OrganisationID: org.ID} - donorDetails, err = organisationStore.CreateLPA(page.ContextWithSessionData(r.Context(), orgSession)) + orgSession := &appcontext.Session{SessionID: donorSessionID, OrganisationID: org.ID} + donorDetails, err = organisationStore.CreateLPA(appcontext.ContextWithSession(r.Context(), orgSession)) if err != nil { return err } - if err := donorStore.Link(page.ContextWithSessionData(r.Context(), orgSession), sharecode.Data{ + if err := donorStore.Link(appcontext.ContextWithSession(r.Context(), orgSession), sharecode.Data{ LpaKey: donorDetails.PK, LpaOwnerKey: donorDetails.SK, }, donorDetails.Donor.Email); err != nil { return err } } else { - donorDetails, err = donorStore.Create(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID})) + donorDetails, err = donorStore.Create(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID})) if err != nil { return err } } var ( - donorCtx = page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, LpaID: donorDetails.LpaID}) - certificateProviderCtx = page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: certificateProviderSessionID, LpaID: donorDetails.LpaID}) + donorCtx = appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID, LpaID: donorDetails.LpaID}) + certificateProviderCtx = appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: certificateProviderSessionID, LpaID: donorDetails.LpaID}) ) donorDetails.Donor = makeDonor(donorEmail) @@ -248,7 +248,7 @@ func CertificateProvider( } if email != "" { - shareCodeSender.SendCertificateProviderInvite(donorCtx, page.AppData{ + shareCodeSender.SendCertificateProviderInvite(donorCtx, appcontext.Data{ SessionID: donorSessionID, LpaID: donorDetails.LpaID, Localizer: appData.Localizer, diff --git a/internal/page/fixtures/dashboard.go b/internal/page/fixtures/dashboard.go index 6aeb3cc180..20d894ac59 100644 --- a/internal/page/fixtures/dashboard.go +++ b/internal/page/fixtures/dashboard.go @@ -20,7 +20,7 @@ func Dashboard( attorneyStore AttorneyStore, shareCodeStore ShareCodeStore, ) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { acceptCookiesConsent(w) var ( @@ -45,12 +45,12 @@ func Dashboard( } if asDonor { - donor, err := donorStore.Create(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: meSessionID})) + donor, err := donorStore.Create(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: meSessionID})) if err != nil { return err } - donorCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: meSessionID, LpaID: donor.LpaID}) + donorCtx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: meSessionID, LpaID: donor.LpaID}) donor.LpaUID = makeUID() donor.Donor = makeDonor(testEmail) @@ -66,18 +66,18 @@ func Dashboard( } if asCertificateProvider { - donor, err := donorStore.Create(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID})) + donor, err := donorStore.Create(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID})) if err != nil { return err } donor.Donor = makeDonor(testEmail) donor.LpaUID = makeUID() - if err := donorStore.Put(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, LpaID: donor.LpaID}), donor); err != nil { + if err := donorStore.Put(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID, LpaID: donor.LpaID}), donor); err != nil { return err } - certificateProviderCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: meSessionID, LpaID: donor.LpaID}) + certificateProviderCtx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: meSessionID, LpaID: donor.LpaID}) _, err = createCertificateProvider(certificateProviderCtx, shareCodeStore, certificateProviderStore, donor.CertificateProvider.UID, donor.SK, testEmail) if err != nil { @@ -86,7 +86,7 @@ func Dashboard( } if asAttorney { - donor, err := donorStore.Create(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID})) + donor, err := donorStore.Create(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID})) if err != nil { return err } @@ -96,11 +96,11 @@ func Dashboard( } donor.LpaUID = makeUID() - if err := donorStore.Put(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, LpaID: donor.LpaID}), donor); err != nil { + if err := donorStore.Put(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID, LpaID: donor.LpaID}), donor); err != nil { return err } - attorneyCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: meSessionID, LpaID: donor.LpaID}) + attorneyCtx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: meSessionID, LpaID: donor.LpaID}) attorney, err := createAttorney( attorneyCtx, diff --git a/internal/page/fixtures/donor.go b/internal/page/fixtures/donor.go index 1c52c27af2..f7e1e7da14 100644 --- a/internal/page/fixtures/donor.go +++ b/internal/page/fixtures/donor.go @@ -93,7 +93,7 @@ func Donor( lpaStoreClient *lpastore.Client, shareCodeStore ShareCodeStore, ) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { acceptCookiesConsent(w) data := setFixtureData(r) @@ -116,7 +116,7 @@ func Donor( return err } - donorDetails, err := donorStore.Create(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID})) + donorDetails, err := donorStore.Create(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID})) if err != nil { return err } @@ -127,7 +127,7 @@ func Donor( return err } - donorCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID, LpaID: donorDetails.LpaID}) + donorCtx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID, LpaID: donorDetails.LpaID}) if data.Progress >= slices.Index(progressValues, "checkAndSendToYourCertificateProvider") { if err = donorDetails.UpdateCheckedHash(); err != nil { @@ -350,7 +350,7 @@ func updateLPAProgress( donorDetails.FeeType = feeType stagedForUpload, err := documentStore.Create( - page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID}), + appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID}), donorDetails, "supporting-evidence.png", make([]byte, 64), @@ -363,12 +363,12 @@ func updateLPAProgress( stagedForUpload.Scanned = true stagedForUpload.VirusDetected = data.WithVirus - if err := documentStore.Put(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID}), stagedForUpload); err != nil { + if err := documentStore.Put(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID}), stagedForUpload); err != nil { return nil, nil, err } previouslyUploaded, err := documentStore.Create( - page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID}), + appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID}), donorDetails, "previously-uploaded-evidence.png", make([]byte, 64), @@ -382,7 +382,7 @@ func updateLPAProgress( previouslyUploaded.VirusDetected = false previouslyUploaded.Sent = time.Now() - if err := documentStore.Put(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: donorSessionID}), previouslyUploaded); err != nil { + if err := documentStore.Put(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: donorSessionID}), previouslyUploaded); err != nil { return nil, nil, err } } else { @@ -448,7 +448,7 @@ func updateLPAProgress( var certificateProviderUID actoruid.UID if data.Progress >= slices.Index(progressValues, "signedByCertificateProvider") { - ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: random.String(16), LpaID: donorDetails.LpaID}) certificateProvider, err := createCertificateProvider(ctx, shareCodeStore, certificateProviderStore, donorDetails.CertificateProvider.UID, donorDetails.SK, donorDetails.CertificateProvider.Email) if err != nil { @@ -472,7 +472,7 @@ func updateLPAProgress( if data.Progress >= slices.Index(progressValues, "signedByAttorneys") { for isReplacement, list := range map[bool]donordata.Attorneys{false: donorDetails.Attorneys, true: donorDetails.ReplacementAttorneys} { for _, a := range list.Attorneys { - ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: random.String(16), LpaID: donorDetails.LpaID}) attorney, err := createAttorney( ctx, @@ -505,7 +505,7 @@ func updateLPAProgress( } if list.TrustCorporation.Name != "" { - ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: random.String(16), LpaID: donorDetails.LpaID}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: random.String(16), LpaID: donorDetails.LpaID}) attorney, err := createAttorney( ctx, diff --git a/internal/page/fixtures/fixtures.go b/internal/page/fixtures/fixtures.go index 87583eaaef..5926f0e531 100644 --- a/internal/page/fixtures/fixtures.go +++ b/internal/page/fixtures/fixtures.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/attorney/attorneydata" "github.com/ministryofjustice/opg-modernising-lpa/internal/certificateprovider/certificateproviderdata" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" @@ -24,8 +25,8 @@ import ( ) type ShareCodeSender interface { - SendCertificateProviderInvite(context context.Context, appData page.AppData, donorProvided page.CertificateProviderInvite) error - SendAttorneys(context context.Context, appData page.AppData, donorProvided *lpastore.Lpa) error + SendCertificateProviderInvite(context context.Context, appData appcontext.Data, donorProvided page.CertificateProviderInvite) error + SendAttorneys(context context.Context, appData appcontext.Data, donorProvided *lpastore.Lpa) error UseTestCode(shareCode string) } @@ -35,7 +36,7 @@ const ( ) type fixturesData struct { - App page.AppData + App appcontext.Data Sub string DonorEmail string Errors validation.List diff --git a/internal/page/fixtures/supporter.go b/internal/page/fixtures/supporter.go index 7cbdbccf1b..2269366db4 100644 --- a/internal/page/fixtures/supporter.go +++ b/internal/page/fixtures/supporter.go @@ -55,7 +55,7 @@ func Supporter( eventClient *event.Client, lpaStoreClient *lpastore.Client, ) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { acceptCookiesConsent(w) var ( @@ -74,7 +74,7 @@ func Supporter( supporterSub = random.String(16) supporterSessionID = base64.StdEncoding.EncodeToString([]byte(supporterSub)) - supporterCtx = page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: supporterSessionID, Email: testEmail}) + supporterCtx = appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: supporterSessionID, Email: testEmail}) ) loginSession := &sesh.LoginSession{Sub: supporterSub, Email: testEmail} @@ -93,7 +93,7 @@ func Supporter( loginSession.OrganisationID = org.ID loginSession.OrganisationName = org.Name - organisationCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{OrganisationID: org.ID}) + organisationCtx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{OrganisationID: org.ID}) if suspended { member.Status = actor.StatusSuspended @@ -108,7 +108,7 @@ func Supporter( if err != nil { return err } - donorCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{OrganisationID: org.ID, LpaID: donor.LpaID, SessionID: random.String(12)}) + donorCtx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{OrganisationID: org.ID, LpaID: donor.LpaID, SessionID: random.String(12)}) donor.LpaUID = makeUID() donor.Donor = makeDonor(testEmail) @@ -161,7 +161,7 @@ func Supporter( if err != nil { return err } - donorCtx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{OrganisationID: org.ID, LpaID: donor.LpaID}) + donorCtx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{OrganisationID: org.ID, LpaID: donor.LpaID}) donor.LpaUID = makeUID() donor.Donor = makeDonor(testEmail) @@ -234,7 +234,7 @@ func Supporter( ReferenceNumber: random.String(12), } - if err := dynamoClient.Create(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{OrganisationID: org.ID}), invite); err != nil { + if err := dynamoClient.Create(appcontext.ContextWithSession(r.Context(), &appcontext.Session{OrganisationID: org.ID}), invite); err != nil { return fmt.Errorf("error creating member invite: %w", err) } } @@ -260,7 +260,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(), &appcontext.SessionData{SessionID: base64.StdEncoding.EncodeToString(sub), Email: email}) + memberCtx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: base64.StdEncoding.EncodeToString(sub), Email: email}) if err = memberStore.CreateFromInvite( memberCtx, diff --git a/internal/page/guidance.go b/internal/page/guidance.go index ae3861b119..be80cd1781 100644 --- a/internal/page/guidance.go +++ b/internal/page/guidance.go @@ -4,16 +4,17 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type guidanceData struct { - App AppData + App appcontext.Data Errors validation.List } func Guidance(tmpl template.Template) Handler { - return func(appData AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { data := &guidanceData{ App: appData, } diff --git a/internal/page/login.go b/internal/page/login.go index f4e4c1ab0d..4c477e8c3b 100644 --- a/internal/page/login.go +++ b/internal/page/login.go @@ -3,6 +3,7 @@ package page import ( "net/http" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" ) @@ -16,7 +17,7 @@ type LoginSessionStore interface { } func Login(oneLoginClient LoginOneLoginClient, sessionStore LoginSessionStore, randomString func(int) string, redirect Path) Handler { - return func(appData AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { locale := "en" if appData.Lang == localize.Cy { locale = "cy" diff --git a/internal/page/login_callback.go b/internal/page/login_callback.go index 47e63a5a7c..3c60ed583b 100644 --- a/internal/page/login_callback.go +++ b/internal/page/login_callback.go @@ -7,6 +7,7 @@ import ( "net/http" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/onelogin" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" ) @@ -22,7 +23,7 @@ type LoginCallbackSessionStore interface { } func LoginCallback(logger Logger, oneLoginClient LoginCallbackOneLoginClient, sessionStore LoginCallbackSessionStore, redirect Path, dashboardStore DashboardStore, actorType actor.Type) Handler { - return func(appData AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { if error := r.FormValue("error"); error != "" { logger.InfoContext(r.Context(), "login error", slog.String("error", error), diff --git a/internal/page/login_callback_test.go b/internal/page/login_callback_test.go index 4f218ba940..4118a1ea85 100644 --- a/internal/page/login_callback_test.go +++ b/internal/page/login_callback_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/onelogin" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" "github.com/stretchr/testify/assert" @@ -65,7 +66,7 @@ func TestLoginCallback(t *testing.T) { logger.EXPECT(). InfoContext(r.Context(), "login", slog.String("session_id", session.SessionID())) - err := LoginCallback(logger, client, sessionStore, Paths.Attorney.EnterReferenceNumber, dashboardStore, actor.TypeAttorney)(AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, Paths.Attorney.EnterReferenceNumber, dashboardStore, actor.TypeAttorney)(appcontext.Data{}, w, r) assert.Nil(t, err) resp := w.Result() @@ -83,7 +84,7 @@ func TestLoginCallbackWhenErrorReturned(t *testing.T) { logger.EXPECT(). InfoContext(r.Context(), "login error", slog.String("error", "hey"), slog.String("error_description", "this is why")) - err := LoginCallback(logger, nil, nil, Paths.Attorney.EnterReferenceNumber, nil, actor.TypeAttorney)(AppData{}, w, r) + err := LoginCallback(logger, nil, nil, Paths.Attorney.EnterReferenceNumber, nil, actor.TypeAttorney)(appcontext.Data{}, w, r) assert.Equal(t, errors.New("access denied"), err) } @@ -96,7 +97,7 @@ func TestLoginCallbackSessionError(t *testing.T) { OneLogin(r). Return(nil, expectedError) - err := LoginCallback(nil, nil, sessionStore, Paths.Attorney.LoginCallback, nil, actor.TypeAttorney)(AppData{}, w, r) + err := LoginCallback(nil, nil, sessionStore, Paths.Attorney.LoginCallback, nil, actor.TypeAttorney)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } @@ -114,7 +115,7 @@ func TestLoginCallbackWhenExchangeErrors(t *testing.T) { OneLogin(r). Return(&sesh.OneLoginSession{State: "my-state", Nonce: "my-nonce", Locale: "en", Redirect: Paths.LoginCallback.Format()}, nil) - err := LoginCallback(nil, client, sessionStore, Paths.LoginCallback, nil, actor.TypeAttorney)(AppData{}, w, r) + err := LoginCallback(nil, client, sessionStore, Paths.LoginCallback, nil, actor.TypeAttorney)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } @@ -135,7 +136,7 @@ func TestLoginCallbackWhenUserInfoError(t *testing.T) { OneLogin(r). Return(&sesh.OneLoginSession{State: "my-state", Nonce: "my-nonce", Locale: "en", Redirect: Paths.LoginCallback.Format()}, nil) - err := LoginCallback(nil, client, sessionStore, Paths.LoginCallback, nil, actor.TypeAttorney)(AppData{}, w, r) + err := LoginCallback(nil, client, sessionStore, Paths.LoginCallback, nil, actor.TypeAttorney)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } @@ -168,7 +169,7 @@ func TestLoginCallbackWhenSessionError(t *testing.T) { logger.EXPECT(). InfoContext(mock.Anything, mock.Anything, mock.Anything) - err := LoginCallback(logger, client, sessionStore, Paths.LoginCallback, nil, actor.TypeAttorney)(AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, Paths.LoginCallback, nil, actor.TypeAttorney)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } @@ -206,6 +207,6 @@ func TestLoginCallbackWhenDashboardStoreError(t *testing.T) { logger.EXPECT(). InfoContext(mock.Anything, mock.Anything, mock.Anything) - err := LoginCallback(logger, client, sessionStore, Paths.LoginCallback, dashboardStore, actor.TypeAttorney)(AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, Paths.LoginCallback, dashboardStore, actor.TypeAttorney)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } diff --git a/internal/page/login_test.go b/internal/page/login_test.go index 8c94b34501..fd9bc7f242 100644 --- a/internal/page/login_test.go +++ b/internal/page/login_test.go @@ -5,6 +5,7 @@ import ( "net/http/httptest" "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/sesh" "github.com/stretchr/testify/assert" @@ -30,7 +31,7 @@ func TestLogin(t *testing.T) { }). Return(nil) - Login(client, sessionStore, func(int) string { return "i am random" }, "/redirect")(AppData{Lang: localize.Cy}, w, r) + Login(client, sessionStore, func(int) string { return "i am random" }, "/redirect")(appcontext.Data{Lang: localize.Cy}, w, r) resp := w.Result() assert.Equal(t, http.StatusFound, resp.StatusCode) @@ -56,7 +57,7 @@ func TestLoginDefaultLocale(t *testing.T) { }). Return(nil) - Login(client, sessionStore, func(int) string { return "i am random" }, "/redirect")(AppData{}, w, r) + Login(client, sessionStore, func(int) string { return "i am random" }, "/redirect")(appcontext.Data{}, w, r) resp := w.Result() assert.Equal(t, http.StatusFound, resp.StatusCode) @@ -72,7 +73,7 @@ func TestLoginWhenAuthCodeURLError(t *testing.T) { AuthCodeURL("i am random", "i am random", "en", false). Return("http://auth?locale=en", expectedError) - err := Login(client, nil, func(int) string { return "i am random" }, "/redirect")(AppData{}, w, r) + err := Login(client, nil, func(int) string { return "i am random" }, "/redirect")(appcontext.Data{}, w, r) resp := w.Result() assert.Equal(t, expectedError, err) @@ -93,7 +94,7 @@ func TestLoginWhenStoreSaveError(t *testing.T) { SetOneLogin(r, w, mock.Anything). Return(expectedError) - err := Login(client, sessionStore, func(int) string { return "i am random" }, "/redirect")(AppData{}, w, r) + err := Login(client, sessionStore, func(int) string { return "i am random" }, "/redirect")(appcontext.Data{}, w, r) resp := w.Result() assert.Equal(t, expectedError, err) diff --git a/internal/page/mock_DashboardStore_test.go b/internal/page/mock_DashboardStore_test.go index 285e427607..915c28ba4a 100644 --- a/internal/page/mock_DashboardStore_test.go +++ b/internal/page/mock_DashboardStore_test.go @@ -5,7 +5,8 @@ package page import ( context "context" - temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" + actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + mock "github.com/stretchr/testify/mock" ) @@ -99,7 +100,7 @@ func (_c *mockDashboardStore_GetAll_Call) RunAndReturn(run func(context.Context) } // SubExistsForActorType provides a mock function with given fields: ctx, sub, actorType -func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType temporary.ActorType) (bool, error) { +func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub string, actorType actor.Type) (bool, error) { ret := _m.Called(ctx, sub, actorType) if len(ret) == 0 { @@ -108,16 +109,16 @@ func (_m *mockDashboardStore) SubExistsForActorType(ctx context.Context, sub str var r0 bool var r1 error - if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) (bool, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) (bool, error)); ok { return rf(ctx, sub, actorType) } - if rf, ok := ret.Get(0).(func(context.Context, string, temporary.ActorType) bool); ok { + if rf, ok := ret.Get(0).(func(context.Context, string, actor.Type) bool); ok { r0 = rf(ctx, sub, actorType) } else { r0 = ret.Get(0).(bool) } - if rf, ok := ret.Get(1).(func(context.Context, string, temporary.ActorType) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, string, actor.Type) error); ok { r1 = rf(ctx, sub, actorType) } else { r1 = ret.Error(1) @@ -134,14 +135,14 @@ type mockDashboardStore_SubExistsForActorType_Call struct { // SubExistsForActorType is a helper method to define mock.On call // - ctx context.Context // - sub string -// - actorType temporary.ActorType +// - actorType actor.Type func (_e *mockDashboardStore_Expecter) SubExistsForActorType(ctx interface{}, sub interface{}, actorType interface{}) *mockDashboardStore_SubExistsForActorType_Call { return &mockDashboardStore_SubExistsForActorType_Call{Call: _e.mock.On("SubExistsForActorType", ctx, sub, actorType)} } -func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType temporary.ActorType)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) Run(run func(ctx context.Context, sub string, actorType actor.Type)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(string), args[2].(temporary.ActorType)) + run(args[0].(context.Context), args[1].(string), args[2].(actor.Type)) }) return _c } @@ -151,7 +152,7 @@ func (_c *mockDashboardStore_SubExistsForActorType_Call) Return(_a0 bool, _a1 er return _c } -func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, temporary.ActorType) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { +func (_c *mockDashboardStore_SubExistsForActorType_Call) RunAndReturn(run func(context.Context, string, actor.Type) (bool, error)) *mockDashboardStore_SubExistsForActorType_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/mock_DonorStore_test.go b/internal/page/mock_DonorStore_test.go index dd76dc3c46..bac1ab7ba4 100644 --- a/internal/page/mock_DonorStore_test.go +++ b/internal/page/mock_DonorStore_test.go @@ -105,7 +105,7 @@ type mockDonorStore_Put_Call struct { // Put is a helper method to define mock.On call // - _a0 context.Context -// - _a1 *donordata.DonorProvidedDetails +// - _a1 *donordata.Provided func (_e *mockDonorStore_Expecter) Put(_a0 interface{}, _a1 interface{}) *mockDonorStore_Put_Call { return &mockDonorStore_Put_Call{Call: _e.mock.On("Put", _a0, _a1)} } diff --git a/internal/page/mock_Handler_test.go b/internal/page/mock_Handler_test.go index 72cd765080..47dd4ca3f8 100644 --- a/internal/page/mock_Handler_test.go +++ b/internal/page/mock_Handler_test.go @@ -5,6 +5,8 @@ package page import ( http "net/http" + appcontext "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" + mock "github.com/stretchr/testify/mock" ) @@ -22,7 +24,7 @@ func (_m *mockHandler) EXPECT() *mockHandler_Expecter { } // Execute provides a mock function with given fields: data, w, r -func (_m *mockHandler) Execute(data AppData, w http.ResponseWriter, r *http.Request) error { +func (_m *mockHandler) Execute(data appcontext.Data, w http.ResponseWriter, r *http.Request) error { ret := _m.Called(data, w, r) if len(ret) == 0 { @@ -30,7 +32,7 @@ func (_m *mockHandler) Execute(data AppData, w http.ResponseWriter, r *http.Requ } var r0 error - if rf, ok := ret.Get(0).(func(AppData, http.ResponseWriter, *http.Request) error); ok { + if rf, ok := ret.Get(0).(func(appcontext.Data, http.ResponseWriter, *http.Request) error); ok { r0 = rf(data, w, r) } else { r0 = ret.Error(0) @@ -45,16 +47,16 @@ type mockHandler_Execute_Call struct { } // Execute is a helper method to define mock.On call -// - data AppData +// - data appcontext.Data // - w http.ResponseWriter // - r *http.Request func (_e *mockHandler_Expecter) Execute(data interface{}, w interface{}, r interface{}) *mockHandler_Execute_Call { return &mockHandler_Execute_Call{Call: _e.mock.On("Execute", data, w, r)} } -func (_c *mockHandler_Execute_Call) Run(run func(data AppData, w http.ResponseWriter, r *http.Request)) *mockHandler_Execute_Call { +func (_c *mockHandler_Execute_Call) Run(run func(data appcontext.Data, w http.ResponseWriter, r *http.Request)) *mockHandler_Execute_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(AppData), args[1].(http.ResponseWriter), args[2].(*http.Request)) + run(args[0].(appcontext.Data), args[1].(http.ResponseWriter), args[2].(*http.Request)) }) return _c } @@ -64,7 +66,7 @@ func (_c *mockHandler_Execute_Call) Return(_a0 error) *mockHandler_Execute_Call return _c } -func (_c *mockHandler_Execute_Call) RunAndReturn(run func(AppData, http.ResponseWriter, *http.Request) error) *mockHandler_Execute_Call { +func (_c *mockHandler_Execute_Call) RunAndReturn(run func(appcontext.Data, http.ResponseWriter, *http.Request) error) *mockHandler_Execute_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/mock_ShareCodeStore_test.go b/internal/page/mock_ShareCodeStore_test.go index a25f5ad227..bcf8b9356b 100644 --- a/internal/page/mock_ShareCodeStore_test.go +++ b/internal/page/mock_ShareCodeStore_test.go @@ -5,10 +5,11 @@ package page import ( context "context" - sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" + actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + mock "github.com/stretchr/testify/mock" - temporary "github.com/ministryofjustice/opg-modernising-lpa/internal/temporary" + sharecode "github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode" ) // mockShareCodeStore is an autogenerated mock type for the ShareCodeStore type @@ -25,7 +26,7 @@ func (_m *mockShareCodeStore) EXPECT() *mockShareCodeStore_Expecter { } // Get provides a mock function with given fields: ctx, actorType, shareCode -func (_m *mockShareCodeStore) Get(ctx context.Context, actorType temporary.ActorType, shareCode string) (sharecode.Data, error) { +func (_m *mockShareCodeStore) Get(ctx context.Context, actorType actor.Type, shareCode string) (sharecode.Data, error) { ret := _m.Called(ctx, actorType, shareCode) if len(ret) == 0 { @@ -34,16 +35,16 @@ func (_m *mockShareCodeStore) Get(ctx context.Context, actorType temporary.Actor var r0 sharecode.Data var r1 error - if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) (sharecode.Data, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) (sharecode.Data, error)); ok { return rf(ctx, actorType, shareCode) } - if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string) sharecode.Data); ok { + if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string) sharecode.Data); ok { r0 = rf(ctx, actorType, shareCode) } else { r0 = ret.Get(0).(sharecode.Data) } - if rf, ok := ret.Get(1).(func(context.Context, temporary.ActorType, string) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, actor.Type, string) error); ok { r1 = rf(ctx, actorType, shareCode) } else { r1 = ret.Error(1) @@ -59,15 +60,15 @@ type mockShareCodeStore_Get_Call struct { // Get is a helper method to define mock.On call // - ctx context.Context -// - actorType temporary.ActorType +// - actorType actor.Type // - shareCode string func (_e *mockShareCodeStore_Expecter) Get(ctx interface{}, actorType interface{}, shareCode interface{}) *mockShareCodeStore_Get_Call { return &mockShareCodeStore_Get_Call{Call: _e.mock.On("Get", ctx, actorType, shareCode)} } -func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, shareCode string)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) Run(run func(ctx context.Context, actorType actor.Type, shareCode string)) *mockShareCodeStore_Get_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string)) + run(args[0].(context.Context), args[1].(actor.Type), args[2].(string)) }) return _c } @@ -77,13 +78,13 @@ func (_c *mockShareCodeStore_Get_Call) Return(_a0 sharecode.Data, _a1 error) *mo return _c } -func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string) (sharecode.Data, error)) *mockShareCodeStore_Get_Call { +func (_c *mockShareCodeStore_Get_Call) RunAndReturn(run func(context.Context, actor.Type, string) (sharecode.Data, error)) *mockShareCodeStore_Get_Call { _c.Call.Return(run) return _c } // Put provides a mock function with given fields: ctx, actorType, shareCode, data -func (_m *mockShareCodeStore) Put(ctx context.Context, actorType temporary.ActorType, shareCode string, data sharecode.Data) error { +func (_m *mockShareCodeStore) Put(ctx context.Context, actorType actor.Type, shareCode string, data sharecode.Data) error { ret := _m.Called(ctx, actorType, shareCode, data) if len(ret) == 0 { @@ -91,7 +92,7 @@ func (_m *mockShareCodeStore) Put(ctx context.Context, actorType temporary.Actor } var r0 error - if rf, ok := ret.Get(0).(func(context.Context, temporary.ActorType, string, sharecode.Data) error); ok { + if rf, ok := ret.Get(0).(func(context.Context, actor.Type, string, sharecode.Data) error); ok { r0 = rf(ctx, actorType, shareCode, data) } else { r0 = ret.Error(0) @@ -107,16 +108,16 @@ type mockShareCodeStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - actorType temporary.ActorType +// - actorType actor.Type // - shareCode string // - data sharecode.Data func (_e *mockShareCodeStore_Expecter) Put(ctx interface{}, actorType interface{}, shareCode interface{}, data interface{}) *mockShareCodeStore_Put_Call { return &mockShareCodeStore_Put_Call{Call: _e.mock.On("Put", ctx, actorType, shareCode, data)} } -func (_c *mockShareCodeStore_Put_Call) Run(run func(ctx context.Context, actorType temporary.ActorType, shareCode string, data sharecode.Data)) *mockShareCodeStore_Put_Call { +func (_c *mockShareCodeStore_Put_Call) Run(run func(ctx context.Context, actorType actor.Type, shareCode string, data sharecode.Data)) *mockShareCodeStore_Put_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(temporary.ActorType), args[2].(string), args[3].(sharecode.Data)) + run(args[0].(context.Context), args[1].(actor.Type), args[2].(string), args[3].(sharecode.Data)) }) return _c } @@ -126,7 +127,7 @@ func (_c *mockShareCodeStore_Put_Call) Return(_a0 error) *mockShareCodeStore_Put return _c } -func (_c *mockShareCodeStore_Put_Call) RunAndReturn(run func(context.Context, temporary.ActorType, string, sharecode.Data) error) *mockShareCodeStore_Put_Call { +func (_c *mockShareCodeStore_Put_Call) RunAndReturn(run func(context.Context, actor.Type, string, sharecode.Data) error) *mockShareCodeStore_Put_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/mock_shareCodeSender_test.go b/internal/page/mock_shareCodeSender_test.go deleted file mode 100644 index d33d03eb24..0000000000 --- a/internal/page/mock_shareCodeSender_test.go +++ /dev/null @@ -1,58 +0,0 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. - -package page - -import ( - context "context" - - "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" - mock "github.com/stretchr/testify/mock" -) - -// mockShareCodeSender is an autogenerated mock type for the shareCodeSender type -type mockShareCodeSender struct { - mock.Mock -} - -// SendAttorneys provides a mock function with given fields: ctx, appData, donor -func (_m *mockShareCodeSender) SendAttorneys(ctx context.Context, appData AppData, donor *donordata.Provided) error { - ret := _m.Called(ctx, appData, donor) - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, AppData, *donordata.Provided) error); ok { - r0 = rf(ctx, appData, donor) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -// SendCertificateProvider provides a mock function with given fields: ctx, appData, identity, donor -func (_m *mockShareCodeSender) SendCertificateProvider(ctx context.Context, appData AppData, identity bool, donor *donordata.Provided) error { - ret := _m.Called(ctx, appData, identity, donor) - - var r0 error - if rf, ok := ret.Get(0).(func(context.Context, AppData, bool, *donordata.Provided) error); ok { - r0 = rf(ctx, appData, identity, donor) - } else { - r0 = ret.Error(0) - } - - return r0 -} - -type mockConstructorTestingTnewMockShareCodeSender interface { - mock.TestingT - Cleanup(func()) -} - -// newMockShareCodeSender creates a new instance of mockShareCodeSender. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func newMockShareCodeSender(t mockConstructorTestingTnewMockShareCodeSender) *mockShareCodeSender { - mock := &mockShareCodeSender{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/page/mock_test.go b/internal/page/mock_test.go index 411ebe0f52..87dbaacb18 100644 --- a/internal/page/mock_test.go +++ b/internal/page/mock_test.go @@ -3,6 +3,7 @@ package page import ( "errors" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/ministryofjustice/opg-modernising-lpa/internal/place" ) @@ -12,7 +13,7 @@ const testRandomString = "123" var ( expectedError = errors.New("err") testAddress = place.Address{Line1: "1"} - TestAppData = AppData{ + TestAppData = appcontext.Data{ SessionID: "session-id", LpaID: "lpa-id", Lang: localize.En, diff --git a/internal/page/paths.go b/internal/page/paths.go index 317c2a3554..41fcb8a25f 100644 --- a/internal/page/paths.go +++ b/internal/page/paths.go @@ -5,6 +5,7 @@ import ( "net/url" "strings" + "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/donor/donordata" @@ -20,12 +21,12 @@ func (p Path) Format() string { return string(p) } -func (p Path) Redirect(w http.ResponseWriter, r *http.Request, appData AppData) error { +func (p Path) Redirect(w http.ResponseWriter, r *http.Request, appData appcontext.Data) error { http.Redirect(w, r, appData.Lang.URL(p.Format()), http.StatusFound) return nil } -func (p Path) RedirectQuery(w http.ResponseWriter, r *http.Request, appData AppData, query url.Values) error { +func (p Path) RedirectQuery(w http.ResponseWriter, r *http.Request, appData appcontext.Data, query url.Values) error { http.Redirect(w, r, appData.Lang.URL(p.Format())+"?"+query.Encode(), http.StatusFound) return nil } @@ -40,7 +41,7 @@ func (p LpaPath) Format(id string) string { return "/lpa/" + id + string(p) } -func (p LpaPath) Redirect(w http.ResponseWriter, r *http.Request, appData AppData, donor *donordata.Provided) error { +func (p LpaPath) Redirect(w http.ResponseWriter, r *http.Request, appData appcontext.Data, donor *donordata.Provided) error { rurl := p.Format(donor.LpaID) if fromURL := r.FormValue("from"); fromURL != "" { rurl = fromURL @@ -50,7 +51,7 @@ func (p LpaPath) Redirect(w http.ResponseWriter, r *http.Request, appData AppDat return nil } -func (p LpaPath) RedirectQuery(w http.ResponseWriter, r *http.Request, appData AppData, donor *donordata.Provided, query url.Values) error { +func (p LpaPath) RedirectQuery(w http.ResponseWriter, r *http.Request, appData appcontext.Data, donor *donordata.Provided, query url.Values) error { rurl := p.Format(donor.LpaID) + "?" + query.Encode() if fromURL := r.FormValue("from"); fromURL != "" { rurl = fromURL @@ -133,12 +134,12 @@ func (p AttorneyPath) Format(id string) string { return "/attorney/" + id + string(p) } -func (p AttorneyPath) Redirect(w http.ResponseWriter, r *http.Request, appData AppData, lpaID string) error { +func (p AttorneyPath) Redirect(w http.ResponseWriter, r *http.Request, appData appcontext.Data, lpaID string) error { http.Redirect(w, r, appData.Lang.URL(p.Format(lpaID)), http.StatusFound) return nil } -func (p AttorneyPath) RedirectQuery(w http.ResponseWriter, r *http.Request, appData AppData, lpaID string, query url.Values) error { +func (p AttorneyPath) RedirectQuery(w http.ResponseWriter, r *http.Request, appData appcontext.Data, lpaID string, query url.Values) error { http.Redirect(w, r, appData.Lang.URL(p.Format(lpaID))+"?"+query.Encode(), http.StatusFound) return nil } @@ -169,7 +170,7 @@ func (p CertificateProviderPath) Format(id string) string { return "/certificate-provider/" + id + string(p) } -func (p CertificateProviderPath) Redirect(w http.ResponseWriter, r *http.Request, appData AppData, lpaID string) error { +func (p CertificateProviderPath) Redirect(w http.ResponseWriter, r *http.Request, appData appcontext.Data, lpaID string) error { http.Redirect(w, r, appData.Lang.URL(p.Format(lpaID)), http.StatusFound) return nil } @@ -202,12 +203,12 @@ func (p SupporterPath) Format() string { return "/supporter" + string(p) } -func (p SupporterPath) Redirect(w http.ResponseWriter, r *http.Request, appData AppData) error { +func (p SupporterPath) Redirect(w http.ResponseWriter, r *http.Request, appData appcontext.Data) error { http.Redirect(w, r, appData.Lang.URL(p.Format()), http.StatusFound) return nil } -func (p SupporterPath) RedirectQuery(w http.ResponseWriter, r *http.Request, appData AppData, query url.Values) error { +func (p SupporterPath) RedirectQuery(w http.ResponseWriter, r *http.Request, appData appcontext.Data, query url.Values) error { http.Redirect(w, r, appData.Lang.URL(p.Format())+"?"+query.Encode(), http.StatusFound) return nil } @@ -229,12 +230,12 @@ func (p SupporterLpaPath) Format(lpaID string) string { return "/supporter" + string(p) + "/" + lpaID } -func (p SupporterLpaPath) Redirect(w http.ResponseWriter, r *http.Request, appData AppData, lpaID string) error { +func (p SupporterLpaPath) Redirect(w http.ResponseWriter, r *http.Request, appData appcontext.Data, lpaID string) error { http.Redirect(w, r, appData.Lang.URL(p.Format(lpaID)), http.StatusFound) return nil } -func (p SupporterLpaPath) RedirectQuery(w http.ResponseWriter, r *http.Request, appData AppData, lpaID string, query url.Values) error { +func (p SupporterLpaPath) RedirectQuery(w http.ResponseWriter, r *http.Request, appData appcontext.Data, lpaID string, query url.Values) error { http.Redirect(w, r, appData.Lang.URL(p.Format(lpaID))+"?"+query.Encode(), http.StatusFound) return nil } diff --git a/internal/page/paths_test.go b/internal/page/paths_test.go index 756f247c71..56ed1ce5cf 100644 --- a/internal/page/paths_test.go +++ b/internal/page/paths_test.go @@ -6,6 +6,7 @@ import ( "net/url" "testing" + "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/donor/donordata" @@ -29,7 +30,7 @@ func TestPathRedirect(t *testing.T) { w := httptest.NewRecorder() p := Path("/something") - err := p.Redirect(w, r, AppData{Lang: localize.En}) + err := p.Redirect(w, r, appcontext.Data{Lang: localize.En}) resp := w.Result() assert.Nil(t, err) @@ -42,7 +43,7 @@ func TestPathRedirectQuery(t *testing.T) { w := httptest.NewRecorder() p := Path("/something") - err := p.RedirectQuery(w, r, AppData{Lang: localize.En}, url.Values{"q": {"1"}}) + err := p.RedirectQuery(w, r, appcontext.Data{Lang: localize.En}, url.Values{"q": {"1"}}) resp := w.Result() assert.Nil(t, err) @@ -98,7 +99,7 @@ func TestLpaPathRedirect(t *testing.T) { r, _ := http.NewRequest(http.MethodGet, tc.url, nil) w := httptest.NewRecorder() - err := Paths.HowToConfirmYourIdentityAndSign.Redirect(w, r, AppData{Lang: localize.En}, tc.donor) + err := Paths.HowToConfirmYourIdentityAndSign.Redirect(w, r, appcontext.Data{Lang: localize.En}, tc.donor) resp := w.Result() assert.Nil(t, err) @@ -112,7 +113,7 @@ func TestLpaPathRedirectQuery(t *testing.T) { r, _ := http.NewRequest(http.MethodGet, "/", nil) w := httptest.NewRecorder() - err := Paths.TaskList.RedirectQuery(w, r, AppData{Lang: localize.En}, &donordata.Provided{LpaID: "lpa-id"}, url.Values{"q": {"1"}}) + err := Paths.TaskList.RedirectQuery(w, r, appcontext.Data{Lang: localize.En}, &donordata.Provided{LpaID: "lpa-id"}, url.Values{"q": {"1"}}) resp := w.Result() assert.Nil(t, err) @@ -133,7 +134,7 @@ func TestAttorneyPathRedirect(t *testing.T) { w := httptest.NewRecorder() p := AttorneyPath("/something") - err := p.Redirect(w, r, AppData{Lang: localize.En}, "lpa-id") + err := p.Redirect(w, r, appcontext.Data{Lang: localize.En}, "lpa-id") resp := w.Result() assert.Nil(t, err) @@ -146,7 +147,7 @@ func TestAttorneyPathRedirectQuery(t *testing.T) { w := httptest.NewRecorder() p := AttorneyPath("/something") - err := p.RedirectQuery(w, r, AppData{Lang: localize.En}, "lpa-id", url.Values{"q": {"1"}}) + err := p.RedirectQuery(w, r, appcontext.Data{Lang: localize.En}, "lpa-id", url.Values{"q": {"1"}}) resp := w.Result() assert.Nil(t, err) @@ -167,7 +168,7 @@ func TestCertificateProviderPathRedirect(t *testing.T) { w := httptest.NewRecorder() p := CertificateProviderPath("/something") - err := p.Redirect(w, r, AppData{Lang: localize.En}, "lpa-id") + err := p.Redirect(w, r, appcontext.Data{Lang: localize.En}, "lpa-id") resp := w.Result() assert.Nil(t, err) @@ -188,7 +189,7 @@ func TestSupporterPathRedirect(t *testing.T) { w := httptest.NewRecorder() p := SupporterPath("/something") - err := p.Redirect(w, r, AppData{Lang: localize.En}) + err := p.Redirect(w, r, appcontext.Data{Lang: localize.En}) resp := w.Result() assert.Nil(t, err) @@ -218,7 +219,7 @@ func TestSupporterLpaPathRedirect(t *testing.T) { w := httptest.NewRecorder() p := SupporterLpaPath("/something") - err := p.Redirect(w, r, AppData{Lang: localize.En}, "abc") + err := p.Redirect(w, r, appcontext.Data{Lang: localize.En}, "abc") resp := w.Result() assert.Nil(t, err) @@ -231,7 +232,7 @@ func TestSupporterLpaPathRedirectQuery(t *testing.T) { w := httptest.NewRecorder() p := SupporterLpaPath("/something") - err := p.RedirectQuery(w, r, AppData{Lang: localize.En}, "abc", url.Values{"x": {"y"}}) + err := p.RedirectQuery(w, r, appcontext.Data{Lang: localize.En}, "abc", url.Values{"x": {"y"}}) resp := w.Result() assert.Nil(t, err) diff --git a/internal/page/recover.go b/internal/page/recover.go index 8133a6bad6..61f79ae436 100644 --- a/internal/page/recover.go +++ b/internal/page/recover.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" ) @@ -17,7 +18,7 @@ func Recover(tmpl template.Template, logger Logger, bundle Bundle, next http.Han logger.ErrorContext(r.Context(), "recover error", slog.Any("req", r), slog.Any("err", err), slog.String("stack", string(debug.Stack()))) w.WriteHeader(http.StatusInternalServerError) - appData := AppData{CookieConsentSet: true} + appData := appcontext.Data{CookieConsentSet: true} if strings.HasPrefix(r.URL.Path, "/cy/") { appData.Lang = localize.Cy } else { diff --git a/internal/page/recover_test.go b/internal/page/recover_test.go index 50dbe177c4..d7fc14384d 100644 --- a/internal/page/recover_test.go +++ b/internal/page/recover_test.go @@ -6,6 +6,7 @@ import ( "net/http/httptest" "testing" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -29,7 +30,7 @@ func TestRecover(t *testing.T) { template := newMockTemplate(t) template.EXPECT(). - Execute(w, &errorData{App: AppData{ + Execute(w, &errorData{App: appcontext.Data{ CookieConsentSet: true, Lang: lang, Localizer: (*localize.Localizer)(nil), diff --git a/internal/page/root.go b/internal/page/root.go index 1c4de1022f..ec9c4a897a 100644 --- a/internal/page/root.go +++ b/internal/page/root.go @@ -5,16 +5,17 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type rootData struct { - App AppData + App appcontext.Data Errors validation.List } func Root(tmpl template.Template, logger Logger) Handler { - return func(appData AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { if r.URL.Path == "/" { http.Redirect(w, r, Paths.Start.Format(), http.StatusFound) return nil diff --git a/internal/page/share_code.go b/internal/page/share_code.go index 77666b2522..69fe942b51 100644 --- a/internal/page/share_code.go +++ b/internal/page/share_code.go @@ -6,6 +6,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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/event" @@ -50,7 +51,7 @@ type CertificateProviderInvite struct { CertificateProviderEmail string } -func (s *ShareCodeSender) SendCertificateProviderInvite(ctx context.Context, appData AppData, invite CertificateProviderInvite) error { +func (s *ShareCodeSender) SendCertificateProviderInvite(ctx context.Context, appData appcontext.Data, invite CertificateProviderInvite) error { shareCode, err := s.createShareCode(ctx, invite.LpaKey, invite.LpaOwnerKey, invite.CertificateProviderUID, actor.TypeCertificateProvider) if err != nil { return err @@ -69,7 +70,7 @@ func (s *ShareCodeSender) SendCertificateProviderInvite(ctx context.Context, app }) } -func (s *ShareCodeSender) SendCertificateProviderPrompt(ctx context.Context, appData AppData, donor *donordata.Provided) error { +func (s *ShareCodeSender) SendCertificateProviderPrompt(ctx context.Context, appData appcontext.Data, donor *donordata.Provided) error { shareCode, err := s.createShareCode(ctx, donor.PK, donor.SK, donor.CertificateProvider.UID, actor.TypeCertificateProvider) if err != nil { return err @@ -88,7 +89,7 @@ func (s *ShareCodeSender) SendCertificateProviderPrompt(ctx context.Context, app }) } -func (s *ShareCodeSender) SendAttorneys(ctx context.Context, appData AppData, donor *lpastore.Lpa) error { +func (s *ShareCodeSender) SendAttorneys(ctx context.Context, appData appcontext.Data, donor *lpastore.Lpa) error { if err := s.sendTrustCorporation(ctx, appData, donor, donor.Attorneys.TrustCorporation); err != nil { return err } @@ -111,7 +112,7 @@ func (s *ShareCodeSender) SendAttorneys(ctx context.Context, appData AppData, do return nil } -func (s *ShareCodeSender) sendOriginalAttorney(ctx context.Context, appData AppData, lpa *lpastore.Lpa, attorney lpastore.Attorney) error { +func (s *ShareCodeSender) sendOriginalAttorney(ctx context.Context, appData appcontext.Data, lpa *lpastore.Lpa, attorney lpastore.Attorney) error { shareCode, err := s.createShareCode(ctx, lpa.LpaKey, lpa.LpaOwnerKey, attorney.UID, actor.TypeAttorney) if err != nil { return err @@ -134,7 +135,7 @@ func (s *ShareCodeSender) sendOriginalAttorney(ctx context.Context, appData AppD }) } -func (s *ShareCodeSender) sendReplacementAttorney(ctx context.Context, appData AppData, lpa *lpastore.Lpa, attorney lpastore.Attorney) error { +func (s *ShareCodeSender) sendReplacementAttorney(ctx context.Context, appData appcontext.Data, lpa *lpastore.Lpa, attorney lpastore.Attorney) error { shareCode, err := s.createShareCode(ctx, lpa.LpaKey, lpa.LpaOwnerKey, attorney.UID, actor.TypeReplacementAttorney) if err != nil { return err @@ -157,7 +158,7 @@ func (s *ShareCodeSender) sendReplacementAttorney(ctx context.Context, appData A }) } -func (s *ShareCodeSender) sendTrustCorporation(ctx context.Context, appData AppData, lpa *lpastore.Lpa, trustCorporation lpastore.TrustCorporation) error { +func (s *ShareCodeSender) sendTrustCorporation(ctx context.Context, appData appcontext.Data, lpa *lpastore.Lpa, trustCorporation lpastore.TrustCorporation) error { if trustCorporation.Name == "" { return nil } @@ -184,7 +185,7 @@ func (s *ShareCodeSender) sendTrustCorporation(ctx context.Context, appData AppD }) } -func (s *ShareCodeSender) sendReplacementTrustCorporation(ctx context.Context, appData AppData, lpa *lpastore.Lpa, trustCorporation lpastore.TrustCorporation) error { +func (s *ShareCodeSender) sendReplacementTrustCorporation(ctx context.Context, appData appcontext.Data, lpa *lpastore.Lpa, trustCorporation lpastore.TrustCorporation) error { if trustCorporation.Name == "" { return nil } diff --git a/internal/page/sign_out.go b/internal/page/sign_out.go index 7878539e52..0a87119766 100644 --- a/internal/page/sign_out.go +++ b/internal/page/sign_out.go @@ -3,10 +3,12 @@ package page import ( "log/slog" "net/http" + + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" ) func SignOut(logger Logger, sessionStore SessionStore, oneLoginClient OneLoginClient, appPublicURL string) Handler { - return func(appData AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { redirectURL := appPublicURL + Paths.Start.Format() var idToken string diff --git a/internal/page/supporter/confirm_donor_can_interact_online.go b/internal/page/supporter/confirm_donor_can_interact_online.go index 233357a452..677c683163 100644 --- a/internal/page/supporter/confirm_donor_can_interact_online.go +++ b/internal/page/supporter/confirm_donor_can_interact_online.go @@ -5,19 +5,20 @@ 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/form" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type confirmDonorCanInteractOnlineData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *form.YesNoForm } func ConfirmDonorCanInteractOnline(tmpl template.Template, organisationStore OrganisationStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { data := &confirmDonorCanInteractOnlineData{ App: appData, Form: form.NewYesNoForm(form.YesNoUnknown), diff --git a/internal/page/supporter/dashboard.go b/internal/page/supporter/dashboard.go index d886e3a99e..8b70c51c53 100644 --- a/internal/page/supporter/dashboard.go +++ b/internal/page/supporter/dashboard.go @@ -7,8 +7,8 @@ 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/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/search" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) @@ -19,7 +19,7 @@ type SearchClient interface { } type dashboardData struct { - App page.AppData + App appcontext.Data Errors validation.List Donors []donordata.Provided CurrentPage int @@ -29,7 +29,7 @@ type dashboardData struct { func Dashboard(tmpl template.Template, donorStore DonorStore, searchClient SearchClient) Handler { const pageSize = 10 - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { page, err := strconv.Atoi(r.FormValue("page")) if err != nil { page = 1 diff --git a/internal/page/supporter/delete_organisation.go b/internal/page/supporter/delete_organisation.go index 6ed00016de..37f021341b 100644 --- a/internal/page/supporter/delete_organisation.go +++ b/internal/page/supporter/delete_organisation.go @@ -6,19 +6,20 @@ 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/search" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type deleteOrganisationData struct { - App page.AppData + App appcontext.Data Errors validation.List InProgressLPACount int } func DeleteOrganisation(logger Logger, tmpl template.Template, organisationStore OrganisationStore, sessionStore SessionStore, searchClient SearchClient) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { if r.Method == http.MethodPost { if err := organisationStore.SoftDelete(r.Context(), organisation); err != nil { return err diff --git a/internal/page/supporter/donor_access.go b/internal/page/supporter/donor_access.go index 06f1cf2863..90137ada2c 100644 --- a/internal/page/supporter/donor_access.go +++ b/internal/page/supporter/donor_access.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/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -18,7 +19,7 @@ import ( ) type donorAccessData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *donorAccessForm Donor *donordata.Provided @@ -26,7 +27,7 @@ type donorAccessData struct { } func DonorAccess(logger Logger, tmpl template.Template, donorStore DonorStore, shareCodeStore ShareCodeStore, notifyClient NotifyClient, appPublicURL string, randomString func(int) string) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, member *actor.Member) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, member *actor.Member) error { donor, err := donorStore.Get(r.Context()) if err != nil { return err diff --git a/internal/page/supporter/edit_member.go b/internal/page/supporter/edit_member.go index fa937dd896..ceb9288182 100644 --- a/internal/page/supporter/edit_member.go +++ b/internal/page/supporter/edit_member.go @@ -7,12 +7,13 @@ 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/validation" ) type editMemberData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *editMemberForm Member *actor.Member @@ -20,7 +21,7 @@ type editMemberData struct { } func EditMember(logger Logger, tmpl template.Template, memberStore MemberStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, member *actor.Member) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, member *actor.Member) error { memberID := r.FormValue("id") isLoggedInMember := member.ID == memberID if !isLoggedInMember { diff --git a/internal/page/supporter/edit_member_test.go b/internal/page/supporter/edit_member_test.go index e5cf64d2d3..63bf153c09 100644 --- a/internal/page/supporter/edit_member_test.go +++ b/internal/page/supporter/edit_member_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/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" "github.com/stretchr/testify/assert" @@ -153,9 +154,9 @@ func TestPostEditMember(t *testing.T) { Put(r.Context(), tc.expectedMember). Return(nil) - err := EditMember(nil, nil, memberStore)(page.AppData{ + err := EditMember(nil, nil, memberStore)(appcontext.Data{ LoginSessionEmail: "self@example.org", - SupporterData: &page.SupporterData{ + SupporterData: &appcontext.SupporterData{ Permission: tc.userPermission, }, }, w, r, &actor.Organisation{}, tc.member) @@ -208,9 +209,9 @@ func TestPostEditMemberWhenOtherMember(t *testing.T) { logger.EXPECT(). InfoContext(r.Context(), "member permission changed", slog.String("member_id", "member-id"), slog.String("permission_old", "none"), slog.String("permission_new", "admin")) - err := EditMember(logger, nil, memberStore)(page.AppData{ + err := EditMember(logger, nil, memberStore)(appcontext.Data{ LoginSessionEmail: "self@example.org", - SupporterData: &page.SupporterData{ + SupporterData: &appcontext.SupporterData{ Permission: actor.PermissionAdmin, }, }, w, r, &actor.Organisation{}, &actor.Member{}) @@ -252,9 +253,9 @@ func TestPostEditMemberNoUpdate(t *testing.T) { r, _ := http.NewRequest(http.MethodPost, "/?id=an-id", strings.NewReader(form.Encode())) r.Header.Add("Content-Type", page.FormUrlEncoded) - err := EditMember(nil, nil, nil)(page.AppData{ + err := EditMember(nil, nil, nil)(appcontext.Data{ LoginSessionEmail: "self@example.org", - SupporterData: &page.SupporterData{ + SupporterData: &appcontext.SupporterData{ Permission: tc.userPermission, }, }, w, r, &actor.Organisation{}, &actor.Member{ @@ -297,9 +298,9 @@ func TestPostEditMemberNoUpdateWhenOtherMember(t *testing.T) { Permission: actor.PermissionAdmin, }, nil) - err := EditMember(nil, nil, memberStore)(page.AppData{ + err := EditMember(nil, nil, memberStore)(appcontext.Data{ LoginSessionEmail: "self@example.org", - SupporterData: &page.SupporterData{ + SupporterData: &appcontext.SupporterData{ Permission: actor.PermissionAdmin, }, }, w, r, &actor.Organisation{}, &actor.Member{}) diff --git a/internal/page/supporter/edit_organisation_name.go b/internal/page/supporter/edit_organisation_name.go index ae25a8fc7e..8fa842b542 100644 --- a/internal/page/supporter/edit_organisation_name.go +++ b/internal/page/supporter/edit_organisation_name.go @@ -6,18 +6,19 @@ 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/validation" ) type editOrganisationNameData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *organisationNameForm } func EditOrganisationName(tmpl template.Template, organisationStore OrganisationStore) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { data := &editOrganisationNameData{ App: appData, Form: &organisationNameForm{ diff --git a/internal/page/supporter/enter_organisation_name.go b/internal/page/supporter/enter_organisation_name.go index e4cd295ab8..159fdf0d8e 100644 --- a/internal/page/supporter/enter_organisation_name.go +++ b/internal/page/supporter/enter_organisation_name.go @@ -5,18 +5,19 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type enterOrganisationNameData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *organisationNameForm } func EnterOrganisationName(logger Logger, tmpl template.Template, organisationStore OrganisationStore, memberStore MemberStore, sessionStore SessionStore) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { data := &enterOrganisationNameData{ App: appData, Form: &organisationNameForm{}, diff --git a/internal/page/supporter/enter_reference_number.go b/internal/page/supporter/enter_reference_number.go index 3447aa6e6a..80c9abb647 100644 --- a/internal/page/supporter/enter_reference_number.go +++ b/internal/page/supporter/enter_reference_number.go @@ -5,18 +5,19 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type enterReferenceNumber struct { - App page.AppData + App appcontext.Data Errors validation.List Form *referenceNumberForm } func EnterReferenceNumber(logger Logger, tmpl template.Template, memberStore MemberStore, sessionStore SessionStore) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { data := &enterReferenceNumber{ App: appData, Form: &referenceNumberForm{ diff --git a/internal/page/supporter/enter_your_name.go b/internal/page/supporter/enter_your_name.go index 0e0b48c958..70d4e391bc 100644 --- a/internal/page/supporter/enter_your_name.go +++ b/internal/page/supporter/enter_your_name.go @@ -4,18 +4,19 @@ import ( "net/http" "github.com/ministryofjustice/opg-go-common/template" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type enterYourNameData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *enterYourNameForm } func EnterYourName(tmpl template.Template, memberStore MemberStore) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { data := &enterYourNameData{ App: appData, Form: &enterYourNameForm{}, diff --git a/internal/page/supporter/guidance.go b/internal/page/supporter/guidance.go index a1ea1f99f5..d7709cb5d2 100644 --- a/internal/page/supporter/guidance.go +++ b/internal/page/supporter/guidance.go @@ -6,19 +6,19 @@ import ( "github.com/ministryofjustice/opg-go-common/template" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type guidanceData struct { - App page.AppData + App appcontext.Data Query url.Values Errors validation.List Organisation *actor.Organisation } func Guidance(tmpl template.Template) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { return tmpl(w, &guidanceData{ App: appData, Query: r.URL.Query(), diff --git a/internal/page/supporter/invite_member.go b/internal/page/supporter/invite_member.go index 397b38581b..b7bf350464 100644 --- a/internal/page/supporter/invite_member.go +++ b/internal/page/supporter/invite_member.go @@ -6,20 +6,21 @@ 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/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type inviteMemberData struct { - App page.AppData + App appcontext.Data Errors validation.List Form *inviteMemberForm Options actor.PermissionOptions } func InviteMember(tmpl template.Template, memberStore MemberStore, notifyClient NotifyClient, randomString func(int) string, appPublicURL string) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { data := &inviteMemberData{ App: appData, Form: &inviteMemberForm{}, diff --git a/internal/page/supporter/login_callback.go b/internal/page/supporter/login_callback.go index ad71944366..0ba71b6240 100644 --- a/internal/page/supporter/login_callback.go +++ b/internal/page/supporter/login_callback.go @@ -20,7 +20,7 @@ type LoginCallbackOneLoginClient interface { } func LoginCallback(logger Logger, oneLoginClient LoginCallbackOneLoginClient, sessionStore SessionStore, organisationStore OrganisationStore, now func() time.Time, memberStore MemberStore) page.Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error { if error := r.FormValue("error"); error != "" { logger.InfoContext(r.Context(), "login error", slog.String("error", error), @@ -51,8 +51,8 @@ func LoginCallback(logger Logger, oneLoginClient LoginCallbackOneLoginClient, se logger.InfoContext(r.Context(), "login", slog.String("session_id", loginSession.SessionID())) - sessionData := &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email} - ctx := page.ContextWithSessionData(r.Context(), sessionData) + sessionData := &appcontext.Session{SessionID: loginSession.SessionID(), Email: loginSession.Email} + ctx := appcontext.ContextWithSession(r.Context(), sessionData) member, err := memberStore.GetAny(ctx) if errors.Is(err, dynamo.NotFoundError{}) { @@ -92,7 +92,7 @@ func LoginCallback(logger Logger, oneLoginClient LoginCallbackOneLoginClient, se } sessionData.OrganisationID = organisation.ID - ctx = page.ContextWithSessionData(r.Context(), sessionData) + ctx = appcontext.ContextWithSession(r.Context(), sessionData) member.LastLoggedInAt = now() member.Email = loginSession.Email diff --git a/internal/page/supporter/login_callback_test.go b/internal/page/supporter/login_callback_test.go index ca94a62e61..8f8c99631e 100644 --- a/internal/page/supporter/login_callback_test.go +++ b/internal/page/supporter/login_callback_test.go @@ -77,7 +77,7 @@ func TestLoginCallback(t *testing.T) { logger.EXPECT(). InfoContext(r.Context(), "login", slog.String("session_id", session.SessionID())) - err := LoginCallback(logger, client, sessionStore, nil, testNowFn, memberStore)(page.AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, nil, testNowFn, memberStore)(appcontext.Data{}, w, r) resp := w.Result() assert.Nil(t, err) @@ -95,7 +95,7 @@ func TestLoginCallbackWhenErrorReturned(t *testing.T) { logger.EXPECT(). InfoContext(r.Context(), "login error", slog.String("error", "hey"), slog.String("error_description", "this is why")) - err := LoginCallback(logger, nil, nil, nil, testNowFn, nil)(page.AppData{}, w, r) + err := LoginCallback(logger, nil, nil, nil, testNowFn, nil)(appcontext.Data{}, w, r) assert.Equal(t, errors.New("access denied"), err) } @@ -130,7 +130,7 @@ func TestLoginCallbackWhenMemberGetAnyErrors(t *testing.T) { logger.EXPECT(). InfoContext(mock.Anything, mock.Anything, mock.Anything) - err := LoginCallback(logger, client, sessionStore, nil, testNowFn, memberStore)(page.AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, nil, testNowFn, memberStore)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) resp := w.Result() @@ -172,7 +172,7 @@ func TestLoginCallbackWhenInvitedMembersByEmailErrors(t *testing.T) { logger.EXPECT(). InfoContext(mock.Anything, mock.Anything, mock.Anything) - err := LoginCallback(logger, client, sessionStore, nil, testNowFn, memberStore)(page.AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, nil, testNowFn, memberStore)(appcontext.Data{}, w, r) resp := w.Result() assert.Error(t, err) @@ -212,19 +212,19 @@ func TestLoginCallbackHasMember(t *testing.T) { memberStore := newMockMemberStore(t) memberStore.EXPECT(). - GetAny(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email})). + GetAny(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: loginSession.SessionID(), Email: loginSession.Email})). Return(&actor.Member{}, nil) organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: loginSession.SessionID(), Email: loginSession.Email})). Return(nil, dynamo.NotFoundError{}) logger := newMockLogger(t) logger.EXPECT(). InfoContext(mock.Anything, mock.Anything, mock.Anything) - err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(page.AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(appcontext.Data{}, w, r) resp := w.Result() assert.Nil(t, err) @@ -271,7 +271,7 @@ func TestLoginCallbackHasMemberWhenSessionErrors(t *testing.T) { logger.EXPECT(). InfoContext(mock.Anything, mock.Anything, mock.Anything) - err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(page.AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(appcontext.Data{}, w, r) resp := w.Result() assert.Equal(t, expectedError, err) @@ -288,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(), &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email}) + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: loginSession.SessionID(), Email: loginSession.Email}) client := newMockOneLoginClient(t) client.EXPECT(). @@ -322,7 +322,7 @@ func TestLoginCallbackHasMemberWhenOrganisationGetErrors(t *testing.T) { logger.EXPECT(). InfoContext(mock.Anything, mock.Anything, mock.Anything) - err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(page.AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } @@ -377,23 +377,23 @@ func TestLoginCallbackHasOrganisation(t *testing.T) { memberStore := newMockMemberStore(t) memberStore.EXPECT(). - GetAny(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email})). + GetAny(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: loginSession.SessionID(), Email: loginSession.Email})). Return(&actor.Member{Email: tc.existingMemberEmail}, nil) memberStore.EXPECT(). - Put(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email, OrganisationID: "org-id"}), &actor.Member{Email: tc.loginSessionEmail, LastLoggedInAt: testNow}). + Put(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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(), &appcontext.SessionData{SessionID: loginSession.SessionID(), Email: loginSession.Email})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: loginSession.SessionID(), Email: loginSession.Email})). Return(&actor.Organisation{ID: "org-id", Name: "org name"}, nil) logger := newMockLogger(t) logger.EXPECT(). InfoContext(mock.Anything, mock.Anything, mock.Anything) - err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(page.AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(appcontext.Data{}, w, r) resp := w.Result() assert.Nil(t, err) @@ -445,7 +445,7 @@ func TestLoginCallbackHasOrganisationWhenMemberPutErrors(t *testing.T) { logger.EXPECT(). InfoContext(mock.Anything, mock.Anything, mock.Anything) - err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(page.AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } @@ -488,7 +488,7 @@ func TestLoginCallbackHasOrganisationWhenSessionErrors(t *testing.T) { logger.EXPECT(). InfoContext(mock.Anything, mock.Anything, mock.Anything) - err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(page.AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } @@ -501,7 +501,7 @@ func TestLoginCallbackSessionError(t *testing.T) { OneLogin(r). Return(nil, expectedError) - err := LoginCallback(nil, nil, sessionStore, nil, testNowFn, nil)(page.AppData{}, w, r) + err := LoginCallback(nil, nil, sessionStore, nil, testNowFn, nil)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } @@ -519,7 +519,7 @@ func TestLoginCallbackWhenExchangeErrors(t *testing.T) { OneLogin(r). Return(&sesh.OneLoginSession{State: "my-state", Nonce: "my-nonce", Locale: "en", Redirect: page.Paths.Supporter.LoginCallback.Format()}, nil) - err := LoginCallback(nil, client, sessionStore, nil, testNowFn, nil)(page.AppData{}, w, r) + err := LoginCallback(nil, client, sessionStore, nil, testNowFn, nil)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } @@ -540,7 +540,7 @@ func TestLoginCallbackWhenUserInfoError(t *testing.T) { OneLogin(r). Return(&sesh.OneLoginSession{State: "my-state", Nonce: "my-nonce", Locale: "en", Redirect: page.Paths.Supporter.LoginCallback.Format()}, nil) - err := LoginCallback(nil, client, sessionStore, nil, testNowFn, nil)(page.AppData{}, w, r) + err := LoginCallback(nil, client, sessionStore, nil, testNowFn, nil)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } @@ -583,6 +583,6 @@ func TestLoginCallbackWhenSessionError(t *testing.T) { logger.EXPECT(). InfoContext(mock.Anything, mock.Anything, mock.Anything) - err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(page.AppData{}, w, r) + err := LoginCallback(logger, client, sessionStore, organisationStore, testNowFn, memberStore)(appcontext.Data{}, w, r) assert.Equal(t, expectedError, err) } diff --git a/internal/page/supporter/manage_team_members.go b/internal/page/supporter/manage_team_members.go index dba5357a5f..de446953a1 100644 --- a/internal/page/supporter/manage_team_members.go +++ b/internal/page/supporter/manage_team_members.go @@ -7,13 +7,14 @@ 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/notify" "github.com/ministryofjustice/opg-modernising-lpa/internal/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type manageTeamMembersData struct { - App page.AppData + App appcontext.Data Errors validation.List Organisation *actor.Organisation InvitedMembers []*actor.MemberInvite @@ -22,7 +23,7 @@ type manageTeamMembersData struct { } func ManageTeamMembers(tmpl template.Template, memberStore MemberStore, randomString func(int) string, notifyClient NotifyClient, appPublicURL string) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { data := &manageTeamMembersData{ App: appData, Organisation: organisation, diff --git a/internal/page/supporter/mock_DonorStore_test.go b/internal/page/supporter/mock_DonorStore_test.go index 8ff6e878b4..89fdbcbaab 100644 --- a/internal/page/supporter/mock_DonorStore_test.go +++ b/internal/page/supporter/mock_DonorStore_test.go @@ -215,7 +215,7 @@ type mockDonorStore_Put_Call struct { // Put is a helper method to define mock.On call // - ctx context.Context -// - donor *donordata.DonorProvidedDetails +// - donor *donordata.Provided func (_e *mockDonorStore_Expecter) Put(ctx interface{}, donor interface{}) *mockDonorStore_Put_Call { return &mockDonorStore_Put_Call{Call: _e.mock.On("Put", ctx, donor)} } diff --git a/internal/page/supporter/mock_Handler_test.go b/internal/page/supporter/mock_Handler_test.go index b5d7e091e1..85bb765c81 100644 --- a/internal/page/supporter/mock_Handler_test.go +++ b/internal/page/supporter/mock_Handler_test.go @@ -3,13 +3,12 @@ package supporter import ( - http "net/http" - actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + appcontext "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" - mock "github.com/stretchr/testify/mock" + http "net/http" - page "github.com/ministryofjustice/opg-modernising-lpa/internal/page" + mock "github.com/stretchr/testify/mock" ) // mockHandler is an autogenerated mock type for the Handler type @@ -26,7 +25,7 @@ func (_m *mockHandler) EXPECT() *mockHandler_Expecter { } // Execute provides a mock function with given fields: data, w, r, organisation, member -func (_m *mockHandler) Execute(data page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, member *actor.Member) error { +func (_m *mockHandler) Execute(data appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, member *actor.Member) error { ret := _m.Called(data, w, r, organisation, member) if len(ret) == 0 { @@ -34,7 +33,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.Organisation, *actor.Member) error); ok { + if rf, ok := ret.Get(0).(func(appcontext.Data, http.ResponseWriter, *http.Request, *actor.Organisation, *actor.Member) error); ok { r0 = rf(data, w, r, organisation, member) } else { r0 = ret.Error(0) @@ -49,7 +48,7 @@ type mockHandler_Execute_Call struct { } // Execute is a helper method to define mock.On call -// - data page.AppData +// - data appcontext.Data // - w http.ResponseWriter // - r *http.Request // - organisation *actor.Organisation @@ -58,9 +57,9 @@ func (_e *mockHandler_Expecter) Execute(data interface{}, w interface{}, r inter return &mockHandler_Execute_Call{Call: _e.mock.On("Execute", data, w, r, organisation, member)} } -func (_c *mockHandler_Execute_Call) Run(run func(data page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, member *actor.Member)) *mockHandler_Execute_Call { +func (_c *mockHandler_Execute_Call) Run(run func(data appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, member *actor.Member)) *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.Organisation), args[4].(*actor.Member)) + run(args[0].(appcontext.Data), args[1].(http.ResponseWriter), args[2].(*http.Request), args[3].(*actor.Organisation), args[4].(*actor.Member)) }) return _c } @@ -70,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.Organisation, *actor.Member) error) *mockHandler_Execute_Call { +func (_c *mockHandler_Execute_Call) RunAndReturn(run func(appcontext.Data, http.ResponseWriter, *http.Request, *actor.Organisation, *actor.Member) error) *mockHandler_Execute_Call { _c.Call.Return(run) return _c } diff --git a/internal/page/supporter/mock_test.go b/internal/page/supporter/mock_test.go index 928fa75511..a4044db9af 100644 --- a/internal/page/supporter/mock_test.go +++ b/internal/page/supporter/mock_test.go @@ -4,19 +4,19 @@ import ( "errors" "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" - "github.com/ministryofjustice/opg-modernising-lpa/internal/page" ) var ( expectedError = errors.New("err") - testAppData = page.AppData{} - testLpaAppData = page.AppData{LpaID: "lpa-id"} - testOrgMemberAppData = page.AppData{ + testAppData = appcontext.Data{} + testLpaAppData = appcontext.Data{LpaID: "lpa-id"} + testOrgMemberAppData = appcontext.Data{ SessionID: "session-id", Lang: localize.En, LoginSessionEmail: "supporter@example.com", - SupporterData: &page.SupporterData{ + SupporterData: &appcontext.SupporterData{ OrganisationName: "My organisation", Permission: actor.PermissionNone, LoggedInSupporterID: "supporter-id", diff --git a/internal/page/supporter/register.go b/internal/page/supporter/register.go index 48ed297448..ecf9c126e2 100644 --- a/internal/page/supporter/register.go +++ b/internal/page/supporter/register.go @@ -96,7 +96,7 @@ type ShareCodeStore interface { type Template func(w io.Writer, data interface{}) error -type Handler func(data page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, member *actor.Member) error +type Handler func(data appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, member *actor.Member) error type ErrorHandler func(http.ResponseWriter, *http.Request, error) @@ -187,10 +187,10 @@ func makeHandle(mux *http.ServeMux, store SessionStore, errorHandler page.ErrorH mux.HandleFunc(path.String(), func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - appData := page.AppDataFromContext(ctx) + appData := appcontext.DataFromContext(ctx) appData.Page = path.Format() appData.CanToggleWelsh = false - appData.SupporterData = &page.SupporterData{} + appData.SupporterData = &appcontext.SupporterData{} if opt&RequireSession != 0 { session, err := store.Login(r) @@ -201,10 +201,10 @@ func makeHandle(mux *http.ServeMux, store SessionStore, errorHandler page.ErrorH appData.SessionID = session.SessionID() - ctx = page.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: appData.SessionID, Email: session.Email}) + ctx = appcontext.ContextWithSession(ctx, &appcontext.Session{SessionID: appData.SessionID, Email: session.Email}) } - if err := h(appData, w, r.WithContext(page.ContextWithAppData(ctx, appData))); err != nil { + if err := h(appData, w, r.WithContext(appcontext.ContextWithData(ctx, appData))); err != nil { errorHandler(w, r, err) } }) @@ -212,7 +212,7 @@ func makeHandle(mux *http.ServeMux, store SessionStore, errorHandler page.ErrorH } type suspendedData struct { - App page.AppData + App appcontext.Data Errors validation.List OrganisationName string } @@ -231,12 +231,12 @@ func makeSupporterHandle(mux *http.ServeMux, store SessionStore, errorHandler pa return } - appData := page.AppDataFromContext(r.Context()) + appData := appcontext.DataFromContext(r.Context()) appData.SessionID = loginSession.SessionID() appData.CanGoBack = opt&CanGoBack != 0 appData.CanToggleWelsh = false - appData.SupporterData = &page.SupporterData{ + appData.SupporterData = &appcontext.SupporterData{ IsManageOrganisation: path.IsManageOrganisation(), } @@ -252,13 +252,13 @@ func makeSupporterHandle(mux *http.ServeMux, store SessionStore, errorHandler pa panic("non-supporter path registered") } - sessionData, err := appcontext.SessionDataFromContext(r.Context()) + sessionData, err := appcontext.SessionFromContext(r.Context()) if err == nil { sessionData.SessionID = appData.SessionID sessionData.OrganisationID = loginSession.OrganisationID } else { - sessionData = &appcontext.SessionData{ + sessionData = &appcontext.Session{ SessionID: appData.SessionID, Email: loginSession.Email, } @@ -268,13 +268,13 @@ func makeSupporterHandle(mux *http.ServeMux, store SessionStore, errorHandler pa } } - organisation, err := organisationStore.Get(page.ContextWithSessionData(r.Context(), sessionData)) + organisation, err := organisationStore.Get(appcontext.ContextWithSession(r.Context(), sessionData)) if err != nil { errorHandler(w, r, err) return } - ctx := page.ContextWithSessionData(r.Context(), &appcontext.SessionData{ + ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{ SessionID: appData.SessionID, Email: loginSession.Email, OrganisationID: organisation.ID, @@ -307,7 +307,7 @@ func makeSupporterHandle(mux *http.ServeMux, store SessionStore, errorHandler pa appData.SupporterData.Permission = member.Permission appData.SupporterData.LoggedInSupporterID = member.ID - ctx = page.ContextWithAppData(ctx, appData) + ctx = appcontext.ContextWithData(ctx, appData) if err := h(appData, w, r.WithContext(ctx), organisation, member); err != nil { errorHandler(w, r, err) diff --git a/internal/page/supporter/register_test.go b/internal/page/supporter/register_test.go index 450321a462..c4634e9513 100644 --- a/internal/page/supporter/register_test.go +++ b/internal/page/supporter/register_test.go @@ -27,16 +27,16 @@ func TestRegister(t *testing.T) { } func TestMakeHandle(t *testing.T) { - ctx := page.ContextWithAppData(context.Background(), page.AppData{CanToggleWelsh: true}) + ctx := appcontext.ContextWithData(context.Background(), appcontext.Data{CanToggleWelsh: true}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/path?a=b", nil) mux := http.NewServeMux() handle := makeHandle(mux, nil, nil) - handle("/path", None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { - assert.Equal(t, page.AppData{ + handle("/path", None, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { + assert.Equal(t, appcontext.Data{ Page: "/path", - SupporterData: &page.SupporterData{}, + SupporterData: &appcontext.SupporterData{}, }, appData) assert.Equal(t, w, hw) @@ -60,7 +60,7 @@ func TestMakeHandleErrors(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, nil, errorHandler.Execute) - handle("/path", None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { + handle("/path", None, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { return expectedError }) @@ -78,11 +78,11 @@ func TestMakeHandleWhenRequireSession(t *testing.T) { mux := http.NewServeMux() handle := makeHandle(mux, sessionStore, nil) - handle("/path", RequireSession, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request) error { - assert.Equal(t, page.AppData{ + handle("/path", RequireSession, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request) error { + assert.Equal(t, appcontext.Data{ Page: "/path", SessionID: "cmFuZG9t", - SupporterData: &page.SupporterData{}, + SupporterData: &appcontext.SupporterData{}, }, appData) assert.Equal(t, w, hw) @@ -117,7 +117,7 @@ func TestMakeHandleWhenRequireSessionErrors(t *testing.T) { } func TestMakeSupporterHandle(t *testing.T) { - ctx := page.ContextWithAppData(context.Background(), page.AppData{CanToggleWelsh: true}) + ctx := appcontext.ContextWithData(context.Background(), appcontext.Data{CanToggleWelsh: true}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/supporter/path", nil) @@ -130,20 +130,20 @@ func TestMakeSupporterHandle(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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) - handle(page.SupporterPath("/path"), CanGoBack, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, organisation *actor.Organisation, _ *actor.Member) error { - assert.Equal(t, page.AppData{ + handle(page.SupporterPath("/path"), CanGoBack, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request, organisation *actor.Organisation, _ *actor.Member) error { + assert.Equal(t, appcontext.Data{ Page: "/supporter/path", SessionID: "cmFuZG9t", - SupporterData: &page.SupporterData{ + SupporterData: &appcontext.SupporterData{ Permission: actor.PermissionAdmin, LoggedInSupporterID: "member-id", }, @@ -153,8 +153,8 @@ func TestMakeSupporterHandle(t *testing.T) { assert.Equal(t, w, hw) - sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) - assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id"}, sessionData) + sessionData, _ := appcontext.SessionFromContext(hr.Context()) + assert.Equal(t, &appcontext.Session{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil @@ -167,7 +167,7 @@ func TestMakeSupporterHandle(t *testing.T) { } func TestMakeSupporterHandleWithLpaPath(t *testing.T) { - ctx := page.ContextWithAppData(context.Background(), page.AppData{CanToggleWelsh: true}) + ctx := appcontext.ContextWithData(context.Background(), appcontext.Data{CanToggleWelsh: true}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/supporter/path/xyz", nil) @@ -180,20 +180,20 @@ func TestMakeSupporterHandleWithLpaPath(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org", LpaID: "xyz"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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) - handle(page.SupporterLpaPath("/path"), CanGoBack, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, organisation *actor.Organisation, _ *actor.Member) error { - assert.Equal(t, page.AppData{ + handle(page.SupporterLpaPath("/path"), CanGoBack, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request, organisation *actor.Organisation, _ *actor.Member) error { + assert.Equal(t, appcontext.Data{ Page: "/supporter/path/xyz", SessionID: "cmFuZG9t", - SupporterData: &page.SupporterData{ + SupporterData: &appcontext.SupporterData{ Permission: actor.PermissionAdmin, LoggedInSupporterID: "member-id", }, @@ -204,8 +204,8 @@ func TestMakeSupporterHandleWithLpaPath(t *testing.T) { assert.Equal(t, w, hw) - sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) - assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id", LpaID: "xyz"}, sessionData) + sessionData, _ := appcontext.SessionFromContext(hr.Context()) + assert.Equal(t, &appcontext.Session{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id", LpaID: "xyz"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil @@ -218,7 +218,7 @@ func TestMakeSupporterHandleWithLpaPath(t *testing.T) { } func TestMakeSupporterHandleWhenRequireAdmin(t *testing.T) { - ctx := page.ContextWithAppData(context.Background(), page.AppData{CanToggleWelsh: true}) + ctx := appcontext.ContextWithData(context.Background(), appcontext.Data{CanToggleWelsh: true}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/supporter/path", nil) @@ -231,20 +231,20 @@ func TestMakeSupporterHandleWhenRequireAdmin(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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) - handle(page.SupporterPath("/path"), RequireAdmin, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, organisation *actor.Organisation, _ *actor.Member) error { - assert.Equal(t, page.AppData{ + handle(page.SupporterPath("/path"), RequireAdmin, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request, organisation *actor.Organisation, _ *actor.Member) error { + assert.Equal(t, appcontext.Data{ Page: "/supporter/path", SessionID: "cmFuZG9t", - SupporterData: &page.SupporterData{ + SupporterData: &appcontext.SupporterData{ Permission: actor.PermissionAdmin, LoggedInSupporterID: "member-id", }, @@ -253,8 +253,8 @@ func TestMakeSupporterHandleWhenRequireAdmin(t *testing.T) { assert.Equal(t, w, hw) - sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) - assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id"}, sessionData) + sessionData, _ := appcontext.SessionFromContext(hr.Context()) + assert.Equal(t, &appcontext.Session{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil @@ -267,7 +267,7 @@ func TestMakeSupporterHandleWhenRequireAdmin(t *testing.T) { } func TestMakeSupporterHandleWhenRequireAdminAsNonAdmin(t *testing.T) { - ctx := page.ContextWithAppData(context.Background(), page.AppData{CanToggleWelsh: true}) + ctx := appcontext.ContextWithData(context.Background(), appcontext.Data{CanToggleWelsh: true}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/supporter/path", nil) @@ -280,12 +280,12 @@ func TestMakeSupporterHandleWhenRequireAdminAsNonAdmin(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). Return(&actor.Member{Permission: actor.PermissionNone, ID: "member-id"}, nil) errorHandler := newMockErrorHandler(t) @@ -299,7 +299,7 @@ func TestMakeSupporterHandleWhenRequireAdminAsNonAdmin(t *testing.T) { } func TestMakeSupporterHandleWhenSuspended(t *testing.T) { - ctx := page.ContextWithAppData(context.Background(), page.AppData{CanToggleWelsh: true}) + ctx := appcontext.ContextWithData(context.Background(), appcontext.Data{CanToggleWelsh: true}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/supporter/path", nil) @@ -312,21 +312,21 @@ func TestMakeSupporterHandleWhenSuspended(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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) suspendedTmpl.EXPECT(). Execute(w, &suspendedData{ - App: page.AppData{ + App: appcontext.Data{ Page: "/supporter/path", SessionID: "cmFuZG9t", - SupporterData: &page.SupporterData{}, + SupporterData: &appcontext.SupporterData{}, LoginSessionEmail: "a@example.org", }, OrganisationName: "My Org", @@ -343,7 +343,7 @@ func TestMakeSupporterHandleWhenSuspended(t *testing.T) { } func TestMakeSupporterHandleWhenSuspendedTemplateErrors(t *testing.T) { - ctx := page.ContextWithAppData(context.Background(), page.AppData{CanToggleWelsh: true}) + ctx := appcontext.ContextWithData(context.Background(), appcontext.Data{CanToggleWelsh: true}) w := httptest.NewRecorder() r, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/supporter/path", nil) @@ -356,21 +356,21 @@ func TestMakeSupporterHandleWhenSuspendedTemplateErrors(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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) suspendedTmpl.EXPECT(). Execute(w, &suspendedData{ - App: page.AppData{ + App: appcontext.Data{ Page: "/supporter/path", SessionID: "cmFuZG9t", - SupporterData: &page.SupporterData{}, + SupporterData: &appcontext.SupporterData{}, LoginSessionEmail: "a@example.org", }, OrganisationName: "My Org", @@ -390,11 +390,11 @@ func TestMakeSupporterHandleWhenSuspendedTemplateErrors(t *testing.T) { assert.Equal(t, http.StatusOK, resp.StatusCode) } -func TestMakeSupporterHandleWithSessionData(t *testing.T) { +func TestMakeSupporterHandleWithSession(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequestWithContext( - page.ContextWithSessionData(context.Background(), - &appcontext.SessionData{SessionID: "existing-sub", OrganisationID: "an-org-id"}), + appcontext.ContextWithSession(context.Background(), + &appcontext.Session{SessionID: "existing-sub", OrganisationID: "an-org-id"}), http.MethodGet, "/supporter/path", nil, @@ -409,20 +409,20 @@ func TestMakeSupporterHandleWithSessionData(t *testing.T) { organisationStore := newMockOrganisationStore(t) organisationStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: "cmFuZG9t", OrganisationID: "org-id"})). Return(&actor.Organisation{ID: "org-id"}, nil) memberStore := newMockMemberStore(t) memberStore.EXPECT(). - Get(page.ContextWithSessionData(r.Context(), &appcontext.SessionData{SessionID: "cmFuZG9t", OrganisationID: "org-id", Email: "a@example.org"})). + Get(appcontext.ContextWithSession(r.Context(), &appcontext.Session{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) - handle(page.SupporterPath("/path"), None, func(appData page.AppData, hw http.ResponseWriter, hr *http.Request, organisation *actor.Organisation, _ *actor.Member) error { - assert.Equal(t, page.AppData{ + handle(page.SupporterPath("/path"), None, func(appData appcontext.Data, hw http.ResponseWriter, hr *http.Request, organisation *actor.Organisation, _ *actor.Member) error { + assert.Equal(t, appcontext.Data{ Page: "/supporter/path", SessionID: "cmFuZG9t", - SupporterData: &page.SupporterData{ + SupporterData: &appcontext.SupporterData{ Permission: actor.PermissionAdmin, LoggedInSupporterID: "member-id", }, @@ -431,8 +431,8 @@ func TestMakeSupporterHandleWithSessionData(t *testing.T) { assert.Equal(t, w, hw) - sessionData, _ := appcontext.SessionDataFromContext(hr.Context()) - assert.Equal(t, &appcontext.SessionData{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id"}, sessionData) + sessionData, _ := appcontext.SessionFromContext(hr.Context()) + assert.Equal(t, &appcontext.Session{SessionID: "cmFuZG9t", Email: "a@example.org", OrganisationID: "org-id"}, sessionData) hw.WriteHeader(http.StatusTeapot) return nil @@ -547,7 +547,7 @@ func TestMakeSupporterHandleErrors(t *testing.T) { mux := http.NewServeMux() handle := makeSupporterHandle(mux, sessionStore, errorHandler.Execute, organisationStore, memberStore, nil) - handle(page.SupporterPath("/path"), None, func(_ page.AppData, _ http.ResponseWriter, _ *http.Request, _ *actor.Organisation, _ *actor.Member) error { + handle(page.SupporterPath("/path"), None, func(_ appcontext.Data, _ http.ResponseWriter, _ *http.Request, _ *actor.Organisation, _ *actor.Member) error { return expectedError }) diff --git a/internal/page/supporter/view_lpa.go b/internal/page/supporter/view_lpa.go index 6880b51fc9..c8f2f53336 100644 --- a/internal/page/supporter/view_lpa.go +++ b/internal/page/supporter/view_lpa.go @@ -5,20 +5,21 @@ 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/page" "github.com/ministryofjustice/opg-modernising-lpa/internal/validation" ) type viewLPAData struct { - App page.AppData + App appcontext.Data Errors validation.List Lpa *lpastore.Lpa Progress page.Progress } func ViewLPA(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, progressTracker ProgressTracker) Handler { - return func(appData page.AppData, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { + return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, organisation *actor.Organisation, _ *actor.Member) error { lpa, err := lpaStoreResolvingService.Get(r.Context()) if err != nil { return err diff --git a/internal/search/client.go b/internal/search/client.go index 7a6c03de3d..08ffc44b9f 100644 --- a/internal/search/client.go +++ b/internal/search/client.go @@ -230,7 +230,7 @@ func baseQuery(sk string) map[string]map[string]any { } func getSKFromContext(ctx context.Context) (string, error) { - session, err := appcontext.SessionDataFromContext(ctx) + session, err := appcontext.SessionFromContext(ctx) if err != nil { return "", err } diff --git a/internal/search/client_test.go b/internal/search/client_test.go index d0b9966314..377001b12b 100644 --- a/internal/search/client_test.go +++ b/internal/search/client_test.go @@ -126,31 +126,31 @@ func TestClientIndexWhenIndexErrors(t *testing.T) { func TestClientQuery(t *testing.T) { testcases := map[string]struct { - session *appcontext.SessionData + session *appcontext.Session sk dynamo.SK from int page int }{ "donor": { - session: &appcontext.SessionData{SessionID: "abc"}, + session: &appcontext.Session{SessionID: "abc"}, sk: dynamo.DonorKey("abc"), from: 0, page: 1, }, "organisation": { - session: &appcontext.SessionData{SessionID: "abc", OrganisationID: "xyz"}, + session: &appcontext.Session{SessionID: "abc", OrganisationID: "xyz"}, sk: dynamo.OrganisationKey("xyz"), from: 0, page: 1, }, "donor paged": { - session: &appcontext.SessionData{SessionID: "abc"}, + session: &appcontext.Session{SessionID: "abc"}, sk: dynamo.DonorKey("abc"), from: 40, page: 5, }, "organisation paged": { - session: &appcontext.SessionData{SessionID: "abc", OrganisationID: "xyz"}, + session: &appcontext.Session{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 := appcontext.ContextWithSessionData(ctx, tc.session) + ctx := appcontext.ContextWithSession(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 := appcontext.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: "abc"}) + ctx := appcontext.ContextWithSession(ctx, &appcontext.Session{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 := appcontext.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: "1"}) + ctx := appcontext.ContextWithSession(ctx, &appcontext.Session{SessionID: "1"}) svc := newMockOpensearchapiClient(t) svc.EXPECT(). @@ -237,33 +237,33 @@ func TestClientCountWithQuery(t *testing.T) { testcases := map[string]struct { query CountWithQueryReq body []byte - session *appcontext.SessionData + session *appcontext.Session }{ "no query - donor": { query: CountWithQueryReq{}, body: []byte(`{"query":{"bool":{"must":[{"match":{"SK":"DONOR#1"}},{"prefix":{"PK":"LPA#"}}]}},"size":0,"track_total_hits":true}`), - session: &appcontext.SessionData{SessionID: "1"}, + session: &appcontext.Session{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: &appcontext.SessionData{OrganisationID: "1"}, + session: &appcontext.Session{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: &appcontext.SessionData{SessionID: "1"}, + session: &appcontext.Session{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: &appcontext.SessionData{OrganisationID: "1"}, + session: &appcontext.Session{OrganisationID: "1"}, }, } for name, tc := range testcases { t.Run(name, func(t *testing.T) { - ctx := appcontext.ContextWithSessionData(ctx, tc.session) + ctx := appcontext.ContextWithSession(ctx, tc.session) resp := &opensearchapi.SearchResp{} resp.Hits.Total.Value = 1 @@ -305,7 +305,7 @@ func TestClientCountWithQueryWhenSearchError(t *testing.T) { svc: svc, } - ctx := appcontext.ContextWithSessionData(ctx, &appcontext.SessionData{SessionID: "1"}) + ctx := appcontext.ContextWithSession(ctx, &appcontext.Session{SessionID: "1"}) _, err := client.CountWithQuery(ctx, CountWithQueryReq{}) assert.Error(t, err) diff --git a/internal/telemetry/telemetry.go b/internal/telemetry/telemetry.go index dac4549be6..0b54e574f5 100644 --- a/internal/telemetry/telemetry.go +++ b/internal/telemetry/telemetry.go @@ -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 := appcontext.SessionDataFromContext(ctx) + session, err := appcontext.SessionFromContext(ctx) if err == nil { record.AddAttrs(slog.String("session_id", session.SessionID)) diff --git a/internal/templatefn/fn.go b/internal/templatefn/fn.go index b99e9ca7dc..2746fce247 100644 --- a/internal/templatefn/fn.go +++ b/internal/templatefn/fn.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/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -112,7 +113,7 @@ func input(top interface{}, name, label string, value interface{}, attrs ...inte return field } -func button(app page.AppData, label string, attrs ...any) map[string]any { +func button(app appcontext.Data, label string, attrs ...any) map[string]any { field := map[string]any{ "app": app, "label": label, @@ -183,17 +184,17 @@ func inc(i int) int { return i + 1 } -func link(app page.AppData, path string) string { +func link(app appcontext.Data, path string) string { return app.Lang.URL(path) } type lpaIDPath interface{ Format(string) string } -func fromLink(app page.AppData, path lpaIDPath, field string) string { +func fromLink(app appcontext.Data, path lpaIDPath, field string) string { return app.Lang.URL(path.Format(app.LpaID)) + "?from=" + app.Page + field } -func fromLinkActor(app page.AppData, path lpaIDPath, uid actoruid.UID, field string) string { +func fromLinkActor(app appcontext.Data, path lpaIDPath, uid actoruid.UID, field string) string { return app.Lang.URL(path.Format(app.LpaID)) + "?from=" + app.Page + "&id=" + uid.String() + field } @@ -215,7 +216,7 @@ func checkboxEq(needle string, in any) bool { return false } -func tr(app page.AppData, messageID string) string { +func tr(app appcontext.Data, messageID string) string { if messageID == "" { return "" } @@ -223,7 +224,7 @@ func tr(app page.AppData, messageID string) string { return app.Localizer.T(messageID) } -func trFormat(app page.AppData, messageID string, args ...interface{}) string { +func trFormat(app appcontext.Data, messageID string, args ...interface{}) string { if messageID == "" { return "" } @@ -240,7 +241,7 @@ func trFormat(app page.AppData, messageID string, args ...interface{}) string { return app.Localizer.Format(messageID, data) } -func trFormatHtml(app page.AppData, messageID string, args ...interface{}) template.HTML { +func trFormatHtml(app appcontext.Data, messageID string, args ...interface{}) template.HTML { if messageID == "" { return "" } @@ -257,7 +258,7 @@ func trFormatHtml(app page.AppData, messageID string, args ...interface{}) templ return template.HTML(app.Localizer.Format(messageID, data)) } -func trHtml(app page.AppData, messageID string) template.HTML { +func trHtml(app appcontext.Data, messageID string) template.HTML { if messageID == "" { return "" } @@ -265,7 +266,7 @@ func trHtml(app page.AppData, messageID string) template.HTML { return template.HTML(app.Localizer.T(messageID)) } -func trCount(app page.AppData, messageID string, count int) string { +func trCount(app appcontext.Data, messageID string, count int) string { if messageID == "" { return "" } @@ -273,7 +274,7 @@ func trCount(app page.AppData, messageID string, count int) string { return app.Localizer.Count(messageID, count) } -func trFormatCount(app page.AppData, messageID string, count int, args ...interface{}) string { +func trFormatCount(app appcontext.Data, messageID string, count int, args ...interface{}) string { if messageID == "" { return "" } @@ -298,15 +299,15 @@ func addDays(days int, t time.Time) time.Time { return t.AddDate(0, 0, days) } -func formatDate(app page.AppData, t date.TimeOrDate) string { +func formatDate(app appcontext.Data, t date.TimeOrDate) string { return app.Localizer.FormatDate(t) } -func formatTime(app page.AppData, t time.Time) string { +func formatTime(app appcontext.Data, t time.Time) string { return app.Localizer.FormatTime(t) } -func formatDateTime(app page.AppData, t time.Time) string { +func formatDateTime(app appcontext.Data, t time.Time) string { return app.Localizer.FormatDateTime(t) } @@ -327,7 +328,7 @@ func formatPhone(s string) string { } type attorneySummaryData struct { - App page.AppData + App appcontext.Data CanChange bool TrustCorporation lpastore.TrustCorporation Attorneys []lpastore.Attorney @@ -340,7 +341,7 @@ type attorneySummaryDataLinks struct { Attorney, AttorneyAddress, RemoveAttorney string } -func listAttorneys(app page.AppData, attorneys any, attorneyType string, headingLevel int, canChange bool) attorneySummaryData { +func listAttorneys(app appcontext.Data, attorneys any, attorneyType string, headingLevel int, canChange bool) attorneySummaryData { data := attorneySummaryData{ App: app, CanChange: canChange, @@ -395,7 +396,7 @@ func listAttorneys(app page.AppData, attorneys any, attorneyType string, heading return data } -func listPeopleToNotify(app page.AppData, peopleToNotify donordata.PeopleToNotify, headingLevel int, canChange bool) map[string]interface{} { +func listPeopleToNotify(app appcontext.Data, peopleToNotify donordata.PeopleToNotify, headingLevel int, canChange bool) map[string]interface{} { return map[string]interface{}{ "App": app, "HeadingLevel": headingLevel, @@ -404,7 +405,7 @@ func listPeopleToNotify(app page.AppData, peopleToNotify donordata.PeopleToNotif } } -func card(app page.AppData, item any) map[string]any { +func card(app appcontext.Data, item any) map[string]any { return map[string]interface{}{ "App": app, "Item": item, @@ -431,15 +432,15 @@ func printStruct(s interface{}) string { return output } -func possessive(app page.AppData, s string) string { +func possessive(app appcontext.Data, s string) string { return app.Localizer.Possessive(s) } -func concatAnd(app page.AppData, list []string) string { +func concatAnd(app appcontext.Data, list []string) string { return app.Localizer.Concat(list, "and") } -func concatOr(app page.AppData, list []string) string { +func concatOr(app appcontext.Data, list []string) string { return app.Localizer.Concat(list, "or") } @@ -447,7 +448,7 @@ func concatComma(list []string) string { return strings.Join(list, ", ") } -func content(app page.AppData, content string) map[string]interface{} { +func content(app appcontext.Data, content string) map[string]interface{} { return map[string]interface{}{ "App": app, "Content": content, @@ -455,14 +456,14 @@ func content(app page.AppData, content string) map[string]interface{} { } type notificationBannerData struct { - App page.AppData + App appcontext.Data Title string Content template.HTML Heading bool Success bool } -func notificationBanner(app page.AppData, title string, content template.HTML, options ...string) notificationBannerData { +func notificationBanner(app appcontext.Data, title string, content template.HTML, options ...string) notificationBannerData { return notificationBannerData{ App: app, Title: title, @@ -473,12 +474,12 @@ func notificationBanner(app page.AppData, title string, content template.HTML, o } type lpaDecisionsData struct { - App page.AppData + App appcontext.Data Lpa *lpastore.Lpa CanChange bool } -func lpaDecisions(app page.AppData, lpa any, canChange bool) lpaDecisionsData { +func lpaDecisions(app appcontext.Data, lpa any, canChange bool) lpaDecisionsData { data := lpaDecisionsData{ App: app, CanChange: canChange, @@ -494,7 +495,7 @@ func lpaDecisions(app page.AppData, lpa any, canChange bool) lpaDecisionsData { return data } -func summaryRow(app page.AppData, label string, value any, changeLink, fullName string, canChange, summarisingSelf bool) map[string]any { +func summaryRow(app appcontext.Data, label string, value any, changeLink, fullName string, canChange, summarisingSelf bool) map[string]any { return map[string]any{ "App": app, "Label": label, diff --git a/internal/templatefn/fn_test.go b/internal/templatefn/fn_test.go index 1b6880cf65..1474d3c20e 100644 --- a/internal/templatefn/fn_test.go +++ b/internal/templatefn/fn_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/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/localize" @@ -68,13 +69,13 @@ func TestInputWithUnevenAttrs(t *testing.T) { } func TestButton(t *testing.T) { - appData := page.AppData{Path: "1"} + appData := appcontext.Data{Path: "1"} assert.Equal(t, map[string]any{"app": appData, "label": "label", "link": "a"}, button(appData, "label", "link", "a")) } func TestButtonWithUnevenAttrs(t *testing.T) { - appData := page.AppData{Path: "1"} + appData := appcontext.Data{Path: "1"} assert.Panics(t, func() { button(appData, "label", "a") }) } @@ -156,23 +157,23 @@ func TestInc(t *testing.T) { } func TestLink(t *testing.T) { - assert.Equal(t, "/dashboard", link(page.AppData{}, "/dashboard")) - assert.Equal(t, "/cy/dashboard", link(page.AppData{Lang: localize.Cy}, "/dashboard")) + assert.Equal(t, "/dashboard", link(appcontext.Data{}, "/dashboard")) + assert.Equal(t, "/cy/dashboard", link(appcontext.Data{Lang: localize.Cy}, "/dashboard")) } func TestFromLink(t *testing.T) { assert.Equal(t, "/lpa/lpa-id/your-details?from=/previous#f-first-names", - fromLink(page.AppData{LpaID: "lpa-id", Page: "/previous"}, page.Paths.YourDetails, "#f-first-names")) + fromLink(appcontext.Data{LpaID: "lpa-id", Page: "/previous"}, page.Paths.YourDetails, "#f-first-names")) assert.Equal(t, "/cy/attorney/lpa-id/confirm-your-details?from=/previous", - fromLink(page.AppData{LpaID: "lpa-id", Page: "/previous", Lang: localize.Cy}, page.Paths.Attorney.ConfirmYourDetails, "")) + fromLink(appcontext.Data{LpaID: "lpa-id", Page: "/previous", Lang: localize.Cy}, page.Paths.Attorney.ConfirmYourDetails, "")) } func TestFromLinkActor(t *testing.T) { uid := actoruid.New() assert.Equal(t, fmt.Sprintf("/lpa/lpa-id/your-details?from=/previous&id=%s#f-first-names", uid.String()), - fromLinkActor(page.AppData{LpaID: "lpa-id", Page: "/previous"}, page.Paths.YourDetails, uid, "#f-first-names")) + fromLinkActor(appcontext.Data{LpaID: "lpa-id", Page: "/previous"}, page.Paths.YourDetails, uid, "#f-first-names")) assert.Equal(t, "/cy/attorney/lpa-id/confirm-your-details?from=/previous&id="+uid.String(), - fromLinkActor(page.AppData{LpaID: "lpa-id", Page: "/previous", Lang: localize.Cy}, page.Paths.Attorney.ConfirmYourDetails, uid, "")) + fromLinkActor(appcontext.Data{LpaID: "lpa-id", Page: "/previous", Lang: localize.Cy}, page.Paths.Attorney.ConfirmYourDetails, uid, "")) } func TestCheckboxEq(t *testing.T) { @@ -187,7 +188,7 @@ func TestCheckboxEq(t *testing.T) { func TestTr(t *testing.T) { bundle, _ := localize.NewBundle("testdata/en.json") - app := page.AppData{ + app := appcontext.Data{ Localizer: bundle.For(localize.En), } @@ -197,7 +198,7 @@ func TestTr(t *testing.T) { func TestTrFormat(t *testing.T) { bundle, _ := localize.NewBundle("testdata/en.json") - app := page.AppData{ + app := appcontext.Data{ Localizer: bundle.For(localize.En), } @@ -207,7 +208,7 @@ func TestTrFormat(t *testing.T) { func TestTrHtml(t *testing.T) { bundle, _ := localize.NewBundle("testdata/en.json") - app := page.AppData{ + app := appcontext.Data{ Localizer: bundle.For(localize.En), } @@ -217,7 +218,7 @@ func TestTrHtml(t *testing.T) { func TestTrFormatHtml(t *testing.T) { bundle, _ := localize.NewBundle("testdata/en.json") - app := page.AppData{ + app := appcontext.Data{ Localizer: bundle.For(localize.En), } @@ -230,12 +231,12 @@ func TestTrFormatHtml(t *testing.T) { func TestTrCount(t *testing.T) { bundle, _ := localize.NewBundle("testdata/en.json", "testdata/cy.json") - enApp := page.AppData{Localizer: bundle.For(localize.En)} + enApp := appcontext.Data{Localizer: bundle.For(localize.En)} assert.Equal(t, "hi one", trCount(enApp, "with-count", 1)) assert.Equal(t, "hi other", trCount(enApp, "with-count", 2)) assert.Equal(t, "", trCount(enApp, "", 2)) - cyApp := page.AppData{Localizer: bundle.For(localize.Cy)} + cyApp := appcontext.Data{Localizer: bundle.For(localize.Cy)} assert.Equal(t, "cy one", trCount(cyApp, "with-count", 1)) assert.Equal(t, "cy two", trCount(cyApp, "with-count", 2)) assert.Equal(t, "cy few", trCount(cyApp, "with-count", 3)) @@ -248,7 +249,7 @@ func TestTrCount(t *testing.T) { func TestTrFormatCount(t *testing.T) { bundle, _ := localize.NewBundle("testdata/en.json") - enApp := page.AppData{ + enApp := appcontext.Data{ Localizer: bundle.For(localize.En), } @@ -257,7 +258,7 @@ func TestTrFormatCount(t *testing.T) { assert.Equal(t, "", trFormatCount(enApp, "", 2, "name", "Person")) bundle, _ = localize.NewBundle("testdata/cy.json") - cyApp := page.AppData{ + cyApp := appcontext.Data{ Localizer: bundle.For(localize.Cy), } @@ -281,8 +282,8 @@ func TestAddDays(t *testing.T) { func TestFormatDate(t *testing.T) { bundle, _ := localize.NewBundle("testdata/en.json", "testdata/cy.json") - appEn := page.AppData{Localizer: bundle.For(localize.En)} - appCy := page.AppData{Localizer: bundle.For(localize.Cy)} + appEn := appcontext.Data{Localizer: bundle.For(localize.En)} + appCy := appcontext.Data{Localizer: bundle.For(localize.Cy)} assert.Equal(t, "7 March 2020", formatDate(appEn, time.Date(2020, time.March, 7, 3, 4, 5, 6, time.UTC))) assert.Equal(t, "7 March 2020", formatDate(appEn, date.New("2020", "3", "7"))) @@ -293,8 +294,8 @@ func TestFormatDate(t *testing.T) { func TestFormatTime(t *testing.T) { bundle, _ := localize.NewBundle("testdata/en.json", "testdata/cy.json") - appEn := page.AppData{Localizer: bundle.For(localize.En)} - appCy := page.AppData{Localizer: bundle.For(localize.Cy)} + appEn := appcontext.Data{Localizer: bundle.For(localize.En)} + appCy := appcontext.Data{Localizer: bundle.For(localize.Cy)} assert.Equal(t, "3:04am", formatTime(appEn, time.Date(2020, time.March, 7, 3, 4, 0, 0, time.UTC))) @@ -303,8 +304,8 @@ func TestFormatTime(t *testing.T) { func TestFormatDateTime(t *testing.T) { bundle, _ := localize.NewBundle("testdata/en.json", "testdata/cy.json") - appEn := page.AppData{Localizer: bundle.For(localize.En)} - appCy := page.AppData{Localizer: bundle.For(localize.Cy)} + appEn := appcontext.Data{Localizer: bundle.For(localize.En)} + appCy := appcontext.Data{Localizer: bundle.For(localize.Cy)} assert.Equal(t, "7 March 2020 at 3:04am", formatDateTime(appEn, time.Date(2020, time.March, 7, 3, 4, 0, 0, time.UTC))) @@ -318,7 +319,7 @@ func TestFormatPhone(t *testing.T) { } func TestListAttorneysWithAttorneys(t *testing.T) { - app := page.AppData{SessionID: "abc", Page: "/here", ActorType: actor.TypeDonor, LpaID: "lpa-id"} + app := appcontext.Data{SessionID: "abc", Page: "/here", ActorType: actor.TypeDonor, LpaID: "lpa-id"} headingLevel := 3 uid1 := actoruid.New() uid2 := actoruid.New() @@ -431,12 +432,12 @@ func TestListAttorneysWithAttorneys(t *testing.T) { func TestListAttorneysWithIncorrectType(t *testing.T) { assert.Panics(t, func() { - listAttorneys(page.AppData{}, 5, "attorney", 3, true) + listAttorneys(appcontext.Data{}, 5, "attorney", 3, true) }) } func TestListPeopleToNotify(t *testing.T) { - app := page.AppData{SessionID: "abc"} + app := appcontext.Data{SessionID: "abc"} headingLevel := 3 peopleToNotify := donordata.PeopleToNotify{{}} @@ -453,7 +454,7 @@ func TestListPeopleToNotify(t *testing.T) { } func TestCard(t *testing.T) { - app := page.AppData{SessionID: "abc"} + app := appcontext.Data{SessionID: "abc"} want := map[string]interface{}{ "App": app, @@ -479,7 +480,7 @@ func TestPrintStruct(t *testing.T) { func TestPossessive(t *testing.T) { bundle, _ := localize.NewBundle("testdata/en.json") - app := page.AppData{ + app := appcontext.Data{ Localizer: bundle.For(localize.En), } @@ -488,7 +489,7 @@ func TestPossessive(t *testing.T) { func TestConcatAnd(t *testing.T) { bundle, _ := localize.NewBundle("testdata/en.json") - app := page.AppData{ + app := appcontext.Data{ Localizer: bundle.For(localize.En), } @@ -500,7 +501,7 @@ func TestConcatAnd(t *testing.T) { func TestConcatOr(t *testing.T) { bundle, _ := localize.NewBundle("testdata/en.json") - app := page.AppData{ + app := appcontext.Data{ Localizer: bundle.For(localize.En), } @@ -518,7 +519,7 @@ func TestConcatComma(t *testing.T) { } func TestContent(t *testing.T) { - app := page.AppData{SessionID: "abc"} + app := appcontext.Data{SessionID: "abc"} componentContent := "content" v := content(app, componentContent) @@ -528,7 +529,7 @@ func TestContent(t *testing.T) { } func TestNotificationBanner(t *testing.T) { - app := page.AppData{SessionID: "abc"} + app := appcontext.Data{SessionID: "abc"} assert.Equal(t, notificationBannerData{ App: app, @@ -546,7 +547,7 @@ func TestNotificationBanner(t *testing.T) { } func TestLpaDecisions(t *testing.T) { - app := page.AppData{SessionID: "abc"} + app := appcontext.Data{SessionID: "abc"} assert.Equal(t, lpaDecisionsData{ App: app, @@ -556,7 +557,7 @@ func TestLpaDecisions(t *testing.T) { } func TestLpaDecisionsWithDonorProvidedDetails(t *testing.T) { - app := page.AppData{SessionID: "abc"} + app := appcontext.Data{SessionID: "abc"} assert.Equal(t, lpaDecisionsData{ App: app, @@ -566,7 +567,7 @@ func TestLpaDecisionsWithDonorProvidedDetails(t *testing.T) { } func TestSummaryRow(t *testing.T) { - app := page.AppData{SessionID: "abc"} + app := appcontext.Data{SessionID: "abc"} label := "a-label" value := "aValue" changeLink := "a-link.com" diff --git a/internal/temporary/actor_type.go b/internal/temporary/actor_type.go deleted file mode 100644 index 9629350954..0000000000 --- a/internal/temporary/actor_type.go +++ /dev/null @@ -1,72 +0,0 @@ -package temporary - -type ActorType uint8 - -const ( - ActorTypeNone ActorType = iota - ActorTypeDonor - ActorTypeAttorney - ActorTypeReplacementAttorney - ActorTypeCertificateProvider - ActorTypePersonToNotify - ActorTypeAuthorisedSignatory - ActorTypeIndependentWitness - ActorTypeTrustCorporation - ActorTypeReplacementTrustCorporation - ActorTypeVoucher -) - -func (t ActorType) String() string { - switch t { - case ActorTypeDonor: - return "donor" - case ActorTypeAttorney: - return "attorney" - case ActorTypeReplacementAttorney: - return "replacementAttorney" - case ActorTypeCertificateProvider: - return "certificateProvider" - case ActorTypePersonToNotify: - return "personToNotify" - case ActorTypeAuthorisedSignatory: - return "signatory" - case ActorTypeIndependentWitness: - return "independentWitness" - case ActorTypeTrustCorporation: - return "trustCorporation" - case ActorTypeReplacementTrustCorporation: - return "replacementTrustCorporation" - case ActorTypeVoucher: - return "voucher" - default: - return "" - } -} - -type Types struct { - None ActorType - Donor ActorType - Attorney ActorType - ReplacementAttorney ActorType - TrustCorporation ActorType - ReplacementTrustCorporation ActorType - CertificateProvider ActorType - PersonToNotify ActorType - AuthorisedSignatory ActorType - IndependentWitness ActorType - Voucher ActorType -} - -var ActorTypes = Types{ - None: ActorTypeNone, - Donor: ActorTypeDonor, - Attorney: ActorTypeAttorney, - ReplacementAttorney: ActorTypeReplacementAttorney, - TrustCorporation: ActorTypeTrustCorporation, - ReplacementTrustCorporation: ActorTypeReplacementTrustCorporation, - CertificateProvider: ActorTypeCertificateProvider, - PersonToNotify: ActorTypePersonToNotify, - AuthorisedSignatory: ActorTypeAuthorisedSignatory, - IndependentWitness: ActorTypeIndependentWitness, - Voucher: ActorTypeVoucher, -}