From 989c8e8367671162127c41d6f2a29430b749114f Mon Sep 17 00:00:00 2001 From: Alex Saunders Date: Wed, 1 May 2024 14:42:09 +0100 Subject: [PATCH] MLPAB-2088: Make email optional, channel required for create trust corporation (#188) --- lambda/create/validate.go | 5 ++++- lambda/create/validate_test.go | 28 +++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lambda/create/validate.go b/lambda/create/validate.go index 88058b00..24f9ff7c 100644 --- a/lambda/create/validate.go +++ b/lambda/create/validate.go @@ -124,8 +124,11 @@ func validateTrustCorporation(prefix string, trustCorporation shared.TrustCorpor validate.UUID(fmt.Sprintf("%s/uid", prefix), trustCorporation.UID), validate.Required(fmt.Sprintf("%s/name", prefix), trustCorporation.Name), validate.Required(fmt.Sprintf("%s/companyNumber", prefix), trustCorporation.CompanyNumber), - validate.Required(fmt.Sprintf("%s/email", prefix), trustCorporation.Email), validate.Address(fmt.Sprintf("%s/address", prefix), trustCorporation.Address), + validate.IsValid(fmt.Sprintf("%s/channel", prefix), trustCorporation.Channel), validate.IsValid(fmt.Sprintf("%s/status", prefix), trustCorporation.Status), + //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 91fc8ca9..9416ed02 100644 --- a/lambda/create/validate_test.go +++ b/lambda/create/validate_test.go @@ -100,10 +100,10 @@ func TestValidateTrustCorporationEmpty(t *testing.T) { assert.Contains(t, errors, shared.FieldError{Source: "/test/name", Detail: "field is required"}) assert.Contains(t, errors, shared.FieldError{Source: "/test/companyNumber", Detail: "field is required"}) - assert.Contains(t, errors, shared.FieldError{Source: "/test/email", Detail: "field is required"}) assert.Contains(t, errors, shared.FieldError{Source: "/test/status", Detail: "field is required"}) assert.Contains(t, errors, shared.FieldError{Source: "/test/address/line1", Detail: "field is required"}) assert.Contains(t, errors, shared.FieldError{Source: "/test/address/country", Detail: "field is required"}) + assert.Contains(t, errors, shared.FieldError{Source: "/test/channel", Detail: "field is required"}) } func TestValidateTrustCorporationValid(t *testing.T) { @@ -114,6 +114,7 @@ func TestValidateTrustCorporationValid(t *testing.T) { Email: "corp@example.com", Address: validAddress, Status: shared.AttorneyStatusActive, + Channel: shared.ChannelOnline, } errors := validateTrustCorporation("/test", trustCorporation) @@ -298,6 +299,31 @@ func TestValidateLpaInvalid(t *testing.T) { {Source: "/lifeSustainingTreatmentOption", Detail: "field must not be provided"}, }, }, + //"online trust corporation missing email": { + // lpa: shared.LpaInit{ + // TrustCorporations: []shared.TrustCorporation{ + // { + // Channel: shared.ChannelOnline, + // }, + // }, + // }, + // contains: []shared.FieldError{ + // {Source: "/trustCorporations/0/email", Detail: "field is required"}, + // }, + //}, + //"paper trust corporation with email": { + // lpa: shared.LpaInit{ + // TrustCorporations: []shared.TrustCorporation{ + // { + // Channel: shared.ChannelPaper, + // Email: "a@example.com", + // }, + // }, + // }, + // contains: []shared.FieldError{ + // {Source: "/trustCorporations/0/email", Detail: "field must not be provided"}, + // }, + //}, } for name, tc := range testcases {