Skip to content

Commit

Permalink
Increase Code Coverage
Browse files Browse the repository at this point in the history
Increase Code Coverage
  • Loading branch information
bkmoovio committed Apr 25, 2019
1 parent 24e81b4 commit 8cf3732
Show file tree
Hide file tree
Showing 12 changed files with 451 additions and 151 deletions.
3 changes: 3 additions & 0 deletions accountCreditedDrawdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func (creditDD *AccountCreditedDrawdown) Validate() error {
// fieldInclusion validate mandatory fields. If fields are
// invalid the WIRE will return an error.
func (creditDD *AccountCreditedDrawdown) fieldInclusion() error {
if creditDD.DrawdownCreditAccountNumber == "" {
return fieldError("DrawdownCreditAccountNumber", ErrFieldRequired)
}
return nil
}

Expand Down
35 changes: 35 additions & 0 deletions accountCreditedDrawdown_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
package wire

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

// mockAccountCreditedDrawdown creates a AccountCreditedDrawdown
func mockAccountCreditedDrawdown() *AccountCreditedDrawdown {
creditDD := NewAccountCreditedDrawdown()
creditDD.DrawdownCreditAccountNumber = "123456789"
return creditDD
}

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

// TestDrawdownCreditAccountNumberAlphaNumeric validates DrawdownCreditAccountNumber is alphanumeric
func TestDrawdownCreditAccountNumberAlphaNumeric(t *testing.T) {
creditDD := mockAccountCreditedDrawdown()
creditDD.DrawdownCreditAccountNumber = "®"
if err := creditDD.Validate(); err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestDrawdownCreditAccountNumberRequired validates DrawdownCreditAccountNumber is required
func TestDrawdownCreditAccountNumberRequired(t *testing.T) {
creditDD := mockAccountCreditedDrawdown()
creditDD.DrawdownCreditAccountNumber = ""
if err := creditDD.Validate(); err != nil {
if !base.Match(err, ErrFieldRequired) {
t.Errorf("%T: %s", err, err)
}
}
}
2 changes: 1 addition & 1 deletion accountDebitedDrawdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (debitDD *AccountDebitedDrawdown) Validate() error {
// Can only be these Identification Codes
switch debitDD.IdentificationCode {
case
"D":
DemandDepositAccountNumber:
default:
return fieldError("IdentificationCode", ErrIdentificationCode, debitDD.IdentificationCode)
}
Expand Down
114 changes: 113 additions & 1 deletion accountDebitedDrawdown_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,125 @@
package wire

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

// mockAccountDebitedDrawdown creates a AccountDebitedDrawdown
func mockAccountDebitedDrawdown() *AccountDebitedDrawdown {
debitDD := NewAccountDebitedDrawdown()
debitDD.IdentificationCode = "DemandDepositAccountNumber"
debitDD.IdentificationCode = DemandDepositAccountNumber
debitDD.Identifier = "123456789"
debitDD.Name = "debitDD Name"
debitDD.Address.AddressLineOne = "Address One"
debitDD.Address.AddressLineTwo = "Address Two"
debitDD.Address.AddressLineThree = "Address Three"
return debitDD
}

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

// TestIdentifierAlphaNumeric validates Name is alphanumeric
func TestIdentifierAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Identifier = "®"
if err := debitDD.Validate(); err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestNameAlphaNumeric validates Identifier is alphanumeric
func TestNameAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Name = "®"
if err := debitDD.Validate(); err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestAddressLineOneAlphaNumeric validates AddressLineOne is alphanumeric
func TestAddressLineOneAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Address.AddressLineOne = "®"
if err := debitDD.Validate(); err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestAddressLineTwoAlphaNumeric validates AddressLineTwo is alphanumeric
func TestAddressLineTwoAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Address.AddressLineTwo = "®"
if err := debitDD.Validate(); err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestAddressLineThreeAlphaNumeric validates AddressLineThree is alphanumeric
func TestAddressLineThreeAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Address.AddressLineThree = "®"
if err := debitDD.Validate(); err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestIdentifierRequired validates Identifier is required
func TestIdentifierRequired(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Identifier = ""
if err := debitDD.Validate(); err != nil {
if !base.Match(err, ErrFieldRequired) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestNameRequired validates Name is required
func TestNameRequired(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Name = ""
if err := debitDD.Validate(); err != nil {
if !base.Match(err, ErrFieldRequired) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestIdentificationRequired validates IdentificationCode is required
func TestIdentificationCodeNull(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.IdentificationCode = ""
if err := debitDD.Validate(); err != nil {
if !base.Match(err, ErrFieldRequired) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestIdentificationCodeValid validates IdentificationCode
func TestIdentificationCodeRequired(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.IdentificationCode = TaxIdentificationNumber
if err := debitDD.Validate(); err != nil {
if !base.Match(err, ErrIdentificationCode) {
t.Errorf("%T: %s", err, err)
}
}
}
57 changes: 57 additions & 0 deletions actualAmountPaid_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,66 @@
package wire

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

// ActualAmountPaid creates a ActualAmountPaid
func mockActualAmountPaid() *ActualAmountPaid {
aap := NewActualAmountPaid()
aap.RemittanceAmount.CurrencyCode = "USD"
aap.RemittanceAmount.Amount = "1234.56"
return aap
}

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

// TestAmountRequired validates Amount is required
func TestAmountRequired(t *testing.T) {
aap := mockActualAmountPaid()
aap.RemittanceAmount.Amount = ""
if err := aap.Validate(); err != nil {
if !base.Match(err, ErrFieldRequired) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestCurrencyCodeRequired validates CurrencyCode is required
func TestCurrencyCodeRequired(t *testing.T) {
aap := mockActualAmountPaid()
aap.RemittanceAmount.CurrencyCode = ""
if err := aap.Validate(); err != nil {
if !base.Match(err, ErrFieldRequired) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestAmountValid validates Amount
func TestAmountValid(t *testing.T) {
aap := mockActualAmountPaid()
aap.RemittanceAmount.Amount = "X,"
if err := aap.Validate(); err != nil {
if !base.Match(err, ErrNonAmount) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestCurrencyCodeValid validates Amount
func TestCurrencyCodeValid(t *testing.T) {
aap := mockActualAmountPaid()
aap.RemittanceAmount.CurrencyCode = "XZP"
if err := aap.Validate(); err != nil {
if !base.Match(err, ErrNonCurrencyCode) {
t.Errorf("%T: %s", err, err)
}
}
}
4 changes: 3 additions & 1 deletion fieldErrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ var (
// ErrNonAlphanumeric is returned when a field has non-alphanumeric characters
ErrNonAlphanumeric = errors.New("has non alphanumeric characters")
// ErrNonAmount is returned for an incorrect wire amount format
ErrNonAmount = errors.New("is an incorrect wire amount format")
ErrNonAmount = errors.New("is an incorrect amount format")
// ErrNonCurrencyCode is returned for an incorrect currency code
ErrNonCurrencyCode = errors.New("is not a recognized currency code")
// ErrUpperAlpha is returned when a field is not in uppercase
ErrUpperAlpha = errors.New("is not uppercase A-Z or 0-9")
// ErrFieldInclusion is returned when a field is mandatory and has a default value
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190423205934-9f3314589c9a h1:rM1gZGYTi0P9XM/4jvWkpEIpV8rH+xG03ymiMMtL5QE=
golang.org/x/oauth2 v0.0.0-20190423205934-9f3314589c9a/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
Expand Down
2 changes: 1 addition & 1 deletion localInstrument_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package wire
// mockLocalInstrument creates a LocalInstrument
func mockLocalInstrument() *LocalInstrument {
li := NewLocalInstrument()
li.LocalInstrumentCode = "ANSI"
li.LocalInstrumentCode = ANSIX12format
li.ProprietaryCode = ""
return li
}
2 changes: 1 addition & 1 deletion primaryRemittanceDocument.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (prd *PrimaryRemittanceDocument) fieldInclusion() error {
return fieldError("ProprietaryDocumentTypeCode", ErrFieldRequired)
}
default:
if prd.ProprietaryDocumentTypeCode != "" {
if strings.TrimSpace(prd.ProprietaryDocumentTypeCode) != "" {
return fieldError("ProprietaryDocumentTypeCode", ErrInvalidProperty)
}
}
Expand Down
3 changes: 1 addition & 2 deletions remittanceBeneficiary.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func (rb *RemittanceBeneficiary) Validate() error {
return fieldError("IdentificationCode", err, rb.IdentificationCode)
}
}

if err := rb.isAlphanumeric(rb.IdentificationNumber); err != nil {
return fieldError("IdentificationNumber", err, rb.IdentificationNumber)
}
Expand Down Expand Up @@ -189,7 +188,7 @@ func (rb *RemittanceBeneficiary) Validate() error {
}
if rb.IdentificationCode != PICDateBirthPlace {
if rb.RemittanceData.DateBirthPlace != "" {
return fieldError("IdentificationNumberIssuer", ErrInvalidProperty)
return fieldError("DateBirthPlace", ErrInvalidProperty)
}
}
return nil
Expand Down
5 changes: 4 additions & 1 deletion validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ func (v *validator) isAdjustmentReasonCode(code string) error {

func (v *validator) isCurrencyCode(code string) error {
_, err := currency.ParseISO(code)
return err
if err != nil {
return ErrNonCurrencyCode
}
return nil
}

// isCentury validates a 2 digit century 20-29
Expand Down
Loading

0 comments on commit 8cf3732

Please sign in to comment.