Skip to content

Commit

Permalink
MLPAB-1535: Vary certificate provider phone field label for paper don…
Browse files Browse the repository at this point in the history
…ors (#1167)
  • Loading branch information
acsauk authored Apr 9, 2024
1 parent 4b6aef2 commit cbb9127
Show file tree
Hide file tree
Showing 26 changed files with 298 additions and 72 deletions.
2 changes: 1 addition & 1 deletion cmd/mlpa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func run(ctx context.Context, logger *slog.Logger) error {

mux := http.NewServeMux()
mux.HandleFunc(page.Paths.HealthCheck.Service.String(), func(w http.ResponseWriter, r *http.Request) {})
mux.Handle(page.Paths.HealthCheck.Dependency.String(), page.DependencyHealthCheck(logger, map[string]page.HealthChecker{
mux.Handle(page.Paths.HealthCheck.Dependency.String(), page.DependencyHealthCheck(map[string]page.HealthChecker{
"uid": uidClient,
"onelogin": oneloginClient,
"lpaStore": lpaStoreClient,
Expand Down
7 changes: 7 additions & 0 deletions cypress/e2e/certificate-provider/confirm-your-details.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,12 @@ describe('Confirm your details', () => {
cy.contains('button', 'Continue').click();
cy.url().should('contain', '/your-role');
});

it('shows contact number when donor acting on paper', () => {
cy.visit('/fixtures/certificate-provider?redirect=/confirm-your-details&donorChannel=paper');

cy.contains('Contact number').should('exist');
cy.contains('Mobile number').should('not.exist');
})
})
});
14 changes: 9 additions & 5 deletions docker/mock-lpa-store/lpa-store.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ def lpaStore = stores.open('lpa')

switch (context.request.method) {
case 'GET':
def parts = context.request.path.split('/')
def lpa = lpaStore.load(parts[2])
if (lpa) {
respond().withContent(lpa)
if (context.request.path.contains('/lpa')) {
def parts = context.request.path.split('/')
def lpa = lpaStore.load(parts[2])
if (lpa) {
respond().withContent(lpa)
} else {
respond().withStatusCode(404)
}
} else {
respond().withStatusCode(404)
respond()
}
break

Expand Down
25 changes: 25 additions & 0 deletions docs/conventions/template-logic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Template logic

Logic that varies content in page templates should be controlled in code rather than the template. For example:

```gotemplate
{{ $detailsContent := "whatToDoIfAnyDetailsAreIncorrectCertificateProviderContentLay" }}
{{ if .Lpa.CertificateProvider.Relationship.IsProfessionally }}
{{ $detailsContent = "whatToDoIfAnyDetailsAreIncorrectCertificateProviderContentProfessional" }}
{{ end }}
```

should be set in a handler:

```go
data := &confirmYourDetailsData{
DetailComponentContent: "whatToDoIfAnyDetailsAreIncorrectCertificateProviderContentLay",
}

if lpa.CertificateProvider.Relationship.IsProfessionally() {
data.DetailComponentContent = "whatToDoIfAnyDetailsAreIncorrectCertificateProviderContentProfessional"
}
```

This allows for easier testing in unit tests vs e2e tests and keeps logic in one place.
9 changes: 9 additions & 0 deletions internal/actor/channel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package actor

//go:generate enumerator -type Channel -linecomment -empty -trimprefix
type Channel uint8

const (
ChannelPaper Channel = iota + 1 // paper
ChannelOnline // online
)
2 changes: 2 additions & 0 deletions internal/actor/donor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type Donor struct {
ThinksCanSign YesNoMaybe
// CanSign is Yes if the donor has said they will sign online
CanSign form.YesNo
// Channel is how the Donor is applying for their LPA (paper or online)
Channel Channel
}

func (d Donor) FullName() string {
Expand Down
4 changes: 2 additions & 2 deletions internal/actor/donor_provided_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func TestGenerateHash(t *testing.T) {
}}
hash, err := donor.GenerateHash()
assert.Nil(t, err)
assert.Equal(t, uint64(0x237cd6c0f6339a69), hash)
assert.Equal(t, uint64(0x297cf8fea06bba4f), hash)

donor.Attorneys.Attorneys[0].DateOfBirth = date.New("2001", "1", "2")
hash, err = donor.GenerateHash()
assert.Nil(t, err)
assert.Equal(t, uint64(0xf28a35e77ddfb6c0), hash)
assert.Equal(t, uint64(0xfb9a92b69eaeee6), hash)
}

func TestIdentityConfirmed(t *testing.T) {
Expand Down
74 changes: 74 additions & 0 deletions internal/actor/enum_channel.go

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

4 changes: 2 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ func App(
handleRoot(page.Paths.Fixtures, None,
fixtures.Donor(tmpls.Get("fixtures.gohtml"), sessionStore, donorStore, certificateProviderStore, attorneyStore, documentStore, eventClient, lpaStoreClient))
handleRoot(page.Paths.CertificateProviderFixtures, None,
fixtures.CertificateProvider(tmpls.Get("certificate_provider_fixtures.gohtml"), sessionStore, shareCodeSender, donorStore, certificateProviderStore, eventClient, lpaStoreClient))
fixtures.CertificateProvider(tmpls.Get("certificate_provider_fixtures.gohtml"), sessionStore, shareCodeSender, donorStore, certificateProviderStore, eventClient, lpaStoreClient, lpaDynamoClient))
handleRoot(page.Paths.AttorneyFixtures, None,
fixtures.Attorney(tmpls.Get("attorney_fixtures.gohtml"), sessionStore, shareCodeSender, donorStore, certificateProviderStore, attorneyStore, eventClient, lpaStoreClient))
handleRoot(page.Paths.SupporterFixtures, None,
fixtures.Supporter(sessionStore, organisationStore, donorStore, memberStore, lpaDynamoClient, searchClient, shareCodeStore, certificateProviderStore, attorneyStore, documentStore, eventClient, lpaStoreClient))
handleRoot(page.Paths.DashboardFixtures, None,
fixtures.Dashboard(tmpls.Get("dashboard_fixtures.gohtml"), sessionStore, shareCodeSender, donorStore, certificateProviderStore, attorneyStore))
fixtures.Dashboard(tmpls.Get("dashboard_fixtures.gohtml"), sessionStore, donorStore, certificateProviderStore, attorneyStore))
handleRoot(page.Paths.YourLegalRightsAndResponsibilities, None,
page.Guidance(tmpls.Get("your_legal_rights_and_responsibilities_general.gohtml")))
handleRoot(page.Paths.Start, None,
Expand Down
3 changes: 2 additions & 1 deletion internal/app/donor_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ func (s *donorStore) Create(ctx context.Context) (*actor.DonorProvidedDetails, e
CreatedAt: s.now(),
Version: 1,
Donor: actor.Donor{
UID: donorUID,
UID: donorUID,
Channel: actor.ChannelOnline,
},
}

Expand Down
1 change: 1 addition & 0 deletions internal/app/donor_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ func TestDonorStoreCreate(t *testing.T) {
OtherNames: previousDetails.Donor.OtherNames,
DateOfBirth: previousDetails.Donor.DateOfBirth,
Address: previousDetails.Donor.Address,
Channel: actor.ChannelOnline,
},
}
donor.Hash, _ = donor.GenerateHash()
Expand Down
2 changes: 2 additions & 0 deletions internal/lpastore/resolving_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ func (s *ResolvingService) Get(ctx context.Context) (*Lpa, error) {
// set to Professionally so we always show the certificate provider home
// address question
lpa.CertificateProvider.Relationship = actor.Professionally
lpa.Donor.Channel = actor.ChannelPaper
} else {
lpa.DonorIdentityConfirmed = donor.DonorIdentityConfirmed()
lpa.Submitted = !donor.SubmittedAt.IsZero()
lpa.Paid = donor.Tasks.PayForLpa.IsCompleted()
lpa.IsOrganisationDonor = strings.HasPrefix(donor.SK, dynamo.OrganisationKey(""))
lpa.Donor.Channel = actor.ChannelOnline

// copy the relationship as it isn't stored in the lpastore.
lpa.CertificateProvider.Relationship = donor.CertificateProvider.Relationship
Expand Down
12 changes: 9 additions & 3 deletions internal/lpastore/resolving_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestResolvingServiceGet(t *testing.T) {
error error
expected *Lpa
}{
"digital with all true": {
"online with all true": {
donor: &actor.DonorProvidedDetails{
SK: dynamo.OrganisationKey("S"),
LpaID: "1",
Expand Down Expand Up @@ -58,16 +58,18 @@ func TestResolvingServiceGet(t *testing.T) {
FirstNames: "Paul",
Relationship: actor.Personally,
},
Donor: actor.Donor{Channel: actor.ChannelOnline},
},
},
"digital with no lpastore record": {
"online with no lpastore record": {
donor: &actor.DonorProvidedDetails{
SK: dynamo.DonorKey("S"),
LpaUID: "M-1111",
CertificateProvider: actor.CertificateProvider{
FirstNames: "John",
Relationship: actor.Personally,
},
Donor: actor.Donor{Channel: actor.ChannelOnline},
},
error: ErrNotFound,
expected: &Lpa{
Expand All @@ -76,9 +78,10 @@ func TestResolvingServiceGet(t *testing.T) {
FirstNames: "John",
Relationship: actor.Personally,
},
Donor: actor.Donor{Channel: actor.ChannelOnline},
},
},
"digital with all false": {
"online with all false": {
donor: &actor.DonorProvidedDetails{
SK: dynamo.DonorKey("S"),
LpaID: "1",
Expand All @@ -88,6 +91,7 @@ func TestResolvingServiceGet(t *testing.T) {
expected: &Lpa{
LpaID: "1",
LpaUID: "M-1111",
Donor: actor.Donor{Channel: actor.ChannelOnline},
},
},
"paper": {
Expand All @@ -105,6 +109,7 @@ func TestResolvingServiceGet(t *testing.T) {
CertificateProvider: actor.CertificateProvider{
Relationship: actor.Professionally,
},
Donor: actor.Donor{Channel: actor.ChannelPaper},
},
},
}
Expand Down Expand Up @@ -151,6 +156,7 @@ func TestResolvingServiceGetWhenNotFound(t *testing.T) {
assert.Equal(t, &Lpa{
LpaID: "1",
LpaUID: "M-1111",
Donor: actor.Donor{Channel: actor.ChannelOnline},
}, lpa)
assert.Nil(t, err)
}
Expand Down
29 changes: 22 additions & 7 deletions internal/page/certificateprovider/confirm_your_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import (
)

type confirmYourDetailsData struct {
App page.AppData
Errors validation.List
Lpa *lpastore.Lpa
CertificateProvider *actor.CertificateProviderProvidedDetails
App page.AppData
Errors validation.List
Lpa *lpastore.Lpa
CertificateProvider *actor.CertificateProviderProvidedDetails
PhoneNumberLabel string
AddressLabel string
DetailComponentContent string
}

func ConfirmYourDetails(tmpl template.Template, lpaStoreResolvingService LpaStoreResolvingService, certificateProviderStore CertificateProviderStore) page.Handler {
Expand Down Expand Up @@ -45,9 +48,21 @@ func ConfirmYourDetails(tmpl template.Template, lpaStoreResolvingService LpaStor
}

data := &confirmYourDetailsData{
App: appData,
CertificateProvider: certificateProvider,
Lpa: lpa,
App: appData,
CertificateProvider: certificateProvider,
Lpa: lpa,
PhoneNumberLabel: "mobileNumber",
AddressLabel: "address",
DetailComponentContent: "whatToDoIfAnyDetailsAreIncorrectCertificateProviderContentLay",
}

if lpa.Donor.Channel.IsPaper() {
data.PhoneNumberLabel = "contactNumber"
}

if lpa.CertificateProvider.Relationship.IsProfessionally() {
data.AddressLabel = "workAddress"
data.DetailComponentContent = "whatToDoIfAnyDetailsAreIncorrectCertificateProviderContentProfessional"
}

return tmpl(w, data)
Expand Down
Loading

0 comments on commit cbb9127

Please sign in to comment.