Skip to content

Commit

Permalink
Merge f8f8688 into df2dcaf
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx authored Apr 5, 2024
2 parents df2dcaf + f8f8688 commit 88548fb
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docker/mock-lpa-store/lpa-store.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ switch (context.request.method) {
if (lpa) {
respond().withContent(lpa)
} else {
respond()
respond().withStatusCode(404)
}
break

Expand Down
4 changes: 4 additions & 0 deletions internal/date/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func Today() Date {
}

func FromTime(t time.Time) Date {
if t.IsZero() {
return Date{}
}

return Date{
year: t.Format("2006"),
month: t.Format("1"),
Expand Down
1 change: 1 addition & 0 deletions internal/date/date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestToday(t *testing.T) {

func TestFromTime(t *testing.T) {
assert.Equal(t, New("2000", "1", "2"), FromTime(time.Date(2000, time.January, 2, 0, 0, 0, 0, time.UTC)))
assert.Equal(t, Date{}, FromTime(time.Time{}))
}

func TestEquals(t *testing.T) {
Expand Down
27 changes: 25 additions & 2 deletions internal/lpastore/lpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (l *Lpa) AllAttorneysSigned(attorneys []*actor.AttorneyProvidedDetails) boo
return true
}

func (l *lpaResponse) ToResolvedLpa() *Lpa {
func lpaResponseToLpa(l lpaResponse) *Lpa {
var attorneys, replacementAttorneys []actor.Attorney
for _, a := range l.Attorneys {
at := actor.Attorney{
Expand Down Expand Up @@ -402,6 +402,29 @@ func (l *lpaResponse) ToResolvedLpa() *Lpa {
}
}

func donorProvidedDetailsToLpa(l *actor.DonorProvidedDetails) *Lpa {
return &Lpa{
LpaUID: l.LpaUID,
RegisteredAt: date.FromTime(l.RegisteredAt),
UpdatedAt: date.FromTime(l.UpdatedAt),
Type: l.Type,
Donor: l.Donor,
Attorneys: l.Attorneys,
ReplacementAttorneys: l.ReplacementAttorneys,
CertificateProvider: l.CertificateProvider,
PeopleToNotify: l.PeopleToNotify,
AttorneyDecisions: l.AttorneyDecisions,
ReplacementAttorneyDecisions: l.ReplacementAttorneyDecisions,
HowShouldReplacementAttorneysStepIn: l.HowShouldReplacementAttorneysStepIn,
HowShouldReplacementAttorneysStepInDetails: l.HowShouldReplacementAttorneysStepInDetails,
Restrictions: l.Restrictions,
WhenCanTheLpaBeUsed: l.WhenCanTheLpaBeUsed,
LifeSustainingTreatmentOption: l.LifeSustainingTreatmentOption,
SignedAt: l.SignedAt,
CertificateProviderNotRelatedConfirmedAt: l.CertificateProviderNotRelatedConfirmedAt,
}
}

func (c *Client) Lpa(ctx context.Context, lpaUID string) (*Lpa, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.baseURL+"/lpas/"+lpaUID, nil)
if err != nil {
Expand All @@ -413,5 +436,5 @@ func (c *Client) Lpa(ctx context.Context, lpaUID string) (*Lpa, error) {
return nil, err
}

return v.ToResolvedLpa(), nil
return lpaResponseToLpa(v), nil
}
5 changes: 4 additions & 1 deletion internal/lpastore/resolving_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (s *ResolvingService) Get(ctx context.Context) (*Lpa, error) {

lpa, err := s.client.Lpa(ctx, donor.LpaUID)
if errors.Is(err, ErrNotFound) {
lpa = &Lpa{}
lpa = donorProvidedDetailsToLpa(donor)
} else if err != nil {
return nil, err
}
Expand All @@ -55,7 +55,10 @@ func (s *ResolvingService) Get(ctx context.Context) (*Lpa, error) {
lpa.Submitted = !donor.SubmittedAt.IsZero()
lpa.Paid = donor.Tasks.PayForLpa.IsCompleted()
lpa.IsOrganisationDonor = strings.HasPrefix(donor.SK, dynamo.OrganisationKey(""))

// copy the relationship as it isn't stored in the lpastore.
lpa.CertificateProvider.Relationship = donor.CertificateProvider.Relationship

// TODO: eventually we'll need to remove the RegisteredAt field as mlpa
// won't be tracking that data, then we'll need to figure out how to expose
// the data for testing
Expand Down
30 changes: 28 additions & 2 deletions internal/lpastore/resolving_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestResolvingServiceGet(t *testing.T) {
testcases := map[string]struct {
donor *actor.DonorProvidedDetails
resolved *Lpa
error error
expected *Lpa
}{
"digital with all true": {
Expand All @@ -29,6 +30,7 @@ func TestResolvingServiceGet(t *testing.T) {
SubmittedAt: time.Now(),
RegisteredAt: registeredAt,
CertificateProvider: actor.CertificateProvider{
FirstNames: "Barry",
Relationship: actor.Personally,
},
Tasks: actor.DonorTasks{
Expand All @@ -38,7 +40,12 @@ func TestResolvingServiceGet(t *testing.T) {
OK: true,
},
},
resolved: &Lpa{LpaID: "1"},
resolved: &Lpa{
LpaID: "1",
CertificateProvider: actor.CertificateProvider{
FirstNames: "Paul",
},
},
expected: &Lpa{
LpaID: "1",
LpaUID: "M-1111",
Expand All @@ -48,6 +55,25 @@ func TestResolvingServiceGet(t *testing.T) {
IsOrganisationDonor: true,
RegisteredAt: date.FromTime(registeredAt),
CertificateProvider: actor.CertificateProvider{
FirstNames: "Paul",
Relationship: actor.Personally,
},
},
},
"digital with no lpastore record": {
donor: &actor.DonorProvidedDetails{
SK: dynamo.DonorKey("S"),
LpaUID: "M-1111",
CertificateProvider: actor.CertificateProvider{
FirstNames: "John",
Relationship: actor.Personally,
},
},
error: ErrNotFound,
expected: &Lpa{
LpaUID: "M-1111",
CertificateProvider: actor.CertificateProvider{
FirstNames: "John",
Relationship: actor.Personally,
},
},
Expand Down Expand Up @@ -95,7 +121,7 @@ func TestResolvingServiceGet(t *testing.T) {
lpaClient := newMockLpaClient(t)
lpaClient.EXPECT().
Lpa(ctx, "M-1111").
Return(tc.resolved, nil)
Return(tc.resolved, tc.error)

service := NewResolvingService(donorStore, lpaClient)
lpa, err := service.Get(ctx)
Expand Down
20 changes: 3 additions & 17 deletions internal/page/fixtures/attorney.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import (
"github.com/ministryofjustice/opg-go-common/template"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor"
"github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid"
"github.com/ministryofjustice/opg-modernising-lpa/internal/date"
"github.com/ministryofjustice/opg-modernising-lpa/internal/event"
"github.com/ministryofjustice/opg-modernising-lpa/internal/form"
"github.com/ministryofjustice/opg-modernising-lpa/internal/localize"
"github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore"
"github.com/ministryofjustice/opg-modernising-lpa/internal/page"
"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/uid"
Expand Down Expand Up @@ -106,21 +104,8 @@ func Attorney(
attorneyCtx = page.ContextWithSessionData(r.Context(), &page.SessionData{SessionID: attorneySessionID, LpaID: donorDetails.LpaID})
)

donorDetails.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,
}
donorDetails.SignedAt = time.Now()
donorDetails.Donor = makeDonor()

if lpaType == "personal-welfare" && !isTrustCorporation {
donorDetails.Type = actor.LpaTypePersonalWelfare
Expand Down Expand Up @@ -189,6 +174,7 @@ func Attorney(

donorDetails.AttorneyDecisions = actor.AttorneyDecisions{How: actor.JointlyAndSeverally}
donorDetails.ReplacementAttorneyDecisions = actor.AttorneyDecisions{How: actor.JointlyAndSeverally}
donorDetails.HowShouldReplacementAttorneysStepIn = actor.ReplacementAttorneysStepInWhenAllCanNoLongerAct

certificateProvider, err := certificateProviderStore.Create(certificateProviderCtx, donorSessionID, donorDetails.CertificateProvider.UID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/page/fixtures/certificate_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func CertificateProvider(
if err := donorStore.Put(donorCtx, donorDetails); err != nil {
return err
}
if donorDetails.LpaUID != "" {
if !donorDetails.SignedAt.IsZero() && donorDetails.LpaUID != "" {
if err := lpaStoreClient.SendLpa(donorCtx, donorDetails); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion web/template/donor/read_your_lpa.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{{ tr .App "peopleNamedOnTheLpa" }}
</h2>

{{ template "people-named-on-lpa" . }}
{{ template "people-named-on-lpa" (lpaDecisions .App .Donor (not .Donor.Tasks.ConfirmYourIdentityAndSign.Completed)) }}

<div class="govuk-button-group">
<a href="{{ link .App (global.Paths.LpaYourLegalRightsAndResponsibilities.Format .App.LpaID) }}" role="button" draggable="false" class="govuk-button" data-module="govuk-button">
Expand Down

0 comments on commit 88548fb

Please sign in to comment.