-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more feedback rename lint
- Loading branch information
Showing
4 changed files
with
73 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
internal/serve/validators/disbursement_request_validator.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package validators | ||
|
||
import "github.com/stellar/stellar-disbursement-platform-backend/internal/data" | ||
|
||
type DisbursementRequestValidator struct { | ||
verificationField data.VerificationField | ||
*Validator | ||
} | ||
|
||
func NewDisbursementRequestValidator(verificationField data.VerificationField) *DisbursementRequestValidator { | ||
return &DisbursementRequestValidator{ | ||
verificationField: verificationField, | ||
Validator: NewValidator(), | ||
} | ||
} | ||
|
||
// ValidateAndGetVerificationType validates if the verification type field is a valid value. | ||
func (dv *DisbursementRequestValidator) ValidateAndGetVerificationType() data.VerificationField { | ||
switch dv.verificationField { | ||
case data.VerificationFieldDateOfBirth, data.VerificationFieldPin, data.VerificationFieldNationalID: | ||
return dv.verificationField | ||
default: | ||
dv.Check(false, "verification_field", "invalid parameter. valid values are: DATE_OF_BIRTH, PIN, NATIONAL_ID_NUMBER") | ||
return "" | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
internal/serve/validators/disbursement_request_validator_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package validators | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stellar/stellar-disbursement-platform-backend/internal/data" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_DisbursementRequestValidator_ValidateAndGetVerificationType(t *testing.T) { | ||
t.Run("Valid verification type", func(t *testing.T) { | ||
validField := []data.VerificationField{ | ||
data.VerificationFieldDateOfBirth, | ||
data.VerificationFieldPin, | ||
data.VerificationFieldNationalID, | ||
} | ||
for _, field := range validField { | ||
validator := NewDisbursementRequestValidator(field) | ||
assert.Equal(t, field, validator.ValidateAndGetVerificationType()) | ||
} | ||
}) | ||
|
||
t.Run("Invalid verification type", func(t *testing.T) { | ||
field := data.VerificationField("field") | ||
validator := NewDisbursementRequestValidator(field) | ||
|
||
actual := validator.ValidateAndGetVerificationType() | ||
assert.Empty(t, actual) | ||
assert.Equal(t, 1, len(validator.Errors)) | ||
assert.Equal(t, "invalid parameter. valid values are: DATE_OF_BIRTH, PIN, NATIONAL_ID_NUMBER", validator.Errors["verification_field"]) | ||
}) | ||
} |