Skip to content

Commit

Permalink
Split out certificate provider fixtures page
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx committed Sep 28, 2023
1 parent 5fafb47 commit 36d9d6f
Show file tree
Hide file tree
Showing 15 changed files with 274 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Certificate provided', () => {
beforeEach(() => {
cy.visit('/testing-start?redirect=/certificate-provided&loginAs=certificate-provider');
cy.visit('/fixtures/certificate-provider?redirect=/certificate-provided');
});

it('has a button to the dashboard', () => {
Expand Down
10 changes: 5 additions & 5 deletions cypress/e2e/certificate-provider/confirm-your-details.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Confirm your details', () => {
it('shows details', () => {
cy.visit('/testing-start?redirect=/enter-date-of-birth&lpa.certificateProvider=1&asCertificateProvider=1&loginAs=certificate-provider');
cy.visit('/fixtures/certificate-provider?redirect=/enter-date-of-birth');

cy.get('#f-date-of-birth').type('1');
cy.get('#f-date-of-birth-month').type('2');
Expand All @@ -20,8 +20,8 @@ describe('Confirm your details', () => {
cy.url().should('contain', '/your-role');
});

it('redirects to tasklist when details have already been confirmed', () => {
cy.visit('/testing-start?redirect=/confirm-your-details&lpa.certificateProvider=1&asCertificateProvider=1&cp.confirmYourDetails=1&loginAs=certificate-provider');
it('redirects to tasklist when LPA has already been witnessed', () => {
cy.visit('/fixtures/certificate-provider?redirect=/confirm-your-details&progress=signedByDonor');

cy.url().should('contain', '/confirm-your-details');
cy.checkA11yApp();
Expand All @@ -32,8 +32,8 @@ describe('Confirm your details', () => {
cy.contains('li', 'Confirm your details').should('contain', 'Completed');
});

it('redirects to tasklist when LPA has already been witnessed', () => {
cy.visit('/testing-start?redirect=/confirm-your-details&lpa.certificateProvider=1&asCertificateProvider=1&lpa.signedByDonor=1&loginAs=certificate-provider');
it('redirects to tasklist when details have already been confirmed', () => {
cy.visit('/fixtures/certificate-provider?redirect=/confirm-your-details&progress=detailsConfirmed');

cy.url().should('contain', '/confirm-your-details');
cy.checkA11yApp();
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/certificate-provider/enter-date-of-birth.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Enter date of birth', () => {
beforeEach(() => {
cy.visit('/testing-start?redirect=/enter-date-of-birth&asCertificateProvider=1&loginAs=certificate-provider');
cy.visit('/fixtures/certificate-provider?redirect=/enter-date-of-birth');
});

it('can be completed', () => {
Expand Down
14 changes: 6 additions & 8 deletions cypress/e2e/certificate-provider/enter-reference-number.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const { TestEmail } = require("../../support/e2e");

describe('Enter reference number', () => {
it('can enter a valid reference number', { pageLoadTimeout: 6000 }, () => {
cy.visit('/testing-start?lpa.complete=1&startCpFlowDonorHasPaid=1&useTestShareCode=1');
beforeEach(() => {
cy.visit('/fixtures/certificate-provider?redirect=/certificate-provider-start&use-test-code=1&email=' + TestEmail);
});

it('can enter a valid reference number', { pageLoadTimeout: 6000 }, () => {
cy.contains('a', 'Start').click()

cy.checkA11yApp();
Expand All @@ -13,8 +17,6 @@ describe('Enter reference number', () => {
});

it('errors when empty number', () => {
cy.visit('/testing-start?lpa.complete=1&startCpFlowDonorHasPaid=1&useTestShareCode=1');

cy.contains('a', 'Start').click()

cy.checkA11yApp();
Expand All @@ -29,8 +31,6 @@ describe('Enter reference number', () => {
});

it('errors when incorrect code', () => {
cy.visit('/testing-start?lpa.complete=1&startCpFlowDonorHasPaid=1&useTestShareCode=1');

cy.contains('a', 'Start').click()

cy.checkA11yApp();
Expand All @@ -46,8 +46,6 @@ describe('Enter reference number', () => {
});

it('errors when incorrect code length', () => {
cy.visit('/testing-start?lpa.complete=1&startCpFlowDonorHasPaid=1&useTestShareCode=1');

cy.contains('a', 'Start').click()

cy.checkA11yApp();
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/certificate-provider/provide-certificate.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Provide the certificate', () => {
beforeEach(() => {
cy.visit('/testing-start?redirect=/provide-certificate&lpa.complete=1&asCertificateProvider=1&loginAs=certificate-provider');
cy.visit('/fixtures/certificate-provider?redirect=/provide-certificate&progress=signedByDonor');
});

it('can provide the certificate', () => {
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/certificate-provider/read-the-lpa.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe('Read the LPA', () => {
describe('when the LPA is signed', () => {
beforeEach(() => {
cy.visit('/testing-start?redirect=/read-the-lpa&lpa.complete=1&asCertificateProvider=1&loginAs=certificate-provider');
cy.visit('/fixtures/certificate-provider?redirect=/read-the-lpa&progress=signedByDonor');
});

it('displays the LPA details and goes to provide certificate', () => {
Expand All @@ -18,7 +18,7 @@ describe('Read the LPA', () => {

describe('when the LPA is not yet signed', () => {
beforeEach(() => {
cy.visit('/testing-start?redirect=/read-the-lpa&lpa.certificateProvider=1&lpa.yourDetails=1&asCertificateProvider=1&loginAs=certificate-provider');
cy.visit('/fixtures/certificate-provider?redirect=/read-the-lpa');
});

it('displays the LPA details and goes to task list', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Select your identity options', () => {
beforeEach(() => {
cy.visit('/testing-start?redirect=/select-your-identity-options&lpa.complete=1&asCertificateProvider=1&loginAs=certificate-provider');
cy.visit('/fixtures/certificate-provider?redirect=/select-your-identity-options');
});

it('can select on first page', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/certificate-provider/start.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Start', () => {
beforeEach(() => {
cy.visit('/testing-start?startCpFlowDonorHasPaid=1');
cy.visit('/certificate-provider-start');
});

it('can be completed', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/certificate-provider/task-list.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Task list', () => {
beforeEach(() => {
cy.visit('/testing-start?redirect=/task-list&lpa.complete=1&asCertificateProvider=1&loginAs=certificate-provider');
cy.visit('/fixtures/certificate-provider?redirect=/task-list&progress=signedByDonor');
});

it('shows tasks', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/certificate-provider/who-is-eligible.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Who is eligible', () => {
beforeEach(() => {
cy.visit('/testing-start?redirect=/certificate-provider-who-is-eligible&loginAs=certificate-provider');
cy.visit('/fixtures/certificate-provider?redirect=/certificate-provider-who-is-eligible');
});

it('can continue', () => {
Expand Down
2 changes: 2 additions & 0 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ func App(
page.SignOut(logger, sessionStore, oneLoginClient, appPublicURL))
handleRoot(paths.Fixtures, None,
page.Fixtures(tmpls.Get("fixtures.gohtml")))
handleRoot(paths.CertificateProviderFixtures, None,
page.CertificateProviderFixtures(tmpls.Get("certificate_provider_fixtures.gohtml"), sessionStore, shareCodeSender, donorStore, certificateProviderStore))
handleRoot(paths.AttorneyFixtures, None,
page.AttorneyFixtures(tmpls.Get("attorney_fixtures.gohtml"), sessionStore, shareCodeSender, donorStore, certificateProviderStore, attorneyStore))
handleRoot(paths.YourLegalRightsAndResponsibilities, None,
Expand Down
201 changes: 201 additions & 0 deletions internal/page/certificate_provider_fixtures.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
package page

import (
"encoding/base64"
"net/http"
"slices"
"time"

"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/date"
"github.com/ministryofjustice/opg-modernising-lpa/internal/form"
"github.com/ministryofjustice/opg-modernising-lpa/internal/notify"
"github.com/ministryofjustice/opg-modernising-lpa/internal/place"
"github.com/ministryofjustice/opg-modernising-lpa/internal/random"
"github.com/ministryofjustice/opg-modernising-lpa/internal/sesh"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)

type certificateProviderFixturesData struct {
App AppData
Errors validation.List
}

func CertificateProviderFixtures(
tmpl template.Template,
sessionStore sesh.Store,
shareCodeSender *ShareCodeSender,
donorStore DonorStore,
certificateProviderStore CertificateProviderStore,
) Handler {
const (
testEmail = "[email protected]"
testMobile = "07700900000"
)

type Name struct {
Firstnames, Lastname string
}

var (
progressValues = []string{
"paid",
"signedByDonor",
"detailsConfirmed",
}
attorneyNames = []Name{
{Firstnames: "Jessie", Lastname: "Jones"},
{Firstnames: "Robin", Lastname: "Redcar"},
{Firstnames: "Leslie", Lastname: "Lewis"},
{Firstnames: "Ashley", Lastname: "Alwinton"},
{Firstnames: "Frankie", Lastname: "Fernandes"},
}
)

makeAttorney := func(name Name) actor.Attorney {
return actor.Attorney{
ID: name.Firstnames + name.Lastname,
FirstNames: name.Firstnames,
LastName: name.Lastname,
Email: testEmail,
DateOfBirth: date.New("2000", "1", "2"),
Address: place.Address{
Line1: "2 RICHMOND PLACE",
Line2: "KINGS HEATH",
Line3: "WEST MIDLANDS",
TownOrCity: "BIRMINGHAM",
Postcode: "B14 7ED",
},
}
}

Check warning on line 71 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L31-L71

Added lines #L31 - L71 were not covered by tests

return func(appData AppData, w http.ResponseWriter, r *http.Request) error {
var (
lpaType = r.FormValue("lpa-type")
progress = slices.Index(progressValues, r.FormValue("progress"))
email = r.FormValue("email")
redirect = r.FormValue("redirect")
)

if r.Method != http.MethodPost && redirect == "" {
return tmpl(w, &certificateProviderFixturesData{App: appData})
}

Check warning on line 83 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L73-L83

Added lines #L73 - L83 were not covered by tests

var (
donorSub = random.String(16)
certificateProviderSub = random.String(16)
donorSessionID = base64.StdEncoding.EncodeToString([]byte(donorSub))
certificateProviderSessionID = base64.StdEncoding.EncodeToString([]byte(certificateProviderSub))
)

if err := sesh.SetLoginSession(sessionStore, r, w, &sesh.LoginSession{Sub: certificateProviderSub, Email: testEmail}); err != nil {
return err
}

Check warning on line 94 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L85-L94

Added lines #L85 - L94 were not covered by tests

lpa, err := donorStore.Create(ContextWithSessionData(r.Context(), &SessionData{SessionID: donorSessionID}))
if err != nil {
return err
}

Check warning on line 99 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L96-L99

Added lines #L96 - L99 were not covered by tests

var (
donorCtx = ContextWithSessionData(r.Context(), &SessionData{SessionID: donorSessionID, LpaID: lpa.ID})
certificateProviderCtx = ContextWithSessionData(r.Context(), &SessionData{SessionID: certificateProviderSessionID, LpaID: lpa.ID})
)

lpa.Donor = actor.Donor{
FirstNames: "Sam",
LastName: "Smith",
Address: place.Address{
Line1: "1 RICHMOND PLACE",
Line2: "KINGS HEATH",
Line3: "WEST MIDLANDS",
TownOrCity: "BIRMINGHAM",
Postcode: "B14 7ED",
},
Email: testEmail,
DateOfBirth: date.New("2000", "1", "2"),
ThinksCanSign: actor.Yes,
CanSign: form.Yes,
}
lpa.Type = LpaTypePropertyFinance
if lpaType == "hw" {
lpa.Type = LpaTypeHealthWelfare
}

Check warning on line 124 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L101-L124

Added lines #L101 - L124 were not covered by tests

lpa.Attorneys = actor.Attorneys{
Attorneys: []actor.Attorney{makeAttorney(attorneyNames[0]), makeAttorney(attorneyNames[1])},
}

lpa.CertificateProvider = actor.CertificateProvider{
FirstNames: "Charlie",
LastName: "Cooper",
Email: testEmail,
Mobile: testMobile,
Relationship: actor.Personally,
RelationshipLength: "gte-2-years",
CarryOutBy: actor.Online,
Address: place.Address{
Line1: "5 RICHMOND PLACE",
Line2: "KINGS HEATH",
Line3: "WEST MIDLANDS",
TownOrCity: "BIRMINGHAM",
Postcode: "B14 7ED",
},
}

if email != "" {
lpa.CertificateProvider.Email = email
}

Check warning on line 149 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L126-L149

Added lines #L126 - L149 were not covered by tests

certificateProvider, err := certificateProviderStore.Create(certificateProviderCtx, donorSessionID)
if err != nil {
return err
}

Check warning on line 154 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L151-L154

Added lines #L151 - L154 were not covered by tests

if progress >= slices.Index(progressValues, "paid") {
lpa.PaymentDetails = append(lpa.PaymentDetails, Payment{
PaymentReference: random.String(12),
PaymentId: random.String(12),
})
lpa.Tasks.PayForLpa = actor.PaymentTaskCompleted
}
if progress >= slices.Index(progressValues, "signedByDonor") {
lpa.SignedAt = time.Now()
}
if progress >= slices.Index(progressValues, "detailsConfirmed") {
certificateProvider.DateOfBirth = date.New("1990", "1", "2")
certificateProvider.Tasks.ConfirmYourDetails = actor.TaskCompleted
}

Check warning on line 169 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L156-L169

Added lines #L156 - L169 were not covered by tests

if err := donorStore.Put(donorCtx, lpa); err != nil {
return err
}
if err := certificateProviderStore.Put(certificateProviderCtx, certificateProvider); err != nil {
return err
}

Check warning on line 176 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L171-L176

Added lines #L171 - L176 were not covered by tests

// should only be used in tests as otherwise people can read their emails...
if r.FormValue("use-test-code") == "1" {
useTestCode = true
}

Check warning on line 181 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L179-L181

Added lines #L179 - L181 were not covered by tests

if email != "" {
shareCodeSender.SendCertificateProvider(donorCtx, notify.CertificateProviderInviteEmail, AppData{
SessionID: donorSessionID,
LpaID: lpa.ID,
Localizer: appData.Localizer,
}, true, lpa)

return AppData{}.Redirect(w, r, nil, Paths.CertificateProviderStart.Format())
}

Check warning on line 191 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L183-L191

Added lines #L183 - L191 were not covered by tests

if redirect == "" {
redirect = Paths.Dashboard.Format()
} else {
redirect = "/certificate-provider/" + lpa.ID + redirect
}

Check warning on line 197 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L193-L197

Added lines #L193 - L197 were not covered by tests

return AppData{}.Redirect(w, r, nil, redirect)

Check warning on line 199 in internal/page/certificate_provider_fixtures.go

View check run for this annotation

Codecov / codecov/patch

internal/page/certificate_provider_fixtures.go#L199

Added line #L199 was not covered by tests
}
}
2 changes: 2 additions & 0 deletions internal/page/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ type AppPaths struct {
SignOut Path
Fixtures Path
AttorneyFixtures Path
CertificateProviderFixtures Path
YourLegalRightsAndResponsibilities Path
CertificateProviderStart Path
Start Path
Expand Down Expand Up @@ -265,6 +266,7 @@ var Paths = AppPaths{
CanEvidenceBeUploaded: "/can-evidence-be-uploaded",
CertificateProviderAddress: "/certificate-provider-address",
CertificateProviderDetails: "/certificate-provider-details",
CertificateProviderFixtures: "/fixtures/certificate-provider",
CertificateProviderOptOut: "/certificate-provider-opt-out",
CertificateProviderStart: "/certificate-provider-start",
CheckYouCanSign: "/check-you-can-sign",
Expand Down
Loading

0 comments on commit 36d9d6f

Please sign in to comment.