Skip to content

Commit

Permalink
VEGA-2656 make appointment type required (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
MishNajam authored Nov 22, 2024
1 parent 49ac85b commit a88828d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/shared/person.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const (
)

func (a AppointmentType) IsValid() bool {
return true
return a == AppointmentTypeOriginal || a == AppointmentTypeReplacement
}

type Attorney struct {
Expand Down
14 changes: 8 additions & 6 deletions lambda/create/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
}
Expand Down Expand Up @@ -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)),
Expand All @@ -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)),
Expand Down
12 changes: 7 additions & 5 deletions lambda/create/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down

0 comments on commit a88828d

Please sign in to comment.