diff --git a/internal/shared/person.go b/internal/shared/person.go index 7cf06585..f06c92ab 100644 --- a/internal/shared/person.go +++ b/internal/shared/person.go @@ -74,7 +74,7 @@ const ( ) func (a AppointmentType) IsValid() bool { - return true + return a == AppointmentTypeOriginal || a == AppointmentTypeReplacement } type Attorney struct { diff --git a/lambda/create/validate.go b/lambda/create/validate.go index d4a6fab0..33ee4212 100644 --- a/lambda/create/validate.go +++ b/lambda/create/validate.go @@ -81,19 +81,19 @@ func Validate(lpa shared.LpaInit) []shared.FieldError { func countAttorneys(as []shared.Attorney, ts []shared.TrustCorporation) (actives, replacements int) { for _, a := range as { - switch a.Status { - case shared.AttorneyStatusActive: + switch a.AppointmentType { + case shared.AppointmentTypeOriginal: actives++ - case shared.AttorneyStatusReplacement: + case shared.AppointmentTypeReplacement: replacements++ } } for _, t := range ts { - switch t.Status { - case shared.AttorneyStatusActive: + switch t.AppointmentType { + case shared.AppointmentTypeOriginal: actives++ - case shared.AttorneyStatusReplacement: + case shared.AppointmentTypeReplacement: replacements++ } } @@ -126,6 +126,7 @@ func validateAttorney(prefix string, attorney shared.Attorney) []shared.FieldErr validate.Address(fmt.Sprintf("%s/address", prefix), attorney.Address), validate.IsValid(fmt.Sprintf("%s/status", prefix), attorney.Status), validate.IsValid(fmt.Sprintf("%s/channel", prefix), attorney.Channel), + validate.IsValid(fmt.Sprintf("%s/appointmentType", prefix), attorney.AppointmentType), validate.IfElse(attorney.Channel == shared.ChannelOnline, validate.Required(fmt.Sprintf("%s/email", prefix), attorney.Email), validate.Empty(fmt.Sprintf("%s/email", prefix), attorney.Email)), @@ -152,6 +153,7 @@ func validateTrustCorporation(prefix string, trustCorporation shared.TrustCorpor validate.Address(fmt.Sprintf("%s/address", prefix), trustCorporation.Address), validate.IsValid(fmt.Sprintf("%s/status", prefix), trustCorporation.Status), validate.IsValid(fmt.Sprintf("%s/channel", prefix), trustCorporation.Channel), + validate.IsValid(fmt.Sprintf("%s/appointmentType", prefix), trustCorporation.AppointmentType), validate.IfElse(trustCorporation.Channel == shared.ChannelOnline, validate.Required(fmt.Sprintf("%s/email", prefix), trustCorporation.Email), validate.Empty(fmt.Sprintf("%s/email", prefix), trustCorporation.Email)), diff --git a/lambda/create/validate_test.go b/lambda/create/validate_test.go index bda92089..a465dcf3 100644 --- a/lambda/create/validate_test.go +++ b/lambda/create/validate_test.go @@ -106,12 +106,12 @@ func TestCountAttorneys(t *testing.T) { assert.Equal(t, 0, replacements) actives, replacements = countAttorneys([]shared.Attorney{ - {Status: shared.AttorneyStatusReplacement}, - {Status: shared.AttorneyStatusActive}, - {Status: shared.AttorneyStatusReplacement}, + {AppointmentType: shared.AppointmentTypeReplacement}, + {AppointmentType: shared.AppointmentTypeOriginal}, + {AppointmentType: shared.AppointmentTypeReplacement}, }, []shared.TrustCorporation{ - {Status: shared.AttorneyStatusReplacement}, - {Status: shared.AttorneyStatusActive}, + {AppointmentType: shared.AppointmentTypeReplacement}, + {AppointmentType: shared.AppointmentTypeOriginal}, }) assert.Equal(t, 2, actives) assert.Equal(t, 3, replacements) @@ -124,6 +124,7 @@ func TestValidateAttorneyEmpty(t *testing.T) { {Source: "/test/uid", Detail: "field is required"}, {Source: "/test/firstNames", Detail: "field is required"}, {Source: "/test/lastName", Detail: "field is required"}, + {Source: "/test/appointmentType", Detail: "field is required"}, {Source: "/test/status", Detail: "field is required"}, {Source: "/test/address/line1", Detail: "field is required"}, {Source: "/test/address/country", Detail: "field is required"}, @@ -165,6 +166,7 @@ func TestValidateTrustCorporationEmpty(t *testing.T) { {Source: "/test/uid", Detail: "field is required"}, {Source: "/test/name", Detail: "field is required"}, {Source: "/test/companyNumber", Detail: "field is required"}, + {Source: "/test/appointmentType", Detail: "field is required"}, {Source: "/test/status", Detail: "field is required"}, {Source: "/test/address/line1", Detail: "field is required"}, {Source: "/test/address/country", Detail: "field is required"},