diff --git a/internal/actor/certificate_provider_provided.go b/internal/actor/certificate_provider_provided.go index 95657f6293..a20b8c613d 100644 --- a/internal/actor/certificate_provider_provided.go +++ b/internal/actor/certificate_provider_provided.go @@ -1,12 +1,10 @@ package actor import ( - "fmt" "time" "github.com/ministryofjustice/opg-modernising-lpa/internal/date" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" - "github.com/ministryofjustice/opg-modernising-lpa/internal/place" ) // CertificateProviderProvidedDetails contains details about the certificate provider, provided by the certificate provider @@ -16,20 +14,8 @@ type CertificateProviderProvidedDetails struct { LpaID string // Tracking when CertificateProviderProvidedDetails is updated UpdatedAt time.Time - // First names of the certificate provider - FirstNames string - // Last name of the certificate provider - LastName string - // Email of the certificate provider - Email string - // Address of the certificate provider - Address place.Address - // Mobile number of the certificate provider - Mobile string // Date of birth of the certificate provider DateOfBirth date.Date - // The full name provided by the certificate provider. Only requested if the certificate provider indicates their name as provided by the applicant is incorrect - DeclaredFullName string // The method by which the certificate provider will complete identity checks IdentityOption identity.Option // Data returned from an identity check service @@ -40,13 +26,9 @@ type CertificateProviderProvidedDetails struct { Tasks CertificateProviderTasks } -func (c CertificateProviderProvidedDetails) FullName() string { - return fmt.Sprintf("%s %s", c.FirstNames, c.LastName) -} - -func (c *CertificateProviderProvidedDetails) CertificateProviderIdentityConfirmed() bool { +func (c *CertificateProviderProvidedDetails) CertificateProviderIdentityConfirmed(firstNames, lastName string) bool { return c.IdentityUserData.OK && c.IdentityUserData.Provider != identity.UnknownOption && - c.IdentityUserData.MatchName(c.FirstNames, c.LastName) && + c.IdentityUserData.MatchName(firstNames, lastName) && c.IdentityUserData.DateOfBirth.Equals(c.DateOfBirth) } diff --git a/internal/actor/certificate_provider_provided_test.go b/internal/actor/certificate_provider_provided_test.go index 48386e947e..33dfdf918c 100644 --- a/internal/actor/certificate_provider_provided_test.go +++ b/internal/actor/certificate_provider_provided_test.go @@ -7,24 +7,20 @@ import ( "github.com/stretchr/testify/assert" ) -func TestCertificateProviderProvidedFullName(t *testing.T) { - p := CertificateProviderProvidedDetails{FirstNames: "Bob Alan George", LastName: "Smith Jones-Doe"} - - assert.Equal(t, "Bob Alan George Smith Jones-Doe", p.FullName()) -} - func TestCertificateProviderProvidedIdentityConfirmed(t *testing.T) { testCases := map[string]struct { - cp *CertificateProviderProvidedDetails - expected bool + cp *CertificateProviderProvidedDetails + firstNames string + lastName string + expected bool }{ "set": { cp: &CertificateProviderProvidedDetails{ - FirstNames: "a", - LastName: "b", IdentityUserData: identity.UserData{OK: true, Provider: identity.OneLogin, FirstNames: "a", LastName: "b"}, }, - expected: true, + firstNames: "a", + lastName: "b", + expected: true, }, "missing provider": { cp: &CertificateProviderProvidedDetails{ @@ -40,11 +36,11 @@ func TestCertificateProviderProvidedIdentityConfirmed(t *testing.T) { }, "no match": { cp: &CertificateProviderProvidedDetails{ - FirstNames: "a", - LastName: "b", IdentityUserData: identity.UserData{Provider: identity.OneLogin}, }, - expected: false, + firstNames: "a", + lastName: "b", + expected: false, }, "none": { cp: &CertificateProviderProvidedDetails{}, @@ -54,7 +50,7 @@ func TestCertificateProviderProvidedIdentityConfirmed(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { - assert.Equal(t, tc.expected, tc.cp.CertificateProviderIdentityConfirmed()) + assert.Equal(t, tc.expected, tc.cp.CertificateProviderIdentityConfirmed(tc.firstNames, tc.lastName)) }) } } diff --git a/internal/page/certificateprovider/identity_with_one_login_callback.go b/internal/page/certificateprovider/identity_with_one_login_callback.go index aa30166e81..11faa89063 100644 --- a/internal/page/certificateprovider/identity_with_one_login_callback.go +++ b/internal/page/certificateprovider/identity_with_one_login_callback.go @@ -22,15 +22,20 @@ type identityWithOneLoginCallbackData struct { CouldNotConfirm bool } -func IdentityWithOneLoginCallback(tmpl template.Template, oneLoginClient OneLoginClient, sessionStore sesh.Store, certificateProviderStore CertificateProviderStore) page.Handler { +func IdentityWithOneLoginCallback(tmpl template.Template, oneLoginClient OneLoginClient, sessionStore sesh.Store, certificateProviderStore CertificateProviderStore, donorStore DonorStore) page.Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { certificateProvider, err := certificateProviderStore.Get(r.Context()) if err != nil { return err } + lpa, err := donorStore.GetAny(r.Context()) + if err != nil { + return err + } + if r.Method == http.MethodPost { - if certificateProvider.CertificateProviderIdentityConfirmed() { + if certificateProvider.CertificateProviderIdentityConfirmed(lpa.CertificateProvider.FirstNames, lpa.CertificateProvider.LastName) { return appData.Redirect(w, r, nil, page.Paths.CertificateProvider.ReadTheLpa.Format(certificateProvider.LpaID)) } else { return appData.Redirect(w, r, nil, page.Paths.CertificateProvider.SelectYourIdentityOptions1.Format(certificateProvider.LpaID)) @@ -39,7 +44,7 @@ func IdentityWithOneLoginCallback(tmpl template.Template, oneLoginClient OneLogi data := &identityWithOneLoginCallbackData{App: appData} - if certificateProvider.CertificateProviderIdentityConfirmed() { + if certificateProvider.CertificateProviderIdentityConfirmed(lpa.CertificateProvider.FirstNames, lpa.CertificateProvider.LastName) { data.FirstNames = certificateProvider.IdentityUserData.FirstNames data.LastName = certificateProvider.IdentityUserData.LastName data.DateOfBirth = certificateProvider.IdentityUserData.DateOfBirth @@ -77,7 +82,7 @@ func IdentityWithOneLoginCallback(tmpl template.Template, oneLoginClient OneLogi certificateProvider.IdentityUserData = userData certificateProvider.Tasks.ConfirmYourIdentity = actor.TaskCompleted - if certificateProvider.CertificateProviderIdentityConfirmed() { + if certificateProvider.CertificateProviderIdentityConfirmed(lpa.CertificateProvider.FirstNames, lpa.CertificateProvider.LastName) { data.FirstNames = userData.FirstNames data.LastName = userData.LastName data.DateOfBirth = userData.DateOfBirth diff --git a/internal/page/certificateprovider/identity_with_one_login_callback_test.go b/internal/page/certificateprovider/identity_with_one_login_callback_test.go index 36a240f3c0..33f429286e 100644 --- a/internal/page/certificateprovider/identity_with_one_login_callback_test.go +++ b/internal/page/certificateprovider/identity_with_one_login_callback_test.go @@ -27,11 +27,9 @@ func TestGetIdentityWithOneLoginCallback(t *testing.T) { certificateProviderStore := newMockCertificateProviderStore(t) certificateProviderStore. On("Get", r.Context()). - Return(&actor.CertificateProviderProvidedDetails{FirstNames: "John", LastName: "Doe"}, nil) + Return(&actor.CertificateProviderProvidedDetails{}, nil) certificateProviderStore. On("Put", r.Context(), &actor.CertificateProviderProvidedDetails{ - FirstNames: "John", - LastName: "Doe", IdentityUserData: userData, Tasks: actor.CertificateProviderTasks{ ConfirmYourIdentity: actor.TaskCompleted, @@ -39,6 +37,11 @@ func TestGetIdentityWithOneLoginCallback(t *testing.T) { }). Return(nil) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "John", LastName: "Doe"}}, nil) + sessionStore := newMockSessionStore(t) sessionStore. On("Get", mock.Anything, "params"). @@ -69,7 +72,7 @@ func TestGetIdentityWithOneLoginCallback(t *testing.T) { }). Return(nil) - err := IdentityWithOneLoginCallback(template.Execute, oneLoginClient, sessionStore, certificateProviderStore)(testAppData, w, r) + err := IdentityWithOneLoginCallback(template.Execute, oneLoginClient, sessionStore, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) @@ -221,11 +224,16 @@ func TestGetIdentityWithOneLoginCallbackWhenIdentityNotConfirmed(t *testing.T) { On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{}, nil) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{}}, nil) + sessionStore := tc.sessionStore(t) oneLoginClient := tc.oneLoginClient(t) template := tc.template(t, w) - err := IdentityWithOneLoginCallback(template.Execute, oneLoginClient, sessionStore, certificateProviderStore)(testAppData, w, r) + err := IdentityWithOneLoginCallback(template.Execute, oneLoginClient, sessionStore, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Equal(t, tc.error, err) @@ -234,7 +242,7 @@ func TestGetIdentityWithOneLoginCallbackWhenIdentityNotConfirmed(t *testing.T) { } } -func TestGetIdentityWithOneLoginCallbackWhenGetDataCertificateProviderStoreError(t *testing.T) { +func TestGetIdentityWithOneLoginCallbackWhenGetCertificateProviderStoreError(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/?code=a-code", nil) @@ -243,7 +251,26 @@ func TestGetIdentityWithOneLoginCallbackWhenGetDataCertificateProviderStoreError On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{}, expectedError) - err := IdentityWithOneLoginCallback(nil, nil, nil, certificateProviderStore)(testAppData, w, r) + err := IdentityWithOneLoginCallback(nil, nil, nil, certificateProviderStore, nil)(testAppData, w, r) + + assert.Equal(t, expectedError, err) +} + +func TestGetIdentityWithOneLoginCallbackWhenGetDonorStoreError(t *testing.T) { + w := httptest.NewRecorder() + r, _ := http.NewRequest(http.MethodGet, "/?code=a-code", nil) + + certificateProviderStore := newMockCertificateProviderStore(t) + certificateProviderStore. + On("Get", r.Context()). + Return(&actor.CertificateProviderProvidedDetails{}, nil) + + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{}}, expectedError) + + err := IdentityWithOneLoginCallback(nil, nil, nil, certificateProviderStore, donorStore)(testAppData, w, r) assert.Equal(t, expectedError, err) } @@ -261,6 +288,11 @@ func TestGetIdentityWithOneLoginCallbackWhenPutCertificateProviderStoreError(t * On("Put", r.Context(), mock.Anything). Return(expectedError) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{}}, nil) + sessionStore := newMockSessionStore(t) sessionStore. On("Get", mock.Anything, "params"). @@ -281,7 +313,7 @@ func TestGetIdentityWithOneLoginCallbackWhenPutCertificateProviderStoreError(t * On("ParseIdentityClaim", mock.Anything, mock.Anything). Return(identity.UserData{OK: true, Provider: identity.OneLogin}, nil) - err := IdentityWithOneLoginCallback(nil, oneLoginClient, sessionStore, certificateProviderStore)(testAppData, w, r) + err := IdentityWithOneLoginCallback(nil, oneLoginClient, sessionStore, certificateProviderStore, donorStore)(testAppData, w, r) assert.Equal(t, expectedError, err) } @@ -296,11 +328,14 @@ func TestGetIdentityWithOneLoginCallbackWhenReturning(t *testing.T) { certificateProviderStore. On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{ - FirstNames: "first-names", - LastName: "last-name", IdentityUserData: userData, }, nil) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "first-names", LastName: "last-name"}}, nil) + template := newMockTemplate(t) template. On("Execute", w, &identityWithOneLoginCallbackData{ @@ -311,7 +346,7 @@ func TestGetIdentityWithOneLoginCallbackWhenReturning(t *testing.T) { }). Return(nil) - err := IdentityWithOneLoginCallback(template.Execute, nil, nil, certificateProviderStore)(testAppData, w, r) + err := IdentityWithOneLoginCallback(template.Execute, nil, nil, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) @@ -330,7 +365,12 @@ func TestPostIdentityWithOneLoginCallback(t *testing.T) { IdentityUserData: identity.UserData{OK: true, Provider: identity.OneLogin}, }, nil) - err := IdentityWithOneLoginCallback(nil, nil, nil, certificateProviderStore)(testAppData, w, r) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{}}, nil) + + err := IdentityWithOneLoginCallback(nil, nil, nil, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) @@ -347,7 +387,12 @@ func TestPostIdentityWithOneLoginCallbackNotConfirmed(t *testing.T) { On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{LpaID: "lpa-id"}, nil) - err := IdentityWithOneLoginCallback(nil, nil, nil, certificateProviderStore)(testAppData, w, r) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{}}, nil) + + err := IdentityWithOneLoginCallback(nil, nil, nil, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) diff --git a/internal/page/certificateprovider/identity_with_todo.go b/internal/page/certificateprovider/identity_with_todo.go index 1c0fcda03e..713d8d9165 100644 --- a/internal/page/certificateprovider/identity_with_todo.go +++ b/internal/page/certificateprovider/identity_with_todo.go @@ -17,13 +17,18 @@ type identityWithTodoData struct { IdentityOption identity.Option } -func IdentityWithTodo(tmpl template.Template, now func() time.Time, identityOption identity.Option, certificateProviderStore CertificateProviderStore) page.Handler { +func IdentityWithTodo(tmpl template.Template, now func() time.Time, identityOption identity.Option, certificateProviderStore CertificateProviderStore, donorStore DonorStore) page.Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { certificateProvider, err := certificateProviderStore.Get(r.Context()) if err != nil { return err } + lpa, err := donorStore.GetAny(r.Context()) + if err != nil { + return err + } + if r.Method == http.MethodPost { return appData.Redirect(w, r, nil, page.Paths.CertificateProvider.ReadTheLpa.Format(certificateProvider.LpaID)) } @@ -31,8 +36,8 @@ func IdentityWithTodo(tmpl template.Template, now func() time.Time, identityOpti certificateProvider.IdentityUserData = identity.UserData{ OK: true, Provider: identityOption, - FirstNames: certificateProvider.FirstNames, - LastName: certificateProvider.LastName, + FirstNames: lpa.CertificateProvider.FirstNames, + LastName: lpa.CertificateProvider.LastName, DateOfBirth: certificateProvider.DateOfBirth, RetrievedAt: now(), } diff --git a/internal/page/certificateprovider/identity_with_todo_test.go b/internal/page/certificateprovider/identity_with_todo_test.go index 148cbfb157..c9b3acf587 100644 --- a/internal/page/certificateprovider/identity_with_todo_test.go +++ b/internal/page/certificateprovider/identity_with_todo_test.go @@ -21,11 +21,9 @@ func TestGetIdentityWithTodo(t *testing.T) { certificateProviderStore := newMockCertificateProviderStore(t) certificateProviderStore. On("Get", r.Context()). - Return(&actor.CertificateProviderProvidedDetails{FirstNames: "a", LastName: "b"}, nil) + Return(&actor.CertificateProviderProvidedDetails{}, nil) certificateProviderStore. On("Put", r.Context(), &actor.CertificateProviderProvidedDetails{ - FirstNames: "a", - LastName: "b", IdentityUserData: identity.UserData{ OK: true, Provider: identity.Passport, @@ -39,6 +37,11 @@ func TestGetIdentityWithTodo(t *testing.T) { }). Return(nil) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "a", LastName: "b"}}, nil) + template := newMockTemplate(t) template. On("Execute", w, &identityWithTodoData{ @@ -47,7 +50,7 @@ func TestGetIdentityWithTodo(t *testing.T) { }). Return(nil) - err := IdentityWithTodo(template.Execute, func() time.Time { return now }, identity.Passport, certificateProviderStore)(testAppData, w, r) + err := IdentityWithTodo(template.Execute, func() time.Time { return now }, identity.Passport, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) @@ -63,23 +66,46 @@ func TestGetIdentityWithTodoWhenCertificateProviderStoreGetErrors(t *testing.T) On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{}, expectedError) - err := IdentityWithTodo(nil, nil, identity.Passport, certificateProviderStore)(testAppData, w, r) + err := IdentityWithTodo(nil, nil, identity.Passport, certificateProviderStore, nil)(testAppData, w, r) + assert.Equal(t, expectedError, err) +} + +func TestGetIdentityWithTodoWhenDonorStoreGetErrors(t *testing.T) { + w := httptest.NewRecorder() + r, _ := http.NewRequest(http.MethodGet, "/", nil) + + certificateProviderStore := newMockCertificateProviderStore(t) + certificateProviderStore. + On("Get", r.Context()). + Return(&actor.CertificateProviderProvidedDetails{}, nil) + + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "a", LastName: "b"}}, expectedError) + + err := IdentityWithTodo(nil, nil, identity.Passport, certificateProviderStore, donorStore)(testAppData, w, r) assert.Equal(t, expectedError, err) } -func TestGetIdentityWithTodoWhenDonorStorePutErrors(t *testing.T) { +func TestGetIdentityWithTodoWhenCertificateProviderStorePutErrors(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/", nil) certificateProviderStore := newMockCertificateProviderStore(t) certificateProviderStore. On("Get", r.Context()). - Return(&actor.CertificateProviderProvidedDetails{FirstNames: "a", LastName: "b"}, nil) + Return(&actor.CertificateProviderProvidedDetails{}, nil) certificateProviderStore. On("Put", r.Context(), mock.Anything). Return(expectedError) - err := IdentityWithTodo(nil, time.Now, identity.Passport, certificateProviderStore)(testAppData, w, r) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "a", LastName: "b"}}, nil) + + err := IdentityWithTodo(nil, time.Now, identity.Passport, certificateProviderStore, donorStore)(testAppData, w, r) assert.Equal(t, expectedError, err) } @@ -92,7 +118,12 @@ func TestPostIdentityWithTodo(t *testing.T) { On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{LpaID: "lpa-id"}, nil) - err := IdentityWithTodo(nil, nil, identity.Passport, certificateProviderStore)(testAppData, w, r) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "a", LastName: "b"}}, nil) + + err := IdentityWithTodo(nil, nil, identity.Passport, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) diff --git a/internal/page/certificateprovider/identity_with_yoti.go b/internal/page/certificateprovider/identity_with_yoti.go index c73dc97a30..acfb529550 100644 --- a/internal/page/certificateprovider/identity_with_yoti.go +++ b/internal/page/certificateprovider/identity_with_yoti.go @@ -16,14 +16,19 @@ type identityWithYotiData struct { ScenarioID string } -func IdentityWithYoti(tmpl template.Template, sessionStore SessionStore, yotiClient YotiClient, certificateProviderStore CertificateProviderStore) page.Handler { +func IdentityWithYoti(tmpl template.Template, sessionStore SessionStore, yotiClient YotiClient, certificateProviderStore CertificateProviderStore, donorStore DonorStore) page.Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { certificateProvider, err := certificateProviderStore.Get(r.Context()) if err != nil { return err } - if certificateProvider.CertificateProviderIdentityConfirmed() || yotiClient.IsTest() { + lpa, err := donorStore.GetAny(r.Context()) + if err != nil { + return err + } + + if certificateProvider.CertificateProviderIdentityConfirmed(lpa.CertificateProvider.FirstNames, lpa.CertificateProvider.LastName) || yotiClient.IsTest() { return appData.Redirect(w, r, nil, page.Paths.CertificateProvider.IdentityWithYotiCallback.Format(certificateProvider.LpaID)) } diff --git a/internal/page/certificateprovider/identity_with_yoti_callback.go b/internal/page/certificateprovider/identity_with_yoti_callback.go index 992f7392be..85d0d07f1d 100644 --- a/internal/page/certificateprovider/identity_with_yoti_callback.go +++ b/internal/page/certificateprovider/identity_with_yoti_callback.go @@ -20,15 +20,20 @@ type identityWithYotiCallbackData struct { CouldNotConfirm bool } -func IdentityWithYotiCallback(tmpl template.Template, yotiClient YotiClient, certificateProviderStore CertificateProviderStore) page.Handler { +func IdentityWithYotiCallback(tmpl template.Template, yotiClient YotiClient, certificateProviderStore CertificateProviderStore, donorStore DonorStore) page.Handler { return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error { certificateProvider, err := certificateProviderStore.Get(r.Context()) if err != nil { return err } + lpa, err := donorStore.GetAny(r.Context()) + if err != nil { + return err + } + if r.Method == http.MethodPost { - if certificateProvider.CertificateProviderIdentityConfirmed() { + if certificateProvider.CertificateProviderIdentityConfirmed(lpa.CertificateProvider.FirstNames, lpa.CertificateProvider.LastName) { return appData.Redirect(w, r, nil, page.Paths.CertificateProvider.ReadTheLpa.Format(certificateProvider.LpaID)) } else { return appData.Redirect(w, r, nil, page.Paths.CertificateProvider.SelectYourIdentityOptions1.Format(certificateProvider.LpaID)) @@ -37,7 +42,7 @@ func IdentityWithYotiCallback(tmpl template.Template, yotiClient YotiClient, cer data := &identityWithYotiCallbackData{App: appData} - if certificateProvider.CertificateProviderIdentityConfirmed() { + if certificateProvider.CertificateProviderIdentityConfirmed(lpa.CertificateProvider.FirstNames, lpa.CertificateProvider.LastName) { data.FirstNames = certificateProvider.IdentityUserData.FirstNames data.LastName = certificateProvider.IdentityUserData.LastName data.DateOfBirth = certificateProvider.IdentityUserData.DateOfBirth @@ -53,7 +58,7 @@ func IdentityWithYotiCallback(tmpl template.Template, yotiClient YotiClient, cer certificateProvider.IdentityUserData = user - if certificateProvider.CertificateProviderIdentityConfirmed() { + if certificateProvider.CertificateProviderIdentityConfirmed(lpa.CertificateProvider.FirstNames, lpa.CertificateProvider.LastName) { if err := certificateProviderStore.Put(r.Context(), certificateProvider); err != nil { return err } diff --git a/internal/page/certificateprovider/identity_with_yoti_callback_test.go b/internal/page/certificateprovider/identity_with_yoti_callback_test.go index b1484c83d2..3d25c04bf8 100644 --- a/internal/page/certificateprovider/identity_with_yoti_callback_test.go +++ b/internal/page/certificateprovider/identity_with_yoti_callback_test.go @@ -23,15 +23,16 @@ func TestGetIdentityWithYotiCallback(t *testing.T) { certificateProviderStore := newMockCertificateProviderStore(t) certificateProviderStore. On("Get", r.Context()). - Return(&actor.CertificateProviderProvidedDetails{FirstNames: "first-name", LastName: "last-name"}, nil) + Return(&actor.CertificateProviderProvidedDetails{}, nil) certificateProviderStore. - On("Put", r.Context(), &actor.CertificateProviderProvidedDetails{ - FirstNames: "first-name", - LastName: "last-name", - IdentityUserData: userData, - }). + On("Put", r.Context(), &actor.CertificateProviderProvidedDetails{IdentityUserData: userData}). Return(nil) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "first-name", LastName: "last-name"}}, nil) + yotiClient := newMockYotiClient(t) yotiClient.On("User", "a-token").Return(userData, nil) @@ -45,7 +46,7 @@ func TestGetIdentityWithYotiCallback(t *testing.T) { }). Return(nil) - err := IdentityWithYotiCallback(template.Execute, yotiClient, certificateProviderStore)(testAppData, w, r) + err := IdentityWithYotiCallback(template.Execute, yotiClient, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) @@ -120,10 +121,15 @@ func TestGetIdentityWithYotiCallbackWhenIdentityNotConfirmed(t *testing.T) { On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{}, nil) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{}}, nil) + yotiClient := tc.yotiClient(t) template := tc.template(t, w) - err := IdentityWithYotiCallback(template.Execute, yotiClient, certificateProviderStore)(testAppData, w, r) + err := IdentityWithYotiCallback(template.Execute, yotiClient, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Equal(t, tc.error, err) @@ -141,7 +147,26 @@ func TestGetIdentityWithYotiCallbackWhenGetCertificateProviderStoreError(t *test On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{}, expectedError) - err := IdentityWithYotiCallback(nil, nil, certificateProviderStore)(testAppData, w, r) + err := IdentityWithYotiCallback(nil, nil, certificateProviderStore, nil)(testAppData, w, r) + + assert.Equal(t, expectedError, err) +} + +func TestGetIdentityWithYotiCallbackWhenGetDonorStoreError(t *testing.T) { + w := httptest.NewRecorder() + r, _ := http.NewRequest(http.MethodGet, "/?token=a-token", nil) + + certificateProviderStore := newMockCertificateProviderStore(t) + certificateProviderStore. + On("Get", r.Context()). + Return(&actor.CertificateProviderProvidedDetails{}, nil) + + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "first-name", LastName: "last-name"}}, expectedError) + + err := IdentityWithYotiCallback(nil, nil, certificateProviderStore, donorStore)(testAppData, w, r) assert.Equal(t, expectedError, err) } @@ -155,19 +180,20 @@ func TestGetIdentityWithYotiCallbackWhenPutCertificateProviderStoreError(t *test certificateProviderStore := newMockCertificateProviderStore(t) certificateProviderStore. On("Get", r.Context()). - Return(&actor.CertificateProviderProvidedDetails{FirstNames: "first-name", LastName: "last-name"}, nil) + Return(&actor.CertificateProviderProvidedDetails{}, nil) certificateProviderStore. - On("Put", r.Context(), &actor.CertificateProviderProvidedDetails{ - FirstNames: "first-name", - LastName: "last-name", - IdentityUserData: userData, - }). + On("Put", r.Context(), &actor.CertificateProviderProvidedDetails{IdentityUserData: userData}). Return(expectedError) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "first-name", LastName: "last-name"}}, nil) + yotiClient := newMockYotiClient(t) yotiClient.On("User", "a-token").Return(userData, nil) - err := IdentityWithYotiCallback(nil, yotiClient, certificateProviderStore)(testAppData, w, r) + err := IdentityWithYotiCallback(nil, yotiClient, certificateProviderStore, donorStore)(testAppData, w, r) assert.Equal(t, expectedError, err) } @@ -181,11 +207,12 @@ func TestGetIdentityWithYotiCallbackWhenReturning(t *testing.T) { certificateProviderStore := newMockCertificateProviderStore(t) certificateProviderStore. On("Get", r.Context()). - Return(&actor.CertificateProviderProvidedDetails{ - FirstNames: "first-name", - LastName: "last-name", - IdentityUserData: userData, - }, nil) + Return(&actor.CertificateProviderProvidedDetails{IdentityUserData: userData}, nil) + + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "first-name", LastName: "last-name"}}, nil) template := newMockTemplate(t) template. @@ -197,7 +224,7 @@ func TestGetIdentityWithYotiCallbackWhenReturning(t *testing.T) { }). Return(nil) - err := IdentityWithYotiCallback(template.Execute, nil, certificateProviderStore)(testAppData, w, r) + err := IdentityWithYotiCallback(template.Execute, nil, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) @@ -213,10 +240,15 @@ func TestPostIdentityWithYotiCallback(t *testing.T) { On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{ LpaID: "lpa-id", - IdentityUserData: identity.UserData{OK: true, Provider: identity.EasyID}, + IdentityUserData: identity.UserData{OK: true, Provider: identity.EasyID, FirstNames: "first-name", LastName: "last-name"}, }, nil) - err := IdentityWithYotiCallback(nil, nil, certificateProviderStore)(testAppData, w, r) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "first-name", LastName: "last-name"}}, nil) + + err := IdentityWithYotiCallback(nil, nil, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) @@ -233,7 +265,12 @@ func TestPostIdentityWithYotiCallbackNotConfirmed(t *testing.T) { On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{LpaID: "lpa-id"}, nil) - err := IdentityWithYotiCallback(nil, nil, certificateProviderStore)(testAppData, w, r) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "first-name", LastName: "last-name"}}, nil) + + err := IdentityWithYotiCallback(nil, nil, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) diff --git a/internal/page/certificateprovider/identity_with_yoti_test.go b/internal/page/certificateprovider/identity_with_yoti_test.go index cef5e23147..739fbe7f26 100644 --- a/internal/page/certificateprovider/identity_with_yoti_test.go +++ b/internal/page/certificateprovider/identity_with_yoti_test.go @@ -23,6 +23,11 @@ func TestGetIdentityWithYoti(t *testing.T) { On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{LpaID: "lpa-id"}, nil) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "first-names", LastName: "last-name"}}, nil) + sessionStore := newMockSessionStore(t) session := sessions.NewSession(sessionStore, "yoti") session.Options = &sessions.Options{ @@ -53,7 +58,7 @@ func TestGetIdentityWithYoti(t *testing.T) { }). Return(nil) - err := IdentityWithYoti(template.Execute, sessionStore, yotiClient, certificateProviderStore)(testAppData, w, r) + err := IdentityWithYoti(template.Execute, sessionStore, yotiClient, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) @@ -69,6 +74,11 @@ func TestGetIdentityWithYotiWhenSessionErrors(t *testing.T) { On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{LpaID: "lpa-id"}, nil) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "first-names", LastName: "last-name"}}, nil) + yotiClient := newMockYotiClient(t) yotiClient.On("IsTest").Return(false) @@ -77,7 +87,7 @@ func TestGetIdentityWithYotiWhenSessionErrors(t *testing.T) { On("Save", r, w, mock.Anything). Return(expectedError) - err := IdentityWithYoti(nil, sessionStore, yotiClient, certificateProviderStore)(testAppData, w, r) + err := IdentityWithYoti(nil, sessionStore, yotiClient, certificateProviderStore, donorStore)(testAppData, w, r) assert.Equal(t, expectedError, err) } @@ -91,10 +101,15 @@ func TestGetIdentityWithYotiWhenAlreadyProvided(t *testing.T) { On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{ LpaID: "lpa-id", - IdentityUserData: identity.UserData{OK: true, Provider: identity.EasyID}, + IdentityUserData: identity.UserData{OK: true, Provider: identity.EasyID, FirstNames: "first-names", LastName: "last-name"}, }, nil) - err := IdentityWithYoti(nil, nil, nil, certificateProviderStore)(testAppData, w, r) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "first-names", LastName: "last-name"}}, nil) + + err := IdentityWithYoti(nil, nil, nil, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) @@ -111,10 +126,15 @@ func TestGetIdentityWithYotiWhenTest(t *testing.T) { On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{LpaID: "lpa-id"}, nil) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "first-names", LastName: "last-name"}}, nil) + yotiClient := newMockYotiClient(t) yotiClient.On("IsTest").Return(true) - err := IdentityWithYoti(nil, nil, yotiClient, certificateProviderStore)(testAppData, w, r) + err := IdentityWithYoti(nil, nil, yotiClient, certificateProviderStore, donorStore)(testAppData, w, r) resp := w.Result() assert.Nil(t, err) @@ -131,7 +151,26 @@ func TestGetIdentityWithYotiWhenCertificateProviderStoreError(t *testing.T) { On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{}, expectedError) - err := IdentityWithYoti(nil, nil, nil, certificateProviderStore)(testAppData, w, r) + err := IdentityWithYoti(nil, nil, nil, certificateProviderStore, nil)(testAppData, w, r) + + assert.Equal(t, expectedError, err) +} + +func TestGetIdentityWithYotiWhenDonorStoreError(t *testing.T) { + w := httptest.NewRecorder() + r, _ := http.NewRequest(http.MethodGet, "/", nil) + + certificateProviderStore := newMockCertificateProviderStore(t) + certificateProviderStore. + On("Get", r.Context()). + Return(&actor.CertificateProviderProvidedDetails{}, nil) + + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{}}, expectedError) + + err := IdentityWithYoti(nil, nil, nil, certificateProviderStore, donorStore)(testAppData, w, r) assert.Equal(t, expectedError, err) } @@ -145,6 +184,11 @@ func TestGetIdentityWithYotiWhenTemplateError(t *testing.T) { On("Get", r.Context()). Return(&actor.CertificateProviderProvidedDetails{}, nil) + donorStore := newMockDonorStore(t) + donorStore. + On("GetAny", r.Context()). + Return(&page.Lpa{CertificateProvider: actor.CertificateProvider{FirstNames: "first-names", LastName: "last-name"}}, nil) + sessionStore := newMockSessionStore(t) sessionStore. On("Save", r, w, mock.Anything). @@ -160,7 +204,7 @@ func TestGetIdentityWithYotiWhenTemplateError(t *testing.T) { On("Execute", w, mock.Anything). Return(expectedError) - err := IdentityWithYoti(template.Execute, sessionStore, yotiClient, certificateProviderStore)(testAppData, w, r) + err := IdentityWithYoti(template.Execute, sessionStore, yotiClient, certificateProviderStore, donorStore)(testAppData, w, r) assert.Equal(t, expectedError, err) } diff --git a/internal/page/certificateprovider/register.go b/internal/page/certificateprovider/register.go index cb8e417d72..ddccd3e73a 100644 --- a/internal/page/certificateprovider/register.go +++ b/internal/page/certificateprovider/register.go @@ -126,13 +126,13 @@ func Register( handleCertificateProvider(page.Paths.CertificateProvider.YourChosenIdentityOptions, YourChosenIdentityOptions(tmpls.Get("your_chosen_identity_options.gohtml"), certificateProviderStore)) handleCertificateProvider(page.Paths.CertificateProvider.IdentityWithYoti, - IdentityWithYoti(tmpls.Get("identity_with_yoti.gohtml"), sessionStore, yotiClient, certificateProviderStore)) + IdentityWithYoti(tmpls.Get("identity_with_yoti.gohtml"), sessionStore, yotiClient, certificateProviderStore, donorStore)) handleCertificateProvider(page.Paths.CertificateProvider.IdentityWithYotiCallback, - IdentityWithYotiCallback(tmpls.Get("identity_with_yoti_callback.gohtml"), yotiClient, certificateProviderStore)) + IdentityWithYotiCallback(tmpls.Get("identity_with_yoti_callback.gohtml"), yotiClient, certificateProviderStore, donorStore)) handleCertificateProvider(page.Paths.CertificateProvider.IdentityWithOneLogin, IdentityWithOneLogin(logger, oneLoginClient, sessionStore, random.String)) handleCertificateProvider(page.Paths.CertificateProvider.IdentityWithOneLoginCallback, - IdentityWithOneLoginCallback(tmpls.Get("identity_with_one_login_callback.gohtml"), oneLoginClient, sessionStore, certificateProviderStore)) + IdentityWithOneLoginCallback(tmpls.Get("identity_with_one_login_callback.gohtml"), oneLoginClient, sessionStore, certificateProviderStore, donorStore)) for path, identityOption := range map[page.CertificateProviderPath]identity.Option{ page.Paths.CertificateProvider.IdentityWithPassport: identity.Passport, @@ -142,7 +142,7 @@ func Register( page.Paths.CertificateProvider.IdentityWithOnlineBankAccount: identity.OnlineBankAccount, } { handleCertificateProvider(path, - IdentityWithTodo(tmpls.Get("identity_with_todo.gohtml"), time.Now, identityOption, certificateProviderStore)) + IdentityWithTodo(tmpls.Get("identity_with_todo.gohtml"), time.Now, identityOption, certificateProviderStore, donorStore)) } handleCertificateProvider(page.Paths.CertificateProvider.ReadTheLpa, diff --git a/internal/page/data.go b/internal/page/data.go index ddf098781c..16c1f3d947 100644 --- a/internal/page/data.go +++ b/internal/page/data.go @@ -180,8 +180,6 @@ type Lpa struct { // FeeType is the type of fee the user is applying for FeeType FeeType - // EvidenceFormAddress is where the form to provide evidence for a fee reduction will be sent - EvidenceFormAddress place.Address // EvidenceKeys is the S3 keys for uploaded evidence with a record of when it's been sent to caseworkers EvidenceKeys []Evidence diff --git a/internal/page/donor/witnessing_as_certificate_provider.go b/internal/page/donor/witnessing_as_certificate_provider.go index 0ed6323a9b..2bbf242cfc 100644 --- a/internal/page/donor/witnessing_as_certificate_provider.go +++ b/internal/page/donor/witnessing_as_certificate_provider.go @@ -67,7 +67,7 @@ func WitnessingAsCertificateProvider(tmpl template.Template, donorStore DonorSto return err } - if err == nil && certificateProvider.CertificateProviderIdentityConfirmed() { + if err == nil && certificateProvider.CertificateProviderIdentityConfirmed(lpa.CertificateProvider.FirstNames, lpa.CertificateProvider.LastName) { if err := shareCodeSender.SendCertificateProvider(r.Context(), notify.CertificateProviderReturnEmail, appData, false, lpa); err != nil { return err } diff --git a/internal/page/donor/witnessing_as_certificate_provider_test.go b/internal/page/donor/witnessing_as_certificate_provider_test.go index 5a8828edb4..dc12c5c83c 100644 --- a/internal/page/donor/witnessing_as_certificate_provider_test.go +++ b/internal/page/donor/witnessing_as_certificate_provider_test.go @@ -95,7 +95,6 @@ func TestPostWitnessingAsCertificateProvider(t *testing.T) { }, "identity not confirmed": { certificateProvider: &actor.CertificateProviderProvidedDetails{ - FirstNames: "Fred", IdentityUserData: identity.UserData{ FirstNames: "Barry", }, @@ -120,6 +119,7 @@ func TestPostWitnessingAsCertificateProvider(t *testing.T) { ID: "lpa-id", DonorIdentityUserData: identity.UserData{OK: true, Provider: identity.OneLogin}, CertificateProviderCodes: page.WitnessCodes{{Code: "1234", Created: now}}, + CertificateProvider: actor.CertificateProvider{FirstNames: "Fred"}, WitnessedByCertificateProviderAt: now, SignedAt: now, }). @@ -139,6 +139,7 @@ func TestPostWitnessingAsCertificateProvider(t *testing.T) { ID: "lpa-id", DonorIdentityUserData: identity.UserData{OK: true, Provider: identity.OneLogin}, CertificateProviderCodes: page.WitnessCodes{{Code: "1234", Created: now}}, + CertificateProvider: actor.CertificateProvider{FirstNames: "Fred"}, }) resp := w.Result() diff --git a/internal/page/fixtures/testing_start.go b/internal/page/fixtures/testing_start.go index 375df503c8..7721695a8c 100644 --- a/internal/page/fixtures/testing_start.go +++ b/internal/page/fixtures/testing_start.go @@ -555,8 +555,7 @@ func TestingStart(store sesh.Store, donorStore DonorStore, randomString func(int } if signedByCertificateProvider || asCertificateProvider == "certified" { - certificateProvider.Mobile = testMobile - certificateProvider.Email = testEmail + lpa.CertificateProvider.Email = testMobile certificateProvider.Certificate = actor.Certificate{ AgreeToStatement: true, Agreed: time.Date(2023, time.January, 2, 3, 4, 5, 6, time.UTC), @@ -564,8 +563,7 @@ func TestingStart(store sesh.Store, donorStore DonorStore, randomString func(int } if signedByCertificateProvider { - certificateProvider.Mobile = testMobile - certificateProvider.Email = testEmail + lpa.CertificateProvider.Email = testMobile certificateProvider.DateOfBirth = date.New("2000", "1", "2") certificateProvider.Tasks.ConfirmYourDetails = actor.TaskCompleted } diff --git a/web/assets/data-loss-warning.js b/web/assets/data-loss-warning.js index e9a0354051..30c878fcf7 100644 --- a/web/assets/data-loss-warning.js +++ b/web/assets/data-loss-warning.js @@ -9,7 +9,6 @@ export class DataLossWarning { if (this.dialog && this.dialogOverlay && this.returnToTaskListButton) { this.formValuesOnPageLoad = this.getEncodedStringifiedFormValues() this.formValuesPriorToPageLoad = this.getFormValuesFromCookie() - this.registerListeners() } } @@ -60,10 +59,10 @@ export class DataLossWarning { e.preventDefault() } }) + document.getElementById('save-and-continue-btn').addEventListener('click', this.addFormValuesToCookie.bind(this)) document.getElementById('return-to-tasklist-btn').addEventListener('click', this.toggleDialogVisibility.bind(this)) document.getElementById('back-to-page-dialog-btn').addEventListener('click', this.toggleDialogVisibility.bind(this)) document.getElementById('return-to-task-list-dialog-btn').addEventListener('click', this.toggleDialogVisibility.bind(this)) - document.getElementById('save-and-continue-btn').addEventListener('click', () => { this.addFormValuesToCookie() }) } handleTrapFocus(e) { @@ -96,13 +95,13 @@ export class DataLossWarning { addFormValuesToCookie() { // so the cookie isn't available for longer than required - const tenSecondsFutureDate = new Date(); - tenSecondsFutureDate.setTime(tenSecondsFutureDate.getTime() + 10) + const tenSecondsFutureDate = new Date() + tenSecondsFutureDate.setSeconds(tenSecondsFutureDate.getSeconds() + 10) - document.cookie = `formValues=${this.getEncodedStringifiedFormValues()}; expires=${tenSecondsFutureDate.toUTCString()}; SameSite=Lax; Secure`; + document.cookie = `formValues=${this.getEncodedStringifiedFormValues()}; expires=${tenSecondsFutureDate.toUTCString()}; SameSite=Lax; Secure` } getFormValuesFromCookie() { - return document.cookie.split("; ").find((row) => row.startsWith("formValues="))?.split("=")[1]; + return document.cookie.split("; ").find((row) => row.startsWith("formValues="))?.split("=")[1] } } diff --git a/web/assets/main.js b/web/assets/main.js index 0cbc116a31..b3a3198a43 100644 --- a/web/assets/main.js +++ b/web/assets/main.js @@ -5,51 +5,60 @@ import $ from 'jquery'; import { CrossServiceHeader } from './service-header'; import { DataLossWarning } from './data-loss-warning'; -window.$ = $ +// Account for DOMContentLoaded firing before JS runs +if (document.readyState !== "loading") { + init() +} else { + document.addEventListener('DOMContentLoaded', init) +} -GOVUKFrontend.initAll(); -MOJFrontend.initAll(); +function init() { + window.$ = $ -const header = document.querySelector("[data-module='one-login-header']"); -if (header) { - new CrossServiceHeader(header).init(); -} + GOVUKFrontend.initAll(); + MOJFrontend.initAll(); -new DataLossWarning().init() + const header = document.querySelector("[data-module='one-login-header']"); + if (header) { + new CrossServiceHeader(header).init(); + } -const backLink = document.querySelector('.govuk-back-link'); -if (backLink) { - backLink.addEventListener('click', function (e) { - window.history.back(); - e.preventDefault(); - }, false); -} + new DataLossWarning().init() -function metaContent(name) { - return document.querySelector(`meta[name=${name}]`).content; -} + const backLink = document.querySelector('.govuk-back-link'); + if (backLink) { + backLink.addEventListener('click', function (e) { + window.history.back(); + e.preventDefault(); + }, false); + } + + function metaContent(name) { + return document.querySelector(`meta[name=${name}]`).content; + } + + try { + const config = { + sessionSampleRate: 1, + guestRoleArn: metaContent('rum-guest-role-arn'), + identityPoolId: metaContent('rum-identity-pool-id'), + endpoint: metaContent('rum-endpoint'), + telemetries: ["http", "errors", "performance"], + allowCookies: true, + enableXRay: true + }; + + const APPLICATION_ID = metaContent('rum-application-id'); + const APPLICATION_VERSION = '1.0.0'; + const APPLICATION_REGION = metaContent('rum-application-region'); -try { - const config = { - sessionSampleRate: 1, - guestRoleArn: metaContent('rum-guest-role-arn'), - identityPoolId: metaContent('rum-identity-pool-id'), - endpoint: metaContent('rum-endpoint'), - telemetries: ["http", "errors", "performance"], - allowCookies: true, - enableXRay: true - }; - - const APPLICATION_ID = metaContent('rum-application-id'); - const APPLICATION_VERSION = '1.0.0'; - const APPLICATION_REGION = metaContent('rum-application-region'); - - const awsRum = new AwsRum( - APPLICATION_ID, - APPLICATION_VERSION, - APPLICATION_REGION, - config - ); -} catch (error) { - // Ignore errors thrown during CloudWatch RUM web client initialization + const awsRum = new AwsRum( + APPLICATION_ID, + APPLICATION_VERSION, + APPLICATION_REGION, + config + ); + } catch (error) { + // Ignore errors thrown during CloudWatch RUM web client initialization + } }