Skip to content

Commit

Permalink
Merge pull request #1671 from ministryofjustice/MLPAB-2320-do-not-reg…
Browse files Browse the repository at this point in the history
…ister

MLPAB-2320 Show lpa-store do not register status on dashboard
  • Loading branch information
hawx authored Dec 9, 2024
2 parents 84437c4 + 3ff39c1 commit 0fcd72b
Show file tree
Hide file tree
Showing 14 changed files with 306 additions and 98 deletions.
3 changes: 3 additions & 0 deletions docker/mock-lpa-store/lpa-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ switch (context.request.method) {
}
break;

case 'OPG_STATUS_CHANGE':
lpa.status = update.changes.find(x => x.key == '/status').new;
break;
}

lpaStore.save(lpaUID, JSON.stringify(lpa));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ConfirmDontWantToBeCertificateProvider(tmpl template.Template, lpaStoreClie
DonorStartPageURL: appPublicURL + page.PathStart.Format(),
}

if !lpa.CannotRegister {
if !lpa.Status.IsCannotRegister() {
if err := lpaStoreClient.SendCertificateProviderOptOut(r.Context(), lpa.LpaUID, lpa.CertificateProvider.UID); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func ConfirmDontWantToBeCertificateProviderLoggedOut(tmpl template.Template, sha
DonorStartPageURL: appPublicURL + page.PathStart.Format(),
}

if !lpa.CannotRegister {
if !lpa.Status.IsCannotRegister() {
if err := lpaStoreClient.SendCertificateProviderOptOut(ctx, lpa.LpaUID, actoruid.Service); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ func TestPostConfirmDontWantToBeCertificateProviderLoggedOut(t *testing.T) {
CertificateProvider: lpadata.CertificateProvider{
FirstNames: "d e", LastName: "f",
},
CannotRegister: true,
Type: lpadata.LpaTypePersonalWelfare,
Status: lpadata.StatusCannotRegister,
Type: lpadata.LpaTypePersonalWelfare,
},
lpaStoreClient: func() *mockLpaStoreClient { return nil },
donorStore: func() *mockDonorStore { return nil },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ func TestPostConfirmDontWantToBeCertificateProvider(t *testing.T) {
CertificateProvider: lpadata.CertificateProvider{
FirstNames: "d e", LastName: "f", UID: uid,
},
Type: lpadata.LpaTypePersonalWelfare,
CannotRegister: true,
Type: lpadata.LpaTypePersonalWelfare,
Status: lpadata.StatusCannotRegister,
},
lpaStoreClient: func() *mockLpaStoreClient { return nil },
donorStore: func() *mockDonorStore { return nil },
Expand Down
4 changes: 2 additions & 2 deletions internal/lpastore/lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,15 @@ type lpaResponse struct {
WitnessedByIndependentWitnessAt *time.Time `json:"witnessedByIndependentWitnessAt"`
CertificateProviderNotRelatedConfirmedAt *time.Time `json:"certificateProviderNotRelatedConfirmedAt"`
UID string `json:"uid"`
Status string `json:"status"`
Status lpadata.Status `json:"status"`
RegistrationDate time.Time `json:"registrationDate"`
UpdatedAt time.Time `json:"updatedAt"`
}

func lpaResponseToLpa(l lpaResponse) *lpadata.Lpa {
data := &lpadata.Lpa{
LpaUID: l.UID,
Status: l.Status,
RegisteredAt: l.RegistrationDate,
UpdatedAt: l.UpdatedAt,
Type: l.LpaType,
Expand Down Expand Up @@ -385,7 +386,6 @@ func lpaResponseToLpa(l lpaResponse) *lpadata.Lpa {
LifeSustainingTreatmentOption: l.LifeSustainingTreatmentOption,
SignedAt: l.SignedAt,
WitnessedByCertificateProviderAt: l.WitnessedByCertificateProviderAt,
CannotRegister: l.Status == "cannot-register",
}

if l.LpaType.IsPersonalWelfare() {
Expand Down
124 changes: 124 additions & 0 deletions internal/lpastore/lpadata/enum_status.go

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

5 changes: 1 addition & 4 deletions internal/lpastore/lpadata/lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Lpa struct {
LpaOwnerKey dynamo.LpaOwnerKeyType
LpaID string
LpaUID string
Status Status
RegisteredAt time.Time
WithdrawnAt time.Time
StatutoryWaitingPeriodAt time.Time
Expand Down Expand Up @@ -68,10 +69,6 @@ type Lpa struct {
// applications, or set to true for paper applications.
Drafted bool

// CannotRegister is set to true if the status in the lpa-store is
// cannot-register.
CannotRegister bool

// Correspondent is set using the data provided by the donor for online
// applications, but is not set for paper applications.
Correspondent Correspondent
Expand Down
15 changes: 15 additions & 0 deletions internal/lpastore/lpadata/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package lpadata

//go:generate enumerator -type Status -trimprefix -linecomment
type Status uint8

const (
StatusInProgress Status = iota // in-progress
StatusStatutoryWaitingPeriod // statutory-waiting-period
StatusRegistered // registered
StatusCannotRegister // cannot-register
StatusWithdrawn // withdrawn
StatusCancelled // cancelled
StatusDoNotRegister // do-not-register
StatusExpired // expired
)
11 changes: 11 additions & 0 deletions internal/lpastore/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ func (c *Client) SendCertificateProviderOptOut(ctx context.Context, lpaUID strin
return c.sendUpdate(ctx, lpaUID, certificateProviderUid, body)
}

func (c *Client) SendChangeStatus(ctx context.Context, lpaUID string, oldStatus, newStatus lpadata.Status) error {
body := updateRequest{
Type: "OPG_STATUS_CHANGE",
Changes: []updateRequestChange{
{Key: "/status", Old: oldStatus, New: newStatus},
},
}

return c.sendUpdate(ctx, lpaUID, actoruid.Service, body)
}

func (c *Client) SendDonorConfirmIdentity(ctx context.Context, donor *donordata.Provided) error {
body := updateRequest{
Type: "DONOR_CONFIRM_IDENTITY",
Expand Down
36 changes: 36 additions & 0 deletions internal/lpastore/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,42 @@ func TestClientSendCertificateProviderOptOut(t *testing.T) {
assert.Nil(t, err)
}

func TestClientSendChangeStatus(t *testing.T) {
json := `{"type":"OPG_STATUS_CHANGE","changes": [
{"key": "/status", "new": "do-not-register", "old": "statutory-waiting-period"}
]}`

ctx := context.Background()

secretsClient := newMockSecretsClient(t)
secretsClient.EXPECT().
Secret(ctx, "secret").
Return("secret", nil)

var body []byte
doer := newMockDoer(t)
doer.EXPECT().
Do(mock.MatchedBy(func(req *http.Request) bool {
if body == nil {
body, _ = io.ReadAll(req.Body)
}

return assert.Equal(t, ctx, req.Context()) &&
assert.Equal(t, http.MethodPost, req.Method) &&
assert.Equal(t, "http://base/lpas/lpa-uid/updates", req.URL.String()) &&
assert.Equal(t, "application/json", req.Header.Get("Content-Type")) &&
assert.Equal(t, "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJvcGcucG9hcy5tYWtlcmVnaXN0ZXIiLCJzdWIiOiJ1cm46b3BnOnBvYXM6bWFrZXJlZ2lzdGVyOnVzZXJzOjAwMDAwMDAwLTAwMDAtNDAwMC0wMDAwLTAwMDAwMDAwMDAwMCIsImlhdCI6OTQ2NzgyMjQ1fQ.V7MxjZw7-K8ehujYn4e0gef7s23r2UDlTbyzQtpTKvo", req.Header.Get("X-Jwt-Authorization")) &&
assert.JSONEq(t, json, string(body))
})).
Return(&http.Response{StatusCode: http.StatusCreated, Body: io.NopCloser(strings.NewReader(""))}, nil)

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.SendChangeStatus(ctx, "lpa-uid", lpadata.StatusStatutoryWaitingPeriod, lpadata.StatusDoNotRegister)

assert.Nil(t, err)
}

func TestClientSendDonorConfirmIdentity(t *testing.T) {
uid, _ := actoruid.Parse("15e5df3d-a053-4537-8066-2f4dd8d1dba8")

Expand Down
25 changes: 22 additions & 3 deletions internal/page/fixtures/donor.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ var progressValues = []string{
"signedByAttorneys",
"submitted",
"statutoryWaitingPeriod",
// end states
"registered",
"withdrawn",
"certificateProviderOptedOut",
"registered",
"doNotRegister",
}

type FixtureData struct {
Expand Down Expand Up @@ -479,6 +481,14 @@ func updateLPAProgress(

var certificateProviderUID actoruid.UID

if data.Progress == slices.Index(progressValues, "certificateProviderOptedOut") {
fns = append(fns, func(ctx context.Context, client *lpastore.Client, _ *lpadata.Lpa) error {
return client.SendCertificateProviderOptOut(ctx, donorDetails.LpaUID, certificateProviderUID)
})

return donorDetails, fns, nil
}

if data.Progress >= slices.Index(progressValues, "signedByCertificateProvider") {
ctx := appcontext.ContextWithSession(r.Context(), &appcontext.Session{SessionID: random.String(16), LpaID: donorDetails.LpaID})

Expand Down Expand Up @@ -587,7 +597,16 @@ func updateLPAProgress(
donorDetails.StatutoryWaitingPeriodAt = time.Now()
}

if data.Progress == slices.Index(progressValues, "registered") {
fns = append(fns, func(ctx context.Context, client *lpastore.Client, _ *lpadata.Lpa) error {
return client.SendRegister(ctx, donorDetails.LpaUID)
})
}

if data.Progress == slices.Index(progressValues, "withdrawn") {
fns = append(fns, func(ctx context.Context, client *lpastore.Client, _ *lpadata.Lpa) error {
return client.SendDonorWithdrawLPA(ctx, donorDetails.LpaUID)
})
donorDetails.WithdrawnAt = time.Now()
}

Expand All @@ -597,9 +616,9 @@ func updateLPAProgress(
})
}

if data.Progress >= slices.Index(progressValues, "registered") {
if data.Progress == slices.Index(progressValues, "doNotRegister") {
fns = append(fns, func(ctx context.Context, client *lpastore.Client, _ *lpadata.Lpa) error {
return client.SendRegister(ctx, donorDetails.LpaUID)
return client.SendChangeStatus(ctx, donorDetails.LpaUID, lpadata.StatusStatutoryWaitingPeriod, lpadata.StatusDoNotRegister)
})
}

Expand Down
Loading

0 comments on commit 0fcd72b

Please sign in to comment.