Skip to content

Commit

Permalink
Additional tests and gocyclo coverage
Browse files Browse the repository at this point in the history
Additional tests and gocyclo coverage
  • Loading branch information
bkmoovio committed Apr 25, 2019
1 parent 8cf3732 commit 002fcbe
Show file tree
Hide file tree
Showing 12 changed files with 562 additions and 80 deletions.
12 changes: 6 additions & 6 deletions actualAmountPaid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func TestMockActualAmountPaid(t *testing.T) {
}
}

// TestAmountRequired validates Amount is required
func TestAmountRequired(t *testing.T) {
// TestActualAmountPaidAmountRequired validates ActualAmountPaid Amount is required
func TestActualAmountPaidAmountRequired(t *testing.T) {
aap := mockActualAmountPaid()
aap.RemittanceAmount.Amount = ""
if err := aap.Validate(); err != nil {
Expand All @@ -32,7 +32,7 @@ func TestAmountRequired(t *testing.T) {
}
}

// TestCurrencyCodeRequired validates CurrencyCode is required
// TestActualAmountPaidCurrencyCodeRequired validates ActualAmountPaid CurrencyCode is required
func TestCurrencyCodeRequired(t *testing.T) {
aap := mockActualAmountPaid()
aap.RemittanceAmount.CurrencyCode = ""
Expand All @@ -43,8 +43,8 @@ func TestCurrencyCodeRequired(t *testing.T) {
}
}

// TestAmountValid validates Amount
func TestAmountValid(t *testing.T) {
// TestActualAmountPaidAmountValid validates Amount
func TestActualAmountPaidAmountValid(t *testing.T) {
aap := mockActualAmountPaid()
aap.RemittanceAmount.Amount = "X,"
if err := aap.Validate(); err != nil {
Expand All @@ -54,7 +54,7 @@ func TestAmountValid(t *testing.T) {
}
}

// TestCurrencyCodeValid validates Amount
// TestActualAmountPaidCurrencyCodeValid validates Amount
func TestCurrencyCodeValid(t *testing.T) {
aap := mockActualAmountPaid()
aap.RemittanceAmount.CurrencyCode = "XZP"
Expand Down
103 changes: 102 additions & 1 deletion adjustment_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package wire

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

// MockAdjustment creates a Adjustment
func mockAdjustment() *Adjustment {
adj := NewAdjustment()
adj.AdjustmentReasonCode = PricingError
Expand All @@ -10,3 +15,99 @@ func mockAdjustment() *Adjustment {
adj.AdditionalInfo = " Adjustment Additional Information"
return adj
}

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

// TestAdjustmentReasonCodeValid validates Adjustment AdjustmentReasonCode
func TestAdjustmentReasonCodeValid(t *testing.T) {
adj := mockAdjustment()
adj.AdjustmentReasonCode = "ZZ"
if err := adj.Validate(); err != nil {
if !base.Match(err, ErrAdjustmentReasonCode) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestCreditDebitIndicatorValid validates Adjustment CreditDebitIndicator
func TestCreditDebitIndicatorValid(t *testing.T) {
adj := mockAdjustment()
adj.CreditDebitIndicator = "ZZZZ"
if err := adj.Validate(); err != nil {
if !base.Match(err, ErrCreditDebitIndicator) {
t.Errorf("%T: %s", err, err)
}
}
}

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

// TestAdjustmentCurrencyCodeValid validates Adjustment CurrencyCode
func TestAdjustmentCurrencyCodeValid(t *testing.T) {
adj := mockAdjustment()
adj.RemittanceAmount.CurrencyCode = "XZP"
if err := adj.Validate(); err != nil {
if !base.Match(err, ErrNonCurrencyCode) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestAdjustmentReasonCodeRequired validates Adjustment AdjustmentReasonCode is required
func TestAdjustmentReasonCodeRequired(t *testing.T) {
adj := mockAdjustment()
adj.AdjustmentReasonCode = ""
if err := adj.Validate(); err != nil {
if !base.Match(err, ErrFieldRequired) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestCreditDebitIndicatorRequired validates Adjustment CreditDebitIndicator is required
func TestCreditDebitIndicatorRequired(t *testing.T) {
adj := mockAdjustment()
adj.CreditDebitIndicator = ""
if err := adj.Validate(); err != nil {
if !base.Match(err, ErrFieldRequired) {
t.Errorf("%T: %s", err, err)
}
}
}

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

// TestAdjustmentCurrencyCodeRequired validates Adjustment CurrencyCode is required
func TestAdjustmentCurrencyCodeRequired(t *testing.T) {
adj := mockAdjustment()
adj.RemittanceAmount.CurrencyCode = ""
if err := adj.Validate(); err != nil {
if !base.Match(err, ErrFieldRequired) {
t.Errorf("%T: %s", err, err)
}
}
}
3 changes: 3 additions & 0 deletions amount.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ func (a *Amount) Validate() error {
// fieldInclusion validate mandatory fields. If fields are
// invalid the WIRE will return an error.
func (a *Amount) fieldInclusion() error {
if a.Amount == "" {
return fieldError("Amount", ErrFieldRequired)
}
return nil
}

Expand Down
6 changes: 6 additions & 0 deletions amountNegotiatedDiscount.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func (nd *AmountNegotiatedDiscount) Validate() error {
// fieldInclusion validate mandatory fields. If fields are
// invalid the WIRE will return an error.
func (nd *AmountNegotiatedDiscount) fieldInclusion() error {
if nd.RemittanceAmount.Amount == "" {
return fieldError("Amount", ErrFieldRequired)
}
if nd.RemittanceAmount.CurrencyCode == "" {
return fieldError("CurrencyCode", ErrFieldRequired)
}
return nil
}

Expand Down
56 changes: 56 additions & 0 deletions amountNegotiatedDiscount_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,65 @@
package wire

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

// AmountNegotiatedDiscount creates a AmountNegotiatedDiscount
func mockAmountNegotiatedDiscount() *AmountNegotiatedDiscount {
nd := NewAmountNegotiatedDiscount()
nd.RemittanceAmount.CurrencyCode = "USD"
nd.RemittanceAmount.Amount = "1234.56"
return nd
}

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

// TestAmountNegotiatedDiscountAmountValid validates AmountNegotiatedDiscount Amount
func TestAmountNegotiatedDiscountValid(t *testing.T) {
nd := mockAmountNegotiatedDiscount()
nd.RemittanceAmount.Amount = "X,"
if err := nd.Validate(); err != nil {
if !base.Match(err, ErrNonAmount) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestAmountNegotiatedDiscountCurrencyCodeValid validates AmountNegotiatedDiscount CurrencyCode
func TestAmountNegotiatedDiscountCurrencyCodeValid(t *testing.T) {
nd := mockAmountNegotiatedDiscount()
nd.RemittanceAmount.CurrencyCode = "XZP"
if err := nd.Validate(); err != nil {
if !base.Match(err, ErrNonCurrencyCode) {
}
}
}

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

// TestAmountNegotiatedDiscountCurrencyCodeRequired validates AmountNegotiatedDiscount CurrencyCode is required
func TestAmountNegotiatedDiscountCurrencyCodeRequired(t *testing.T) {
nd := mockAmountNegotiatedDiscount()
nd.RemittanceAmount.CurrencyCode = ""
if err := nd.Validate(); err != nil {
if !base.Match(err, ErrFieldRequired) {
t.Errorf("%T: %s", err, err)
}
}
}
35 changes: 35 additions & 0 deletions amount_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"
)

// mockAmount creates an a Amount
func mockAmount() *Amount {
a := NewAmount()
a.Amount = "000001234567"
return a
}

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

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

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

0 comments on commit 002fcbe

Please sign in to comment.