Skip to content

Commit

Permalink
Merge pull request #1755 from ministryofjustice/MLPAB-2199-attorney-o…
Browse files Browse the repository at this point in the history
…pt-out-email

MLPAB-2199 Add email for attorney opt out
  • Loading branch information
hawx authored Feb 4, 2025
2 parents e35020c + e0ea3e3 commit e2ba1eb
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 50 deletions.
1 change: 0 additions & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ func App(
lpaStoreClient,
lpaStoreResolvingService,
notifyClient,
appPublicURL,
)

donorpage.Register(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type confirmDontWantToBeAttorneyData struct {
Lpa *lpadata.Lpa
}

func ConfirmDontWantToBeAttorney(tmpl template.Template, attorneyStore AttorneyStore, notifyClient NotifyClient, appPublicURL string, lpaStoreClient LpaStoreClient) Handler {
func ConfirmDontWantToBeAttorney(tmpl template.Template, attorneyStore AttorneyStore, notifyClient NotifyClient, lpaStoreClient LpaStoreClient) Handler {
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided, lpa *lpadata.Lpa) error {
data := &confirmDontWantToBeAttorneyData{
App: appData,
Expand All @@ -34,12 +34,9 @@ func ConfirmDontWantToBeAttorney(tmpl template.Template, attorneyStore AttorneyS
}

email := notify.AttorneyOptedOutEmail{
Greeting: notifyClient.EmailGreeting(lpa),
AttorneyFullName: fullName,
DonorFullName: lpa.Donor.FullName(),
LpaType: appData.Localizer.T(lpa.Type.String()),
LpaUID: lpa.LpaUID,
DonorStartPageURL: appPublicURL + page.PathStart.Format(),
Greeting: notifyClient.EmailGreeting(lpa),
AttorneyFullName: fullName,
LpaType: appData.Localizer.T(lpa.Type.String()),
}

if err := notifyClient.SendActorEmail(r.Context(), notify.ToLpaDonor(lpa), lpa.LpaUID, email); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type confirmDontWantToBeAttorneyDataLoggedOut struct {
Lpa *lpadata.Lpa
}

func ConfirmDontWantToBeAttorneyLoggedOut(tmpl template.Template, shareCodeStore ShareCodeStore, lpaStoreResolvingService LpaStoreResolvingService, sessionStore SessionStore, notifyClient NotifyClient, appPublicURL string, lpaStoreClient LpaStoreClient) page.Handler {
func ConfirmDontWantToBeAttorneyLoggedOut(tmpl template.Template, shareCodeStore ShareCodeStore, lpaStoreResolvingService LpaStoreResolvingService, sessionStore SessionStore, notifyClient NotifyClient, lpaStoreClient LpaStoreClient) page.Handler {
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request) error {
session, err := sessionStore.LpaData(r)
if err != nil {
Expand Down Expand Up @@ -54,12 +54,9 @@ func ConfirmDontWantToBeAttorneyLoggedOut(tmpl template.Template, shareCodeStore
}

email := notify.AttorneyOptedOutEmail{
Greeting: notifyClient.EmailGreeting(lpa),
AttorneyFullName: fullName,
DonorFullName: lpa.Donor.FullName(),
LpaType: appData.Localizer.T(lpa.Type.String()),
LpaUID: lpa.LpaUID,
DonorStartPageURL: appPublicURL + page.PathStart.Format(),
Greeting: notifyClient.EmailGreeting(lpa),
AttorneyFullName: fullName,
LpaType: appData.Localizer.T(lpa.Type.String()),
}

if err := notifyClient.SendActorEmail(ctx, notify.ToLpaDonor(lpa), lpa.LpaUID, email); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestGetConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) {
}).
Return(nil)

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

assert.Nil(t, err)
Expand All @@ -60,7 +60,7 @@ func TestGetConfirmDontWantToBeAttorneyLoggedOutWhenSessionStoreErrors(t *testin
LpaData(r).
Return(&sesh.LpaDataSession{}, expectedError)

err := ConfirmDontWantToBeAttorneyLoggedOut(nil, nil, nil, sessionStore, nil, "example.com", nil)(testAppData, w, r)
err := ConfirmDontWantToBeAttorneyLoggedOut(nil, nil, nil, sessionStore, nil, nil)(testAppData, w, r)
resp := w.Result()

assert.Equal(t, expectedError, err)
Expand All @@ -81,7 +81,7 @@ func TestGetConfirmDontWantToBeAttorneyLoggedOutWhenLpaStoreResolvingServiceErro
Get(mock.Anything).
Return(&lpadata.Lpa{}, expectedError)

err := ConfirmDontWantToBeAttorneyLoggedOut(nil, nil, lpaStoreResolvingService, sessionStore, nil, "example.com", nil)(testAppData, w, r)
err := ConfirmDontWantToBeAttorneyLoggedOut(nil, nil, lpaStoreResolvingService, sessionStore, nil, nil)(testAppData, w, r)
resp := w.Result()

assert.Equal(t, expectedError, err)
Expand All @@ -107,7 +107,7 @@ func TestGetConfirmDontWantToBeAttorneyLoggedOutWhenTemplateErrors(t *testing.T)
Execute(mock.Anything, mock.Anything).
Return(expectedError)

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

assert.Equal(t, expectedError, err)
Expand Down Expand Up @@ -205,12 +205,9 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) {
Return("Dear donor")
notifyClient.EXPECT().
SendActorEmail(ctx, notify.ToLpaDonor(lpa), "lpa-uid", notify.AttorneyOptedOutEmail{
Greeting: "Dear donor",
AttorneyFullName: tc.attorneyFullName,
DonorFullName: "a b c",
LpaType: "Personal welfare",
LpaUID: "lpa-uid",
DonorStartPageURL: "example.com" + page.PathStart.Format(),
Greeting: "Dear donor",
AttorneyFullName: tc.attorneyFullName,
LpaType: "Personal welfare",
}).
Return(nil)

Expand All @@ -226,7 +223,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOut(t *testing.T) {
SendAttorneyOptOut(r.Context(), "lpa-uid", tc.uid, tc.actorType).
Return(nil)

err := ConfirmDontWantToBeAttorneyLoggedOut(nil, shareCodeStore, lpaStoreResolvingService, sessionStore, notifyClient, "example.com", lpaStoreClient)(testAppData, w, r)
err := ConfirmDontWantToBeAttorneyLoggedOut(nil, shareCodeStore, lpaStoreResolvingService, sessionStore, notifyClient, lpaStoreClient)(testAppData, w, r)

resp := w.Result()

Expand Down Expand Up @@ -270,7 +267,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOutWhenAttorneyNotFound(t *testing
Type: lpadata.LpaTypePersonalWelfare,
}, nil)

err := ConfirmDontWantToBeAttorneyLoggedOut(nil, shareCodeStore, lpaStoreResolvingService, sessionStore, nil, "example.com", nil)(testAppData, w, r)
err := ConfirmDontWantToBeAttorneyLoggedOut(nil, shareCodeStore, lpaStoreResolvingService, sessionStore, nil, nil)(testAppData, w, r)
assert.EqualError(t, err, "attorney not found")
}

Expand Down Expand Up @@ -466,7 +463,7 @@ func TestPostConfirmDontWantToBeAttorneyLoggedOutErrors(t *testing.T) {

testAppData.Localizer = evalT(tc.localizer, t)

err := ConfirmDontWantToBeAttorneyLoggedOut(nil, evalT(tc.shareCodeStore, t), evalT(tc.lpaStoreResolvingService, t), evalT(tc.sessionStore, t), evalT(tc.notifyClient, t), "example.com", evalT(tc.lpaStoreClient, t))(testAppData, w, r)
err := ConfirmDontWantToBeAttorneyLoggedOut(nil, evalT(tc.shareCodeStore, t), evalT(tc.lpaStoreResolvingService, t), evalT(tc.sessionStore, t), evalT(tc.notifyClient, t), evalT(tc.lpaStoreClient, t))(testAppData, w, r)

resp := w.Result()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestGetConfirmDontWantToBeAttorney(t *testing.T) {
}).
Return(nil)

err := ConfirmDontWantToBeAttorney(template.Execute, nil, nil, "example.com", nil)(testAppData, w, r, &attorneydata.Provided{}, lpa)
err := ConfirmDontWantToBeAttorney(template.Execute, nil, nil, nil)(testAppData, w, r, &attorneydata.Provided{}, lpa)
resp := w.Result()

assert.Nil(t, err)
Expand All @@ -49,7 +49,7 @@ func TestGetConfirmDontWantToBeAttorneyWhenTemplateErrors(t *testing.T) {
Execute(mock.Anything, mock.Anything).
Return(expectedError)

err := ConfirmDontWantToBeAttorney(template.Execute, nil, nil, "example.com", nil)(testAppData, w, r, &attorneydata.Provided{}, &lpadata.Lpa{})
err := ConfirmDontWantToBeAttorney(template.Execute, nil, nil, nil)(testAppData, w, r, &attorneydata.Provided{}, &lpadata.Lpa{})
resp := w.Result()

assert.Equal(t, expectedError, err)
Expand Down Expand Up @@ -94,12 +94,9 @@ func TestPostConfirmDontWantToBeAttorney(t *testing.T) {
Return("Dear donor")
notifyClient.EXPECT().
SendActorEmail(r.Context(), notify.ToLpaDonor(lpa), "lpa-uid", notify.AttorneyOptedOutEmail{
Greeting: "Dear donor",
AttorneyFullName: "d e f",
DonorFullName: "a b c",
LpaType: "Personal welfare",
LpaUID: "lpa-uid",
DonorStartPageURL: "example.com" + page.PathStart.Format(),
Greeting: "Dear donor",
AttorneyFullName: "d e f",
LpaType: "Personal welfare",
}).
Return(nil)

Expand All @@ -108,7 +105,7 @@ func TestPostConfirmDontWantToBeAttorney(t *testing.T) {
SendAttorneyOptOut(r.Context(), "lpa-uid", uid, actor.TypeAttorney).
Return(nil)

err := ConfirmDontWantToBeAttorney(nil, certificateProviderStore, notifyClient, "example.com", lpaStoreClient)(testAppData, w, r, &attorneydata.Provided{
err := ConfirmDontWantToBeAttorney(nil, certificateProviderStore, notifyClient, lpaStoreClient)(testAppData, w, r, &attorneydata.Provided{
UID: uid,
}, lpa)

Expand All @@ -124,7 +121,7 @@ func TestPostConfirmDontWantToBeAttorneyWhenAttorneyNotFound(t *testing.T) {
w := httptest.NewRecorder()
uid := actoruid.New()

err := ConfirmDontWantToBeAttorney(nil, nil, nil, "example.com", nil)(testAppData, w, r, &attorneydata.Provided{
err := ConfirmDontWantToBeAttorney(nil, nil, nil, nil)(testAppData, w, r, &attorneydata.Provided{
UID: uid,
}, &lpadata.Lpa{
LpaUID: "lpa-uid",
Expand Down Expand Up @@ -219,7 +216,7 @@ func TestPostConfirmDontWantToBeAttorneyErrors(t *testing.T) {

testAppData.Localizer = localizer

err := ConfirmDontWantToBeAttorney(nil, evalT(tc.attorneyStore, t), evalT(tc.notifyClient, t), "example.com", evalT(tc.lpaStoreClient, t))(testAppData, w, r, &attorneydata.Provided{}, &lpadata.Lpa{LpaUID: "lpa-uid", SignedAt: time.Now()})
err := ConfirmDontWantToBeAttorney(nil, evalT(tc.attorneyStore, t), evalT(tc.notifyClient, t), evalT(tc.lpaStoreClient, t))(testAppData, w, r, &attorneydata.Provided{}, &lpadata.Lpa{LpaUID: "lpa-uid", SignedAt: time.Now()})

resp := w.Result()

Expand Down
5 changes: 2 additions & 3 deletions internal/attorney/attorneypage/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ func Register(
lpaStoreClient LpaStoreClient,
lpaStoreResolvingService LpaStoreResolvingService,
notifyClient NotifyClient,
appPublicURL string,
) {
handleRoot := makeHandle(rootMux, sessionStore, errorHandler)

Expand All @@ -118,7 +117,7 @@ func Register(
handleRoot(page.PathAttorneyEnterReferenceNumberOptOut, None,
EnterReferenceNumberOptOut(tmpls.Get("enter_reference_number_opt_out.gohtml"), shareCodeStore, sessionStore))
handleRoot(page.PathAttorneyConfirmDontWantToBeAttorneyLoggedOut, None,
ConfirmDontWantToBeAttorneyLoggedOut(tmpls.Get("confirm_dont_want_to_be_attorney.gohtml"), shareCodeStore, lpaStoreResolvingService, sessionStore, notifyClient, appPublicURL, lpaStoreClient))
ConfirmDontWantToBeAttorneyLoggedOut(tmpls.Get("confirm_dont_want_to_be_attorney.gohtml"), shareCodeStore, lpaStoreResolvingService, sessionStore, notifyClient, lpaStoreClient))
handleRoot(page.PathAttorneyYouHaveDecidedNotToBeAttorney, None,
page.Guidance(tmpls.Get("you_have_decided_not_to_be_attorney.gohtml")))

Expand Down Expand Up @@ -150,7 +149,7 @@ func Register(
Progress(tmpls.Get("progress.gohtml")))

handleAttorney(attorney.PathConfirmDontWantToBeAttorney, CanGoBack,
ConfirmDontWantToBeAttorney(tmpls.Get("confirm_dont_want_to_be_attorney.gohtml"), attorneyStore, notifyClient, appPublicURL, lpaStoreClient))
ConfirmDontWantToBeAttorney(tmpls.Get("confirm_dont_want_to_be_attorney.gohtml"), attorneyStore, notifyClient, lpaStoreClient))
}

type handleOpt byte
Expand Down
2 changes: 1 addition & 1 deletion internal/attorney/attorneypage/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

func TestRegister(t *testing.T) {
mux := http.NewServeMux()
Register(mux, &mockLogger{}, template.Templates{}, template.Templates{}, nil, nil, nil, nil, nil, &mockDashboardStore{}, &lpastore.Client{}, &lpastore.ResolvingService{}, &mockNotifyClient{}, "http://app")
Register(mux, &mockLogger{}, template.Templates{}, template.Templates{}, nil, nil, nil, nil, nil, &mockDashboardStore{}, &lpastore.Client{}, &lpastore.ResolvingService{}, &mockNotifyClient{})

assert.Implements(t, (*http.Handler)(nil), mux)
}
Expand Down
15 changes: 8 additions & 7 deletions internal/notify/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,17 @@ func (e PaymentConfirmationEmail) emailID(isProduction bool, lang localize.Lang)
}

type AttorneyOptedOutEmail struct {
Greeting string
AttorneyFullName string
DonorFullName string
LpaType string
LpaUID string
DonorStartPageURL string
Greeting string
AttorneyFullName string
LpaType string
}

func (e AttorneyOptedOutEmail) emailID(isProduction bool, _ localize.Lang) string {
return "TODO"
if isProduction {
return "38bf7a04-b15c-4563-8214-bada37284744"
}

return "8d912d5a-f3df-4720-808e-167703e03326"
}

type DonorIdentityCheckExpiredEmail struct{}
Expand Down

0 comments on commit e2ba1eb

Please sign in to comment.