Skip to content

Commit

Permalink
Merge pull request #1676 from ministryofjustice/MLPAB-2384-attorney-p…
Browse files Browse the repository at this point in the history
…aper

MLPAB-2384 Allow attorneys to use or change phone number given by paper donor
  • Loading branch information
hawx authored Dec 11, 2024
2 parents 9a15162 + b3a514b commit 8742bdd
Show file tree
Hide file tree
Showing 81 changed files with 1,259 additions and 1,119 deletions.
2 changes: 1 addition & 1 deletion cmd/event-received/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type LambdaClient interface {
}

type LpaStoreClient interface {
SendLpa(ctx context.Context, donor *donordata.Provided) error
SendLpa(ctx context.Context, uid string, body lpastore.CreateLpa) error
Lpa(ctx context.Context, uid string) (*lpadata.Lpa, error)
}

Expand Down
25 changes: 13 additions & 12 deletions cmd/event-received/mock_LpaStoreClient_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions cmd/event-received/sirius_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore"
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
"github.com/ministryofjustice/opg-modernising-lpa/internal/pay"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sharecode"
Expand Down Expand Up @@ -126,7 +127,7 @@ func handleFeeApproved(
donor.Tasks.PayForLpa = task.PaymentStateCompleted

if donor.Tasks.SignTheLpa.IsCompleted() {
if err := lpaStoreClient.SendLpa(ctx, donor); err != nil {
if err := lpaStoreClient.SendLpa(ctx, donor.LpaUID, lpastore.CreateLpaFromDonorProvided(donor)); err != nil {
return fmt.Errorf("failed to send to lpastore: %w", err)
}

Expand Down Expand Up @@ -229,16 +230,19 @@ func handleDonorSubmissionCompleted(ctx context.Context, client dynamodbClient,

lpaID := uuidString()

donor := &donordata.Provided{
PK: dynamo.LpaKey(lpaID),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("PAPER")),
LpaID: lpaID,
LpaUID: v.UID,
CreatedAt: now(),
Version: 1,
}

transaction := dynamo.NewTransaction().
Create(&donordata.Provided{
PK: dynamo.LpaKey(lpaID),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("PAPER")),
LpaID: lpaID,
LpaUID: v.UID,
CreatedAt: now(),
Version: 1,
}).
Create(dynamo.Keys{PK: dynamo.UIDKey(v.UID), SK: dynamo.MetadataKey("")})
Create(donor).
Create(dynamo.Keys{PK: dynamo.UIDKey(v.UID), SK: dynamo.MetadataKey("")}).
Create(dynamo.Keys{PK: donor.PK, SK: dynamo.ReservedKey(dynamo.DonorKey)})

if err := client.WriteTransaction(ctx, transaction); err != nil {
return err
Expand Down
10 changes: 6 additions & 4 deletions cmd/event-received/sirius_event_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
"github.com/ministryofjustice/opg-modernising-lpa/internal/pay"
Expand Down Expand Up @@ -141,7 +142,7 @@ func TestHandleFeeApproved(t *testing.T) {

lpaStoreClient := newMockLpaStoreClient(t)
lpaStoreClient.EXPECT().
SendLpa(ctx, &completedDonorProvided).
SendLpa(ctx, completedDonorProvided.LpaUID, lpastore.CreateLpaFromDonorProvided(&completedDonorProvided)).
Return(nil)

eventClient := newMockEventClient(t)
Expand Down Expand Up @@ -418,7 +419,7 @@ func TestHandleFeeApprovedWhenShareCodeSenderError(t *testing.T) {

lpaStoreClient := newMockLpaStoreClient(t)
lpaStoreClient.EXPECT().
SendLpa(mock.Anything, mock.Anything).
SendLpa(mock.Anything, mock.Anything, mock.Anything).
Return(nil)

eventClient := newMockEventClient(t)
Expand Down Expand Up @@ -464,7 +465,7 @@ func TestHandleFeeApprovedWhenEventClientError(t *testing.T) {

lpaStoreClient := newMockLpaStoreClient(t)
lpaStoreClient.EXPECT().
SendLpa(mock.Anything, mock.Anything).
SendLpa(mock.Anything, mock.Anything, mock.Anything).
Return(nil)

eventClient := newMockEventClient(t)
Expand Down Expand Up @@ -505,7 +506,7 @@ func TestHandleFeeApprovedWhenLpaStoreError(t *testing.T) {

lpaStoreClient := newMockLpaStoreClient(t)
lpaStoreClient.EXPECT().
SendLpa(ctx, mock.Anything).
SendLpa(ctx, mock.Anything, mock.Anything).
Return(expectedError)

err := handleFeeApproved(ctx, client, event, nil, lpaStoreClient, nil, appcontext.Data{}, testNowFn)
Expand Down Expand Up @@ -763,6 +764,7 @@ func TestHandleDonorSubmissionCompleted(t *testing.T) {
Version: 1,
},
dynamo.Keys{PK: dynamo.UIDKey("M-1111-2222-3333"), SK: dynamo.MetadataKey("")},
dynamo.Keys{PK: dynamo.LpaKey(testUuidString), SK: dynamo.ReservedKey(dynamo.DonorKey)},
},
}).
Return(nil)
Expand Down
137 changes: 118 additions & 19 deletions cypress/e2e/attorney/confirm-your-details.cy.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,126 @@
import { TestMobile } from '../../support/e2e';
import { TestMobile, TestMobile2 } from '../../support/e2e';

describe('Confirm your details', () => {
beforeEach(() => {
cy.visit('/fixtures/attorney?redirect=/phone-number');
describe('online donor', () => {
beforeEach(() => {
cy.visit('/fixtures/attorney?redirect=/task-list');

cy.get('#f-phone').type(TestMobile);
cy.contains('button', 'Save and continue').click();
cy.contains('li', 'Confirm your details').should('contain', 'Not started').click();

cy.get('[name="language-preference"]').check('cy', { force: true })
cy.contains('button', 'Save and continue').click()
});
cy.get('#f-phone').type(TestMobile);
cy.contains('button', 'Save and continue').click();

it('shows details', () => {
cy.url().should('contain', '/confirm-your-details');
cy.checkA11yApp();
cy.get('[name="language-preference"]').check('cy', { force: true })
cy.contains('button', 'Save and continue').click()
});

cy.contains('2 January 2000');
cy.contains('Jessie Jones');
cy.contains('2 RICHMOND PLACE');
cy.contains('07700 900 000');
cy.contains('Welsh');
it('shows details', () => {
cy.url().should('contain', '/confirm-your-details');
cy.checkA11yApp();

cy.contains('button', 'Continue').click();
cy.url().should('contain', '/task-list');
});
cy.contains('2 January 2000');
cy.contains('Jessie Jones');
cy.contains('2 RICHMOND PLACE');
cy.contains('07700 900 000');
cy.contains('Welsh');

cy.contains('button', 'Continue').click();
cy.url().should('contain', '/task-list');
});
});

describe('paper donor', () => {
beforeEach(() => {
cy.visit('/fixtures/attorney?is-paper-donor=1&redirect=/task-list');

cy.contains('li', 'Confirm your details').should('contain', 'Not started').click();

cy.get('#f-phone').type(TestMobile);
cy.contains('button', 'Save and continue').click();

cy.get('[name="language-preference"]').check('cy', { force: true })
cy.contains('button', 'Save and continue').click()
});

it('shows details', () => {
cy.url().should('contain', '/confirm-your-details');
cy.checkA11yApp();

cy.contains('2 January 2000');
cy.contains('Jessie Jones');
cy.contains('2 RICHMOND PLACE');
cy.contains('07700 900 000');
cy.contains('Welsh');

cy.contains('button', 'Continue').click();
cy.url().should('contain', '/task-list');
});
});

describe('paper donor gave phone number', () => {
beforeEach(() => {
cy.visit('/fixtures/attorney?is-paper-donor=1&has-phone-number=1&redirect=/task-list');

cy.contains('li', 'Confirm your details').should('contain', 'Not started').click();

cy.get('[name="language-preference"]').check('cy', { force: true })
cy.contains('button', 'Save and continue').click()
});

it('shows details', () => {
cy.url().should('contain', '/confirm-your-details');
cy.checkA11yApp();

cy.contains('h2', 'Details you have given us').next().within(() => {
cy.contains('Welsh');
cy.contains('Phone number').should('not.exist');
});

cy.contains('h2', 'Details the donor has given about you').next().within(() => {
cy.contains('2 January 2000');
cy.contains('Jessie Jones');
cy.contains('2 RICHMOND PLACE');
cy.contains('07700 900 000');
});

cy.contains('button', 'Continue').click();
cy.url().should('contain', '/task-list');
});

it('can change the phone number', () => {
cy.contains('.govuk-summary-list__row', 'Phone number').contains('a', 'Change').click();
cy.get('#f-phone').clear().type(TestMobile2);
cy.contains('button', 'Save and continue').click()

cy.contains('h2', 'Details you have given us').next().within(() => {
cy.contains('07700 900 111');
cy.contains('Welsh');
});

cy.contains('h2', 'Details the donor has given about you').next().within(() => {
cy.contains('2 January 2000');
cy.contains('Jessie Jones');
cy.contains('2 RICHMOND PLACE');
cy.contains('Phone number').should('not.exist');
});
});

it('can remove the phone number', () => {
cy.contains('.govuk-summary-list__row', 'Phone number').contains('a', 'Change').click();
cy.get('#f-phone').clear();
cy.contains('button', 'Save and continue').click()

cy.contains('h2', 'Details you have given us').next().within(() => {
cy.contains('Enter phone number');
cy.contains('Welsh');
});

cy.contains('h2', 'Details the donor has given about you').next().within(() => {
cy.contains('2 January 2000');
cy.contains('Jessie Jones');
cy.contains('2 RICHMOND PLACE');
cy.contains('Phone number').should('not.exist');
});
});
});
});
3 changes: 2 additions & 1 deletion cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import "cypress-real-events"
export const
TestEmail = 'simulate-delivered@notifications.service.gov.uk',
TestEmail2 = 'simulate-delivered-2@notifications.service.gov.uk',
TestMobile = '07700900000'
TestMobile = '07700900000',
TestMobile2 = '07700900111';

export function randomShareCode() {
const characters = 'abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789'
Expand Down
2 changes: 1 addition & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func App(
handleRoot(page.PathCertificateProviderFixtures, None,
fixtures.CertificateProvider(tmpls.Get("certificate_provider_fixtures.gohtml"), sessionStore, shareCodeSender, donorStore, certificateProviderStore, eventClient, lpaStoreClient, lpaDynamoClient, organisationStore, memberStore, shareCodeStore))
handleRoot(page.PathAttorneyFixtures, None,
fixtures.Attorney(tmpls.Get("attorney_fixtures.gohtml"), sessionStore, shareCodeSender, donorStore, certificateProviderStore, attorneyStore, eventClient, lpaStoreClient, organisationStore, memberStore, shareCodeStore))
fixtures.Attorney(tmpls.Get("attorney_fixtures.gohtml"), sessionStore, shareCodeSender, donorStore, certificateProviderStore, attorneyStore, eventClient, lpaStoreClient, organisationStore, memberStore, shareCodeStore, lpaDynamoClient))
handleRoot(page.PathSupporterFixtures, None,
fixtures.Supporter(tmpls.Get("supporter_fixtures.gohtml"), sessionStore, organisationStore, donorStore, memberStore, lpaDynamoClient, searchClient, shareCodeStore, certificateProviderStore, attorneyStore, documentStore, eventClient, lpaStoreClient))
handleRoot(page.PathVoucherFixtures, None,
Expand Down
3 changes: 3 additions & 0 deletions internal/attorney/attorneydata/provided.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type Provided struct {
IsTrustCorporation bool
// Phone number of the attorney or replacement attorney (mobile or landline)
Phone string
// PhoneSet is set to true when Phone is first set, then we can determine if
// the attorney has chosen to remove the number a paper donor provided.
PhoneSet bool
// SignedAt is when the attorney or replacement attorney submitted their
// signature
SignedAt time.Time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,15 @@ type confirmDontWantToBeAttorneyData struct {
Lpa *lpadata.Lpa
}

func ConfirmDontWantToBeAttorney(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, attorneyStore AttorneyStore, notifyClient NotifyClient, appPublicURL string, lpaStoreClient LpaStoreClient) Handler {
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, attorneyProvidedDetails *attorneydata.Provided) error {
lpa, err := lpaStoreResolvingService.Get(r.Context())
if err != nil {
return err
}

func ConfirmDontWantToBeAttorney(tmpl template.Template, attorneyStore AttorneyStore, notifyClient NotifyClient, appPublicURL string, 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,
Lpa: lpa,
}

if r.Method == http.MethodPost {
fullName, actorType := lpa.Attorney(attorneyProvidedDetails.UID)
fullName, _, actorType := lpa.Attorney(attorneyProvidedDetails.UID)
if actorType.IsNone() {
return errors.New("attorney not found")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func ConfirmDontWantToBeAttorneyLoggedOut(tmpl template.Template, shareCodeStore
return err
}

fullName, actorType := lpa.Attorney(shareCode.ActorUID)
fullName, _, actorType := lpa.Attorney(shareCode.ActorUID)
if actorType.IsNone() {
return errors.New("attorney not found")
}
Expand Down
Loading

0 comments on commit 8742bdd

Please sign in to comment.