diff --git a/internal/lpastore/lpa.go b/internal/lpastore/lpa.go index b5185ca28d..2f70bda4ed 100644 --- a/internal/lpastore/lpa.go +++ b/internal/lpastore/lpa.go @@ -9,7 +9,6 @@ import ( "net/http" "time" - "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/donor/donordata" @@ -30,6 +29,8 @@ type lpaRequest struct { TrustCorporations []lpaRequestTrustCorporation `json:"trustCorporations,omitempty"` CertificateProvider lpaRequestCertificateProvider `json:"certificateProvider"` PeopleToNotify []lpaRequestPersonToNotify `json:"peopleToNotify,omitempty"` + IndependentWitness *lpaRequestIndependentWitness `json:"independentWitness,omitempty"` + AuthorisedSignatory *lpaRequestAuthorisedSignatory `json:"authorisedSignatory,omitempty"` HowAttorneysMakeDecisions lpadata.AttorneysAct `json:"howAttorneysMakeDecisions,omitempty"` HowAttorneysMakeDecisionsDetails string `json:"howAttorneysMakeDecisionsDetails,omitempty"` HowReplacementAttorneysMakeDecisions lpadata.AttorneysAct `json:"howReplacementAttorneysMakeDecisions,omitempty"` @@ -98,6 +99,20 @@ type lpaRequestPersonToNotify struct { Address place.Address `json:"address"` } +type lpaRequestIndependentWitness struct { + UID actoruid.UID `json:"uid"` + FirstNames string `json:"firstNames"` + LastName string `json:"lastName"` + Phone string `json:"phone"` + Address place.Address `json:"address"` +} + +type lpaRequestAuthorisedSignatory struct { + UID actoruid.UID `json:"uid"` + FirstNames string `json:"firstNames"` + LastName string `json:"lastName"` +} + func (c *Client) SendLpa(ctx context.Context, donor *donordata.Provided) error { body := lpaRequest{ LpaType: donor.Type, @@ -217,6 +232,24 @@ func (c *Client) SendLpa(ctx context.Context, donor *donordata.Provided) error { }) } + if !donor.IndependentWitness.UID.IsZero() { + body.IndependentWitness = &lpaRequestIndependentWitness{ + UID: donor.IndependentWitness.UID, + FirstNames: donor.IndependentWitness.FirstNames, + LastName: donor.IndependentWitness.LastName, + Phone: donor.IndependentWitness.Mobile, + Address: donor.IndependentWitness.Address, + } + } + + if !donor.AuthorisedSignatory.UID.IsZero() { + body.AuthorisedSignatory = &lpaRequestAuthorisedSignatory{ + UID: donor.AuthorisedSignatory.UID, + FirstNames: donor.AuthorisedSignatory.FirstNames, + LastName: donor.AuthorisedSignatory.LastName, + } + } + var buf bytes.Buffer if err := json.NewEncoder(&buf).Encode(body); err != nil { return err @@ -260,7 +293,6 @@ func (c *Client) SendLpa(ctx context.Context, donor *donordata.Provided) error { name: fmt.Sprintf("expected 201 response but got %d", resp.StatusCode), body: string(body), } - } } @@ -283,20 +315,22 @@ type lpaResponse struct { Donor lpaRequestDonor `json:"donor"` Channel lpadata.Channel `json:"channel"` Attorneys []lpaResponseAttorney `json:"attorneys"` - TrustCorporations []lpaResponseTrustCorporation `json:"trustCorporations,omitempty"` + TrustCorporations []lpaResponseTrustCorporation `json:"trustCorporations"` CertificateProvider lpadata.CertificateProvider `json:"certificateProvider"` - PeopleToNotify []lpaRequestPersonToNotify `json:"peopleToNotify,omitempty"` - HowAttorneysMakeDecisions lpadata.AttorneysAct `json:"howAttorneysMakeDecisions,omitempty"` - HowAttorneysMakeDecisionsDetails string `json:"howAttorneysMakeDecisionsDetails,omitempty"` - HowReplacementAttorneysMakeDecisions lpadata.AttorneysAct `json:"howReplacementAttorneysMakeDecisions,omitempty"` - HowReplacementAttorneysMakeDecisionsDetails string `json:"howReplacementAttorneysMakeDecisionsDetails,omitempty"` - HowReplacementAttorneysStepIn lpadata.ReplacementAttorneysStepIn `json:"howReplacementAttorneysStepIn,omitempty"` - HowReplacementAttorneysStepInDetails string `json:"howReplacementAttorneysStepInDetails,omitempty"` + PeopleToNotify []lpaRequestPersonToNotify `json:"peopleToNotify"` + IndependentWitness *lpaRequestIndependentWitness `json:"independentWitness"` + AuthorisedSignatory *lpaRequestAuthorisedSignatory `json:"authorisedSignatory"` + HowAttorneysMakeDecisions lpadata.AttorneysAct `json:"howAttorneysMakeDecisions"` + HowAttorneysMakeDecisionsDetails string `json:"howAttorneysMakeDecisionsDetails"` + HowReplacementAttorneysMakeDecisions lpadata.AttorneysAct `json:"howReplacementAttorneysMakeDecisions"` + HowReplacementAttorneysMakeDecisionsDetails string `json:"howReplacementAttorneysMakeDecisionsDetails"` + HowReplacementAttorneysStepIn lpadata.ReplacementAttorneysStepIn `json:"howReplacementAttorneysStepIn"` + HowReplacementAttorneysStepInDetails string `json:"howReplacementAttorneysStepInDetails"` Restrictions string `json:"restrictionsAndConditions"` - WhenTheLpaCanBeUsed lpadata.CanBeUsedWhen `json:"whenTheLpaCanBeUsed,omitempty"` - LifeSustainingTreatmentOption lpadata.LifeSustainingTreatment `json:"lifeSustainingTreatmentOption,omitempty"` + WhenTheLpaCanBeUsed lpadata.CanBeUsedWhen `json:"whenTheLpaCanBeUsed"` + LifeSustainingTreatmentOption lpadata.LifeSustainingTreatment `json:"lifeSustainingTreatmentOption"` SignedAt time.Time `json:"signedAt"` - CertificateProviderNotRelatedConfirmedAt *time.Time `json:"certificateProviderNotRelatedConfirmedAt,omitempty"` + CertificateProviderNotRelatedConfirmedAt *time.Time `json:"certificateProviderNotRelatedConfirmedAt"` UID string `json:"uid"` Status string `json:"status"` RegistrationDate time.Time `json:"registrationDate"` @@ -304,7 +338,40 @@ type lpaResponse struct { } func lpaResponseToLpa(l lpaResponse) *lpadata.Lpa { - var attorneys, replacementAttorneys []lpadata.Attorney + data := &lpadata.Lpa{ + LpaUID: l.UID, + RegisteredAt: l.RegistrationDate, + UpdatedAt: l.UpdatedAt, + Type: l.LpaType, + Donor: lpadata.Donor{ + UID: l.Donor.UID, + FirstNames: l.Donor.FirstNames, + LastName: l.Donor.LastName, + DateOfBirth: l.Donor.DateOfBirth, + Email: l.Donor.Email, + Address: l.Donor.Address, + OtherNames: l.Donor.OtherNamesKnownBy, + Channel: l.Channel, + ContactLanguagePreference: l.Donor.ContactLanguagePreference, + }, + CertificateProvider: l.CertificateProvider, + AttorneyDecisions: lpadata.AttorneyDecisions{ + How: l.HowAttorneysMakeDecisions, + Details: l.HowAttorneysMakeDecisionsDetails, + }, + ReplacementAttorneyDecisions: lpadata.AttorneyDecisions{ + How: l.HowReplacementAttorneysMakeDecisions, + Details: l.HowReplacementAttorneysMakeDecisionsDetails, + }, + HowShouldReplacementAttorneysStepIn: l.HowReplacementAttorneysStepIn, + HowShouldReplacementAttorneysStepInDetails: l.HowReplacementAttorneysStepInDetails, + Restrictions: l.Restrictions, + WhenCanTheLpaBeUsed: l.WhenTheLpaCanBeUsed, + LifeSustainingTreatmentOption: l.LifeSustainingTreatmentOption, + SignedAt: l.SignedAt, + CannotRegister: l.Status == "cannot-register", + } + for _, a := range l.Attorneys { at := lpadata.Attorney{ UID: a.UID, @@ -320,13 +387,12 @@ func lpaResponseToLpa(l lpaResponse) *lpadata.Lpa { } if a.Status == "replacement" { - replacementAttorneys = append(replacementAttorneys, at) + data.ReplacementAttorneys.Attorneys = append(data.ReplacementAttorneys.Attorneys, at) } else if a.Status == "active" { - attorneys = append(attorneys, at) + data.Attorneys.Attorneys = append(data.Attorneys.Attorneys, at) } } - var trustCorporation, replacementTrustCorporation lpadata.TrustCorporation for _, t := range l.TrustCorporations { tc := lpadata.TrustCorporation{ UID: t.UID, @@ -341,15 +407,14 @@ func lpaResponseToLpa(l lpaResponse) *lpadata.Lpa { } if t.Status == "replacement" { - replacementTrustCorporation = tc + data.ReplacementAttorneys.TrustCorporation = tc } else if t.Status == "active" { - trustCorporation = tc + data.Attorneys.TrustCorporation = tc } } - var peopleToNotify []lpadata.PersonToNotify for _, p := range l.PeopleToNotify { - peopleToNotify = append(peopleToNotify, lpadata.PersonToNotify{ + data.PeopleToNotify = append(data.PeopleToNotify, lpadata.PersonToNotify{ UID: p.UID, FirstNames: p.FirstNames, LastName: p.LastName, @@ -357,68 +422,86 @@ func lpaResponseToLpa(l lpaResponse) *lpadata.Lpa { }) } - var confirmedAt time.Time + if l.AuthorisedSignatory != nil { + data.AuthorisedSignatory = lpadata.AuthorisedSignatory{ + UID: l.AuthorisedSignatory.UID, + FirstNames: l.AuthorisedSignatory.FirstNames, + LastName: l.AuthorisedSignatory.LastName, + } + } + + if l.IndependentWitness != nil { + data.IndependentWitness = lpadata.IndependentWitness{ + UID: l.IndependentWitness.UID, + FirstNames: l.IndependentWitness.FirstNames, + LastName: l.IndependentWitness.LastName, + Mobile: l.IndependentWitness.Phone, + Address: l.IndependentWitness.Address, + } + } + if v := l.CertificateProviderNotRelatedConfirmedAt; v != nil { - confirmedAt = *v + data.CertificateProviderNotRelatedConfirmedAt = *v } - var identityCheck lpadata.IdentityCheck if l.Donor.IdentityCheck != nil { - identityCheck.CheckedAt = l.Donor.IdentityCheck.CheckedAt - identityCheck.Type = l.Donor.IdentityCheck.Type + data.Donor.IdentityCheck.CheckedAt = l.Donor.IdentityCheck.CheckedAt + data.Donor.IdentityCheck.Type = l.Donor.IdentityCheck.Type } - return &lpadata.Lpa{ - LpaUID: l.UID, - RegisteredAt: l.RegistrationDate, - UpdatedAt: l.UpdatedAt, - Type: l.LpaType, + return data +} + +func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa { + data := &lpadata.Lpa{ + LpaID: l.LpaID, + LpaUID: l.LpaUID, + UpdatedAt: l.UpdatedAt, + Type: l.Type, Donor: lpadata.Donor{ UID: l.Donor.UID, FirstNames: l.Donor.FirstNames, LastName: l.Donor.LastName, - DateOfBirth: l.Donor.DateOfBirth, Email: l.Donor.Email, + OtherNames: l.Donor.OtherNames, + DateOfBirth: l.Donor.DateOfBirth, Address: l.Donor.Address, - OtherNames: l.Donor.OtherNamesKnownBy, - Channel: l.Channel, + Channel: l.Donor.Channel, ContactLanguagePreference: l.Donor.ContactLanguagePreference, - IdentityCheck: identityCheck, }, - Attorneys: lpadata.Attorneys{ - Attorneys: attorneys, - TrustCorporation: trustCorporation, - }, - ReplacementAttorneys: lpadata.Attorneys{ - Attorneys: replacementAttorneys, - TrustCorporation: replacementTrustCorporation, + CertificateProvider: lpadata.CertificateProvider{ + UID: l.CertificateProvider.UID, + FirstNames: l.CertificateProvider.FirstNames, + LastName: l.CertificateProvider.LastName, + Email: l.CertificateProvider.Email, + Phone: l.CertificateProvider.Mobile, + Address: l.CertificateProvider.Address, + Channel: l.CertificateProvider.CarryOutBy, }, - CertificateProvider: l.CertificateProvider, - PeopleToNotify: peopleToNotify, AttorneyDecisions: lpadata.AttorneyDecisions{ - How: l.HowAttorneysMakeDecisions, - Details: l.HowAttorneysMakeDecisionsDetails, + How: l.AttorneyDecisions.How, + Details: l.AttorneyDecisions.Details, }, ReplacementAttorneyDecisions: lpadata.AttorneyDecisions{ - How: l.HowReplacementAttorneysMakeDecisions, - Details: l.HowReplacementAttorneysMakeDecisionsDetails, + How: l.ReplacementAttorneyDecisions.How, + Details: l.ReplacementAttorneyDecisions.Details, }, - HowShouldReplacementAttorneysStepIn: l.HowReplacementAttorneysStepIn, - HowShouldReplacementAttorneysStepInDetails: l.HowReplacementAttorneysStepInDetails, - Restrictions: l.Restrictions, - WhenCanTheLpaBeUsed: l.WhenTheLpaCanBeUsed, - LifeSustainingTreatmentOption: l.LifeSustainingTreatmentOption, - // TODO: add authorised signatory and independent witness when these become available + HowShouldReplacementAttorneysStepIn: l.HowShouldReplacementAttorneysStepIn, + HowShouldReplacementAttorneysStepInDetails: l.HowShouldReplacementAttorneysStepInDetails, + Restrictions: l.Restrictions, + WhenCanTheLpaBeUsed: l.WhenCanTheLpaBeUsed, + LifeSustainingTreatmentOption: l.LifeSustainingTreatmentOption, SignedAt: l.SignedAt, - CertificateProviderNotRelatedConfirmedAt: confirmedAt, - CannotRegister: l.Status == "cannot-register", + CertificateProviderNotRelatedConfirmedAt: l.CertificateProviderNotRelatedConfirmedAt, + Correspondent: lpadata.Correspondent{ + FirstNames: l.Correspondent.FirstNames, + LastName: l.Correspondent.LastName, + Email: l.Correspondent.Email, + }, } -} -func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa { - attorneys := lpadata.Attorneys{} for _, a := range l.Attorneys.Attorneys { - attorneys.Attorneys = append(attorneys.Attorneys, lpadata.Attorney{ + data.Attorneys.Attorneys = append(data.Attorneys.Attorneys, lpadata.Attorney{ UID: a.UID, FirstNames: a.FirstNames, LastName: a.LastName, @@ -429,7 +512,7 @@ func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa { } if c := l.Attorneys.TrustCorporation; c.Name != "" { - attorneys.TrustCorporation = lpadata.TrustCorporation{ + data.Attorneys.TrustCorporation = lpadata.TrustCorporation{ UID: c.UID, Name: c.Name, CompanyNumber: c.CompanyNumber, @@ -438,9 +521,8 @@ func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa { } } - var replacementAttorneys lpadata.Attorneys for _, a := range l.ReplacementAttorneys.Attorneys { - replacementAttorneys.Attorneys = append(replacementAttorneys.Attorneys, lpadata.Attorney{ + data.ReplacementAttorneys.Attorneys = append(data.ReplacementAttorneys.Attorneys, lpadata.Attorney{ UID: a.UID, FirstNames: a.FirstNames, LastName: a.LastName, @@ -451,7 +533,7 @@ func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa { } if c := l.ReplacementAttorneys.TrustCorporation; c.Name != "" { - replacementAttorneys.TrustCorporation = lpadata.TrustCorporation{ + data.ReplacementAttorneys.TrustCorporation = lpadata.TrustCorporation{ UID: c.UID, Name: c.Name, CompanyNumber: c.CompanyNumber, @@ -460,10 +542,9 @@ func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa { } } - var identityCheck lpadata.IdentityCheck if l.DonorIdentityConfirmed() { - identityCheck.CheckedAt = l.IdentityUserData.RetrievedAt - identityCheck.Type = "one-login" + data.Donor.IdentityCheck.CheckedAt = l.IdentityUserData.RetrievedAt + data.Donor.IdentityCheck.Type = "one-login" } var peopleToNotify []lpadata.PersonToNotify @@ -476,9 +557,8 @@ func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa { }) } - var voucher lpadata.Voucher if v := l.Voucher; v.Allowed { - voucher = lpadata.Voucher{ + data.Voucher = lpadata.Voucher{ UID: v.UID, FirstNames: v.FirstNames, LastName: v.LastName, @@ -486,19 +566,16 @@ func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa { } } - var authorisedSignatory actor.Actor - if v := l.AuthorisedSignatory; v.FirstNames != "" { - authorisedSignatory = actor.Actor{ - Type: actor.TypeAuthorisedSignatory, + if v := l.AuthorisedSignatory; !v.UID.IsZero() { + data.AuthorisedSignatory = lpadata.AuthorisedSignatory{ UID: v.UID, FirstNames: v.FirstNames, LastName: v.LastName, } } - var independentWitness lpadata.IndependentWitness - if v := l.IndependentWitness; v.FirstNames != "" { - independentWitness = lpadata.IndependentWitness{ + if v := l.IndependentWitness; !v.UID.IsZero() { + data.IndependentWitness = lpadata.IndependentWitness{ UID: v.UID, FirstNames: v.FirstNames, LastName: v.LastName, @@ -507,59 +584,7 @@ func FromDonorProvidedDetails(l *donordata.Provided) *lpadata.Lpa { } } - return &lpadata.Lpa{ - LpaID: l.LpaID, - LpaUID: l.LpaUID, - UpdatedAt: l.UpdatedAt, - Type: l.Type, - Donor: lpadata.Donor{ - UID: l.Donor.UID, - FirstNames: l.Donor.FirstNames, - LastName: l.Donor.LastName, - Email: l.Donor.Email, - OtherNames: l.Donor.OtherNames, - DateOfBirth: l.Donor.DateOfBirth, - Address: l.Donor.Address, - Channel: l.Donor.Channel, - ContactLanguagePreference: l.Donor.ContactLanguagePreference, - IdentityCheck: identityCheck, - }, - Attorneys: attorneys, - ReplacementAttorneys: replacementAttorneys, - CertificateProvider: lpadata.CertificateProvider{ - UID: l.CertificateProvider.UID, - FirstNames: l.CertificateProvider.FirstNames, - LastName: l.CertificateProvider.LastName, - Email: l.CertificateProvider.Email, - Phone: l.CertificateProvider.Mobile, - Address: l.CertificateProvider.Address, - Channel: l.CertificateProvider.CarryOutBy, - }, - PeopleToNotify: peopleToNotify, - AttorneyDecisions: lpadata.AttorneyDecisions{ - How: l.AttorneyDecisions.How, - Details: l.AttorneyDecisions.Details, - }, - ReplacementAttorneyDecisions: lpadata.AttorneyDecisions{ - How: l.ReplacementAttorneyDecisions.How, - Details: l.ReplacementAttorneyDecisions.Details, - }, - HowShouldReplacementAttorneysStepIn: l.HowShouldReplacementAttorneysStepIn, - HowShouldReplacementAttorneysStepInDetails: l.HowShouldReplacementAttorneysStepInDetails, - Restrictions: l.Restrictions, - WhenCanTheLpaBeUsed: l.WhenCanTheLpaBeUsed, - LifeSustainingTreatmentOption: l.LifeSustainingTreatmentOption, - SignedAt: l.SignedAt, - CertificateProviderNotRelatedConfirmedAt: l.CertificateProviderNotRelatedConfirmedAt, - Correspondent: lpadata.Correspondent{ - FirstNames: l.Correspondent.FirstNames, - LastName: l.Correspondent.LastName, - Email: l.Correspondent.Email, - }, - AuthorisedSignatory: authorisedSignatory, - IndependentWitness: independentWitness, - Voucher: voucher, - } + return data } func (c *Client) Lpa(ctx context.Context, lpaUID string) (*lpadata.Lpa, error) { diff --git a/internal/lpastore/lpa_test.go b/internal/lpastore/lpa_test.go index 31a1639563..50b8b0ca3b 100644 --- a/internal/lpastore/lpa_test.go +++ b/internal/lpastore/lpa_test.go @@ -31,6 +31,8 @@ func TestClientSendLpa(t *testing.T) { replacementAttorney2UID := actoruid.New() certificateProviderUID := actoruid.New() personToNotifyUID := actoruid.New() + authorisedSignatoryUID := actoruid.New() + independentWitnessUID := actoruid.New() testcases := map[string]struct { donor *donordata.Provided @@ -242,6 +244,25 @@ func TestClientSendLpa(t *testing.T) { Country: "GB", }, }}, + AuthorisedSignatory: donordata.AuthorisedSignatory{ + UID: authorisedSignatoryUID, + FirstNames: "Author", + LastName: "Signor", + }, + IndependentWitness: donordata.IndependentWitness{ + UID: independentWitnessUID, + FirstNames: "Indiana", + LastName: "Witness", + Mobile: "0777777777", + Address: place.Address{ + Line1: "i-line-1", + Line2: "i-line-2", + Line3: "i-line-3", + TownOrCity: "i-town", + Postcode: "I1 1WW", + Country: "GB", + }, + }, IdentityUserData: identity.UserData{ Status: identity.StatusConfirmed, FirstNames: "John Johnson", @@ -268,6 +289,8 @@ func TestClientSendLpa(t *testing.T) { ], "certificateProvider":{"uid":"` + certificateProviderUID.String() + `","firstNames":"Carol","lastName":"Cert","email":"carol@example.com","phone":"0700009000","address":{"line1":"c-line-1","line2":"c-line-2","line3":"c-line-3","town":"c-town","postcode":"C1 1FF","country":"GB"},"channel":"online"}, "peopleToNotify":[{"uid":"` + personToNotifyUID.String() + `","firstNames":"Peter","lastName":"Notify","address":{"line1":"p-line-1","line2":"p-line-2","line3":"p-line-3","town":"p-town","postcode":"P1 1FF","country":"GB"}}], +"authorisedSignatory":{"uid":"` + authorisedSignatoryUID.String() + `","firstNames":"Author","lastName":"Signor"}, +"independentWitness":{"uid":"` + independentWitnessUID.String() + `","firstNames":"Indiana","lastName":"Witness","phone":"0777777777","address":{"line1":"i-line-1","line2":"i-line-2","line3":"i-line-3","town":"i-town","postcode":"I1 1WW","country":"GB"}}, "howAttorneysMakeDecisions":"jointly", "howReplacementAttorneysMakeDecisions":"jointly-for-some-severally-for-others", "howReplacementAttorneysMakeDecisionsDetails":"umm", @@ -393,6 +416,8 @@ func TestClientLpa(t *testing.T) { replacementAttorney2UID := actoruid.New() certificateProviderUID := actoruid.New() personToNotifyUID := actoruid.New() + authorisedSignatoryUID := actoruid.New() + independentWitnessUID := actoruid.New() testcases := map[string]struct { donor *lpadata.Lpa @@ -616,6 +641,25 @@ func TestClientLpa(t *testing.T) { Country: "GB", }, }}, + AuthorisedSignatory: lpadata.AuthorisedSignatory{ + UID: authorisedSignatoryUID, + FirstNames: "Author", + LastName: "Signor", + }, + IndependentWitness: lpadata.IndependentWitness{ + UID: independentWitnessUID, + FirstNames: "Indiana", + LastName: "Witness", + Mobile: "0777777777", + Address: place.Address{ + Line1: "i-line-1", + Line2: "i-line-2", + Line3: "i-line-3", + TownOrCity: "i-town", + Postcode: "I1 1WW", + Country: "GB", + }, + }, SignedAt: time.Date(2000, time.January, 2, 3, 4, 5, 6, time.UTC), CertificateProviderNotRelatedConfirmedAt: time.Date(2001, time.February, 3, 4, 5, 6, 7, time.UTC), }, @@ -636,6 +680,9 @@ func TestClientLpa(t *testing.T) { ], "certificateProvider":{"uid":"` + certificateProviderUID.String() + `","firstNames":"Carol","lastName":"Cert","email":"carol@example.com","phone":"0700009000","address":{"line1":"c-line-1","line2":"c-line-2","line3":"c-line-3","town":"c-town","postcode":"C1 1FF","country":"GB"},"channel":"online","identityCheck":{"checkedAt":"2002-01-01T13:14:15.000000016Z","type":"one-login"}}, "peopleToNotify":[{"uid":"` + personToNotifyUID.String() + `","firstNames":"Peter","lastName":"Notify","address":{"line1":"p-line-1","line2":"p-line-2","line3":"p-line-3","town":"p-town","postcode":"P1 1FF","country":"GB"}}], +"authorisedSignatory":{"uid":"` + authorisedSignatoryUID.String() + `","firstNames":"Author","lastName":"Signor"}, +"independentWitness":{"uid":"` + independentWitnessUID.String() + `","firstNames":"Indiana","lastName":"Witness","phone":"0777777777", +"address":{"line1":"i-line-1","line2":"i-line-2","line3":"i-line-3","town":"i-town","postcode":"I1 1WW","country":"GB"}}, "howAttorneysMakeDecisions":"jointly", "howReplacementAttorneysMakeDecisions":"jointly-for-some-severally-for-others", "howReplacementAttorneysMakeDecisionsDetails":"umm", diff --git a/internal/lpastore/lpadata/authorised_signatory.go b/internal/lpastore/lpadata/authorised_signatory.go new file mode 100644 index 0000000000..04b03ffc1d --- /dev/null +++ b/internal/lpastore/lpadata/authorised_signatory.go @@ -0,0 +1,13 @@ +package lpadata + +import "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" + +type AuthorisedSignatory struct { + UID actoruid.UID + FirstNames string + LastName string +} + +func (a AuthorisedSignatory) FullName() string { + return a.FirstNames + " " + a.LastName +} diff --git a/internal/lpastore/lpadata/authorised_signatory_test.go b/internal/lpastore/lpadata/authorised_signatory_test.go new file mode 100644 index 0000000000..39d003b16d --- /dev/null +++ b/internal/lpastore/lpadata/authorised_signatory_test.go @@ -0,0 +1,11 @@ +package lpadata + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestAuthorisedSignatoryFullName(t *testing.T) { + assert.Equal(t, "John Smith", AuthorisedSignatory{FirstNames: "John", LastName: "Smith"}.FullName()) +} diff --git a/internal/lpastore/lpadata/lpa.go b/internal/lpastore/lpadata/lpa.go index 119e00a881..f802f3c3bd 100644 --- a/internal/lpastore/lpadata/lpa.go +++ b/internal/lpastore/lpadata/lpa.go @@ -31,7 +31,7 @@ type Lpa struct { Restrictions string WhenCanTheLpaBeUsed CanBeUsedWhen LifeSustainingTreatmentOption LifeSustainingTreatment - AuthorisedSignatory actor.Actor + AuthorisedSignatory AuthorisedSignatory IndependentWitness IndependentWitness // SignedAt is the date the Donor signed their LPA (and signifies it has been @@ -161,7 +161,12 @@ func (l Lpa) Actors() iter.Seq[actor.Actor] { } if !l.AuthorisedSignatory.UID.IsZero() { - if !yield(l.AuthorisedSignatory) { + if !yield(actor.Actor{ + Type: actor.TypeAuthorisedSignatory, + UID: l.AuthorisedSignatory.UID, + FirstNames: l.AuthorisedSignatory.FirstNames, + LastName: l.AuthorisedSignatory.LastName, + }) { return } } diff --git a/internal/lpastore/lpadata/lpa_test.go b/internal/lpastore/lpadata/lpa_test.go index 10dfbb0bf0..3444d1c9e0 100644 --- a/internal/lpastore/lpadata/lpa_test.go +++ b/internal/lpastore/lpadata/lpa_test.go @@ -92,8 +92,6 @@ func TestLpaCorrespondentEmailWhenCorrespondentProvided(t *testing.T) { } func TestLpaActors(t *testing.T) { - authorisedSignatory := actor.Actor{UID: actoruid.New()} - lpa := &Lpa{ Donor: Donor{ UID: actoruid.New(), @@ -134,7 +132,11 @@ func TestLpaActors(t *testing.T) { FirstNames: "Peter", LastName: "Person", }}, - AuthorisedSignatory: authorisedSignatory, + AuthorisedSignatory: AuthorisedSignatory{ + UID: actoruid.New(), + FirstNames: "Aut", + LastName: "Sig", + }, IndependentWitness: IndependentWitness{ UID: actoruid.New(), FirstNames: "Ind", @@ -181,7 +183,12 @@ func TestLpaActors(t *testing.T) { UID: lpa.PeopleToNotify[0].UID, FirstNames: "Peter", LastName: "Person", - }, authorisedSignatory, { + }, { + Type: actor.TypeAuthorisedSignatory, + UID: lpa.AuthorisedSignatory.UID, + FirstNames: "Aut", + LastName: "Sig", + }, { Type: actor.TypeIndependentWitness, UID: lpa.IndependentWitness.UID, FirstNames: "Ind", diff --git a/internal/lpastore/resolving_service.go b/internal/lpastore/resolving_service.go index 47b145797d..efab5d4777 100644 --- a/internal/lpastore/resolving_service.go +++ b/internal/lpastore/resolving_service.go @@ -4,7 +4,6 @@ import ( "context" "errors" - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/lpastore/lpadata" @@ -112,27 +111,6 @@ func (s *ResolvingService) merge(lpa *lpadata.Lpa, donor *donordata.Provided) *l } } - // TODO: remove this once authorised signatory is in lpa-store - if lpa.AuthorisedSignatory.FirstNames == "" && donor.AuthorisedSignatory.FirstNames != "" { - lpa.AuthorisedSignatory = actor.Actor{ - Type: actor.TypeAuthorisedSignatory, - UID: donor.AuthorisedSignatory.UID, - FirstNames: donor.AuthorisedSignatory.FirstNames, - LastName: donor.AuthorisedSignatory.LastName, - } - } - - // TODO: remove this once independent witness is in lpa-store - if lpa.IndependentWitness.FirstNames == "" && donor.IndependentWitness.FirstNames != "" { - lpa.IndependentWitness = lpadata.IndependentWitness{ - UID: donor.IndependentWitness.UID, - FirstNames: donor.IndependentWitness.FirstNames, - LastName: donor.IndependentWitness.LastName, - Mobile: donor.IndependentWitness.Mobile, - Address: donor.IndependentWitness.Address, - } - } - // copy the relationship as it isn't stored in the lpastore. lpa.CertificateProvider.Relationship = donor.CertificateProvider.Relationship diff --git a/internal/lpastore/resolving_service_test.go b/internal/lpastore/resolving_service_test.go index 34e2858620..52a27eb5f1 100644 --- a/internal/lpastore/resolving_service_test.go +++ b/internal/lpastore/resolving_service_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/ministryofjustice/opg-modernising-lpa/internal/actor" + "github.com/ministryofjustice/opg-modernising-lpa/internal/actor/actoruid" "github.com/ministryofjustice/opg-modernising-lpa/internal/donor/donordata" "github.com/ministryofjustice/opg-modernising-lpa/internal/dynamo" "github.com/ministryofjustice/opg-modernising-lpa/internal/identity" @@ -16,6 +16,8 @@ import ( ) func TestResolvingServiceGet(t *testing.T) { + actorUID := actoruid.New() + testcases := map[string]struct { donor *donordata.Provided resolved *lpadata.Lpa @@ -41,8 +43,8 @@ func TestResolvingServiceGet(t *testing.T) { RetrievedAt: time.Now(), }, Correspondent: donordata.Correspondent{Email: "x"}, - AuthorisedSignatory: donordata.AuthorisedSignatory{FirstNames: "A", LastName: "S"}, - IndependentWitness: donordata.IndependentWitness{FirstNames: "I", LastName: "W"}, + AuthorisedSignatory: donordata.AuthorisedSignatory{UID: actorUID, FirstNames: "A", LastName: "S"}, + IndependentWitness: donordata.IndependentWitness{UID: actorUID, FirstNames: "I", LastName: "W"}, Voucher: donordata.Voucher{Allowed: true, Email: "y"}, }, resolved: &lpadata.Lpa{ @@ -65,16 +67,7 @@ func TestResolvingServiceGet(t *testing.T) { }, Donor: lpadata.Donor{Channel: lpadata.ChannelOnline}, Correspondent: lpadata.Correspondent{Email: "x"}, - AuthorisedSignatory: actor.Actor{ - Type: actor.TypeAuthorisedSignatory, - FirstNames: "A", - LastName: "S", - }, - IndependentWitness: lpadata.IndependentWitness{ - FirstNames: "I", - LastName: "W", - }, - Voucher: lpadata.Voucher{Email: "y"}, + Voucher: lpadata.Voucher{Email: "y"}, }, }, "online with no lpastore record": { @@ -99,8 +92,8 @@ func TestResolvingServiceGet(t *testing.T) { RetrievedAt: time.Date(2020, time.January, 2, 12, 13, 14, 5, time.UTC), }, Correspondent: donordata.Correspondent{Email: "x"}, - AuthorisedSignatory: donordata.AuthorisedSignatory{FirstNames: "A", LastName: "S"}, - IndependentWitness: donordata.IndependentWitness{FirstNames: "I", LastName: "W"}, + AuthorisedSignatory: donordata.AuthorisedSignatory{UID: actorUID, FirstNames: "A", LastName: "S"}, + IndependentWitness: donordata.IndependentWitness{UID: actorUID, FirstNames: "I", LastName: "W"}, Voucher: donordata.Voucher{Allowed: true, Email: "y"}, }, error: ErrNotFound, @@ -127,12 +120,13 @@ func TestResolvingServiceGet(t *testing.T) { TrustCorporation: lpadata.TrustCorporation{Name: "d"}, }, Correspondent: lpadata.Correspondent{Email: "x"}, - AuthorisedSignatory: actor.Actor{ - Type: actor.TypeAuthorisedSignatory, + AuthorisedSignatory: lpadata.AuthorisedSignatory{ + UID: actorUID, FirstNames: "A", LastName: "S", }, IndependentWitness: lpadata.IndependentWitness{ + UID: actorUID, FirstNames: "I", LastName: "W", },