Skip to content

Commit

Permalink
MLPAB-2088: Match old and existing update values on TRUST_CORPORATION…
Browse files Browse the repository at this point in the history
…_SIGN (#190)
  • Loading branch information
acsauk authored May 3, 2024
1 parent 77e13d0 commit cad5f41
Show file tree
Hide file tree
Showing 16 changed files with 183 additions and 83 deletions.
4 changes: 2 additions & 2 deletions docs/attorney-sign.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
},
{
"key": "/attorneys/0/email",
"new": "b@example.com",
"old": "[email protected]"
"new": "a@example.com",
"old": null
}
]
}
2 changes: 0 additions & 2 deletions docs/example-lpa.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"country": "GB"
},
"dateOfBirth": "1982-07-24",
"email": "[email protected]",
"status": "active",
"channel": "paper"
}
Expand All @@ -39,7 +38,6 @@
"town": "Town",
"country": "GB"
},
"email": "[email protected]",
"status": "active",
"channel": "paper"
}
Expand Down
4 changes: 2 additions & 2 deletions docs/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ components:
items:
$ref: "#/components/schemas/Lpa"
Lpa:
$ref: "../schemas/2024-04/lpa.json"
$ref: "../schemas/2024-10/lpa.json"
DonorDetails:
$ref: "../schemas/2024-04/donor-details.json"
$ref: "../schemas/2024-10/donor-details.json"
Update:
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://data-dictionary.opg.service.justice.gov.uk/schema/lpa/2024-04/donor-details.json",
"$id": "https://data-dictionary.opg.service.justice.gov.uk/schema/lpa/2024-10/donor-details.json",
"description": "The data that should be provided when an LPA is executed",
"type": "object",
"required": [
Expand Down Expand Up @@ -212,7 +212,7 @@
}
],
"type": "object",
"required": ["dateOfBirth", "status"],
"required": ["dateOfBirth", "status", "channel"],
"properties": {
"dateOfBirth": {
"type": "string",
Expand All @@ -229,13 +229,26 @@
"channel": {
"type": "string",
"enum": ["paper", "online"]
},
"if": {
"required": ["channel"],
"properties": {
"channel": { "const": "online" }
}
},
"then": {
"required": ["email"]
}
}
},
"TrustCorporation": {
"type": "object",
"required": ["name", "companyNumber", "email", "address", "status"],
"required": ["name", "companyNumber", "address", "status", "channel", "uid"],
"properties": {
"uid": {
"type": "string",
"format": "uuid"
},
"name": {
"type": "string"
},
Expand All @@ -256,6 +269,15 @@
"channel": {
"type": "string",
"enum": ["paper", "online"]
},
"if": {
"required": ["channel"],
"properties": {
"channel": { "const": "online" }
}
},
"then": {
"required": ["email"]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://data-dictionary.opg.service.justice.gov.uk/schema/lpa/2024-04/lpa.json",
"$id": "https://data-dictionary.opg.service.justice.gov.uk/schema/lpa/2024-10/lpa.json",
"description": "A lasting power of attorney document",
"allOf": [
{
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions docs/trust-corporation-sign.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
},
{
"key": "/trustCorporations/0/email",
"new": "b@example.com",
"old": "[email protected]"
"new": "a@example.com",
"old": null
},
{
"key": "/trustCorporations/0/signatories/0/firstNames",
Expand Down
2 changes: 1 addition & 1 deletion fixtures/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h2 class="govuk-error-summary__title">{{ error.detail }}</h2>
required
rows="10"
data-module="json-schema-editor"
data-module-json-schema-editor-url="assets/schemas/2024-04/lpa.json"
data-module-json-schema-editor-url="assets/schemas/2024-10/lpa.json"
>
{{- json_data -}}
</textarea>
Expand Down
4 changes: 2 additions & 2 deletions internal/shared/person.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (a AttorneyStatus) IsValid() bool {
type Attorney struct {
Person
DateOfBirth Date `json:"dateOfBirth"`
Email string `json:"email"`
Email string `json:"email,omitempty"`
Status AttorneyStatus `json:"status"`
Mobile string `json:"mobile,omitempty"`
SignedAt *time.Time `json:"signedAt,omitempty"`
Expand All @@ -77,7 +77,7 @@ type TrustCorporation struct {
UID string `json:"uid"`
Name string `json:"name"`
CompanyNumber string `json:"companyNumber"`
Email string `json:"email"`
Email string `json:"email,omitempty"`
Address Address `json:"address"`
Status AttorneyStatus `json:"status"`
Mobile string `json:"mobile,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion lambda/create/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (l *Lambda) HandleEvent(ctx context.Context, req events.APIGatewayProxyRequ

return problem.Respond()
}

data := shared.Lpa{LpaInit: input}
data.Uid = uid
data.Status = shared.LpaStatusProcessing
Expand Down
13 changes: 8 additions & 5 deletions lambda/create/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ func validateAttorney(prefix string, attorney shared.Attorney) []shared.FieldErr
validate.UUID(fmt.Sprintf("%s/uid", prefix), attorney.UID),
validate.Required(fmt.Sprintf("%s/firstNames", prefix), attorney.FirstNames),
validate.Required(fmt.Sprintf("%s/lastName", prefix), attorney.LastName),
validate.Required(fmt.Sprintf("%s/status", prefix), string(attorney.Status)),
validate.Date(fmt.Sprintf("%s/dateOfBirth", prefix), attorney.DateOfBirth),
validate.Address(fmt.Sprintf("%s/address", prefix), attorney.Address),
validate.IsValid(fmt.Sprintf("%s/status", prefix), attorney.Status),
validate.IsValid(fmt.Sprintf("%s/channel", prefix), attorney.Channel),
validate.IfElse(attorney.Channel == shared.ChannelOnline,
validate.Required(fmt.Sprintf("%s/email", prefix), attorney.Email),
validate.Empty(fmt.Sprintf("%s/email", prefix), attorney.Email)),
)
}

Expand All @@ -125,10 +128,10 @@ func validateTrustCorporation(prefix string, trustCorporation shared.TrustCorpor
validate.Required(fmt.Sprintf("%s/name", prefix), trustCorporation.Name),
validate.Required(fmt.Sprintf("%s/companyNumber", prefix), trustCorporation.CompanyNumber),
validate.Address(fmt.Sprintf("%s/address", prefix), trustCorporation.Address),
validate.IsValid(fmt.Sprintf("%s/channel", prefix), trustCorporation.Channel),
validate.IsValid(fmt.Sprintf("%s/status", prefix), trustCorporation.Status),
//validate.IfElse(trustCorporation.Channel == shared.ChannelOnline,
// validate.Required(fmt.Sprintf("%s/email", prefix), trustCorporation.Email),
// validate.Empty(fmt.Sprintf("%s/email", prefix), trustCorporation.Email)),
validate.IsValid(fmt.Sprintf("%s/channel", prefix), trustCorporation.Channel),
validate.IfElse(trustCorporation.Channel == shared.ChannelOnline,
validate.Required(fmt.Sprintf("%s/email", prefix), trustCorporation.Email),
validate.Empty(fmt.Sprintf("%s/email", prefix), trustCorporation.Email)),
)
}
97 changes: 72 additions & 25 deletions lambda/create/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func TestValidateAttorneyEmpty(t *testing.T) {
assert.Contains(t, errors, shared.FieldError{Source: "/test/dateOfBirth", Detail: "field is required"})
assert.Contains(t, errors, shared.FieldError{Source: "/test/address/line1", Detail: "field is required"})
assert.Contains(t, errors, shared.FieldError{Source: "/test/address/country", Detail: "field is required"})
assert.Contains(t, errors, shared.FieldError{Source: "/test/channel", Detail: "field is required"})
assert.Contains(t, errors, shared.FieldError{Source: "/test/uid", Detail: "field is required"})
}

func TestValidateAttorneyValid(t *testing.T) {
Expand All @@ -58,6 +60,8 @@ func TestValidateAttorneyValid(t *testing.T) {
},
DateOfBirth: newDate("1928-01-18"),
Status: shared.AttorneyStatusActive,
Channel: shared.ChannelOnline,
Email: "[email protected]",
}
errors := validateAttorney("/test", attorney)

Expand All @@ -67,6 +71,7 @@ func TestValidateAttorneyValid(t *testing.T) {
func TestValidateAttorneyMalformedDateOfBirth(t *testing.T) {
attorney := shared.Attorney{
Person: shared.Person{
UID: "0a266ff6-1c7b-49b7-acd0-047f1dcda2ce",
FirstNames: "Lesia",
LastName: "Lathim",
Address: validAddress,
Expand All @@ -82,6 +87,7 @@ func TestValidateAttorneyMalformedDateOfBirth(t *testing.T) {
func TestValidateAttorneyInvalidStatus(t *testing.T) {
attorney := shared.Attorney{
Person: shared.Person{
UID: "0a266ff6-1c7b-49b7-acd0-047f1dcda2ce",
FirstNames: "Lesia",
LastName: "Lathim",
Address: validAddress,
Expand All @@ -104,6 +110,7 @@ func TestValidateTrustCorporationEmpty(t *testing.T) {
assert.Contains(t, errors, shared.FieldError{Source: "/test/address/line1", Detail: "field is required"})
assert.Contains(t, errors, shared.FieldError{Source: "/test/address/country", Detail: "field is required"})
assert.Contains(t, errors, shared.FieldError{Source: "/test/channel", Detail: "field is required"})
assert.Contains(t, errors, shared.FieldError{Source: "/test/uid", Detail: "field is required"})
}

func TestValidateTrustCorporationValid(t *testing.T) {
Expand Down Expand Up @@ -203,6 +210,33 @@ func TestValidateLpaInvalid(t *testing.T) {
{Source: "/howAttorneysMakeDecisionsDetails", Detail: "field must not be provided"},
},
},
"online attorney missing email": {
lpa: shared.LpaInit{
Attorneys: []shared.Attorney{
{
Channel: shared.ChannelOnline,
Status: shared.AttorneyStatusActive,
},
},
},
contains: []shared.FieldError{
{Source: "/attorneys/0/email", Detail: "field is required"},
},
},
"paper attorney with email": {
lpa: shared.LpaInit{
Attorneys: []shared.Attorney{
{
Channel: shared.ChannelPaper,
Email: "[email protected]",
Status: shared.AttorneyStatusActive,
},
},
},
contains: []shared.FieldError{
{Source: "/attorneys/0/email", Detail: "field must not be provided"},
},
},
"single replacement attorney with decisions": {
lpa: shared.LpaInit{
Attorneys: []shared.Attorney{{Status: shared.AttorneyStatusReplacement}},
Expand Down Expand Up @@ -299,31 +333,31 @@ func TestValidateLpaInvalid(t *testing.T) {
{Source: "/lifeSustainingTreatmentOption", Detail: "field must not be provided"},
},
},
//"online trust corporation missing email": {
// lpa: shared.LpaInit{
// TrustCorporations: []shared.TrustCorporation{
// {
// Channel: shared.ChannelOnline,
// },
// },
// },
// contains: []shared.FieldError{
// {Source: "/trustCorporations/0/email", Detail: "field is required"},
// },
//},
//"paper trust corporation with email": {
// lpa: shared.LpaInit{
// TrustCorporations: []shared.TrustCorporation{
// {
// Channel: shared.ChannelPaper,
// Email: "[email protected]",
// },
// },
// },
// contains: []shared.FieldError{
// {Source: "/trustCorporations/0/email", Detail: "field must not be provided"},
// },
//},
"online trust corporation missing email": {
lpa: shared.LpaInit{
TrustCorporations: []shared.TrustCorporation{
{
Channel: shared.ChannelOnline,
},
},
},
contains: []shared.FieldError{
{Source: "/trustCorporations/0/email", Detail: "field is required"},
},
},
"paper trust corporation with email": {
lpa: shared.LpaInit{
TrustCorporations: []shared.TrustCorporation{
{
Channel: shared.ChannelPaper,
Email: "[email protected]",
},
},
},
contains: []shared.FieldError{
{Source: "/trustCorporations/0/email", Detail: "field must not be provided"},
},
},
}

for name, tc := range testcases {
Expand Down Expand Up @@ -360,6 +394,7 @@ func TestValidateLpaValid(t *testing.T) {
DateOfBirth: newDate("1977-10-30"),
Status: shared.AttorneyStatusActive,
Channel: shared.ChannelOnline,
Email: "[email protected]",
},
},
CertificateProvider: shared.CertificateProvider{
Expand All @@ -373,8 +408,20 @@ func TestValidateLpaValid(t *testing.T) {
Email: "[email protected]",
Channel: shared.ChannelOnline,
},
TrustCorporations: []shared.TrustCorporation{
{
UID: "af2f7aa6-2f8e-4311-af2a-4855c4686d30",
Name: "corp",
CompanyNumber: "5",
Email: "[email protected]",
Address: validAddress,
Status: shared.AttorneyStatusActive,
Channel: shared.ChannelOnline,
},
},
LifeSustainingTreatmentOption: shared.LifeSustainingTreatmentOptionA,
SignedAt: time.Now(),
HowAttorneysMakeDecisions: shared.HowMakeDecisionsJointly,
}
errors := Validate(lpa)

Expand Down
7 changes: 5 additions & 2 deletions lambda/update/trust_corporation_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ func validateTrustCorporationSign(changes []shared.Change, lpa *shared.Lpa) (Tru
}

data.Index = &i
data.Email = lpa.TrustCorporations[i].Email
data.Channel = lpa.TrustCorporations[i].Channel

return each.
Field("/mobile", &data.Mobile).
Field("/contactLanguagePreference", &data.ContactLanguagePreference, parse.Validate(func() []shared.FieldError {
return validate.IsValid("", data.ContactLanguagePreference)
})).
Field("/email", &data.Email, parse.Optional()).
Field("/email", &data.Email, parse.Optional(), parse.MustMatchExisting()).
Field("/channel", &data.Channel, parse.Validate(func() []shared.FieldError {
return validate.IsValid("", data.Channel)
}), parse.Optional()).
}), parse.Optional(), parse.MustMatchExisting()).
Prefix("/signatories", func(prefix *parse.Parser) []shared.FieldError {
return prefix.
Each(func(i int, each *parse.Parser) []shared.FieldError {
Expand Down
Loading

0 comments on commit cad5f41

Please sign in to comment.