-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
|
||
|
@@ -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(); | ||
|
@@ -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(); | ||
|
||
|
@@ -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(() => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"}]}`, | ||
|
@@ -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() | ||
|
@@ -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() | ||
|