Skip to content

Commit

Permalink
Validate witnessed at times on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
hawx committed Oct 9, 2024
1 parent d2cf075 commit 96c4ee6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion docs/schemas/2024-10/donor-details.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"donor",
"attorneys",
"certificateProvider",
"signedAt"
"signedAt",
"witnessedByCertificateProviderAt"
],
"properties": {
"lpaType": {
Expand Down
4 changes: 2 additions & 2 deletions internal/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions lambda/create/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
)
}
Expand Down
20 changes: 19 additions & 1 deletion lambda/create/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions mock-apigw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}`

Expand Down

0 comments on commit 96c4ee6

Please sign in to comment.