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: Add channel and email to trust corp sign #186

Merged
merged 4 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ test-api:
./api-test/tester -expectedStatus=400 REQUEST PUT $(URL)/lpas/$(LPA_UID) '{"version":"2"}'

# certificate provider sign
cat ./docs/certificate-provider-change.json | ./api-test/tester -expectedStatus=201 REQUEST POST $(URL)/lpas/$(LPA_UID)/updates "`xargs -0`"
cat ./docs/certificate-provider-sign.json | ./api-test/tester -expectedStatus=201 REQUEST POST $(URL)/lpas/$(LPA_UID)/updates "`xargs -0`"

# attorney sign
cat ./docs/attorney-change.json | ./api-test/tester -expectedStatus=201 REQUEST POST $(URL)/lpas/$(LPA_UID)/updates "`xargs -0`"
cat ./docs/attorney-sign.json | ./api-test/tester -expectedStatus=201 REQUEST POST $(URL)/lpas/$(LPA_UID)/updates "`xargs -0`"

# trust corporation sign
cat ./docs/trust-corporation-sign.json | ./api-test/tester -expectedStatus=201 REQUEST POST $(URL)/lpas/$(LPA_UID)/updates "`xargs -0`"

# get lpa
./api-test/tester -expectedStatus=200 REQUEST GET $(URL)/lpas/$(LPA_UID) ''
Expand Down
File renamed without changes.
18 changes: 17 additions & 1 deletion docs/example-lpa.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
"channel": "paper"
}
],
"trustCorporations": [
{
"uid": "1d95993a-ffbb-484c-b2fe-f4cca51801da",
"name": "Trust us Corp.",
"companyNumber": "666123321",
"address": {
"line1": "103 Line 1",
"town": "Town",
"country": "GB"
},
"email": "[email protected]",
"status": "active",
"channel": "paper"
}
],
"certificateProvider": {
"uid": "6808960d-12cf-47c5-a2bc-3177deb8599c",
"firstNames": "Vone",
Expand All @@ -44,5 +59,6 @@
},
"lifeSustainingTreatmentOption": "option-a",
"signedAt": "2024-01-10T23:00:00Z",
"certificateProviderNotRelatedConfirmedAt": "2024-01-11T22:00:00Z"
"certificateProviderNotRelatedConfirmedAt": "2024-01-11T22:00:00Z",
"howAttorneysMakeDecisions": "jointly"
}
4 changes: 4 additions & 0 deletions docs/schemas/2024-04/donor-details.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@
"status": {
"type": "string",
"enum": ["active", "replacement", "removed"]
},
"channel": {
"type": "string",
"enum": ["paper", "online"]
}
}
},
Expand Down
65 changes: 65 additions & 0 deletions docs/trust-corporation-sign.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"type": "TRUST_CORPORATION_SIGN",
"changes": [
{
"key": "/trustCorporations/0/mobile",
"new": "07700900000",
"old": null
},
{
"key": "/trustCorporations/0/contactLanguagePreference",
"new": "en",
"old": null
},
{
"key": "/trustCorporations/0/channel",
"new": "online",
"old": "paper"
},
{
"key": "/trustCorporations/0/email",
"new": "[email protected]",
"old": "[email protected]"
},
{
"key": "/trustCorporations/0/signatories/0/firstNames",
"new": "Sam",
"old": null
},
{
"key": "/trustCorporations/0/signatories/0/lastName",
"new": "Smith",
"old": null
},
{
"key": "/trustCorporations/0/signatories/0/professionalTitle",
"new": "President",
"old": null
},
{
"key": "/trustCorporations/0/signatories/0/signedAt",
"new": "2024-01-13T22:00:00Z",
"old": null
},
{
"key": "/trustCorporations/0/signatories/1/firstNames",
"new": "Sandra",
"old": null
},
{
"key": "/trustCorporations/0/signatories/1/lastName",
"new": "Smith",
"old": null
},
{
"key": "/trustCorporations/0/signatories/1/professionalTitle",
"new": "Vice President",
"old": null
},
{
"key": "/trustCorporations/0/signatories/1/signedAt",
"new": "2024-01-13T22:00:00Z",
"old": null
}
]
}
1 change: 1 addition & 0 deletions internal/shared/person.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type TrustCorporation struct {
Mobile string `json:"mobile,omitempty"`
Signatories []Signatory `json:"signatories,omitempty"`
ContactLanguagePreference Lang `json:"contactLanguagePreference,omitempty"`
Channel Channel `json:"channel"`
}

type Signatory struct {
Expand Down
13 changes: 11 additions & 2 deletions lambda/update/trust_corporation_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
)

type TrustCorporationSign struct {
Channel shared.Channel
ContactLanguagePreference shared.Lang
Email string
Index *int
Mobile string
Signatories [2]shared.Signatory
ContactLanguagePreference shared.Lang
}

func (a TrustCorporationSign) Apply(lpa *shared.Lpa) []shared.FieldError {
Expand All @@ -19,12 +21,15 @@ func (a TrustCorporationSign) Apply(lpa *shared.Lpa) []shared.FieldError {
}

lpa.TrustCorporations[*a.Index].Mobile = a.Mobile
lpa.TrustCorporations[*a.Index].ContactLanguagePreference = a.ContactLanguagePreference
lpa.TrustCorporations[*a.Index].Channel = a.Channel
lpa.TrustCorporations[*a.Index].Email = a.Email

if a.Signatories[1].IsZero() {
lpa.TrustCorporations[*a.Index].Signatories = a.Signatories[:1]
} else {
lpa.TrustCorporations[*a.Index].Signatories = a.Signatories[:]
}
lpa.TrustCorporations[*a.Index].ContactLanguagePreference = a.ContactLanguagePreference

return nil
}
Expand All @@ -46,6 +51,10 @@ func validateTrustCorporationSign(changes []shared.Change, lpa *shared.Lpa) (Tru
Field("/contactLanguagePreference", &data.ContactLanguagePreference, parse.Validate(func() []shared.FieldError {
return validate.IsValid("", data.ContactLanguagePreference)
})).
Field("/email", &data.Email, parse.Optional()).
Field("/channel", &data.Channel, parse.Validate(func() []shared.FieldError {
return validate.IsValid("", data.Channel)
}), parse.Optional()).
Prefix("/signatories", func(prefix *parse.Parser) []shared.FieldError {
return prefix.
Each(func(i int, each *parse.Parser) []shared.FieldError {
Expand Down
75 changes: 74 additions & 1 deletion lambda/update/trust_corporation_sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,63 @@ func TestValidateUpdateTrustCorporationSign(t *testing.T) {
errors []shared.FieldError
}{
"valid": {
update: shared.Update{
Type: "TRUST_CORPORATION_SIGN",
Changes: []shared.Change{
{
Key: "/trustCorporations/1/mobile",
New: json.RawMessage(`"07777"`),
Old: jsonNull,
},
{
Key: "/trustCorporations/1/signatories/0/firstNames",
New: json.RawMessage(`"John"`),
Old: jsonNull,
},
{
Key: "/trustCorporations/1/signatories/0/lastName",
New: json.RawMessage(`"Smith"`),
Old: jsonNull,
},
{
Key: "/trustCorporations/1/signatories/0/professionalTitle",
New: json.RawMessage(`"Director"`),
Old: jsonNull,
},
{
Key: "/trustCorporations/1/signatories/0/signedAt",
New: json.RawMessage(`"` + time.Now().Format(time.RFC3339) + `"`),
Old: jsonNull,
},
{
Key: "/trustCorporations/1/signatories/1/firstNames",
New: json.RawMessage(`"Jane"`),
Old: jsonNull,
},
{
Key: "/trustCorporations/1/signatories/1/lastName",
New: json.RawMessage(`"Smith"`),
Old: jsonNull,
},
{
Key: "/trustCorporations/1/signatories/1/professionalTitle",
New: json.RawMessage(`"Deputy Director"`),
Old: jsonNull,
},
{
Key: "/trustCorporations/1/signatories/1/signedAt",
New: json.RawMessage(`"` + time.Now().Format(time.RFC3339) + `"`),
Old: jsonNull,
},
{
Key: "/trustCorporations/1/contactLanguagePreference",
New: json.RawMessage(`"cy"`),
Old: jsonNull,
},
},
},
},
"valid - existing values": {
update: shared.Update{
Type: "TRUST_CORPORATION_SIGN",
Changes: []shared.Change{
Expand Down Expand Up @@ -86,6 +143,16 @@ func TestValidateUpdateTrustCorporationSign(t *testing.T) {
New: json.RawMessage(`"cy"`),
Old: jsonNull,
},
{
Key: "/trustCorporations/1/email",
New: json.RawMessage(`"[email protected]"`),
Old: json.RawMessage(`"[email protected]"`),
},
{
Key: "/trustCorporations/1/channel",
New: json.RawMessage(`"online"`),
Old: json.RawMessage(`"paper"`),
},
},
},
},
Expand Down Expand Up @@ -146,7 +213,7 @@ func TestValidateUpdateTrustCorporationSign(t *testing.T) {
{Source: "/changes/7", Detail: "unexpected change provided"},
},
},
"invalid contact language": {
"invalid values": {
update: shared.Update{
Type: "TRUST_CORPORATION_SIGN",
Changes: []shared.Change{
Expand Down Expand Up @@ -180,10 +247,16 @@ func TestValidateUpdateTrustCorporationSign(t *testing.T) {
New: json.RawMessage(`"xy"`),
Old: jsonNull,
},
{
Key: "/trustCorporations/1/channel",
New: json.RawMessage(`"digital"`),
Old: json.RawMessage(`"paper"`),
},
},
},
errors: []shared.FieldError{
{Source: "/changes/5/new", Detail: "invalid value"},
{Source: "/changes/6/new", Detail: "invalid value"},
},
},
"multiple trust corporations": {
Expand Down
18 changes: 17 additions & 1 deletion mock-apigw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ func handlePactState(r *http.Request) error {
"channel": "paper"
}
],
"trustCorporations": [
{
"uid": "1d95993a-ffbb-484c-b2fe-f4cca51801da",
"name": "Trust us Corp.",
"companyNumber": "666123321",
"address": {
"line1": "103 Line 1",
"town": "Town",
"country": "GB"
},
"email": "[email protected]",
"status": "active",
"channel": "paper"
}
],
"certificateProvider": {
"uid": "4fe2ac67-17cc-4e9b-a9d6-ce30b5f9c82e",
"firstNames": "Some",
Expand All @@ -168,7 +183,8 @@ func handlePactState(r *http.Request) error {
}
},
"lifeSustainingTreatmentOption": "option-a",
"signedAt": "2000-01-02T12:13:14Z"
"signedAt": "2000-01-02T12:13:14Z",
"howAttorneysMakeDecisions": "jointly"
}`

req, err := http.NewRequest("PUT", url, strings.NewReader(body))
Expand Down