Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLPAB-2088: Match old and existing update values on TRUST_CORPORATION_SIGN #190

Merged
merged 7 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -229,12 +229,21 @@
"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"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "channel" should be in here, and for attorneys too

"properties": {
"name": {
"type": "string"
Expand All @@ -256,6 +265,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
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
10 changes: 7 additions & 3 deletions lambda/create/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func validateAttorney(prefix string, attorney shared.Attorney) []shared.FieldErr
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.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 @@ -124,11 +127,12 @@ func validateTrustCorporation(prefix string, trustCorporation shared.TrustCorpor
validate.UUID(fmt.Sprintf("%s/uid", prefix), trustCorporation.UID),
validate.Required(fmt.Sprintf("%s/name", prefix), trustCorporation.Name),
validate.Required(fmt.Sprintf("%s/companyNumber", prefix), trustCorporation.CompanyNumber),
validate.Required(fmt.Sprintf("%s/status", prefix), string(trustCorporation.Status)),
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.IfElse(trustCorporation.Channel == shared.ChannelOnline,
validate.Required(fmt.Sprintf("%s/email", prefix), trustCorporation.Email),
validate.Empty(fmt.Sprintf("%s/email", prefix), trustCorporation.Email)),
)
}
78 changes: 53 additions & 25 deletions lambda/create/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,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 +326,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 +387,7 @@ func TestValidateLpaValid(t *testing.T) {
DateOfBirth: newDate("1977-10-30"),
Status: shared.AttorneyStatusActive,
Channel: shared.ChannelOnline,
Email: "[email protected]",
},
},
CertificateProvider: shared.CertificateProvider{
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