Skip to content

Commit

Permalink
Merge 7bf49e4 into ca5e8eb
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Jun 11, 2024
2 parents ca5e8eb + 7bf49e4 commit 801daa1
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 15 deletions.
9 changes: 5 additions & 4 deletions cypress/e2e/donor/check-your-lpa.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
describe('Check the LPA', () => {
beforeEach(() => {
cy.visit('/fixtures?redirect=/check-your-lpa&progress=peopleToNotifyAboutYourLpa');
});

it('cannot change when personal welfare LPA can be used', () => {
cy.visit('/fixtures?redirect=/check-your-lpa&progress=peopleToNotifyAboutYourLpa&lpa-type=personal-welfare');

Expand All @@ -12,6 +8,8 @@ describe('Check the LPA', () => {
});

it("can submit the completed LPA", () => {
cy.visit('/fixtures?redirect=/check-your-lpa&progress=peopleToNotifyAboutYourLpa&[email protected]');

cy.contains('h1', "Check your LPA")

cy.checkA11yApp();
Expand Down Expand Up @@ -47,6 +45,8 @@ describe('Check the LPA', () => {
});

it('does not allow checking when no changes', () => {
cy.visit('/fixtures?redirect=/check-your-lpa&progress=peopleToNotifyAboutYourLpa');

cy.get('#f-checked-and-happy').check({ force: true })
cy.contains('button', 'Confirm').click();

Expand Down Expand Up @@ -186,6 +186,7 @@ describe('Check the LPA', () => {
})

it("errors when not selected", () => {
cy.visit('/fixtures?redirect=/check-your-lpa&progress=peopleToNotifyAboutYourLpa');
cy.contains('button', 'Confirm').click();

cy.get('.govuk-error-summary').within(() => {
Expand Down
39 changes: 28 additions & 11 deletions internal/notify/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,27 @@ import (
"errors"
"log/slog"
"net/http"
"slices"
"strings"
"time"

"github.com/golang-jwt/jwt/v5"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
)

var allowResendAfter = 10 * time.Minute
var (
allowResendAfter = 10 * time.Minute
simulatedEmails = []string{
"[email protected]",
"[email protected]",
"[email protected]",
}
simulatedPhones = []string{
"07700900000",
"07700900111",
"07700900222",
}
)

type Logger interface {
ErrorContext(ctx context.Context, msg string, args ...any)
Expand Down Expand Up @@ -140,11 +153,13 @@ func (c *Client) SendActorEmail(ctx context.Context, to, lpaUID string, email Em
return err
}

if err := c.eventClient.SendNotificationSent(ctx, event.NotificationSent{
UID: lpaUID,
NotificationID: resp.ID,
}); err != nil {
return err
if !slices.Contains(simulatedEmails, to) {
if err := c.eventClient.SendNotificationSent(ctx, event.NotificationSent{
UID: lpaUID,
NotificationID: resp.ID,
}); err != nil {
return err
}
}

return nil
Expand All @@ -171,11 +186,13 @@ func (c *Client) SendActorSMS(ctx context.Context, to, lpaUID string, sms SMS) e
return err
}

if err := c.eventClient.SendNotificationSent(ctx, event.NotificationSent{
UID: lpaUID,
NotificationID: resp.ID,
}); err != nil {
return err
if !slices.Contains(simulatedPhones, to) {
if err := c.eventClient.SendNotificationSent(ctx, event.NotificationSent{
UID: lpaUID,
NotificationID: resp.ID,
}); err != nil {
return err
}
}

return nil
Expand Down
48 changes: 48 additions & 0 deletions internal/notify/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,33 @@ func TestSendActorEmail(t *testing.T) {
}
}

func TestSendActorEmailWhenToSimulated(t *testing.T) {
assert := assert.New(t)
ctx := context.Background()

for _, email := range simulatedEmails {
doer := newMockDoer(t)
doer.EXPECT().
Do(mock.Anything).
Return(&http.Response{
Body: io.NopCloser(strings.NewReader(`{"notifications":[]}`)),
}, nil).
Once()
doer.EXPECT().
Do(mock.Anything).
Return(&http.Response{
Body: io.NopCloser(strings.NewReader(`{"id":"xyz"}`)),
}, nil).
Once()

client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, nil)
client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) }

err := client.SendActorEmail(ctx, email, "lpa-uid", testEmail{A: "value"})
assert.Nil(err)
}
}

func TestSendActorEmailWhenAlreadyRecentlyCreated(t *testing.T) {
testcases := map[string]string{
"previously created": `{"notifications":[{"status":"delivered","created_at":"2020-01-02T02:54:06Z"}]}`,
Expand Down Expand Up @@ -202,6 +229,7 @@ func TestSendActorEmailWhenReferenceExistsError(t *testing.T) {
err := client.SendActorEmail(context.Background(), "[email protected]", "lpa-uid", testEmail{A: "value"})
assert.Equal(t, expectedError, err)
}

func TestSendActorEmailWhenError(t *testing.T) {
assert := assert.New(t)
ctx := context.Background()
Expand Down Expand Up @@ -447,6 +475,26 @@ func TestSendActorSMS(t *testing.T) {
assert.Nil(err)
}

func TestSendActorSMSWhenToSimulated(t *testing.T) {
assert := assert.New(t)
ctx := context.Background()

for _, phone := range simulatedPhones {
doer := newMockDoer(t)
doer.EXPECT().
Do(mock.Anything).
Return(&http.Response{
Body: io.NopCloser(strings.NewReader(`{"id":"xyz"}`)),
}, nil)

client, _ := New(nil, true, "", "my_client-f33517ff-2a88-4f6e-b855-c550268ce08a-740e5834-3a29-46b4-9a6f-16142fde533a", doer, nil)
client.now = func() time.Time { return time.Date(2020, time.January, 2, 3, 4, 5, 6, time.UTC) }

err := client.SendActorSMS(ctx, phone, "lpa-uid", testSMS{A: "value"})
assert.Nil(err)
}
}

func TestSendActorSMSWhenError(t *testing.T) {
assert := assert.New(t)
ctx := context.Background()
Expand Down

0 comments on commit 801daa1

Please sign in to comment.