diff --git a/Makefile b/Makefile index 72d88634..c60ee365 100644 --- a/Makefile +++ b/Makefile @@ -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) '' diff --git a/docs/attorney-change.json b/docs/attorney-sign.json similarity index 100% rename from docs/attorney-change.json rename to docs/attorney-sign.json diff --git a/docs/certificate-provider-change.json b/docs/certificate-provider-sign.json similarity index 100% rename from docs/certificate-provider-change.json rename to docs/certificate-provider-sign.json diff --git a/docs/example-lpa.json b/docs/example-lpa.json index 9556c6fa..a954ae8f 100644 --- a/docs/example-lpa.json +++ b/docs/example-lpa.json @@ -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": "a@example.com", + "status": "active", + "channel": "paper" + } + ], "certificateProvider": { "uid": "6808960d-12cf-47c5-a2bc-3177deb8599c", "firstNames": "Vone", @@ -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" } diff --git a/docs/schemas/2024-04/donor-details.json b/docs/schemas/2024-04/donor-details.json index d87d6512..57471360 100644 --- a/docs/schemas/2024-04/donor-details.json +++ b/docs/schemas/2024-04/donor-details.json @@ -252,6 +252,10 @@ "status": { "type": "string", "enum": ["active", "replacement", "removed"] + }, + "channel": { + "type": "string", + "enum": ["paper", "online"] } } }, diff --git a/docs/trust-corporation-sign.json b/docs/trust-corporation-sign.json new file mode 100644 index 00000000..ace9f3ea --- /dev/null +++ b/docs/trust-corporation-sign.json @@ -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": "b@example.com", + "old": "a@example.com" + }, + { + "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 + } + ] +} diff --git a/internal/shared/person.go b/internal/shared/person.go index 6aea9429..624c588d 100644 --- a/internal/shared/person.go +++ b/internal/shared/person.go @@ -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 { diff --git a/lambda/update/trust_corporation_sign.go b/lambda/update/trust_corporation_sign.go index d314de0f..9d84d1c5 100644 --- a/lambda/update/trust_corporation_sign.go +++ b/lambda/update/trust_corporation_sign.go @@ -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 { @@ -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 } @@ -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 { diff --git a/lambda/update/trust_corporation_sign_test.go b/lambda/update/trust_corporation_sign_test.go index 2d23d8e3..c2770e3e 100644 --- a/lambda/update/trust_corporation_sign_test.go +++ b/lambda/update/trust_corporation_sign_test.go @@ -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{ @@ -86,6 +143,16 @@ func TestValidateUpdateTrustCorporationSign(t *testing.T) { New: json.RawMessage(`"cy"`), Old: jsonNull, }, + { + Key: "/trustCorporations/1/email", + New: json.RawMessage(`"b@example.com"`), + Old: json.RawMessage(`"a@example.com"`), + }, + { + Key: "/trustCorporations/1/channel", + New: json.RawMessage(`"online"`), + Old: json.RawMessage(`"paper"`), + }, }, }, }, @@ -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{ @@ -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": { diff --git a/mock-apigw/main.go b/mock-apigw/main.go index dc47e5ee..e9c567c4 100644 --- a/mock-apigw/main.go +++ b/mock-apigw/main.go @@ -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": "a@example.com", + "status": "active", + "channel": "paper" + } + ], "certificateProvider": { "uid": "4fe2ac67-17cc-4e9b-a9d6-ce30b5f9c82e", "firstNames": "Some", @@ -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))