diff --git a/docs/schemas/2024-10/donor-details.json b/docs/schemas/2024-10/donor-details.json index 2d49ca16..7d7de03a 100644 --- a/docs/schemas/2024-10/donor-details.json +++ b/docs/schemas/2024-10/donor-details.json @@ -9,7 +9,8 @@ "donor", "attorneys", "certificateProvider", - "signedAt" + "signedAt", + "witnessedByCertificateProviderAt" ], "properties": { "lpaType": { diff --git a/internal/validate/validate.go b/internal/validate/validate.go index 89f70168..6c9157eb 100644 --- a/internal/validate/validate.go +++ b/internal/validate/validate.go @@ -75,8 +75,8 @@ func Date(source string, date shared.Date) []shared.FieldError { return nil } -func Time(source string, t time.Time) []shared.FieldError { - return If(t.IsZero(), []shared.FieldError{{Source: source, Detail: "field is required"}}) +func Time(source string, t interface{ IsZero() bool }) []shared.FieldError { + return If(t == (*time.Time)(nil) || t.IsZero(), []shared.FieldError{{Source: source, Detail: "field is required"}}) } func OptionalTime(source string, t *time.Time) []shared.FieldError { diff --git a/lambda/create/validate.go b/lambda/create/validate.go index 1cfe0c61..d4a6fab0 100644 --- a/lambda/create/validate.go +++ b/lambda/create/validate.go @@ -47,7 +47,8 @@ func Validate(lpa shared.LpaInit) []shared.FieldError { validate.Required("/independentWitness/firstNames", lpa.IndependentWitness.FirstNames), validate.Required("/independentWitness/lastName", lpa.IndependentWitness.LastName), validate.Required("/independentWitness/phone", lpa.IndependentWitness.Phone), - validate.Address("/independentWitness/address", lpa.IndependentWitness.Address)) + validate.Address("/independentWitness/address", lpa.IndependentWitness.Address), + validate.Time("/witnessedByIndependentWitnessAt", lpa.WitnessedByIndependentWitnessAt)) }), validate.IfElse(activeAttorneyCount > 1, validate.IsValid("/howAttorneysMakeDecisions", lpa.HowAttorneysMakeDecisions), @@ -73,8 +74,7 @@ func Validate(lpa shared.LpaInit) []shared.FieldError { validate.IsValid("/whenTheLpaCanBeUsed", lpa.WhenTheLpaCanBeUsed), validate.Unset("/lifeSustainingTreatmentOption", lpa.LifeSustainingTreatmentOption))), validate.Time("/signedAt", lpa.SignedAt), - // validate.Time("/witnessedByCertificateProviderAt", lpa.WitnessedByCertificateProviderAt), - // validate.OptionalTime("/witnessedByIndependentWitnessAt", lpa.WitnessedByIndependentWitnessAt), + validate.Time("/witnessedByCertificateProviderAt", lpa.WitnessedByCertificateProviderAt), validate.OptionalTime("/certificateProviderNotRelatedConfirmedAt", lpa.CertificateProviderNotRelatedConfirmedAt), ) } diff --git a/lambda/create/validate_test.go b/lambda/create/validate_test.go index 92983997..bf69cc5b 100644 --- a/lambda/create/validate_test.go +++ b/lambda/create/validate_test.go @@ -213,7 +213,7 @@ func TestValidateLpaInvalid(t *testing.T) { {Source: "/certificateProvider/phone", Detail: "field is required"}, {Source: "/attorneys", Detail: "at least one attorney is required"}, {Source: "/signedAt", Detail: "field is required"}, - // {Source: "/witnessedByCertificateProviderAt", Detail: "field is required"}, + {Source: "/witnessedByCertificateProviderAt", Detail: "field is required"}, }, }, "online certificate provider missing email": { @@ -496,6 +496,24 @@ func TestValidateLpaInvalid(t *testing.T) { {Source: "/donor/identityCheck/type", Detail: "invalid value"}, }, }, + "independent witness missing witnessed at": { + lpa: func() shared.LpaInit { + lpa := makeLpaWithDonorAndActors() + lpa.IndependentWitness = &shared.IndependentWitness{ + Person: shared.Person{ + UID: "b99af83d-5b6c-44f7-8c03-14004699bdb9", + FirstNames: "Some", + LastName: "Person", + }, + Address: validAddress, + Phone: "077777", + } + return lpa + }, + expectedErrors: []shared.FieldError{ + {Source: "/witnessedByIndependentWitnessAt", Detail: "field is required"}, + }, + }, } for name, tc := range testcases { diff --git a/mock-apigw/main.go b/mock-apigw/main.go index abab9eec..a8756417 100644 --- a/mock-apigw/main.go +++ b/mock-apigw/main.go @@ -184,6 +184,7 @@ func handlePactState(r *http.Request) error { }, "lifeSustainingTreatmentOption": "option-a", "signedAt": "2000-01-02T12:13:14Z", + "witnessedByCertificateProviderAt": "2000-01-02T13:13:14Z", "howAttorneysMakeDecisions": "jointly" }`