Skip to content

Commit

Permalink
Merge pull request #1487 from ministryofjustice/MLPAB-2405-event-tests
Browse files Browse the repository at this point in the history
MLPAB-2405 Update event tests
  • Loading branch information
acsauk authored Sep 17, 2024
2 parents 9fd52ec + 85eca76 commit cfaf51a
Show file tree
Hide file tree
Showing 29 changed files with 421 additions and 393 deletions.
56 changes: 28 additions & 28 deletions cypress/e2e/donor/lpa-type.cy.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
describe('LPA type', () => {
it('can be submitted', () => {
cy.visit('/fixtures?redirect=/lpa-type&progress=provideYourDetails');
it('can be submitted', () => {
cy.visit('/fixtures?redirect=/lpa-type&progress=provideYourDetails');

cy.get('#f-lpa-type').check('property-and-affairs');
cy.get('#f-lpa-type').check('property-and-affairs');

cy.checkA11yApp();
cy.checkA11yApp();

cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/task-list');
cy.contains('button', 'Save and continue').click();
cy.url().should('contain', '/task-list');

cy.url().then((url) => {
cy.visit(`http://localhost:9001/?detail-type=uid-requested&detail=${url.split('/')[4]}`);
cy.contains(`"LpaID":"${url.split('/')[4]}"`);
});
cy.url().then((url) => {
cy.visit(`http://localhost:9001/?detail-type=uid-requested&detail=${url.split('/')[4]}`);
cy.contains(`"lpaID":"${url.split('/')[4]}"`);
});

cy.visit('/dashboard')

cy.visit('/dashboard')
cy.contains('.govuk-body-s', 'Reference number:')
.invoke('text')
.then((text) => {
const uid = text.split(':')[1].trim();
cy.visit(`http://localhost:9001/?detail-type=application-updated&detail=${uid}`);

cy.contains('.govuk-body-s', 'Reference number:')
.invoke('text')
.then((text) => {
const uid = text.split(':')[1].trim();
cy.visit(`http://localhost:9001/?detail-type=application-updated&detail=${uid}`);
cy.contains(`"uid":"${uid}"`);
cy.contains('"type":"property-and-affairs"');
});
});

cy.contains(`"uid":"${uid}"`);
cy.contains('"type":"property-and-affairs"');
});
});
it('errors when unselected', () => {
cy.visit('/fixtures?redirect=/lpa-type');

it('errors when unselected', () => {
cy.visit('/fixtures?redirect=/lpa-type');
cy.contains('button', 'Save and continue').click();

cy.contains('button', 'Save and continue').click();
cy.get('.govuk-error-summary').within(() => {
cy.contains('Select the type of LPA to make');
});

cy.get('.govuk-error-summary').within(() => {
cy.contains('Select the type of LPA to make');
cy.contains('.govuk-fieldset .govuk-error-message', 'Select the type of LPA to make');
});

cy.contains('.govuk-fieldset .govuk-error-message', 'Select the type of LPA to make');
});
});
47 changes: 22 additions & 25 deletions cypress/e2e/donor/previous-application-number.cy.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
describe('Previous application number', () => {
beforeEach(() => {
cy.visit('/fixtures?redirect=/previous-application-number');
});
beforeEach(() => {
cy.visit('/fixtures?redirect=/previous-application-number');
});

it('can be submitted', () => {
cy.checkA11yApp();
it('can be submitted', () => {
cy.checkA11yApp();

cy.get('#f-previous-application-number').type('MABC');
cy.contains('button', 'Save and continue').click();
cy.get('#f-previous-application-number').type('MABC');
cy.contains('button', 'Save and continue').click();

cy.url().should('contain', '/evidence-successfully-uploaded');
cy.url().should('contain', '/evidence-successfully-uploaded');
});

cy.visit(`http://localhost:9001/?detail-type=previous-application-linked&detail=`);
cy.contains('"previousApplicationNumber":"MABC"');
});
it('errors when unselected', () => {
cy.contains('button', 'Save and continue').click();

it('errors when unselected', () => {
cy.contains('button', 'Save and continue').click();
cy.get('.govuk-error-summary').within(() => {
cy.contains('Enter previous reference number');
});

cy.get('.govuk-error-summary').within(() => {
cy.contains('Enter previous reference number');
cy.contains('.govuk-error-message', 'Enter previous reference number');
});

cy.contains('.govuk-error-message', 'Enter previous reference number');
});
it('errors when not correct format', () => {
cy.get('#f-previous-application-number').type('ABC');
cy.contains('button', 'Save and continue').click();

it('errors when not correct format', () => {
cy.get('#f-previous-application-number').type('ABC');
cy.contains('button', 'Save and continue').click();
cy.get('.govuk-error-summary').within(() => {
cy.contains('Previous reference number must begin with the number 7 or the letter M');
});

cy.get('.govuk-error-summary').within(() => {
cy.contains('Previous reference number must begin with the number 7 or the letter M');
cy.contains('.govuk-error-message', 'Previous reference number must begin with the number 7 or the letter M');
});

cy.contains('.govuk-error-message', 'Previous reference number must begin with the number 7 or the letter M');
});
});
2 changes: 1 addition & 1 deletion cypress/e2e/donor/provide-your-details.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Provide your details', () => {
const id = url.split('/')[4];

cy.visit(`http://localhost:9001/?detail-type=uid-requested&detail=${id}`);
cy.contains('"Type":"property-and-affairs"');
cy.contains('"type":"property-and-affairs"');
cy.contains(`"name":"John${rnd} Doe${rnd}"`);
cy.contains('"dob":"1990-02-01"');
cy.contains('"postcode":"B14 7ED"');
Expand Down
12 changes: 12 additions & 0 deletions internal/actor/actoruid/uid.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,15 @@ func (u *UID) UnmarshalDynamoDBAttributeValue(av types.AttributeValue) error {

return u.UnmarshalText([]byte(s))
}

// Prefixed can be used to wrap a UID so it JSON marshals with PrefixedString
// instead of String.
type Prefixed UID

func (u Prefixed) MarshalJSON() ([]byte, error) {
if UID(u).IsZero() {
return []byte("null"), nil
}

return []byte(`"` + UID(u).PrefixedString() + `"`), nil
}
12 changes: 12 additions & 0 deletions internal/actor/actoruid/uid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,15 @@ func TestUIDAttributeValue(t *testing.T) {
assert.Error(t, err)
assert.True(t, c.IsZero())
}

func TestPrefixedJSON(t *testing.T) {
uuidString := "2ea1a849-975e-481c-af19-1209d20ed362"
uid, err := Parse(uuidString)
assert.Nil(t, err)

jsonData, _ := json.Marshal(Prefixed(uid))
assert.Equal(t, `"`+prefix+uuidString+`"`, string(jsonData))

emptyData, _ := json.Marshal(Prefixed(UID{}))
assert.Equal(t, `null`, string(emptyData))
}
47 changes: 0 additions & 47 deletions internal/document/mock_EventClient_test.go

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

1 change: 0 additions & 1 deletion internal/document/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type S3Client interface {
type EventClient interface {
SendUidRequested(context.Context, event.UidRequested) error
SendApplicationUpdated(context.Context, event.ApplicationUpdated) error
SendPreviousApplicationLinked(context.Context, event.PreviousApplicationLinked) error
SendReducedFeeRequested(context.Context, event.ReducedFeeRequested) error
}

Expand Down
47 changes: 0 additions & 47 deletions internal/donor/donorpage/mock_EventClient_test.go

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

10 changes: 1 addition & 9 deletions internal/donor/donorpage/previous_application_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/ministryofjustice/opg-modernising-lpa/internal/appcontext"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"github.com/ministryofjustice/opg-modernising-lpa/internal/validation"
)
Expand All @@ -18,7 +17,7 @@ type previousApplicationNumberData struct {
Form *previousApplicationNumberForm
}

func PreviousApplicationNumber(tmpl template.Template, donorStore DonorStore, eventClient EventClient) Handler {
func PreviousApplicationNumber(tmpl template.Template, donorStore DonorStore) Handler {
return func(appData appcontext.Data, w http.ResponseWriter, r *http.Request, provided *donordata.Provided) error {
data := &previousApplicationNumberData{
App: appData,
Expand All @@ -38,13 +37,6 @@ func PreviousApplicationNumber(tmpl template.Template, donorStore DonorStore, ev
return err
}

if err := eventClient.SendPreviousApplicationLinked(r.Context(), event.PreviousApplicationLinked{
UID: provided.LpaUID,
PreviousApplicationNumber: provided.PreviousApplicationNumber,
}); err != nil {
return err
}

if provided.PreviousApplicationNumber[0] == '7' {
return donor.PathPreviousFee.Redirect(w, r, appData, provided)
} else {
Expand Down
Loading

0 comments on commit cfaf51a

Please sign in to comment.