Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bkmoovio committed Apr 26, 2019
1 parent 002fcbe commit 81aaa79
Show file tree
Hide file tree
Showing 27 changed files with 821 additions and 61 deletions.
47 changes: 29 additions & 18 deletions accountDebitedDrawdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func TestMockAccountDebitedDrawdown(t *testing.T) {
}
}

// TestIdentifierAlphaNumeric validates Name is alphanumeric
func TestIdentifierAlphaNumeric(t *testing.T) {
// TestADDIdentifierAlphaNumeric validates Name is alphanumeric
func TestADDIdentifierAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Identifier = "®"
if err := debitDD.Validate(); err != nil {
Expand All @@ -36,8 +36,8 @@ func TestIdentifierAlphaNumeric(t *testing.T) {
}
}

// TestNameAlphaNumeric validates Identifier is alphanumeric
func TestNameAlphaNumeric(t *testing.T) {
// TestADDNameAlphaNumeric validates Identifier is alphanumeric
func TestADDNameAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Name = "®"
if err := debitDD.Validate(); err != nil {
Expand All @@ -47,8 +47,8 @@ func TestNameAlphaNumeric(t *testing.T) {
}
}

// TestAddressLineOneAlphaNumeric validates AddressLineOne is alphanumeric
func TestAddressLineOneAlphaNumeric(t *testing.T) {
// TestADDAddressLineOneAlphaNumeric validates AddressLineOne is alphanumeric
func TestADDAddressLineOneAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Address.AddressLineOne = "®"
if err := debitDD.Validate(); err != nil {
Expand All @@ -58,8 +58,8 @@ func TestAddressLineOneAlphaNumeric(t *testing.T) {
}
}

// TestAddressLineTwoAlphaNumeric validates AddressLineTwo is alphanumeric
func TestAddressLineTwoAlphaNumeric(t *testing.T) {
// TestADDAddressLineTwoAlphaNumeric validates AddressLineTwo is alphanumeric
func TestADDAddressLineTwoAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Address.AddressLineTwo = "®"
if err := debitDD.Validate(); err != nil {
Expand All @@ -69,8 +69,8 @@ func TestAddressLineTwoAlphaNumeric(t *testing.T) {
}
}

// TestAddressLineThreeAlphaNumeric validates AddressLineThree is alphanumeric
func TestAddressLineThreeAlphaNumeric(t *testing.T) {
// TestADDAddressLineThreeAlphaNumeric validates AddressLineThree is alphanumeric
func TestADDAddressLineThreeAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Address.AddressLineThree = "®"
if err := debitDD.Validate(); err != nil {
Expand All @@ -80,8 +80,8 @@ func TestAddressLineThreeAlphaNumeric(t *testing.T) {
}
}

// TestIdentifierRequired validates Identifier is required
func TestIdentifierRequired(t *testing.T) {
// TestADDIdentifierRequired validates Identifier is required
func TestADDIdentifierRequired(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Identifier = ""
if err := debitDD.Validate(); err != nil {
Expand All @@ -91,8 +91,8 @@ func TestIdentifierRequired(t *testing.T) {
}
}

// TestNameRequired validates Name is required
func TestNameRequired(t *testing.T) {
// TestADDNameRequired validates Name is required
func TestADDNameRequired(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Name = ""
if err := debitDD.Validate(); err != nil {
Expand All @@ -102,8 +102,8 @@ func TestNameRequired(t *testing.T) {
}
}

// TestIdentificationRequired validates IdentificationCode is required
func TestIdentificationCodeNull(t *testing.T) {
// TestADDIdentificationRequired validates IdentificationCode is required
func TestADDIdentificationCodeRequired(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.IdentificationCode = ""
if err := debitDD.Validate(); err != nil {
Expand All @@ -113,8 +113,8 @@ func TestIdentificationCodeNull(t *testing.T) {
}
}

// TestIdentificationCodeValid validates IdentificationCode
func TestIdentificationCodeRequired(t *testing.T) {
// TestADDIdentificationCodeValid validates IdentificationCode
func TestADDIdentificationCodeValid(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.IdentificationCode = TaxIdentificationNumber
if err := debitDD.Validate(); err != nil {
Expand All @@ -123,3 +123,14 @@ func TestIdentificationCodeRequired(t *testing.T) {
}
}
}

// TestADDIdentificationCodeBogus validates IdentificationCode if the IdentificationCode is bogus
func TestIdentificationCodeBogus(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.IdentificationCode = "Card ID"
if err := debitDD.Validate(); err != nil {
if !base.Match(err, ErrIdentificationCode) {
t.Errorf("%T: %s", err, err)
}
}
}
2 changes: 1 addition & 1 deletion adjustment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ func TestAdjustmentCurrencyCodeRequired(t *testing.T) {
t.Errorf("%T: %s", err, err)
}
}
}
}
2 changes: 1 addition & 1 deletion amountNegotiatedDiscount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ func TestAmountNegotiatedDiscountCurrencyCodeRequired(t *testing.T) {
t.Errorf("%T: %s", err, err)
}
}
}
}
2 changes: 1 addition & 1 deletion amount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ func TestAmountRequired(t *testing.T) {
t.Errorf("%T: %s", err, err)
}
}
}
}
12 changes: 6 additions & 6 deletions beneficiary.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,18 @@ func (ben *Beneficiary) Validate() error {
if err := ben.isAlphanumeric(ben.Personal.Address.AddressLineThree); err != nil {
return fieldError("AddressLineThree", err, ben.Personal.Address.AddressLineThree)
}
if ben.Personal.IdentificationCode != "" && ben.Personal.Identifier == "" {
return fieldError("Identifier", ErrFieldRequired)
}
if ben.Personal.IdentificationCode == "" && ben.Personal.Identifier != "" {
return fieldError("IdentificationCode", ErrFieldRequired)
}
return nil
}

// fieldInclusion validate mandatory fields. If fields are
// invalid the WIRE will return an error.
func (ben *Beneficiary) fieldInclusion() error {
if ben.Personal.IdentificationCode != "" && ben.Personal.Identifier == "" {
return fieldError("Identifier", ErrFieldRequired)
}
if ben.Personal.IdentificationCode == "" && ben.Personal.Identifier != "" {
return fieldError("IdentificationCode", ErrFieldRequired)
}
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions beneficiaryCustomer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func (bc *BeneficiaryCustomer) Validate() error {
// fieldInclusion validate mandatory fields. If fields are
// invalid the WIRE will return an error.
func (bc *BeneficiaryCustomer) fieldInclusion() error {
// If the BeneficiaryCustomer is defined the default required field is SwiftFieldTag
if bc.CoverPayment.SwiftFieldTag == "" {
return fieldError("SwiftFieldTag", ErrFieldRequired)
}
return nil
}

Expand Down
90 changes: 90 additions & 0 deletions beneficiaryCustomer_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package wire

import (
"github.com/moov-io/base"
"testing"
)

// mockBeneficiaryCustomer creates a BeneficiaryCustomer
func mockBeneficiaryCustomer() *BeneficiaryCustomer {
bc := NewBeneficiaryCustomer()
Expand All @@ -11,3 +16,88 @@ func mockBeneficiaryCustomer() *BeneficiaryCustomer {
bc.CoverPayment.SwiftLineFive = "Swift Line Five"
return bc
}

// TestMockBeneficiaryCustomer validates mockBeneficiaryCustomer
func TestMockBeneficiaryCustomer(t *testing.T) {
bc := mockBeneficiaryCustomer()
if err := bc.Validate(); err != nil {
t.Error("mockBeneficiaryCustomer does not validate and will break other tests")
}
}

// TestBeneficiaryCustomerSwiftFieldTagAlphaNumeric validates BeneficiaryCustomer SwiftFieldTag is alphanumeric
func TestBeneficiaryCustomerSwiftFieldTagAlphaNumeric(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftFieldTag = "®"
if err := bc.Validate(); err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestBeneficiaryCustomerSwiftLineOneAlphaNumeric validates BeneficiaryCustomer SwiftLineOne is alphanumeric
func TestBeneficiaryCustomerSwiftLineOneAlphaNumeric(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftLineOne = "®"
if err := bc.Validate(); err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestBeneficiaryCustomerSwiftLineTwoAlphaNumeric validates BeneficiaryCustomer SwiftLineTwo is alphanumeric
func TestBeneficiaryCustomerSwiftLineTwoAlphaNumeric(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftLineTwo = "®"
if err := bc.Validate(); err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestBeneficiaryCustomerSwiftLineThreeAlphaNumeric validates BeneficiaryCustomer SwiftLineThree is alphanumeric
func TestBeneficiaryCustomerSwiftLineThreeAlphaNumeric(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftLineThree = "®"
if err := bc.Validate(); err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestBeneficiaryCustomerSwiftLineFourAlphaNumeric validates BeneficiaryCustomer SwiftLineFour is alphanumeric
func TestBeneficiaryCustomerSwiftLineFourAlphaNumeric(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftLineFour = "®"
if err := bc.Validate(); err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestBeneficiaryCustomerSwiftLineFiveAlphaNumeric validates BeneficiaryCustomer SwiftLineFive is alphanumeric
func TestBeneficiaryCustomerSwiftLineFiveAlphaNumeric(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftLineFive = "®"
if err := bc.Validate(); err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestBeneficiaryCustomerSwiftFieldTagRequired validates BeneficiaryCustomer SwiftFieldTag is required
func TestBeneficiaryCustomerSwiftFieldTagRequired(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.CoverPayment.SwiftFieldTag = ""
if err := bc.Validate(); err != nil {
if !base.Match(err, ErrFieldRequired) {
t.Errorf("%T: %s", err, err)
}
}
}
18 changes: 11 additions & 7 deletions beneficiaryFI.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ func (bfi *BeneficiaryFI) Validate() error {
// Can only be these Identification Codes
switch bfi.FinancialInstitution.IdentificationCode {
case
"B", "C", "D", "F", "U":
SWIFTBankIdentifierCode,
CHIPSParticipant,
DemandDepositAccountNumber,
FEDRoutingNumber,
CHIPSIdentifier:
default:
return fieldError("IdentificationCode", ErrIdentificationCode, bfi.FinancialInstitution.IdentificationCode)
}
Expand All @@ -86,18 +90,18 @@ func (bfi *BeneficiaryFI) Validate() error {
if err := bfi.isAlphanumeric(bfi.FinancialInstitution.Address.AddressLineThree); err != nil {
return fieldError("AddressLineThree", err, bfi.FinancialInstitution.Address.AddressLineThree)
}
if bfi.FinancialInstitution.IdentificationCode != "" && bfi.FinancialInstitution.Identifier == "" {
return fieldError("Identifier", ErrFieldRequired)
}
if bfi.FinancialInstitution.IdentificationCode == "" && bfi.FinancialInstitution.Identifier != "" {
return fieldError("IdentificationCode", ErrFieldRequired)
}
return nil
}

// fieldInclusion validate mandatory fields. If fields are
// invalid the WIRE will return an error.
func (bfi *BeneficiaryFI) fieldInclusion() error {
if bfi.FinancialInstitution.IdentificationCode != "" && bfi.FinancialInstitution.Identifier == "" {
return fieldError("Identifier", ErrFieldRequired)
}
if bfi.FinancialInstitution.IdentificationCode == "" && bfi.FinancialInstitution.Identifier != "" {
return fieldError("IdentificationCode", ErrFieldRequired)
}
return nil
}

Expand Down
Loading

0 comments on commit 81aaa79

Please sign in to comment.