Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyliu committed Nov 28, 2023
1 parent f9c9c8a commit de1714f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/serve/httphandler/disbursement_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (d DisbursementHandler) PostDisbursement(w http.ResponseWriter, r *http.Req
return
}

v := validators.NewDisbursementValidator(disbursementRequest.VerificationField)
v := validators.NewDisbursementRequestValidator(disbursementRequest.VerificationField)
v.Check(disbursementRequest.Name != "", "name", "name is required")
v.Check(disbursementRequest.CountryCode != "", "country_code", "country_code is required")
v.Check(disbursementRequest.WalletID != "", "wallet_id", "wallet_id is required")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package validators

import "github.com/stellar/stellar-disbursement-platform-backend/internal/data"

type DisbursementValidator struct {
type DisbursementRequestValidator struct {
verificationField data.VerificationField
*Validator
}

func NewDisbursementValidator(verificationField data.VerificationField) *DisbursementValidator {
return &DisbursementValidator{
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 *DisbursementValidator) ValidateAndGetVerificationType() data.VerificationField {
func (dv *DisbursementRequestValidator) ValidateAndGetVerificationType() data.VerificationField {
switch dv.verificationField {
case data.VerificationFieldDateOfBirth, data.VerificationFieldPin, data.VerificationFieldNationalID:
return dv.verificationField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import (
"github.com/stretchr/testify/assert"
)

func Test_DisbursementValidator_ValidateAndGetVerificationType(t *testing.T) {
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 := NewDisbursementValidator(field)
validator := NewDisbursementRequestValidator(field)
assert.Equal(t, field, validator.ValidateAndGetVerificationType())
}
})

t.Run("Invalid verification type", func(t *testing.T) {
field := data.VerificationField("field")
validator := NewDisbursementValidator(field)
validator := NewDisbursementRequestValidator(field)

actual := validator.ValidateAndGetVerificationType()
assert.Empty(t, actual)
Expand Down

0 comments on commit de1714f

Please sign in to comment.