Skip to content

Commit

Permalink
Merge pull request #1608 from ministryofjustice/MLPAB-2651-perfect
Browse files Browse the repository at this point in the history
MLPAB-2651 Change Perfect to Statutory waiting period
  • Loading branch information
hawx authored Nov 8, 2024
2 parents 8b70662 + 4757829 commit ad6b5fc
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 56 deletions.
4 changes: 2 additions & 2 deletions cmd/event-received/lpastore_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func handleLpaUpdated(ctx context.Context, client dynamodbClient, event *events.
return fmt.Errorf("failed to unmarshal detail: %w", err)
}

if v.ChangeType != "PERFECT" {
if v.ChangeType != "STATUTORY_WAITING_PERIOD" {
return nil
}

Expand All @@ -41,7 +41,7 @@ func handleLpaUpdated(ctx context.Context, client dynamodbClient, event *events.
return err
}

donor.PerfectAt = now()
donor.StatutoryWaitingPeriodAt = now()

if err := putDonor(ctx, donor, now, client); err != nil {
return fmt.Errorf("failed to update donor details: %w", err)
Expand Down
32 changes: 16 additions & 16 deletions cmd/event-received/lpastore_event_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func TestLpaStoreEventHandlerHandleUnknownEvent(t *testing.T) {
func TestLpaStoreEventHandlerHandleLpaUpdated(t *testing.T) {
event := &events.CloudWatchEvent{
DetailType: "lpa-updated",
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"PERFECT"}`),
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"STATUTORY_WAITING_PERIOD"}`),
}

updated := &donordata.Provided{
PK: dynamo.LpaKey("123"),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")),
PerfectAt: testNow,
UpdatedAt: testNow,
PK: dynamo.LpaKey("123"),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")),
StatutoryWaitingPeriodAt: testNow,
UpdatedAt: testNow,
}
updated.UpdateHash()

Expand Down Expand Up @@ -63,7 +63,7 @@ func TestLpaStoreEventHandlerHandleLpaUpdated(t *testing.T) {
assert.Nil(t, err)
}

func TestLpaStoreEventHandlerHandleLpaUpdatedWhenChangeTypeNotPerfect(t *testing.T) {
func TestLpaStoreEventHandlerHandleLpaUpdatedWhenChangeTypeNotStatutoryWaitingPeriod(t *testing.T) {
event := &events.CloudWatchEvent{
DetailType: "lpa-updated",
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"WHAT"}`),
Expand All @@ -82,14 +82,14 @@ func TestLpaStoreEventHandlerHandleLpaUpdatedWhenChangeTypeNotPerfect(t *testing
func TestLpaStoreEventHandlerHandleLpaUpdatedWhenDynamoGetErrors(t *testing.T) {
event := &events.CloudWatchEvent{
DetailType: "lpa-updated",
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"PERFECT"}`),
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"STATUTORY_WAITING_PERIOD"}`),
}

updated := &donordata.Provided{
PK: dynamo.LpaKey("123"),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")),
PerfectAt: testNow,
UpdatedAt: testNow,
PK: dynamo.LpaKey("123"),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")),
StatutoryWaitingPeriodAt: testNow,
UpdatedAt: testNow,
}
updated.UpdateHash()

Expand All @@ -111,14 +111,14 @@ func TestLpaStoreEventHandlerHandleLpaUpdatedWhenDynamoGetErrors(t *testing.T) {
func TestLpaStoreEventHandlerHandleLpaUpdatedWhenDynamoPutErrors(t *testing.T) {
event := &events.CloudWatchEvent{
DetailType: "lpa-updated",
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"PERFECT"}`),
Detail: json.RawMessage(`{"uid":"M-1111-2222-3333","changeType":"STATUTORY_WAITING_PERIOD"}`),
}

updated := &donordata.Provided{
PK: dynamo.LpaKey("123"),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")),
PerfectAt: testNow,
UpdatedAt: testNow,
PK: dynamo.LpaKey("123"),
SK: dynamo.LpaOwnerKey(dynamo.DonorKey("456")),
StatutoryWaitingPeriodAt: testNow,
UpdatedAt: testNow,
}
updated.UpdateHash()

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/donor/dashboard.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Dashboard', () => {
});
});

context('with perfect LPA', () => {
context('with statutory waiting period LPA', () => {
it('shows the correct options', () => {
cy.visit('/fixtures?redirect=&progress=submitted');

Expand Down
6 changes: 3 additions & 3 deletions docker/mock-lpa-store/lpa-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ switch (context.request.method) {
lpa.certificateProvider.signedAt = signedAt;
break;

case 'PERFECT':
lpa.status = 'perfect';
case 'STATUTORY_WAITING_PERIOD':
lpa.status = 'statutory-waiting-period';
break;

case 'REGISTER':
if (lpa.status === 'perfect') {
if (lpa.status === 'statutory-waiting-period') {
lpa.status = 'registered';
lpa.registrationDate = new Date(Date.now()).toISOString();
}
Expand Down
7 changes: 4 additions & 3 deletions internal/donor/donordata/provided.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ type Provided struct {
SubmittedAt time.Time
// WithdrawnAt is when the Lpa was withdrawn by the donor
WithdrawnAt time.Time
// PerfectAt is when the Lpa transitioned to the PERFECT status in the lpa-store
PerfectAt time.Time
// StatutoryWaitingPeriodAt is when the Lpa transitioned to the STATUTORY_WAITING_PERIOD
// status in the lpa-store
StatutoryWaitingPeriodAt time.Time
// RegisteringWithCourtOfProtection is set when the donor wishes to take the
// Lpa to the Court of Protection for registration.
RegisteringWithCourtOfProtection bool
Expand Down Expand Up @@ -198,7 +199,7 @@ func (c toCheck) HashInclude(field string, _ any) (bool, error) {
"SignedAt",
"SubmittedAt",
"WithdrawnAt",
"PerfectAt",
"StatutoryWaitingPeriodAt",
"CertificateProviderCodes",
"WitnessedByCertificateProviderAt",
"IndependentWitnessCodes",
Expand Down
4 changes: 2 additions & 2 deletions internal/donor/donordata/provided_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func TestGenerateHash(t *testing.T) {
}

// DO change this value to match the updates
const modified uint64 = 0x171cc2a0256d4510
const modified uint64 = 0x1270f2b79d9db4a5

// DO NOT change these initial hash values. If a field has been added/removed
// you will need to handle the version gracefully by modifying
// (*Provided).HashInclude and adding another testcase for the new
// version.
testcases := map[uint8]uint64{
0: 0x556e667fbc8c5f94,
0: 0x71bd1fb1ede66b54,
}

for version, initial := range testcases {
Expand Down
2 changes: 1 addition & 1 deletion internal/lpastore/lpadata/lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Lpa struct {
LpaUID string
RegisteredAt time.Time
WithdrawnAt time.Time
PerfectAt time.Time
StatutoryWaitingPeriodAt time.Time
UpdatedAt time.Time
Type LpaType
Donor Donor
Expand Down
2 changes: 1 addition & 1 deletion internal/lpastore/resolving_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *ResolvingService) merge(lpa *lpadata.Lpa, donor *donordata.Provided) *l
lpa.LpaOwnerKey = donor.SK
lpa.LpaID = donor.LpaID
lpa.LpaUID = donor.LpaUID
lpa.PerfectAt = donor.PerfectAt
lpa.StatutoryWaitingPeriodAt = donor.StatutoryWaitingPeriodAt
if donor.SK.Equals(dynamo.DonorKey("PAPER")) {
lpa.Drafted = true
lpa.Submitted = true
Expand Down
4 changes: 2 additions & 2 deletions internal/lpastore/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func (c *Client) SendRegister(ctx context.Context, lpaUID string) error {
return c.sendUpdate(ctx, lpaUID, actoruid.Service, body)
}

func (c *Client) SendPerfect(ctx context.Context, lpaUID string) error {
func (c *Client) SendStatutoryWaitingPeriod(ctx context.Context, lpaUID string) error {
body := updateRequest{
Type: "PERFECT",
Type: "STATUTORY_WAITING_PERIOD",
}

return c.sendUpdate(ctx, lpaUID, actoruid.Service, body)
Expand Down
6 changes: 3 additions & 3 deletions internal/lpastore/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func TestClientSendRegister(t *testing.T) {
assert.Nil(t, err)
}

func TestClientSendPerfect(t *testing.T) {
json := `{"type":"PERFECT","changes":null}`
func TestClientSendStatutoryWaitingPeriod(t *testing.T) {
json := `{"type":"STATUTORY_WAITING_PERIOD","changes":null}`

ctx := context.Background()

Expand Down Expand Up @@ -84,7 +84,7 @@ func TestClientSendPerfect(t *testing.T) {

client := New("http://base", secretsClient, "secret", doer)
client.now = func() time.Time { return time.Date(2000, time.January, 2, 3, 4, 5, 6, time.UTC) }
err := client.SendPerfect(ctx, "lpa-uid")
err := client.SendStatutoryWaitingPeriod(ctx, "lpa-uid")

assert.Nil(t, err)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/page/fixtures/donor.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var progressValues = []string{
"signedByCertificateProvider",
"signedByAttorneys",
"submitted",
"perfect",
"statutoryWaitingPeriod",
"withdrawn",
"certificateProviderOptedOut",
"registered",
Expand Down Expand Up @@ -575,11 +575,11 @@ func updateLPAProgress(
donorDetails.SubmittedAt = time.Now()
}

if data.Progress >= slices.Index(progressValues, "perfect") {
if data.Progress >= slices.Index(progressValues, "statutoryWaitingPeriod") {
fns = append(fns, func(ctx context.Context, client *lpastore.Client, _ *lpadata.Lpa) error {
return client.SendPerfect(ctx, donorDetails.LpaUID)
return client.SendStatutoryWaitingPeriod(ctx, donorDetails.LpaUID)
})
donorDetails.PerfectAt = time.Now()
donorDetails.StatutoryWaitingPeriodAt = time.Now()
}

if data.Progress == slices.Index(progressValues, "withdrawn") {
Expand Down
4 changes: 2 additions & 2 deletions internal/task/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ func (pt ProgressTracker) Progress(lpa *lpadata.Lpa) Progress {

progress.LpaSubmitted.State = StateCompleted

if lpa.PerfectAt.IsZero() {
if lpa.StatutoryWaitingPeriodAt.IsZero() {
return progress
}

progress.NoticesOfIntentSent.Label = pt.Localizer.Format(labels["noticesOfIntentSent"], map[string]any{
"SentOn": pt.Localizer.FormatDate(lpa.PerfectAt),
"SentOn": pt.Localizer.FormatDate(lpa.StatutoryWaitingPeriodAt),
})
progress.NoticesOfIntentSent.State = StateCompleted
progress.StatutoryWaitingPeriod.State = StateInProgress
Expand Down
28 changes: 14 additions & 14 deletions internal/task/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func TestProgressTrackerProgress(t *testing.T) {
Return("AttorneysSigned translation")
},
},
"perfect": {
"statutory waiting period": {
lpa: &lpadata.Lpa{
Paid: true,
Donor: lpadata.Donor{FirstNames: "a", LastName: "b"},
Expand All @@ -254,7 +254,7 @@ func TestProgressTrackerProgress(t *testing.T) {
SignedAt: lpaSignedAt,
WitnessedByCertificateProviderAt: lpaSignedAt,
Submitted: true,
PerfectAt: lpaSignedAt,
StatutoryWaitingPeriodAt: lpaSignedAt,
},
expectedProgress: func() Progress {
progress := initialProgress
Expand All @@ -276,11 +276,11 @@ func TestProgressTrackerProgress(t *testing.T) {
Count("attorneysHaveDeclared", 1).
Return("AttorneysSigned translation")
localizer.EXPECT().
Format("weSentAnEmailYourLpaIsReadyToRegister", map[string]any{"SentOn": "perfect-on"}).
Format("weSentAnEmailYourLpaIsReadyToRegister", map[string]any{"SentOn": "statutory-waiting-period-on"}).
Return("NoticesOfIntentSent translation")
localizer.EXPECT().
FormatDate(lpaSignedAt).
Return("perfect-on")
Return("statutory-waiting-period-on")
},
},
"registered": {
Expand All @@ -292,7 +292,7 @@ func TestProgressTrackerProgress(t *testing.T) {
Attorneys: lpadata.Attorneys{Attorneys: []lpadata.Attorney{{UID: uid1, SignedAt: lpaSignedAt.Add(time.Minute)}}},
CertificateProvider: lpadata.CertificateProvider{SignedAt: lpaSignedAt},
Submitted: true,
PerfectAt: lpaSignedAt,
StatutoryWaitingPeriodAt: lpaSignedAt,
RegisteredAt: lpaSignedAt,
},
expectedProgress: func() Progress {
Expand All @@ -316,11 +316,11 @@ func TestProgressTrackerProgress(t *testing.T) {
Count("attorneysHaveDeclared", 1).
Return("AttorneysSigned translation")
localizer.EXPECT().
Format("weSentAnEmailYourLpaIsReadyToRegister", map[string]any{"SentOn": "perfect-on"}).
Format("weSentAnEmailYourLpaIsReadyToRegister", map[string]any{"SentOn": "statutory-waiting-period-on"}).
Return("NoticesOfIntentSent translation")
localizer.EXPECT().
FormatDate(lpaSignedAt).
Return("perfect-on")
Return("statutory-waiting-period-on")
},
},
}
Expand Down Expand Up @@ -525,7 +525,7 @@ func TestLpaProgressAsSupporter(t *testing.T) {
return progress
},
},
"perfect": {
"statutory waiting period": {
lpa: &lpadata.Lpa{
IsOrganisationDonor: true,
Donor: lpadata.Donor{
Expand All @@ -540,7 +540,7 @@ func TestLpaProgressAsSupporter(t *testing.T) {
SignedAt: lpaSignedAt,
WitnessedByCertificateProviderAt: lpaSignedAt,
Submitted: true,
PerfectAt: lpaSignedAt,
StatutoryWaitingPeriodAt: lpaSignedAt,
},
expectedProgress: func() Progress {
progress := initialProgress
Expand All @@ -558,11 +558,11 @@ func TestLpaProgressAsSupporter(t *testing.T) {
},
setupLocalizer: func(localizer *mockLocalizer) {
localizer.EXPECT().
Format("weSentAnEmailTheLpaIsReadyToRegister", map[string]any{"SentOn": "perfect-on"}).
Format("weSentAnEmailTheLpaIsReadyToRegister", map[string]any{"SentOn": "statutory-waiting-period-on"}).
Return("NoticesOfIntentSent translation")
localizer.EXPECT().
FormatDate(lpaSignedAt).
Return("perfect-on")
Return("statutory-waiting-period-on")
},
},
"registered": {
Expand All @@ -580,7 +580,7 @@ func TestLpaProgressAsSupporter(t *testing.T) {
SignedAt: lpaSignedAt,
WitnessedByCertificateProviderAt: lpaSignedAt,
Submitted: true,
PerfectAt: lpaSignedAt,
StatutoryWaitingPeriodAt: lpaSignedAt,
RegisteredAt: lpaSignedAt,
},
expectedProgress: func() Progress {
Expand All @@ -600,11 +600,11 @@ func TestLpaProgressAsSupporter(t *testing.T) {
},
setupLocalizer: func(localizer *mockLocalizer) {
localizer.EXPECT().
Format("weSentAnEmailTheLpaIsReadyToRegister", map[string]any{"SentOn": "perfect-on"}).
Format("weSentAnEmailTheLpaIsReadyToRegister", map[string]any{"SentOn": "statutory-waiting-period-on"}).
Return("NoticesOfIntentSent translation")
localizer.EXPECT().
FormatDate(lpaSignedAt).
Return("perfect-on")
Return("statutory-waiting-period-on")
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion web/template/dashboard.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<strong class="app-tag govuk-tag--red">{{ tr .App "cannotRegister" }}</strong>
{{ else if not .Item.Lpa.RegisteredAt.IsZero }}
<strong class="app-tag govuk-tag--green">{{ tr .App "registered" }}</strong>
{{ else if not .Item.Lpa.PerfectAt.IsZero }}
{{ else if not .Item.Lpa.StatutoryWaitingPeriodAt.IsZero }}
<strong class="app-tag govuk-tag--turquoise">{{ tr .App "waitingPeriod" }}</strong>
{{ else if .Item.Lpa.Drafted }}
<strong class="app-tag govuk-tag--blue">{{ tr .App "inProgress" }}</strong>
Expand Down
2 changes: 1 addition & 1 deletion web/template/fixtures.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
(item "signedByCertificateProvider" "Signed by certificate provider")
(item "signedByAttorneys" "Signed by attorneys")
(item "submitted" "Submitted")
(item "perfect" "Perfect")
(item "statutoryWaitingPeriod" "Statutory waiting period")
(item "withdrawn" "Withdrawn")
(item "certificateProviderOptedOut" "Certificate provider opted out (post signing)")
(item "registered" "registered")
Expand Down

0 comments on commit ad6b5fc

Please sign in to comment.