diff --git a/internal/shared/lpa.go b/internal/shared/lpa.go index 17db3b4d..a102ea71 100644 --- a/internal/shared/lpa.go +++ b/internal/shared/lpa.go @@ -3,9 +3,9 @@ package shared import "time" type LpaInit struct { - Type Type `json:"type"` - Donor Donor `json:"donor" dynamodbav:""` - Attorneys []Attorney `json:"attorneys" dynamodbav:""` + LpaType LpaType `json:"lpaType"` + Donor Donor `json:"donor"` + Attorneys []Attorney `json:"attorneys"` CertificateProvider CertificateProvider `json:"certificateProvider"` PeopleToNotify []PersonToNotify `json:"peopleToNotify"` HowAttorneysMakeDecisions HowMakeDecisions `json:"howAttorneysMakeDecisions"` @@ -14,7 +14,7 @@ type LpaInit struct { HowReplacementAttorneysMakeDecisionsDetails string `json:"howReplacementAttorneysMakeDecisionsDetails"` HowReplacementAttorneysStepIn HowStepIn `json:"howReplacementAttorneysStepIn"` HowReplacementAttorneysStepInDetails string `json:"howReplacementAttorneysStepInDetails"` - WhenTheLpaCanBeUsed CanUseWhen `json:"whenTheLpaCanBeUsed"` + WhenTheLpaCanBeUsed CanUse `json:"whenTheLpaCanBeUsed"` LifeSustainingTreatmentOption LifeSustainingTreatment `json:"lifeSustainingTreatmentOption"` Restrictions string `json:"restrictions"` SignedAt time.Time `json:"signedAt"` @@ -22,21 +22,21 @@ type LpaInit struct { type Lpa struct { LpaInit - Uid string `json:"uid" dynamodbav:""` - Status LpaStatus `json:"status" dynamodbav:""` - RegistrationDate time.Time `json:"registrationDate" dynamodbav:""` - UpdatedAt time.Time `json:"updatedAt" dynamodbav:""` + Uid string `json:"uid"` + Status LpaStatus `json:"status"` + RegistrationDate time.Time `json:"registrationDate"` + UpdatedAt time.Time `json:"updatedAt"` } -type Type string +type LpaType string const ( - TypeHealthWelfare = Type("hw") - TypePropertyFinance = Type("pfa") + LpaTypePersonalWelfare = LpaType("personal-welfare") + LpaTypePropertyAndAffairs = LpaType("property-and-affairs") ) -func (e Type) IsValid() bool { - return e == TypeHealthWelfare || e == TypePropertyFinance +func (e LpaType) IsValid() bool { + return e == LpaTypePersonalWelfare || e == LpaTypePropertyAndAffairs } type LpaStatus string diff --git a/internal/shared/person.go b/internal/shared/person.go index 3e1d39e6..7c103588 100644 --- a/internal/shared/person.go +++ b/internal/shared/person.go @@ -1,42 +1,42 @@ package shared type Address struct { - Line1 string `json:"line1" dynamodbav:""` - Line2 string `json:"line2" dynamodbav:""` - Line3 string `json:"line3" dynamodbav:""` - Town string `json:"town" dynamodbav:""` - Postcode string `json:"postcode" dynamodbav:""` - Country string `json:"country" dynamodbav:""` + Line1 string `json:"line1"` + Line2 string `json:"line2"` + Line3 string `json:"line3"` + Town string `json:"town"` + Postcode string `json:"postcode"` + Country string `json:"country"` } type Person struct { - FirstNames string `json:"firstNames" dynamodbav:""` + FirstNames string `json:"firstNames"` LastName string `json:"lastName"` - Address Address `json:"address" dynamodbav:""` + Address Address `json:"address"` } type Donor struct { Person - DateOfBirth Date `json:"dateOfBirth" dynamodbav:""` - Email string `json:"email" dynamodbav:""` - OtherNamesKnownBy string `json:"otherNamesKnownBy" dynamodbav:""` + DateOfBirth Date `json:"dateOfBirth"` + Email string `json:"email"` + OtherNamesKnownBy string `json:"otherNamesKnownBy"` } type CertificateProvider struct { Person - Email string `json:"email" dynamodbav:""` - CarryOutBy CarryOutBy `json:"carryOutBy"` + Email string `json:"email"` + Channel Channel `json:"channel"` } -type CarryOutBy string +type Channel string const ( - CarryOutByOnline = CarryOutBy("online") - CarryOutByPaper = CarryOutBy("paper") + ChannelOnline = Channel("online") + ChannelPaper = Channel("paper") ) -func (e CarryOutBy) IsValid() bool { - return e == CarryOutByOnline || e == CarryOutByPaper +func (e Channel) IsValid() bool { + return e == ChannelOnline || e == ChannelPaper } type AttorneyStatus string @@ -53,9 +53,9 @@ func (a AttorneyStatus) IsValid() bool { type Attorney struct { Person - DateOfBirth Date `json:"dateOfBirth" dynamodbav:""` - Email string `json:"email" dynamodbav:""` - Status AttorneyStatus `json:"status" dynamodbav:""` + DateOfBirth Date `json:"dateOfBirth"` + Email string `json:"email"` + Status AttorneyStatus `json:"status"` } type PersonToNotify struct { @@ -68,7 +68,7 @@ const ( HowMakeDecisionsUnset = HowMakeDecisions("") HowMakeDecisionsJointly = HowMakeDecisions("jointly") HowMakeDecisionsJointlyAndSeverally = HowMakeDecisions("jointly-and-severally") - HowMakeDecisionsJointlyForSomeSeverallyForOthers = HowMakeDecisions("mixed") + HowMakeDecisionsJointlyForSomeSeverallyForOthers = HowMakeDecisions("jointly-for-some-severally-for-others") ) func (e HowMakeDecisions) IsValid() bool { @@ -83,29 +83,29 @@ type HowStepIn string const ( HowStepInUnset = HowStepIn("") - HowStepInAllCanNoLongerAct = HowStepIn("all") - HowStepInOneCanNoLongerAct = HowStepIn("one") - HowStepInAnotherWay = HowStepIn("other") + HowStepInAllCanNoLongerAct = HowStepIn("all-can-no-longer-act") + HowStepInOneCanNoLongerAct = HowStepIn("one-can-no-longer-act") + HowStepInAnotherWay = HowStepIn("another-way") ) func (e HowStepIn) IsValid() bool { return e == HowStepInUnset || e == HowStepInAllCanNoLongerAct || e == HowStepInOneCanNoLongerAct || e == HowStepInAnotherWay } -type CanUseWhen string +type CanUse string const ( - CanUseWhenUnset = CanUseWhen("") - CanUseWhenCapacityLost = CanUseWhen("when-capacity-lost") - CanUseWhenHasCapacity = CanUseWhen("when-has-capacity") + CanUseUnset = CanUse("") + CanUseWhenCapacityLost = CanUse("when-capacity-lost") + CanUseWhenHasCapacity = CanUse("when-has-capacity") ) -func (e CanUseWhen) IsValid() bool { +func (e CanUse) IsValid() bool { return e == CanUseWhenCapacityLost || e == CanUseWhenHasCapacity } -func (e CanUseWhen) Unset() bool { - return e == CanUseWhenUnset +func (e CanUse) Unset() bool { + return e == CanUseUnset } type LifeSustainingTreatment string diff --git a/lambda/create/validate.go b/lambda/create/validate.go index b7103936..214ae4d7 100644 --- a/lambda/create/validate.go +++ b/lambda/create/validate.go @@ -12,7 +12,7 @@ func Validate(lpa shared.LpaInit) []shared.FieldError { activeAttorneyCount, replacementAttorneyCount := countAttorneys(lpa.Attorneys) return flatten( - validateIsValid("/type", lpa.Type), + validateIsValid("/lpaType", lpa.LpaType), required("/donor/firstNames", lpa.Donor.FirstNames), required("/donor/lastName", lpa.Donor.LastName), validateDate("/donor/dateOfBirth", lpa.Donor.DateOfBirth), @@ -20,8 +20,8 @@ func Validate(lpa shared.LpaInit) []shared.FieldError { required("/certificateProvider/firstNames", lpa.CertificateProvider.FirstNames), required("/certificateProvider/lastName", lpa.CertificateProvider.LastName), validateAddress("/certificateProvider/address", lpa.CertificateProvider.Address), - validateIsValid("/certificateProvider/carryOutBy", lpa.CertificateProvider.CarryOutBy), - validateIfElse(lpa.CertificateProvider.CarryOutBy == shared.CarryOutByOnline, + validateIsValid("/certificateProvider/channel", lpa.CertificateProvider.Channel), + validateIfElse(lpa.CertificateProvider.Channel == shared.ChannelOnline, required("/certificateProvider/email", lpa.CertificateProvider.Email), empty("/certificateProvider/email", lpa.CertificateProvider.Email)), validateAttorneys("/attorneys", lpa.Attorneys), @@ -42,10 +42,10 @@ func Validate(lpa shared.LpaInit) []shared.FieldError { validateIfElse(lpa.HowReplacementAttorneysMakeDecisions == shared.HowMakeDecisionsJointlyForSomeSeverallyForOthers, required("/howReplacementAttorneysMakeDecisionsDetails", lpa.HowReplacementAttorneysMakeDecisionsDetails), empty("/howReplacementAttorneysMakeDecisionsDetails", lpa.HowReplacementAttorneysMakeDecisionsDetails)), - validateIf(lpa.Type == "hw", flatten( + validateIf(lpa.LpaType == shared.LpaTypePersonalWelfare, flatten( validateIsValid("/lifeSustainingTreatmentOption", lpa.LifeSustainingTreatmentOption), validateUnset("/whenTheLpaCanBeUsed", lpa.WhenTheLpaCanBeUsed))), - validateIf(lpa.Type == "pfa", flatten( + validateIf(lpa.LpaType == shared.LpaTypePropertyAndAffairs, flatten( validateIsValid("/whenTheLpaCanBeUsed", lpa.WhenTheLpaCanBeUsed), validateUnset("/lifeSustainingTreatmentOption", lpa.LifeSustainingTreatmentOption))), validateTime("/signedAt", lpa.SignedAt), diff --git a/lambda/create/validate_test.go b/lambda/create/validate_test.go index 7e9dcf37..02dba71d 100644 --- a/lambda/create/validate_test.go +++ b/lambda/create/validate_test.go @@ -190,7 +190,7 @@ func TestValidateLpaInvalid(t *testing.T) { }{ "empty": { contains: []shared.FieldError{ - {Source: "/type", Detail: "field is required"}, + {Source: "/lpaType", Detail: "field is required"}, {Source: "/donor/firstNames", Detail: "field is required"}, {Source: "/donor/lastName", Detail: "field is required"}, {Source: "/donor/dateOfBirth", Detail: "field is required"}, @@ -200,7 +200,7 @@ func TestValidateLpaInvalid(t *testing.T) { "online certificate provider missing email": { lpa: shared.LpaInit{ CertificateProvider: shared.CertificateProvider{ - CarryOutBy: shared.CarryOutByOnline, + Channel: shared.ChannelOnline, }, }, contains: []shared.FieldError{ @@ -210,8 +210,8 @@ func TestValidateLpaInvalid(t *testing.T) { "paper certificate provider with email": { lpa: shared.LpaInit{ CertificateProvider: shared.CertificateProvider{ - CarryOutBy: shared.CarryOutByPaper, - Email: "something", + Channel: shared.ChannelPaper, + Email: "something", }, }, contains: []shared.FieldError{ @@ -332,7 +332,7 @@ func TestValidateLpaInvalid(t *testing.T) { }, "health welfare with when can be used": { lpa: shared.LpaInit{ - Type: shared.TypeHealthWelfare, + LpaType: shared.LpaTypePersonalWelfare, WhenTheLpaCanBeUsed: shared.CanUseWhenHasCapacity, }, contains: []shared.FieldError{ @@ -342,7 +342,7 @@ func TestValidateLpaInvalid(t *testing.T) { }, "property finance with life sustaining treatment": { lpa: shared.LpaInit{ - Type: shared.TypePropertyFinance, + LpaType: shared.LpaTypePropertyAndAffairs, LifeSustainingTreatmentOption: shared.LifeSustainingTreatmentOptionA, }, contains: []shared.FieldError{ @@ -364,7 +364,7 @@ func TestValidateLpaInvalid(t *testing.T) { func TestValidateLpaValid(t *testing.T) { lpa := shared.LpaInit{ - Type: "hw", + LpaType: "personal-welfare", Donor: shared.Donor{ Person: shared.Person{ FirstNames: "Otto", @@ -390,8 +390,8 @@ func TestValidateLpaValid(t *testing.T) { LastName: "Person", Address: validAddress, }, - Email: "some@example.com", - CarryOutBy: "online", + Email: "some@example.com", + Channel: "online", }, LifeSustainingTreatmentOption: shared.LifeSustainingTreatmentOptionA, SignedAt: time.Now(),