Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Jul 24, 2024
2 parents c2add89 + 432d74f commit 84db283
Show file tree
Hide file tree
Showing 29 changed files with 173 additions and 655 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ministryofjustice/opg-modernising-lpa

go 1.22
go 1.22.5

require (
github.com/MicahParks/jwkset v0.5.18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type confirmDontWantToBeCertificateProviderData struct {
Lpa *lpastore.Lpa
}

func ConfirmDontWantToBeCertificateProvider(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, lpaStoreClient LpaStoreClient, donorStore DonorStore, certificateProviderStore CertificateProviderStore, notifyClient NotifyClient, appPublicURL string) page.Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error {
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 *actor.CertificateProviderProvidedDetails) error {
lpa, err := lpaStoreResolvingService.Get(r.Context())
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestGetConfirmDontWantToBeCertificateProvider(t *testing.T) {
}).
Return(nil)

err := ConfirmDontWantToBeCertificateProvider(template.Execute, lpaStoreResolvingService, nil, nil, nil, nil, "example.com")(testAppData, w, r)
err := ConfirmDontWantToBeCertificateProvider(template.Execute, lpaStoreResolvingService, nil, nil, nil, nil, "example.com")(testAppData, w, r, nil)
resp := w.Result()

assert.Nil(t, err)
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestGetConfirmDontWantToBeCertificateProviderErrors(t *testing.T) {

for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
err := ConfirmDontWantToBeCertificateProvider(tc.template().Execute, tc.lpaStoreResolvingService(), nil, nil, nil, nil, "example.com")(testAppData, w, r)
err := ConfirmDontWantToBeCertificateProvider(tc.template().Execute, tc.lpaStoreResolvingService(), nil, nil, nil, nil, "example.com")(testAppData, w, r, nil)
resp := w.Result()

assert.Equal(t, expectedError, err)
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestPostConfirmDontWantToBeCertificateProvider(t *testing.T) {
SendActorEmail(r.Context(), "[email protected]", "lpa-uid", tc.email).
Return(nil)

err := ConfirmDontWantToBeCertificateProvider(nil, lpaStoreResolvingService, tc.lpaStoreClient(), tc.donorStore(), certificateProviderStore, notifyClient, "example.com")(testAppData, w, r)
err := ConfirmDontWantToBeCertificateProvider(nil, lpaStoreResolvingService, tc.lpaStoreClient(), tc.donorStore(), certificateProviderStore, notifyClient, "example.com")(testAppData, w, r, nil)

resp := w.Result()

Expand Down Expand Up @@ -447,7 +447,7 @@ func TestPostConfirmDontWantToBeCertificateProviderErrors(t *testing.T) {

testAppData.Localizer = tc.localizer()

err := ConfirmDontWantToBeCertificateProvider(nil, tc.lpaStoreResolvingService(), tc.lpaStoreClient(), tc.donorStore(), tc.certificateProviderStore(), tc.notifyClient(), "example.com")(testAppData, w, r)
err := ConfirmDontWantToBeCertificateProvider(nil, tc.lpaStoreResolvingService(), tc.lpaStoreClient(), tc.donorStore(), tc.certificateProviderStore(), tc.notifyClient(), "example.com")(testAppData, w, r, nil)

resp := w.Result()

Expand Down
9 changes: 2 additions & 7 deletions internal/page/certificateprovider/confirm_your_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ type confirmYourDetailsData struct {
DetailComponentContent string
}

func ConfirmYourDetails(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, certificateProviderStore CertificateProviderStore) 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
}

func ConfirmYourDetails(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, certificateProviderStore CertificateProviderStore) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *actor.CertificateProviderProvidedDetails) error {
lpa, err := lpaStoreResolvingService.Get(r.Context())
if err != nil {
return err
Expand Down
45 changes: 5 additions & 40 deletions internal/page/certificateprovider/confirm_your_details_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ func TestGetConfirmYourDetails(t *testing.T) {
Get(r.Context()).
Return(lpa, nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(certificateProvider, nil)

template := newMockTemplate(t)
template.EXPECT().
Execute(w, &confirmYourDetailsData{
Expand All @@ -80,7 +75,7 @@ func TestGetConfirmYourDetails(t *testing.T) {
}).
Return(nil)

err := ConfirmYourDetails(template.Execute, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r)
err := ConfirmYourDetails(template.Execute, lpaStoreResolvingService, nil)(testAppData, w, r, certificateProvider)
resp := w.Result()

assert.Nil(t, err)
Expand All @@ -89,35 +84,16 @@ func TestGetConfirmYourDetails(t *testing.T) {
}
}

func TestGetConfirmYourDetailsWhenCertificateProviderStoreErrors(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequest(http.MethodGet, "/", nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(&actor.CertificateProviderProvidedDetails{}, expectedError)

err := ConfirmYourDetails(nil, nil, certificateProviderStore)(testAppData, w, r)

assert.Equal(t, expectedError, err)
}

func TestGetConfirmYourDetailsWhenLpaStoreResolvingServiceErrors(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequest(http.MethodGet, "/", nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(&actor.CertificateProviderProvidedDetails{}, nil)

lpaStoreResolvingService := newMockLpaStoreResolvingService(t)
lpaStoreResolvingService.EXPECT().
Get(r.Context()).
Return(&lpastore.Lpa{}, expectedError)

err := ConfirmYourDetails(nil, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r)
err := ConfirmYourDetails(nil, lpaStoreResolvingService, nil)(testAppData, w, r, &actor.CertificateProviderProvidedDetails{})

assert.Equal(t, expectedError, err)
}
Expand All @@ -126,11 +102,6 @@ func TestGetConfirmYourDetailsWhenTemplateErrors(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequest(http.MethodGet, "/", nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(&actor.CertificateProviderProvidedDetails{}, nil)

lpaStoreResolvingService := newMockLpaStoreResolvingService(t)
lpaStoreResolvingService.EXPECT().
Get(r.Context()).
Expand All @@ -141,7 +112,7 @@ func TestGetConfirmYourDetailsWhenTemplateErrors(t *testing.T) {
Execute(w, mock.Anything).
Return(expectedError)

err := ConfirmYourDetails(template.Execute, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r)
err := ConfirmYourDetails(template.Execute, lpaStoreResolvingService, nil)(testAppData, w, r, &actor.CertificateProviderProvidedDetails{})

assert.Equal(t, expectedError, err)
}
Expand All @@ -166,9 +137,6 @@ func TestPostConfirmYourDetails(t *testing.T) {
Return(&lpastore.Lpa{SignedAt: tc.signedAt}, nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(&actor.CertificateProviderProvidedDetails{LpaID: "lpa-id"}, nil)
certificateProviderStore.EXPECT().
Put(r.Context(), &actor.CertificateProviderProvidedDetails{
LpaID: "lpa-id",
Expand All @@ -178,7 +146,7 @@ func TestPostConfirmYourDetails(t *testing.T) {
}).
Return(nil)

err := ConfirmYourDetails(nil, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r)
err := ConfirmYourDetails(nil, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r, &actor.CertificateProviderProvidedDetails{LpaID: "lpa-id"})
resp := w.Result()

assert.Nil(t, err)
Expand All @@ -198,13 +166,10 @@ func TestPostConfirmYourDetailsWhenStoreErrors(t *testing.T) {
Return(&lpastore.Lpa{}, nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(&actor.CertificateProviderProvidedDetails{}, nil)
certificateProviderStore.EXPECT().
Put(r.Context(), mock.Anything).
Return(expectedError)

err := ConfirmYourDetails(nil, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r)
err := ConfirmYourDetails(nil, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r, &actor.CertificateProviderProvidedDetails{})
assert.Equal(t, expectedError, err)
}
9 changes: 2 additions & 7 deletions internal/page/certificateprovider/enter_date_of_birth.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,13 @@ type dateOfBirthForm struct {
IgnoreDobWarning string
}

func EnterDateOfBirth(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, certificateProviderStore CertificateProviderStore) page.Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error {
func EnterDateOfBirth(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, certificateProviderStore CertificateProviderStore) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *actor.CertificateProviderProvidedDetails) error {
lpa, err := lpaStoreResolvingService.Get(r.Context())
if err != nil {
return err
}

certificateProvider, err := certificateProviderStore.Get(r.Context())
if err != nil {
return err
}

data := &dateOfBirthData{
App: appData,
Lpa: lpa,
Expand Down
63 changes: 8 additions & 55 deletions internal/page/certificateprovider/enter_date_of_birth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ func TestGetEnterDateOfBirth(t *testing.T) {
Get(r.Context()).
Return(donor, nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(&actor.CertificateProviderProvidedDetails{}, nil)

template := newMockTemplate(t)
template.EXPECT().
Execute(w, &dateOfBirthData{
Expand All @@ -45,7 +40,7 @@ func TestGetEnterDateOfBirth(t *testing.T) {
}).
Return(nil)

err := EnterDateOfBirth(template.Execute, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r)
err := EnterDateOfBirth(template.Execute, lpaStoreResolvingService, nil)(testAppData, w, r, &actor.CertificateProviderProvidedDetails{})
resp := w.Result()

assert.Nil(t, err)
Expand All @@ -61,11 +56,6 @@ func TestGetEnterDateOfBirthFromStore(t *testing.T) {
Get(r.Context()).
Return(&lpastore.Lpa{}, nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(&actor.CertificateProviderProvidedDetails{DateOfBirth: date.New("1997", "1", "2")}, nil)

template := newMockTemplate(t)
template.EXPECT().
Execute(w, &dateOfBirthData{
Expand All @@ -77,7 +67,7 @@ func TestGetEnterDateOfBirthFromStore(t *testing.T) {
}).
Return(nil)

err := EnterDateOfBirth(template.Execute, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r)
err := EnterDateOfBirth(template.Execute, lpaStoreResolvingService, nil)(testAppData, w, r, &actor.CertificateProviderProvidedDetails{DateOfBirth: date.New("1997", "1", "2")})
resp := w.Result()

assert.Nil(t, err)
Expand All @@ -93,28 +83,7 @@ func TestGetEnterDateOfBirthWhenLpaStoreResolvingServiceErrors(t *testing.T) {
Get(r.Context()).
Return(&lpastore.Lpa{}, expectedError)

err := EnterDateOfBirth(nil, lpaStoreResolvingService, nil)(testAppData, w, r)
resp := w.Result()

assert.Equal(t, expectedError, err)
assert.Equal(t, http.StatusOK, resp.StatusCode)
}

func TestGetEnterDateOfBirthWhenCertificateProviderStoreErrors(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequest(http.MethodGet, "/", nil)

lpaStoreResolvingService := newMockLpaStoreResolvingService(t)
lpaStoreResolvingService.EXPECT().
Get(r.Context()).
Return(&lpastore.Lpa{}, nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(&actor.CertificateProviderProvidedDetails{}, expectedError)

err := EnterDateOfBirth(nil, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r)
err := EnterDateOfBirth(nil, lpaStoreResolvingService, nil)(testAppData, w, r, nil)
resp := w.Result()

assert.Equal(t, expectedError, err)
Expand All @@ -134,11 +103,6 @@ func TestGetEnterDateOfBirthWhenTemplateErrors(t *testing.T) {
Get(r.Context()).
Return(donor, nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(&actor.CertificateProviderProvidedDetails{}, nil)

template := newMockTemplate(t)
template.EXPECT().
Execute(w, &dateOfBirthData{
Expand All @@ -148,7 +112,7 @@ func TestGetEnterDateOfBirthWhenTemplateErrors(t *testing.T) {
}).
Return(expectedError)

err := EnterDateOfBirth(template.Execute, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r)
err := EnterDateOfBirth(template.Execute, lpaStoreResolvingService, nil)(testAppData, w, r, &actor.CertificateProviderProvidedDetails{})
resp := w.Result()

assert.Equal(t, expectedError, err)
Expand Down Expand Up @@ -229,14 +193,11 @@ func TestPostEnterDateOfBirth(t *testing.T) {
Return(&lpastore.Lpa{LpaID: "lpa-id"}, nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(tc.retrieved, nil)
certificateProviderStore.EXPECT().
Put(r.Context(), tc.updated).
Return(nil)

err := EnterDateOfBirth(nil, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r)
err := EnterDateOfBirth(nil, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r, tc.retrieved)
resp := w.Result()

assert.Nil(t, err)
Expand Down Expand Up @@ -264,9 +225,6 @@ func TestPostEnterDateOfBirthWhenProfessionalCertificateProvider(t *testing.T) {
Return(&lpastore.Lpa{LpaID: "lpa-id", CertificateProvider: lpastore.CertificateProvider{Relationship: actor.Professionally}}, nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(&actor.CertificateProviderProvidedDetails{LpaID: "lpa-id"}, nil)
certificateProviderStore.EXPECT().
Put(r.Context(), &actor.CertificateProviderProvidedDetails{
LpaID: "lpa-id",
Expand All @@ -277,7 +235,7 @@ func TestPostEnterDateOfBirthWhenProfessionalCertificateProvider(t *testing.T) {
}).
Return(nil)

err := EnterDateOfBirth(nil, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r)
err := EnterDateOfBirth(nil, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r, &actor.CertificateProviderProvidedDetails{LpaID: "lpa-id"})
resp := w.Result()

assert.Nil(t, err)
Expand Down Expand Up @@ -333,12 +291,7 @@ func TestPostEnterDateOfBirthWhenInputRequired(t *testing.T) {
})).
Return(nil)

certificateProviderStore := newMockCertificateProviderStore(t)
certificateProviderStore.EXPECT().
Get(r.Context()).
Return(&actor.CertificateProviderProvidedDetails{}, nil)

err := EnterDateOfBirth(template.Execute, lpaStoreResolvingService, certificateProviderStore)(testAppData, w, r)
err := EnterDateOfBirth(template.Execute, lpaStoreResolvingService, nil)(testAppData, w, r, &actor.CertificateProviderProvidedDetails{})
resp := w.Result()

assert.Nil(t, err)
Expand All @@ -364,7 +317,7 @@ func TestPostYourDetailsWhenLpaStoreResolvingServiceErrors(t *testing.T) {
Get(r.Context()).
Return(&lpastore.Lpa{}, expectedError)

err := EnterDateOfBirth(nil, lpaStoreResolvingService, nil)(testAppData, w, r)
err := EnterDateOfBirth(nil, lpaStoreResolvingService, nil)(testAppData, w, r, nil)
resp := w.Result()

assert.Equal(t, expectedError, err)
Expand Down
15 changes: 4 additions & 11 deletions internal/page/certificateprovider/guidance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ type guidanceData struct {
CertificateProvider *actor.CertificateProviderProvidedDetails
}

func Guidance(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, certificateProviderStore CertificateProviderStore) page.Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request) error {
func Guidance(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService) Handler {
return func(appData page.AppData, w http.ResponseWriter, r *http.Request, certificateProvider *actor.CertificateProviderProvidedDetails) error {
data := &guidanceData{
App: appData,
App: appData,
CertificateProvider: certificateProvider,
}

if lpaStoreResolvingService != nil {
Expand All @@ -31,14 +32,6 @@ func Guidance(tmpl template.Template, lpaStoreResolvingService LpaStoreResolving
data.Lpa = lpa
}

if certificateProviderStore != nil {
certificateProvider, err := certificateProviderStore.Get(r.Context())
if err != nil {
return err
}
data.CertificateProvider = certificateProvider
}

return tmpl(w, data)
}
}
Loading

0 comments on commit 84db283

Please sign in to comment.