diff --git a/.codecov.yml b/.codecov.yml index fa554b0a95..91c3e7ecdf 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -12,7 +12,8 @@ coverage: - "./cmd/mock-onelogin/main.go" - "./cmd/mock-os-api/main.go" - "./internal/identity/yoti*" - - "./internal/notify/emails.go" + - "./internal/notify/email.go" + - "./internal/notify/sms.go" - "./internal/page/fixtures" - "./internal/telemetry" - "./mocks/*" diff --git a/internal/notify/client.go b/internal/notify/client.go index 7f2bdf2436..be13d393fa 100644 --- a/internal/notify/client.go +++ b/internal/notify/client.go @@ -5,7 +5,6 @@ import ( "context" "encoding/json" "errors" - "io" "net/http" "strings" "time" @@ -13,33 +12,6 @@ import ( "github.com/golang-jwt/jwt/v4" ) -type Template uint8 - -const ( - CertificateProviderActingDigitallyHasNotConfirmedPersonalDetailsLPADetailsChangedPromptSMS Template = iota - CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS - CertificateProviderActingOnPaperDetailsChangedSMS - CertificateProviderActingOnPaperMeetingPromptSMS - WitnessCodeSMS -) - -var ( - productionTemplates = map[Template]string{ - CertificateProviderActingDigitallyHasNotConfirmedPersonalDetailsLPADetailsChangedPromptSMS: "19948d7d-a2df-4e85-930b-5d800978f41f", - CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS: "71d21daa-11f9-4a2a-9ae2-bb5c2247bfb7", - CertificateProviderActingOnPaperDetailsChangedSMS: "ab90c6be-806e-411a-a354-de10f7a70c47", - CertificateProviderActingOnPaperMeetingPromptSMS: "b5cd2c1b-e9b4-4f3e-8cf1-504aff93b16d", - WitnessCodeSMS: "e39849c0-ecab-4e16-87ec-6b22afb9d535", - } - testingTemplates = map[Template]string{ - CertificateProviderActingDigitallyHasNotConfirmedPersonalDetailsLPADetailsChangedPromptSMS: "d7513751-49ba-4276-aef5-ad67361d29c4", - CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS: "359fffa0-e1ec-444c-a886-6f046af374ab", - CertificateProviderActingOnPaperDetailsChangedSMS: "94477364-281a-4032-9a88-b215f969cd12", - CertificateProviderActingOnPaperMeetingPromptSMS: "ee39cd81-5802-44bb-b967-27da7e25e897", - WitnessCodeSMS: "dfa15e16-1f23-494a-bffb-a475513df6cc", - } -) - //go:generate mockery --testonly --inpackage --name Doer --structname mockDoer type Doer interface { Do(*http.Request) (*http.Response, error) @@ -51,7 +23,6 @@ type Client struct { issuer string secretKey []byte now func() time.Time - templates map[Template]string isProduction bool } @@ -61,18 +32,12 @@ func New(isProduction bool, baseURL, apiKey string, httpClient Doer) (*Client, e return nil, errors.New("invalid apiKey format") } - templates := testingTemplates - if isProduction { - templates = productionTemplates - } - return &Client{ baseURL: baseURL, doer: httpClient, issuer: strings.Join(keyParts[1:6], "-"), secretKey: []byte(strings.Join(keyParts[6:11], "-")), now: time.Now, - templates: templates, isProduction: isProduction, }, nil } @@ -105,14 +70,6 @@ type errorItem struct { Message string `json:"message"` } -func (c *Client) TemplateID(id Template) string { - return c.templates[id] -} - -type Email interface { - emailID(bool) string -} - type emailWrapper struct { EmailAddress string `json:"email_address"` TemplateID string `json:"template_id"` @@ -120,23 +77,16 @@ type emailWrapper struct { } func (c *Client) SendEmail(ctx context.Context, to string, email Email) (string, error) { - wrapper := emailWrapper{ + req, err := c.newRequest(ctx, "/v2/notifications/email", emailWrapper{ EmailAddress: to, TemplateID: email.emailID(c.isProduction), Personalisation: email, - } - - var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(wrapper); err != nil { - return "", err - } - - req, err := c.request(ctx, "/v2/notifications/email", &buf) + }) if err != nil { return "", err } - resp, err := c.doRequest(req) + resp, err := c.do(req) if err != nil { return "", err } @@ -144,18 +94,23 @@ func (c *Client) SendEmail(ctx context.Context, to string, email Email) (string, return resp.ID, nil } -func (c *Client) Sms(ctx context.Context, sms Sms) (string, error) { - var buf bytes.Buffer - if err := json.NewEncoder(&buf).Encode(sms); err != nil { - return "", err - } +type smsWrapper struct { + PhoneNumber string `json:"phone_number"` + TemplateID string `json:"template_id"` + Personalisation any `json:"personalisation,omitempty"` +} - req, err := c.request(ctx, "/v2/notifications/sms", &buf) +func (c *Client) SendSMS(ctx context.Context, to string, sms SMS) (string, error) { + req, err := c.newRequest(ctx, "/v2/notifications/sms", smsWrapper{ + PhoneNumber: to, + TemplateID: sms.smsID(c.isProduction), + Personalisation: sms, + }) if err != nil { return "", err } - resp, err := c.doRequest(req) + resp, err := c.do(req) if err != nil { return "", err } @@ -163,18 +118,23 @@ func (c *Client) Sms(ctx context.Context, sms Sms) (string, error) { return resp.ID, nil } -func (c *Client) request(ctx context.Context, url string, body io.Reader) (*http.Request, error) { +func (c *Client) newRequest(ctx context.Context, url string, wrapper any) (*http.Request, error) { + var buf bytes.Buffer + if err := json.NewEncoder(&buf).Encode(wrapper); err != nil { + return nil, err + } + token, err := jwt.NewWithClaims(jwt.SigningMethodHS256, &jwt.RegisteredClaims{ Issuer: c.issuer, IssuedAt: jwt.NewNumericDate(c.now()), }).SignedString(c.secretKey) if err != nil { - return &http.Request{}, err + return nil, err } - req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+url, body) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+url, &buf) if err != nil { - return &http.Request{}, err + return nil, err } req.Header.Add("Content-Type", "application/json") req.Header.Add("Authorization", "Bearer "+token) @@ -182,7 +142,7 @@ func (c *Client) request(ctx context.Context, url string, body io.Reader) (*http return req, nil } -func (c *Client) doRequest(req *http.Request) (response, error) { +func (c *Client) do(req *http.Request) (response, error) { var r response resp, err := c.doer.Do(req) diff --git a/internal/notify/client_test.go b/internal/notify/client_test.go index 883c988ed1..1e2b1c67be 100644 --- a/internal/notify/client_test.go +++ b/internal/notify/client_test.go @@ -85,28 +85,15 @@ func TestSendEmailWhenError(t *testing.T) { assert.Equal(`error sending message: This happened: Plus this`, err.Error()) } -func TestTemplateID(t *testing.T) { - production, _ := New(true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", nil) - assert.Equal(t, "e39849c0-ecab-4e16-87ec-6b22afb9d535", production.TemplateID(WitnessCodeSMS)) - assert.Equal(t, "", production.TemplateID(Template(200))) - - test, _ := New(false, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", nil) - assert.Equal(t, "dfa15e16-1f23-494a-bffb-a475513df6cc", test.TemplateID(WitnessCodeSMS)) - assert.Equal(t, "", test.TemplateID(Template(200))) -} - -func TestRequest(t *testing.T) { +func TestNewRequest(t *testing.T) { assert := assert.New(t) ctx := context.Background() doer := newMockDoer(t) - var jsonBody bytes.Buffer - jsonBody.WriteString(`{"some": "json"}`) - client, _ := New(true, "http://base", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - req, err := client.request(ctx, "/an/url", &jsonBody) + req, err := client.newRequest(ctx, "/an/url", map[string]string{"some": "json"}) assert.Nil(err) assert.Equal(http.MethodPost, req.Method) @@ -115,22 +102,19 @@ func TestRequest(t *testing.T) { assert.Equal("Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJmMzM1MTdmZi0yYTg4LTRmNmUtYjg1NS1jNTUwMjY4Y2UwOGEiLCJpYXQiOjE1Nzc5MzQyNDV9.V0iR-Foo_twZdWttAxy4koJoSYJzyZHMr-tJIBwZj8k", req.Header.Get("Authorization")) } -func TestRequestWhenNewRequestError(t *testing.T) { +func TestNewRequestWhenNewRequestError(t *testing.T) { assert := assert.New(t) doer := newMockDoer(t) - var jsonBody bytes.Buffer - jsonBody.WriteString(`{"some": "json"}`) - client, _ := New(true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer) client.now = func() time.Time { return time.Now().Add(-time.Minute) } - _, err := client.request(nil, "/an/url", &jsonBody) + _, err := client.newRequest(nil, "/an/url", map[string]string{"some": "json"}) assert.Equal(errors.New("net/http: nil Context"), err) } -func TestDoRequest(t *testing.T) { +func TestDo(t *testing.T) { assert := assert.New(t) ctx := context.Background() jsonString := `{"id": "123", "status_code": 400}` @@ -148,16 +132,16 @@ func TestDoRequest(t *testing.T) { client, _ := New(true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - req, _ := client.request(ctx, "/an/url", &jsonBody) + req, _ := client.newRequest(ctx, "/an/url", &jsonBody) - response, err := client.doRequest(req) + response, err := client.do(req) assert.Nil(err) assert.Equal(response.ID, "123") assert.Equal(response.StatusCode, 400) } -func TestDoRequestWhenContainsErrorList(t *testing.T) { +func TestDoWhenContainsErrorList(t *testing.T) { assert := assert.New(t) ctx := context.Background() jsonString := `{"id": "123", "status_code": 400, "errors": [{"error":"SomeError","message":"This happened"}, {"error":"AndError","message":"Plus this"}]}` @@ -175,9 +159,9 @@ func TestDoRequestWhenContainsErrorList(t *testing.T) { client, _ := New(true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - req, _ := client.request(ctx, "/an/url", &jsonBody) + req, _ := client.newRequest(ctx, "/an/url", &jsonBody) - response, err := client.doRequest(req) + response, err := client.do(req) assert.Equal(errorsList{ errorItem{ @@ -220,9 +204,9 @@ func TestDoRequestWhenRequestError(t *testing.T) { client, _ := New(true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - req, _ := client.request(ctx, "/an/url", &jsonBody) + req, _ := client.newRequest(ctx, "/an/url", &jsonBody) - resp, err := client.doRequest(req) + resp, err := client.do(req) assert.Equal(errors.New("err"), err) assert.Equal(response{}, resp) @@ -245,15 +229,21 @@ func TestDoRequestWhenJsonDecodeFails(t *testing.T) { client, _ := New(true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - req, _ := client.request(ctx, "/an/url", &jsonBody) + req, _ := client.newRequest(ctx, "/an/url", &jsonBody) - resp, err := client.doRequest(req) + resp, err := client.do(req) assert.IsType(&json.SyntaxError{}, err) assert.Equal(response{}, resp) } -func TestSms(t *testing.T) { +type testSMS struct { + A string +} + +func (e testSMS) smsID(bool) string { return "template-id" } + +func TestSendSMS(t *testing.T) { assert := assert.New(t) ctx := context.Background() @@ -264,11 +254,13 @@ func TestSms(t *testing.T) { io.Copy(&buf, req.Body) req.Body = ioutil.NopCloser(&buf) - var v map[string]string + var v map[string]any json.Unmarshal(buf.Bytes(), &v) - return assert.Equal("+447535111111", v["phone_number"]) && - assert.Equal("template-123", v["template_id"]) + return assert.Equal("+447535111111", v["phone_number"].(string)) && + assert.Equal("template-id", v["template_id"].(string)) && + assert.Equal(map[string]any{"A": "value"}, v["personalisation"].(map[string]any)) + })). Return(&http.Response{ Body: io.NopCloser(strings.NewReader(`{"id":"xyz"}`)), @@ -277,13 +269,13 @@ func TestSms(t *testing.T) { client, _ := New(true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer) client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) } - id, err := client.Sms(ctx, Sms{PhoneNumber: "+447535111111", TemplateID: "template-123"}) + id, err := client.SendSMS(ctx, "+447535111111", testSMS{A: "value"}) assert.Nil(err) assert.Equal("xyz", id) } -func TestSmsWhenError(t *testing.T) { +func TestSendSMSWhenError(t *testing.T) { assert := assert.New(t) ctx := context.Background() @@ -296,6 +288,6 @@ func TestSmsWhenError(t *testing.T) { client, _ := New(true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer) - _, err := client.Sms(ctx, Sms{PhoneNumber: "+447535111111", TemplateID: "template-123"}) + _, err := client.SendSMS(ctx, "+447535111111", testSMS{}) assert.Equal(`error sending message: This happened: Plus this`, err.Error()) } diff --git a/internal/notify/emails.go b/internal/notify/email.go similarity index 98% rename from internal/notify/emails.go rename to internal/notify/email.go index 1d0082b467..d8eba4491f 100644 --- a/internal/notify/emails.go +++ b/internal/notify/email.go @@ -1,5 +1,9 @@ package notify +type Email interface { + emailID(bool) string +} + type InitialOriginalAttorneyEmail struct { DonorFullName string LpaType string diff --git a/internal/notify/sms.go b/internal/notify/sms.go new file mode 100644 index 0000000000..1780920d2b --- /dev/null +++ b/internal/notify/sms.go @@ -0,0 +1,76 @@ +package notify + +type SMS interface { + smsID(bool) string +} + +type CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS struct { + DonorFullNamePossessive string + LpaType string + LpaUID string + DonorFirstNames string +} + +func (s CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS) smsID(isProduction bool) string { + if isProduction { + return "28873afc-f019-48c1-bd25-df88c27813e0" + } + + return "bcdc85a7-32b1-40a6-a61f-a552406e6ecc" +} + +type CertificateProviderActingDigitallyHasNotConfirmedPersonalDetailsLPADetailsChangedPromptSMS struct { + DonorFullName string + LpaType string +} + +func (s CertificateProviderActingDigitallyHasNotConfirmedPersonalDetailsLPADetailsChangedPromptSMS) smsID(isProduction bool) string { + if isProduction { + return "796990f2-cf49-48a4-9f04-fc12f4a9702b" + } + + return "292cc508-811e-44fa-9962-3fdf10e2e8cd" +} + +type CertificateProviderActingOnPaperDetailsChangedSMS struct { + DonorFullName string + LpaUID string + DonorFirstNames string +} + +func (s CertificateProviderActingOnPaperDetailsChangedSMS) smsID(isProduction bool) string { + if isProduction { + return "b3044df8-b58d-4eb0-bfc2-de6fa778a2c9" + } + + return "dfa5e0d7-6327-4053-8f51-d2d7e60128dc" +} + +type CertificateProviderActingOnPaperMeetingPromptSMS struct { + DonorFullName string + LpaType string + DonorFirstNames string + CertificateProviderStartPageURL string +} + +func (s CertificateProviderActingOnPaperMeetingPromptSMS) smsID(isProduction bool) string { + if isProduction { + return "45589f2d-c45e-420f-9d16-f2c7a3d64bfb" + } + + return "aa76d354-200d-461b-a1ff-ba99fb9c4d9e" +} + +type WitnessCodeSMS struct { + WitnessCode string + DonorFullName string + LpaType string +} + +func (s WitnessCodeSMS) smsID(isProduction bool) string { + if isProduction { + return "e39849c0-ecab-4e16-87ec-6b22afb9d535" + } + + return "dfa15e16-1f23-494a-bffb-a475513df6cc" +} diff --git a/internal/page/attorney/mock_NotifyClient_test.go b/internal/page/attorney/mock_NotifyClient_test.go deleted file mode 100644 index eeb86160df..0000000000 --- a/internal/page/attorney/mock_NotifyClient_test.go +++ /dev/null @@ -1,68 +0,0 @@ -// Code generated by mockery v2.20.0. DO NOT EDIT. - -package attorney - -import ( - context "context" - - notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" - mock "github.com/stretchr/testify/mock" -) - -// mockNotifyClient is an autogenerated mock type for the NotifyClient type -type mockNotifyClient struct { - mock.Mock -} - -// Sms provides a mock function with given fields: ctx, sms -func (_m *mockNotifyClient) Sms(ctx context.Context, sms notify.Sms) (string, error) { - ret := _m.Called(ctx, sms) - - var r0 string - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, notify.Sms) (string, error)); ok { - return rf(ctx, sms) - } - if rf, ok := ret.Get(0).(func(context.Context, notify.Sms) string); ok { - r0 = rf(ctx, sms) - } else { - r0 = ret.Get(0).(string) - } - - if rf, ok := ret.Get(1).(func(context.Context, notify.Sms) error); ok { - r1 = rf(ctx, sms) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// TemplateID provides a mock function with given fields: id -func (_m *mockNotifyClient) TemplateID(id notify.Template) string { - ret := _m.Called(id) - - var r0 string - if rf, ok := ret.Get(0).(func(notify.Template) string); ok { - r0 = rf(id) - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - -type mockConstructorTestingTnewMockNotifyClient interface { - mock.TestingT - Cleanup(func()) -} - -// newMockNotifyClient creates a new instance of mockNotifyClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -func newMockNotifyClient(t mockConstructorTestingTnewMockNotifyClient) *mockNotifyClient { - mock := &mockNotifyClient{} - mock.Mock.Test(t) - - t.Cleanup(func() { mock.AssertExpectations(t) }) - - return mock -} diff --git a/internal/page/auth_redirect_test.go b/internal/page/auth_redirect_test.go index 8f75d02a6f..796abccc31 100644 --- a/internal/page/auth_redirect_test.go +++ b/internal/page/auth_redirect_test.go @@ -79,8 +79,8 @@ func TestAuthRedirectSessionMissing(t *testing.T) { "missing session": { url: "/?code=auth-code&state=my-state", session: nil, - getErr: ExpectedError, - expectedErr: ExpectedError, + getErr: expectedError, + expectedErr: expectedError, }, "missing state": { url: "/?code=auth-code&state=my-state", diff --git a/internal/page/common.go b/internal/page/common.go index 653086398c..39e201de85 100644 --- a/internal/page/common.go +++ b/internal/page/common.go @@ -35,8 +35,7 @@ type ShareCodeStore interface { //go:generate mockery --testonly --inpackage --name NotifyClient --structname mockNotifyClient type NotifyClient interface { SendEmail(context.Context, string, notify.Email) (string, error) - Sms(ctx context.Context, sms notify.Sms) (string, error) - TemplateID(id notify.Template) string + SendSMS(context.Context, string, notify.SMS) (string, error) } //go:generate mockery --testonly --inpackage --name OneLoginClient --structname mockOneLoginClient @@ -79,12 +78,6 @@ type Localizer interface { FormatDateTime(time.Time) string } -//go:generate mockery --testonly --inpackage --name shareCodeSender --structname mockShareCodeSender -type shareCodeSender interface { - SendCertificateProvider(ctx context.Context, template notify.Template, appData AppData, identity bool, donor *actor.DonorProvidedDetails) error - SendAttorneys(ctx context.Context, appData AppData, donor *actor.DonorProvidedDetails) error -} - func PostFormString(r *http.Request, name string) string { return strings.TrimSpace(r.PostFormValue(name)) } diff --git a/internal/page/csrf_test.go b/internal/page/csrf_test.go index fdd34d083d..d2ad3542d4 100644 --- a/internal/page/csrf_test.go +++ b/internal/page/csrf_test.go @@ -164,11 +164,11 @@ func TestPostValidateCsrfErrorWhenDecodingSession(t *testing.T) { sessionStore := newMockSessionStore(t) sessionStore. On("Get", r, "csrf"). - Return(&sessions.Session{Values: map[interface{}]interface{}{}}, ExpectedError) + Return(&sessions.Session{Values: map[interface{}]interface{}{}}, expectedError) errorHandler := newMockErrorHandler(t) errorHandler. - On("Execute", w, r, ExpectedError). + On("Execute", w, r, expectedError). Return(nil) ValidateCsrf(http.NotFoundHandler(), sessionStore, MockRandom, errorHandler.Execute).ServeHTTP(w, r) diff --git a/internal/page/donor/check_your_lpa.go b/internal/page/donor/check_your_lpa.go index f4ceea5a7b..6938ac00dc 100644 --- a/internal/page/donor/check_your_lpa.go +++ b/internal/page/donor/check_your_lpa.go @@ -39,25 +39,23 @@ func (n *checkYourLpaNotifier) Notify(ctx context.Context, appData page.AppData, } func (n *checkYourLpaNotifier) sendPaperNotification(ctx context.Context, appData page.AppData, donor *actor.DonorProvidedDetails, wasCompleted bool) error { - sms := notify.Sms{ - PhoneNumber: donor.CertificateProvider.Mobile, - Personalisation: map[string]string{ - "donorFullName": donor.Donor.FullName(), - "donorFirstNames": donor.Donor.FirstNames, - }, - } - + var sms notify.SMS if wasCompleted { - sms.TemplateID = n.notifyClient.TemplateID(notify.CertificateProviderActingOnPaperDetailsChangedSMS) - sms.Personalisation["lpaId"] = donor.LpaUID + sms = notify.CertificateProviderActingOnPaperDetailsChangedSMS{ + DonorFullName: donor.Donor.FullName(), + DonorFirstNames: donor.Donor.FirstNames, + LpaUID: donor.LpaUID, + } } else { - sms.TemplateID = n.notifyClient.TemplateID(notify.CertificateProviderActingOnPaperMeetingPromptSMS) - sms.Personalisation["donorFirstNames"] = donor.Donor.FirstNames - sms.Personalisation["lpaType"] = appData.Localizer.T(donor.Type.LegalTermTransKey()) - sms.Personalisation["CPLandingPageLink"] = appData.AppPublicURL + appData.Lang.URL(page.Paths.CertificateProviderStart.Format()) + sms = notify.CertificateProviderActingOnPaperMeetingPromptSMS{ + DonorFullName: donor.Donor.FullName(), + DonorFirstNames: donor.Donor.FirstNames, + LpaType: appData.Localizer.T(donor.Type.LegalTermTransKey()), + CertificateProviderStartPageURL: appData.AppPublicURL + appData.Lang.URL(page.Paths.CertificateProviderStart.Format()), + } } - _, err := n.notifyClient.Sms(ctx, sms) + _, err := n.notifyClient.SendSMS(ctx, donor.CertificateProvider.Mobile, sms) return err } @@ -71,23 +69,22 @@ func (n *checkYourLpaNotifier) sendOnlineNotification(ctx context.Context, appDa return err } - sms := notify.Sms{ - PhoneNumber: donor.CertificateProvider.Mobile, - Personalisation: map[string]string{ - "lpaType": appData.Localizer.T(donor.Type.LegalTermTransKey()), - }, - } + var sms notify.SMS if certificateProvider.Tasks.ConfirmYourDetails.NotStarted() { - sms.TemplateID = n.notifyClient.TemplateID(notify.CertificateProviderActingDigitallyHasNotConfirmedPersonalDetailsLPADetailsChangedPromptSMS) - sms.Personalisation["donorFullName"] = donor.Donor.FullName() + sms = notify.CertificateProviderActingDigitallyHasNotConfirmedPersonalDetailsLPADetailsChangedPromptSMS{ + LpaType: appData.Localizer.T(donor.Type.LegalTermTransKey()), + DonorFullName: donor.Donor.FullName(), + } } else { - sms.TemplateID = n.notifyClient.TemplateID(notify.CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS) - sms.Personalisation["donorFullNamePossessive"] = appData.Localizer.Possessive(donor.Donor.FullName()) - sms.Personalisation["donorFirstNames"] = donor.Donor.FirstNames + sms = notify.CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS{ + LpaType: appData.Localizer.T(donor.Type.LegalTermTransKey()), + DonorFullNamePossessive: appData.Localizer.Possessive(donor.Donor.FullName()), + DonorFirstNames: donor.Donor.FirstNames, + } } - _, err = n.notifyClient.Sms(ctx, sms) + _, err = n.notifyClient.SendSMS(ctx, donor.CertificateProvider.Mobile, sms) return err } diff --git a/internal/page/donor/check_your_lpa_test.go b/internal/page/donor/check_your_lpa_test.go index 402a100ddc..ad7348594f 100644 --- a/internal/page/donor/check_your_lpa_test.go +++ b/internal/page/donor/check_your_lpa_test.go @@ -153,45 +153,29 @@ func TestPostCheckYourLpaDigitalCertificateProviderOnFirstCheck(t *testing.T) { func TestPostCheckYourLpaDigitalCertificateProviderOnSubsequentChecks(t *testing.T) { testCases := map[string]struct { certificateProviderDetailsTaskState actor.TaskState - expectedTemplateId notify.Template - expectedSms notify.Sms + expectedSms notify.SMS }{ "cp not started": { certificateProviderDetailsTaskState: actor.TaskNotStarted, - expectedTemplateId: notify.CertificateProviderActingDigitallyHasNotConfirmedPersonalDetailsLPADetailsChangedPromptSMS, - expectedSms: notify.Sms{ - PhoneNumber: "07700900000", - TemplateID: "template-id", - Personalisation: map[string]string{ - "donorFullName": "Teneil Throssell", - "lpaType": "property and affairs", - }, + expectedSms: notify.CertificateProviderActingDigitallyHasNotConfirmedPersonalDetailsLPADetailsChangedPromptSMS{ + DonorFullName: "Teneil Throssell", + LpaType: "property and affairs", }, }, "cp in progress": { certificateProviderDetailsTaskState: actor.TaskInProgress, - expectedTemplateId: notify.CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS, - expectedSms: notify.Sms{ - PhoneNumber: "07700900000", - TemplateID: "template-id", - Personalisation: map[string]string{ - "donorFullNamePossessive": "Teneil Throssell’s", - "lpaType": "property and affairs", - "donorFirstNames": "Teneil", - }, + expectedSms: notify.CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS{ + DonorFullNamePossessive: "Teneil Throssell’s", + LpaType: "property and affairs", + DonorFirstNames: "Teneil", }, }, "cp completed": { certificateProviderDetailsTaskState: actor.TaskCompleted, - expectedTemplateId: notify.CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS, - expectedSms: notify.Sms{ - PhoneNumber: "07700900000", - TemplateID: "template-id", - Personalisation: map[string]string{ - "donorFullNamePossessive": "Teneil Throssell’s", - "lpaType": "property and affairs", - "donorFirstNames": "Teneil", - }, + expectedSms: notify.CertificateProviderActingDigitallyHasConfirmedPersonalDetailsLPADetailsChangedPromptSMS{ + DonorFullNamePossessive: "Teneil Throssell’s", + LpaType: "property and affairs", + DonorFirstNames: "Teneil", }, }, } @@ -229,10 +213,7 @@ func TestPostCheckYourLpaDigitalCertificateProviderOnSubsequentChecks(t *testing notifyClient := newMockNotifyClient(t) notifyClient. - On("TemplateID", tc.expectedTemplateId). - Return("template-id") - notifyClient. - On("Sms", r.Context(), tc.expectedSms). + On("SendSMS", r.Context(), "07700900000", tc.expectedSms). Return("", nil) donorStore := newMockDonorStore(t) @@ -333,18 +314,11 @@ func TestPostCheckYourLpaPaperCertificateProviderOnFirstCheck(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient. - On("TemplateID", notify.CertificateProviderActingOnPaperMeetingPromptSMS). - Return("template-id") - notifyClient. - On("Sms", r.Context(), notify.Sms{ - PhoneNumber: "07700900000", - TemplateID: "template-id", - Personalisation: map[string]string{ - "donorFullName": "Teneil Throssell", - "lpaType": "property and affairs", - "donorFirstNames": "Teneil", - "CPLandingPageLink": "http://example.org/certificate-provider-start", - }, + On("SendSMS", r.Context(), "07700900000", notify.CertificateProviderActingOnPaperMeetingPromptSMS{ + DonorFullName: "Teneil Throssell", + LpaType: "property and affairs", + DonorFirstNames: "Teneil", + CertificateProviderStartPageURL: "http://example.org/certificate-provider-start", }). Return("", nil) @@ -385,17 +359,10 @@ func TestPostCheckYourLpaPaperCertificateProviderOnSubsequentCheck(t *testing.T) notifyClient := newMockNotifyClient(t) notifyClient. - On("TemplateID", notify.CertificateProviderActingOnPaperDetailsChangedSMS). - Return("template-id") - notifyClient. - On("Sms", r.Context(), notify.Sms{ - PhoneNumber: "07700900000", - TemplateID: "template-id", - Personalisation: map[string]string{ - "donorFullName": "Teneil Throssell", - "donorFirstNames": "Teneil", - "lpaId": "lpa-uid", - }, + On("SendSMS", r.Context(), "07700900000", notify.CertificateProviderActingOnPaperDetailsChangedSMS{ + DonorFullName: "Teneil Throssell", + DonorFirstNames: "Teneil", + LpaUID: "lpa-uid", }). Return("", nil) @@ -483,10 +450,7 @@ func TestPostCheckYourLpaWhenNotifyClientErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient. - On("TemplateID", mock.Anything). - Return("template-id") - notifyClient. - On("Sms", mock.Anything, mock.Anything). + On("SendSMS", mock.Anything, mock.Anything, mock.Anything). Return("", expectedError) err := CheckYourLpa(nil, donorStore, nil, notifyClient, nil, testNowFn)(testAppData, w, r, &actor.DonorProvidedDetails{Hash: 5, CertificateProvider: actor.CertificateProvider{CarryOutBy: actor.Paper}}) diff --git a/internal/page/donor/mock_NotifyClient_test.go b/internal/page/donor/mock_NotifyClient_test.go index 5ede7ddb8d..479358c306 100644 --- a/internal/page/donor/mock_NotifyClient_test.go +++ b/internal/page/donor/mock_NotifyClient_test.go @@ -14,23 +14,23 @@ type mockNotifyClient struct { mock.Mock } -// Sms provides a mock function with given fields: ctx, sms -func (_m *mockNotifyClient) Sms(ctx context.Context, sms notify.Sms) (string, error) { - ret := _m.Called(ctx, sms) +// SendSMS provides a mock function with given fields: _a0, _a1, _a2 +func (_m *mockNotifyClient) SendSMS(_a0 context.Context, _a1 string, _a2 notify.SMS) (string, error) { + ret := _m.Called(_a0, _a1, _a2) var r0 string var r1 error - if rf, ok := ret.Get(0).(func(context.Context, notify.Sms) (string, error)); ok { - return rf(ctx, sms) + if rf, ok := ret.Get(0).(func(context.Context, string, notify.SMS) (string, error)); ok { + return rf(_a0, _a1, _a2) } - if rf, ok := ret.Get(0).(func(context.Context, notify.Sms) string); ok { - r0 = rf(ctx, sms) + if rf, ok := ret.Get(0).(func(context.Context, string, notify.SMS) string); ok { + r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Get(0).(string) } - if rf, ok := ret.Get(1).(func(context.Context, notify.Sms) error); ok { - r1 = rf(ctx, sms) + if rf, ok := ret.Get(1).(func(context.Context, string, notify.SMS) error); ok { + r1 = rf(_a0, _a1, _a2) } else { r1 = ret.Error(1) } @@ -38,20 +38,6 @@ func (_m *mockNotifyClient) Sms(ctx context.Context, sms notify.Sms) (string, er return r0, r1 } -// TemplateID provides a mock function with given fields: id -func (_m *mockNotifyClient) TemplateID(id notify.Template) string { - ret := _m.Called(id) - - var r0 string - if rf, ok := ret.Get(0).(func(notify.Template) string); ok { - r0 = rf(id) - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - type mockConstructorTestingTnewMockNotifyClient interface { mock.TestingT Cleanup(func()) diff --git a/internal/page/donor/register.go b/internal/page/donor/register.go index 5145208f08..95227f30e1 100644 --- a/internal/page/donor/register.go +++ b/internal/page/donor/register.go @@ -95,8 +95,7 @@ type OneLoginClient interface { //go:generate mockery --testonly --inpackage --name NotifyClient --structname mockNotifyClient type NotifyClient interface { - Sms(ctx context.Context, sms notify.Sms) (string, error) - TemplateID(id notify.Template) string + SendSMS(context.Context, string, notify.SMS) (string, error) } //go:generate mockery --testonly --inpackage --name SessionStore --structname mockSessionStore diff --git a/internal/page/error_test.go b/internal/page/error_test.go index e32fc4bbfe..9ef8d15e10 100644 --- a/internal/page/error_test.go +++ b/internal/page/error_test.go @@ -17,14 +17,14 @@ func TestError(t *testing.T) { logger := newMockLogger(t) logger. - On("Request", r, ExpectedError) + On("Request", r, expectedError) template := newMockTemplate(t) template. On("Execute", w, &errorData{App: TestAppData}). Return(nil) - Error(template.Execute, logger)(w, r, ExpectedError) + Error(template.Execute, logger)(w, r, expectedError) resp := w.Result() assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) @@ -57,7 +57,7 @@ func TestErrorWhenTemplateErrors(t *testing.T) { logger := newMockLogger(t) logger. - On("Request", r, ExpectedError) + On("Request", r, expectedError) logger. On("Request", r, fmt.Errorf("Error rendering page: %w", templateError)) @@ -66,7 +66,7 @@ func TestErrorWhenTemplateErrors(t *testing.T) { On("Execute", w, &errorData{App: TestAppData}). Return(templateError) - Error(template.Execute, logger)(w, r, ExpectedError) + Error(template.Execute, logger)(w, r, expectedError) resp := w.Result() assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) diff --git a/internal/page/guidance_test.go b/internal/page/guidance_test.go index 718dc36f11..b245cc4e12 100644 --- a/internal/page/guidance_test.go +++ b/internal/page/guidance_test.go @@ -32,9 +32,9 @@ func TestGuidanceWhenTemplateErrors(t *testing.T) { template := newMockTemplate(t) template. On("Execute", w, &guidanceData{App: TestAppData, Query: url.Values{}}). - Return(ExpectedError) + Return(expectedError) err := Guidance(template.Execute)(TestAppData, w, r) - assert.Equal(t, ExpectedError, err) + assert.Equal(t, expectedError, err) } diff --git a/internal/page/login_test.go b/internal/page/login_test.go index 001340b0e2..b70af66005 100644 --- a/internal/page/login_test.go +++ b/internal/page/login_test.go @@ -1,7 +1,6 @@ package page import ( - "errors" "net/http" "net/http/httptest" "testing" @@ -13,8 +12,6 @@ import ( "github.com/stretchr/testify/mock" ) -var expectedError = errors.New("err") - func TestLogin(t *testing.T) { w := httptest.NewRecorder() r, _ := http.NewRequest(http.MethodGet, "/?sessionId=session-id&lpaId=lpa-id", nil) diff --git a/internal/page/mock_NotifyClient_test.go b/internal/page/mock_NotifyClient_test.go index a5ca620c69..748a2f4577 100644 --- a/internal/page/mock_NotifyClient_test.go +++ b/internal/page/mock_NotifyClient_test.go @@ -38,23 +38,23 @@ func (_m *mockNotifyClient) SendEmail(_a0 context.Context, _a1 string, _a2 notif return r0, r1 } -// Sms provides a mock function with given fields: ctx, sms -func (_m *mockNotifyClient) Sms(ctx context.Context, sms notify.Sms) (string, error) { - ret := _m.Called(ctx, sms) +// SendSMS provides a mock function with given fields: _a0, _a1, _a2 +func (_m *mockNotifyClient) SendSMS(_a0 context.Context, _a1 string, _a2 notify.SMS) (string, error) { + ret := _m.Called(_a0, _a1, _a2) var r0 string var r1 error - if rf, ok := ret.Get(0).(func(context.Context, notify.Sms) (string, error)); ok { - return rf(ctx, sms) + if rf, ok := ret.Get(0).(func(context.Context, string, notify.SMS) (string, error)); ok { + return rf(_a0, _a1, _a2) } - if rf, ok := ret.Get(0).(func(context.Context, notify.Sms) string); ok { - r0 = rf(ctx, sms) + if rf, ok := ret.Get(0).(func(context.Context, string, notify.SMS) string); ok { + r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Get(0).(string) } - if rf, ok := ret.Get(1).(func(context.Context, notify.Sms) error); ok { - r1 = rf(ctx, sms) + if rf, ok := ret.Get(1).(func(context.Context, string, notify.SMS) error); ok { + r1 = rf(_a0, _a1, _a2) } else { r1 = ret.Error(1) } @@ -62,20 +62,6 @@ func (_m *mockNotifyClient) Sms(ctx context.Context, sms notify.Sms) (string, er return r0, r1 } -// TemplateID provides a mock function with given fields: id -func (_m *mockNotifyClient) TemplateID(id notify.Template) string { - ret := _m.Called(id) - - var r0 string - if rf, ok := ret.Get(0).(func(notify.Template) string); ok { - r0 = rf(id) - } else { - r0 = ret.Get(0).(string) - } - - return r0 -} - type mockConstructorTestingTnewMockNotifyClient interface { mock.TestingT Cleanup(func()) diff --git a/internal/page/mock_shareCodeSender_test.go b/internal/page/mock_shareCodeSender_test.go index d78b4120a7..7315ced405 100644 --- a/internal/page/mock_shareCodeSender_test.go +++ b/internal/page/mock_shareCodeSender_test.go @@ -8,8 +8,6 @@ import ( actor "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" mock "github.com/stretchr/testify/mock" - - notify "github.com/ministryofjustice/opg-modernising-lpa/internal/notify" ) // mockShareCodeSender is an autogenerated mock type for the shareCodeSender type @@ -31,13 +29,13 @@ func (_m *mockShareCodeSender) SendAttorneys(ctx context.Context, appData AppDat return r0 } -// SendCertificateProvider provides a mock function with given fields: ctx, template, appData, identity, donor -func (_m *mockShareCodeSender) SendCertificateProvider(ctx context.Context, template notify.Template, appData AppData, identity bool, donor *actor.DonorProvidedDetails) error { - ret := _m.Called(ctx, template, appData, identity, donor) +// SendCertificateProvider provides a mock function with given fields: ctx, appData, identity, donor +func (_m *mockShareCodeSender) SendCertificateProvider(ctx context.Context, appData AppData, identity bool, donor *actor.DonorProvidedDetails) error { + ret := _m.Called(ctx, appData, identity, donor) var r0 error - if rf, ok := ret.Get(0).(func(context.Context, notify.Template, AppData, bool, *actor.DonorProvidedDetails) error); ok { - r0 = rf(ctx, template, appData, identity, donor) + if rf, ok := ret.Get(0).(func(context.Context, AppData, bool, *actor.DonorProvidedDetails) error); ok { + r0 = rf(ctx, appData, identity, donor) } else { r0 = ret.Error(0) } diff --git a/internal/page/mock_test.go b/internal/page/mock_test.go index 345613506e..eeebe045c0 100644 --- a/internal/page/mock_test.go +++ b/internal/page/mock_test.go @@ -14,7 +14,7 @@ import ( var MockRandom = func(int) string { return "123" } var ( - ExpectedError = errors.New("err") + expectedError = errors.New("err") TestAppData = AppData{ SessionID: "session-id", LpaID: "lpa-id", diff --git a/internal/page/recover_test.go b/internal/page/recover_test.go index 85f197b3f4..9d610b10f5 100644 --- a/internal/page/recover_test.go +++ b/internal/page/recover_test.go @@ -67,7 +67,7 @@ func TestRecoverWhenTemplateErrors(t *testing.T) { template := newMockTemplate(t) template. On("Execute", w, mock.Anything). - Return(ExpectedError) + Return(expectedError) logger := newMockLogger(t) logger. diff --git a/internal/page/root_test.go b/internal/page/root_test.go index 4fd757562b..f61e8398f3 100644 --- a/internal/page/root_test.go +++ b/internal/page/root_test.go @@ -41,11 +41,11 @@ func TestRootNotFoundTemplateErrors(t *testing.T) { template := newMockTemplate(t) template. On("Execute", w, &rootData{App: TestAppData}). - Return(ExpectedError) + Return(expectedError) logger := newMockLogger(t) logger. - On("Print", "Error rendering page: "+ExpectedError.Error()) + On("Print", "Error rendering page: "+expectedError.Error()) Root(template.Execute, logger)(TestAppData, w, r) } diff --git a/internal/page/share_code_test.go b/internal/page/share_code_test.go index db3f8dd829..e1f09f2b97 100644 --- a/internal/page/share_code_test.go +++ b/internal/page/share_code_test.go @@ -214,12 +214,12 @@ func TestShareCodeSenderSendCertificateProviderInviteWhenEmailErrors(t *testing. notifyClient := newMockNotifyClient(t) notifyClient. On("SendEmail", ctx, mock.Anything, mock.Anything). - Return("", ExpectedError) + Return("", expectedError) sender := NewShareCodeSender(shareCodeStore, notifyClient, "http://app", MockRandom) err := sender.SendCertificateProviderInvite(ctx, TestAppData, donor) - assert.Equal(t, ExpectedError, errors.Unwrap(err)) + assert.Equal(t, expectedError, errors.Unwrap(err)) } func TestShareCodeSenderSendCertificateProviderInviteWhenShareCodeStoreErrors(t *testing.T) { @@ -237,12 +237,12 @@ func TestShareCodeSenderSendCertificateProviderInviteWhenShareCodeStoreErrors(t shareCodeStore := newMockShareCodeStore(t) shareCodeStore. On("Put", mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(ExpectedError) + Return(expectedError) sender := NewShareCodeSender(shareCodeStore, nil, "http://app", MockRandom) err := sender.SendCertificateProviderInvite(ctx, TestAppData, &actor.DonorProvidedDetails{}) - assert.Equal(t, ExpectedError, errors.Unwrap(err)) + assert.Equal(t, expectedError, errors.Unwrap(err)) } func TestShareCodeSenderSendCertificateProviderPrompt(t *testing.T) { @@ -424,12 +424,12 @@ func TestShareCodeSenderSendCertificateProviderPromptWhenEmailErrors(t *testing. notifyClient := newMockNotifyClient(t) notifyClient. On("SendEmail", ctx, mock.Anything, mock.Anything). - Return("", ExpectedError) + Return("", expectedError) sender := NewShareCodeSender(shareCodeStore, notifyClient, "http://app", MockRandom) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, donor) - assert.Equal(t, ExpectedError, errors.Unwrap(err)) + assert.Equal(t, expectedError, errors.Unwrap(err)) } func TestShareCodeSenderSendCertificateProviderPromptWhenShareCodeStoreErrors(t *testing.T) { @@ -438,12 +438,12 @@ func TestShareCodeSenderSendCertificateProviderPromptWhenShareCodeStoreErrors(t shareCodeStore := newMockShareCodeStore(t) shareCodeStore. On("Put", mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(ExpectedError) + Return(expectedError) sender := NewShareCodeSender(shareCodeStore, nil, "http://app", MockRandom) err := sender.SendCertificateProviderPrompt(ctx, TestAppData, &actor.DonorProvidedDetails{}) - assert.Equal(t, ExpectedError, errors.Unwrap(err)) + assert.Equal(t, expectedError, errors.Unwrap(err)) } func TestShareCodeSenderSendAttorneys(t *testing.T) { @@ -717,12 +717,12 @@ func TestShareCodeSenderSendAttorneysWhenEmailErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient. On("SendEmail", ctx, mock.Anything, mock.Anything). - Return("", ExpectedError) + Return("", expectedError) sender := NewShareCodeSender(shareCodeStore, notifyClient, "http://app", MockRandom) err := sender.SendAttorneys(ctx, TestAppData, donor) - assert.Equal(t, ExpectedError, errors.Unwrap(err)) + assert.Equal(t, expectedError, errors.Unwrap(err)) } func TestShareCodeSenderSendAttorneysWhenShareCodeStoreErrors(t *testing.T) { @@ -740,12 +740,12 @@ func TestShareCodeSenderSendAttorneysWhenShareCodeStoreErrors(t *testing.T) { shareCodeStore := newMockShareCodeStore(t) shareCodeStore. On("Put", mock.Anything, mock.Anything, mock.Anything, mock.Anything). - Return(ExpectedError) + Return(expectedError) sender := NewShareCodeSender(shareCodeStore, nil, "http://app", MockRandom) err := sender.SendAttorneys(ctx, TestAppData, &actor.DonorProvidedDetails{ Attorneys: actor.Attorneys{Attorneys: []actor.Attorney{{Email: "hey@example.com"}}}, }) - assert.Equal(t, ExpectedError, errors.Unwrap(err)) + assert.Equal(t, expectedError, errors.Unwrap(err)) } diff --git a/internal/page/witness_code.go b/internal/page/witness_code.go index 513884aefd..b590169736 100644 --- a/internal/page/witness_code.go +++ b/internal/page/witness_code.go @@ -36,14 +36,10 @@ func (s *WitnessCodeSender) SendToCertificateProvider(ctx context.Context, donor code := s.randomCode(4) donor.CertificateProviderCodes = append(donor.CertificateProviderCodes, actor.WitnessCode{Code: code, Created: s.now()}) - _, err := s.notifyClient.Sms(ctx, notify.Sms{ - PhoneNumber: donor.CertificateProvider.Mobile, - TemplateID: s.notifyClient.TemplateID(notify.WitnessCodeSMS), - Personalisation: map[string]string{ - "WitnessCode": code, - "DonorFullName": localizer.Possessive(donor.Donor.FullName()), - "LpaType": localizer.T(donor.Type.LegalTermTransKey()), - }, + _, err := s.notifyClient.SendSMS(ctx, donor.CertificateProvider.Mobile, notify.WitnessCodeSMS{ + WitnessCode: code, + DonorFullName: localizer.Possessive(donor.Donor.FullName()), + LpaType: localizer.T(donor.Type.LegalTermTransKey()), }) if err != nil { return err @@ -60,14 +56,10 @@ func (s *WitnessCodeSender) SendToIndependentWitness(ctx context.Context, donor code := s.randomCode(4) donor.IndependentWitnessCodes = append(donor.IndependentWitnessCodes, actor.WitnessCode{Code: code, Created: s.now()}) - _, err := s.notifyClient.Sms(ctx, notify.Sms{ - PhoneNumber: donor.IndependentWitness.Mobile, - TemplateID: s.notifyClient.TemplateID(notify.WitnessCodeSMS), - Personalisation: map[string]string{ - "WitnessCode": code, - "DonorFullName": localizer.Possessive(donor.Donor.FullName()), - "LpaType": localizer.T(donor.Type.LegalTermTransKey()), - }, + _, err := s.notifyClient.SendSMS(ctx, donor.IndependentWitness.Mobile, notify.WitnessCodeSMS{ + WitnessCode: code, + DonorFullName: localizer.Possessive(donor.Donor.FullName()), + LpaType: localizer.T(donor.Type.LegalTermTransKey()), }) if err != nil { return err diff --git a/internal/page/witness_code_test.go b/internal/page/witness_code_test.go index b1a030dbd4..dbb6472cbb 100644 --- a/internal/page/witness_code_test.go +++ b/internal/page/witness_code_test.go @@ -17,17 +17,10 @@ func TestWitnessCodeSenderSendToCertificateProvider(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient. - On("TemplateID", notify.WitnessCodeSMS). - Return("template-id") - notifyClient. - On("Sms", ctx, notify.Sms{ - PhoneNumber: "0777", - TemplateID: "template-id", - Personalisation: map[string]string{ - "WitnessCode": "1234", - "DonorFullName": "Joe Jones’", - "LpaType": "property and affairs", - }, + On("SendSMS", ctx, "0777", notify.WitnessCodeSMS{ + WitnessCode: "1234", + DonorFullName: "Joe Jones’", + LpaType: "property and affairs", }). Return("sms-id", nil) @@ -79,11 +72,8 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenTooRecentlySent(t *testin func TestWitnessCodeSenderSendToCertificateProviderWhenNotifyClientErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient. - On("TemplateID", mock.Anything). - Return("template-id") - notifyClient. - On("Sms", mock.Anything, mock.Anything). - Return("", ExpectedError) + On("SendSMS", mock.Anything, mock.Anything, mock.Anything). + Return("", expectedError) localizer := newMockLocalizer(t) localizer. @@ -104,22 +94,19 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenNotifyClientErrors(t *tes Type: actor.LpaTypePropertyFinance, }, localizer) - assert.Equal(t, ExpectedError, err) + assert.Equal(t, expectedError, err) } func TestWitnessCodeSenderSendToCertificateProviderWhenDonorStoreErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient. - On("TemplateID", mock.Anything). - Return("template-id") - notifyClient. - On("Sms", mock.Anything, mock.Anything). + On("SendSMS", mock.Anything, mock.Anything, mock.Anything). Return("sms-id", nil) donorStore := newMockDonorStore(t) donorStore. On("Put", mock.Anything, mock.Anything). - Return(ExpectedError) + Return(expectedError) localizer := newMockLocalizer(t) localizer. @@ -141,7 +128,7 @@ func TestWitnessCodeSenderSendToCertificateProviderWhenDonorStoreErrors(t *testi Type: actor.LpaTypePropertyFinance, }, localizer) - assert.Equal(t, ExpectedError, err) + assert.Equal(t, expectedError, err) } func TestWitnessCodeSenderSendToIndependentWitness(t *testing.T) { @@ -150,17 +137,10 @@ func TestWitnessCodeSenderSendToIndependentWitness(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient. - On("TemplateID", notify.WitnessCodeSMS). - Return("template-id") - notifyClient. - On("Sms", ctx, notify.Sms{ - PhoneNumber: "0777", - TemplateID: "template-id", - Personalisation: map[string]string{ - "WitnessCode": "1234", - "DonorFullName": "Joe Jones’", - "LpaType": "property and affairs", - }, + On("SendSMS", ctx, "0777", notify.WitnessCodeSMS{ + WitnessCode: "1234", + DonorFullName: "Joe Jones’", + LpaType: "property and affairs", }). Return("sms-id", nil) @@ -212,11 +192,8 @@ func TestWitnessCodeSenderSendToIndependentWitnessWhenTooRecentlySent(t *testing func TestWitnessCodeSenderSendToIndependentWitnessWhenNotifyClientErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient. - On("TemplateID", mock.Anything). - Return("template-id") - notifyClient. - On("Sms", mock.Anything, mock.Anything). - Return("", ExpectedError) + On("SendSMS", mock.Anything, mock.Anything, mock.Anything). + Return("", expectedError) localizer := newMockLocalizer(t) localizer. @@ -237,22 +214,19 @@ func TestWitnessCodeSenderSendToIndependentWitnessWhenNotifyClientErrors(t *test Type: actor.LpaTypePropertyFinance, }, localizer) - assert.Equal(t, ExpectedError, err) + assert.Equal(t, expectedError, err) } func TestWitnessCodeSenderSendToIndependentWitnessWhenDonorStoreErrors(t *testing.T) { notifyClient := newMockNotifyClient(t) notifyClient. - On("TemplateID", mock.Anything). - Return("template-id") - notifyClient. - On("Sms", mock.Anything, mock.Anything). + On("SendSMS", mock.Anything, mock.Anything, mock.Anything). Return("sms-id", nil) donorStore := newMockDonorStore(t) donorStore. On("Put", mock.Anything, mock.Anything). - Return(ExpectedError) + Return(expectedError) localizer := newMockLocalizer(t) localizer. @@ -274,5 +248,5 @@ func TestWitnessCodeSenderSendToIndependentWitnessWhenDonorStoreErrors(t *testin Type: actor.LpaTypePropertyFinance, }, localizer) - assert.Equal(t, ExpectedError, err) + assert.Equal(t, expectedError, err) }