Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyliu committed Nov 28, 2023
1 parent bee783d commit 54a5174
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
4 changes: 2 additions & 2 deletions internal/serve/httphandler/disbursement_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func Test_DisbursementHandler_PostDisbursement(t *testing.T) {
assertPOSTResponse(t, ctx, handler, method, url, requestBody, want, http.StatusBadRequest)
})

t.Run("returns error when no verification type is provided", func(t *testing.T) {
t.Run("returns error when no verification field is provided", func(t *testing.T) {
requestBody, err := json.Marshal(PostDisbursementRequest{
Name: "disbursement 1",
CountryCode: country.Code,
Expand All @@ -163,7 +163,7 @@ func Test_DisbursementHandler_PostDisbursement(t *testing.T) {
})
require.NoError(t, err)

want := `{"error":"Verification field invalid", "extras": {"verification_type": "invalid parameter. valid values are: DATE_OF_BIRTH, PIN, NATIONAL_ID_NUMBER"}}`
want := `{"error":"Verification field invalid", "extras": {"verification_field": "invalid parameter. valid values are: DATE_OF_BIRTH, PIN, NATIONAL_ID_NUMBER"}}`

assertPOSTResponse(t, ctx, handler, method, url, string(requestBody), want, http.StatusBadRequest)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (iv *DisbursementInstructionsValidator) ValidateInstruction(instruction *da
iv.addError(fmt.Sprintf("line %d - national id", lineNumber), "invalid national id. Cannot have more than 50 characters in national id")
}
} else {
log.Warnf("Verification type %v is not being validated for ValidateReceiver", iv)
log.Warnf("Verification field %v is not being validated for ValidateReceiver", iv)
}
}

Expand All @@ -74,7 +74,7 @@ func (iv *DisbursementInstructionsValidator) ValidateAndGetVerificationType(veri
case data.VerificationFieldDateOfBirth, data.VerificationFieldPin, data.VerificationFieldNationalID:
return vt
default:
iv.Check(false, "verification_type", "invalid parameter. valid values are: DATE_OF_BIRTH, PIN, NATIONAL_ID_NUMBER")
iv.Check(false, "verification_field", "invalid parameter. valid values are: DATE_OF_BIRTH, PIN, NATIONAL_ID_NUMBER")
return ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (

func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing.T) {
tests := []struct {
name string
actual *data.DisbursementInstruction
lineNumber int
verificationType data.VerificationField
hasErrors bool
expectedErrors map[string]interface{}
name string
actual *data.DisbursementInstruction
lineNumber int
verificationField data.VerificationField
hasErrors bool
expectedErrors map[string]interface{}
}{
{
name: "valid record",
Expand All @@ -24,9 +24,9 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
Amount: "100.5",
VerificationValue: "1990-01-01",
},
lineNumber: 1,
verificationType: data.VerificationFieldDateOfBirth,
hasErrors: false,
lineNumber: 1,
verificationField: data.VerificationFieldDateOfBirth,
hasErrors: false,
},
{
name: "empty phone number",
Expand All @@ -35,19 +35,19 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
Amount: "100.5",
VerificationValue: "1990-01-01",
},
lineNumber: 2,
verificationType: data.VerificationFieldDateOfBirth,
hasErrors: true,
lineNumber: 2,
verificationField: data.VerificationFieldDateOfBirth,
hasErrors: true,
expectedErrors: map[string]interface{}{
"line 2 - phone": "phone cannot be empty",
},
},
{
name: "empty phone, id, amount and birthday",
actual: &data.DisbursementInstruction{},
lineNumber: 2,
verificationType: data.VerificationFieldDateOfBirth,
hasErrors: true,
name: "empty phone, id, amount and birthday",
actual: &data.DisbursementInstruction{},
lineNumber: 2,
verificationField: data.VerificationFieldDateOfBirth,
hasErrors: true,
expectedErrors: map[string]interface{}{
"line 2 - amount": "invalid amount. Amount must be a positive number",
"line 2 - birthday": "invalid date of birth format. Correct format: 1990-01-01",
Expand All @@ -63,9 +63,9 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
Amount: "100.5",
VerificationValue: "1990-01-01",
},
lineNumber: 2,
verificationType: data.VerificationFieldDateOfBirth,
hasErrors: true,
lineNumber: 2,
verificationField: data.VerificationFieldDateOfBirth,
hasErrors: true,
expectedErrors: map[string]interface{}{
"line 2 - phone": "invalid phone format. Correct format: +380445555555",
},
Expand All @@ -78,9 +78,9 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
Amount: "100.5USDC",
VerificationValue: "1990-01-01",
},
lineNumber: 3,
verificationType: data.VerificationFieldDateOfBirth,
hasErrors: true,
lineNumber: 3,
verificationField: data.VerificationFieldDateOfBirth,
hasErrors: true,
expectedErrors: map[string]interface{}{
"line 3 - amount": "invalid amount. Amount must be a positive number",
},
Expand All @@ -93,9 +93,9 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
Amount: "-100.5",
VerificationValue: "1990-01-01",
},
lineNumber: 3,
verificationType: data.VerificationFieldDateOfBirth,
hasErrors: true,
lineNumber: 3,
verificationField: data.VerificationFieldDateOfBirth,
hasErrors: true,
expectedErrors: map[string]interface{}{
"line 3 - amount": "invalid amount. Amount must be a positive number",
},
Expand All @@ -108,9 +108,9 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
Amount: "100.5",
VerificationValue: "1990/01/01",
},
lineNumber: 3,
verificationType: data.VerificationFieldDateOfBirth,
hasErrors: true,
lineNumber: 3,
verificationField: data.VerificationFieldDateOfBirth,
hasErrors: true,
expectedErrors: map[string]interface{}{
"line 3 - birthday": "invalid date of birth format. Correct format: 1990-01-01",
},
Expand All @@ -123,9 +123,9 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
Amount: "100.5",
VerificationValue: "2090-01-01",
},
lineNumber: 3,
verificationType: data.VerificationFieldDateOfBirth,
hasErrors: true,
lineNumber: 3,
verificationField: data.VerificationFieldDateOfBirth,
hasErrors: true,
expectedErrors: map[string]interface{}{
"line 3 - birthday": "date of birth cannot be in the future",
},
Expand All @@ -138,9 +138,9 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
Amount: "100.5",
VerificationValue: "1234",
},
lineNumber: 3,
verificationType: data.VerificationFieldPin,
hasErrors: false,
lineNumber: 3,
verificationField: data.VerificationFieldPin,
hasErrors: false,
},
{
name: "invalid pin - less than 4 characters",
Expand All @@ -150,9 +150,9 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
Amount: "100.5",
VerificationValue: "123",
},
lineNumber: 3,
verificationType: data.VerificationFieldPin,
hasErrors: true,
lineNumber: 3,
verificationField: data.VerificationFieldPin,
hasErrors: true,
expectedErrors: map[string]interface{}{
"line 3 - pin": "invalid pin. Cannot have less than 4 or more than 8 characters in pin",
},
Expand All @@ -165,9 +165,9 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
Amount: "100.5",
VerificationValue: "123456789",
},
lineNumber: 3,
verificationType: data.VerificationFieldPin,
hasErrors: true,
lineNumber: 3,
verificationField: data.VerificationFieldPin,
hasErrors: true,
expectedErrors: map[string]interface{}{
"line 3 - pin": "invalid pin. Cannot have less than 4 or more than 8 characters in pin",
},
Expand All @@ -180,9 +180,9 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
Amount: "100.5",
VerificationValue: "ABCD123",
},
lineNumber: 3,
verificationType: data.VerificationFieldNationalID,
hasErrors: false,
lineNumber: 3,
verificationField: data.VerificationFieldNationalID,
hasErrors: false,
},
{
name: "invalid national - more than 50 characters",
Expand All @@ -192,9 +192,9 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing
Amount: "100.5",
VerificationValue: "6UZMB56FWTKV4U0PJ21TBR6VOQVYSGIMZG2HW2S0L7EK5K83W78",
},
lineNumber: 3,
verificationType: data.VerificationFieldNationalID,
hasErrors: true,
lineNumber: 3,
verificationField: data.VerificationFieldNationalID,
hasErrors: true,
expectedErrors: map[string]interface{}{
"line 3 - national id": "invalid national id. Cannot have more than 50 characters in national id",
},
Expand All @@ -203,7 +203,7 @@ func Test_DisbursementInstructionsValidator_ValidateAndGetInstruction(t *testing

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
iv := NewDisbursementInstructionsValidator(tt.verificationType)
iv := NewDisbursementInstructionsValidator(tt.verificationField)
iv.ValidateInstruction(tt.actual, tt.lineNumber)

if tt.hasErrors {
Expand Down

0 comments on commit 54a5174

Please sign in to comment.