Skip to content

Commit

Permalink
refactor unit tests - through grossAmountRemittanceDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
atonks2 committed Oct 30, 2020
1 parent a4f8112 commit 5dd02e6
Show file tree
Hide file tree
Showing 29 changed files with 456 additions and 820 deletions.
29 changes: 8 additions & 21 deletions accountCreditedDrawdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,18 @@ func TestMockAccountCreditedDrawdown(t *testing.T) {
func TestDrawdownCreditAccountNumberAlphaNumeric(t *testing.T) {
creditDD := mockAccountCreditedDrawdown()
creditDD.DrawdownCreditAccountNumber = "®"

err := creditDD.Validate()

require.NotNil(t, err)
expected := fieldError("DrawdownCreditAccountNumber", ErrNonNumeric, creditDD.DrawdownCreditAccountNumber).Error()
require.Equal(t, expected, err.Error())

require.EqualError(t, creditDD.Validate(), expected)
}

// TestAccountCreditedDrawdownNumberRequired validates AccountCreditedDrawdown is required
func TestDrawdownCreditAccountNumberRequired(t *testing.T) {
creditDD := mockAccountCreditedDrawdown()
creditDD.DrawdownCreditAccountNumber = ""

err := creditDD.Validate()

require.NotNil(t, err)
expected := fieldError("DrawdownCreditAccountNumber", ErrFieldRequired).Error()
require.Equal(t, expected, err.Error())

require.EqualError(t, creditDD.Validate(), expected)
}

// TestParseAccountCreditedDrawdownWrongLength parses a wrong AccountCreditedDrawdown record length
Expand All @@ -53,31 +47,25 @@ func TestParseAccountCreditedDrawdownWrongLength(t *testing.T) {

err := r.parseAccountCreditedDrawdown()

require.NotNil(t, err)
expected := r.parseError(NewTagWrongLengthErr(15, len(r.line))).Error()
require.Equal(t, expected, err.Error())
require.EqualError(t, err, expected)
}

// TestParseAccountCreditedDrawdownReaderParseError parses a wrong AccountCreditedDrawdown reader parse error
func TestParseAccountCreditedDrawdownReaderParseError(t *testing.T) {
var line = "{5400}12345678Z"
r := NewReader(strings.NewReader(line))
r.line = line
fwm := new(FEDWireMessage)
crediDD := mockAccountCreditedDrawdown()
fwm.SetAccountCreditedDrawdown(crediDD)

err := r.parseAccountCreditedDrawdown()

require.NotNil(t, err)
expected := r.parseError(fieldError("DrawdownCreditAccountNumber", ErrNonNumeric, "12345678Z")).Error()
require.Equal(t, expected, err.Error())
require.EqualError(t, err, expected)

_, err = r.Read()

require.NotNil(t, err)
expected = r.parseError(fieldError("DrawdownCreditAccountNumber", ErrNonNumeric, "12345678Z")).Error()
require.Equal(t, expected, err.Error())
require.EqualError(t, err, expected)
}

// TestAccountCreditedDrawdownTagError validates AccountCreditedDrawdown tag
Expand All @@ -87,7 +75,6 @@ func TestAccountCreditedDrawdownTagError(t *testing.T) {

err := creditDD.Validate()

require.NotNil(t, err)
expected := fieldError("tag", ErrValidTagForType, creditDD.tag).Error()
require.Equal(t, expected, err.Error())
require.EqualError(t, err, expected)
}
57 changes: 18 additions & 39 deletions accountDebitedDrawdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,24 @@ func TestMockAccountDebitedDrawdown(t *testing.T) {
require.NoError(t, debitDD.Validate(), "mockAccountDebitedDrawdown does not validate and will break other tests")
}

// TestADDIdentifierAlphaNumeric validates Name is alphanumeric
// TestADDIdentifierAlphaNumeric validates Identifier is alphanumeric
func TestADDIdentifierAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Identifier = "®"

err := debitDD.Validate()

require.NotNil(t, err)
require.Contains(t, err.Error(), ErrNonAlphanumeric.Error())
require.EqualError(t, err, fieldError("Identifier", ErrNonAlphanumeric, debitDD.Identifier).Error())
}

// TestADDNameAlphaNumeric validates Identifier is alphanumeric
// TestADDNameAlphaNumeric validates Name is alphanumeric
func TestADDNameAlphaNumeric(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.Name = "®"

err := debitDD.Validate()

require.NotNil(t, err)
require.Contains(t, err.Error(), ErrNonAlphanumeric.Error())
require.EqualError(t, err, fieldError("Name", ErrNonAlphanumeric, debitDD.Name).Error())
}

// TestADDAddressLineOneAlphaNumeric validates AddressLineOne is alphanumeric
Expand All @@ -55,8 +53,7 @@ func TestADDAddressLineOneAlphaNumeric(t *testing.T) {

err := debitDD.Validate()

require.NotNil(t, err)
require.Contains(t, err.Error(), ErrNonAlphanumeric.Error())
require.EqualError(t, err, fieldError("AddressLineOne", ErrNonAlphanumeric, debitDD.Address.AddressLineOne).Error())
}

// TestADDAddressLineTwoAlphaNumeric validates AddressLineTwo is alphanumeric
Expand All @@ -66,8 +63,7 @@ func TestADDAddressLineTwoAlphaNumeric(t *testing.T) {

err := debitDD.Validate()

require.NotNil(t, err)
require.Contains(t, err.Error(), ErrNonAlphanumeric.Error())
require.EqualError(t, err, fieldError("AddressLineTwo", ErrNonAlphanumeric, debitDD.Address.AddressLineTwo).Error())
}

// TestADDAddressLineThreeAlphaNumeric validates AddressLineThree is alphanumeric
Expand All @@ -77,8 +73,7 @@ func TestADDAddressLineThreeAlphaNumeric(t *testing.T) {

err := debitDD.Validate()

require.NotNil(t, err)
require.Contains(t, err.Error(), ErrNonAlphanumeric.Error())
require.EqualError(t, err, fieldError("AddressLineThree", ErrNonAlphanumeric, debitDD.Address.AddressLineThree).Error())
}

// TestADDIdentifierRequired validates Identifier is required
Expand All @@ -88,9 +83,7 @@ func TestADDIdentifierRequired(t *testing.T) {

err := debitDD.Validate()

require.NotNil(t, err)
expected := fieldError("Identifier", ErrFieldRequired).Error()
require.Equal(t, expected, err.Error())
require.EqualError(t, err, fieldError("Identifier", ErrFieldRequired).Error())
}

// TestADDNameRequired validates Name is required
Expand All @@ -100,9 +93,7 @@ func TestADDNameRequired(t *testing.T) {

err := debitDD.Validate()

require.NotNil(t, err)
expected := fieldError("Name", ErrFieldRequired).Error()
require.Equal(t, expected, err.Error())
require.EqualError(t, err, fieldError("Name", ErrFieldRequired).Error())
}

// TestADDIdentificationRequired validates IdentificationCode is required
Expand All @@ -112,9 +103,7 @@ func TestADDIdentificationCodeRequired(t *testing.T) {

err := debitDD.Validate()

require.NotNil(t, err)
expected := fieldError("IdentificationCode", ErrFieldRequired).Error()
require.Equal(t, expected, err.Error())
require.EqualError(t, err, fieldError("IdentificationCode", ErrFieldRequired).Error())
}

// TestADDIdentificationCodeValid validates IdentificationCode
Expand All @@ -124,9 +113,7 @@ func TestADDIdentificationCodeValid(t *testing.T) {

err := debitDD.Validate()

require.NotNil(t, err)
expected := fieldError("IdentificationCode", ErrIdentificationCode, debitDD.IdentificationCode).Error()
require.Equal(t, expected, err.Error())
require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, debitDD.IdentificationCode).Error())
}

// TestADDIdentificationCodeBogus validates IdentificationCode if the IdentificationCode is bogus
Expand All @@ -136,9 +123,7 @@ func TestIdentificationCodeBogus(t *testing.T) {

err := debitDD.Validate()

require.NotNil(t, err)
expected := fieldError("IdentificationCode", ErrIdentificationCode, debitDD.IdentificationCode).Error()
require.Equal(t, expected, err.Error())
require.EqualError(t, err, fieldError("IdentificationCode", ErrIdentificationCode, debitDD.IdentificationCode).Error())
}

// TestParseAccountDebitedDrawdownWrongLength parses a wrong AccountDebitedDrawdown record length
Expand All @@ -149,29 +134,24 @@ func TestParseAccountDebitedDrawdownWrongLength(t *testing.T) {

err := r.parseAccountDebitedDrawdown()

require.NotNil(t, err)
expected := r.parseError(NewTagWrongLengthErr(181, len(r.line))).Error()
require.Equal(t, expected, err.Error())
require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(181, len(r.line))).Error())
}

// TestParseAccountDebitedDrawdownReaderParseError parses a wrong AccountDebitedDrawdown reader parse error
func TestParseAccountDebitedDrawdownReaderParseError(t *testing.T) {
var line = "{4400}D123456789 debitDD ®ame Address One Address Two Address Three "
r := NewReader(strings.NewReader(line))
r.line = line
fwm := new(FEDWireMessage)
debitDD := mockAccountDebitedDrawdown()
fwm.SetAccountDebitedDrawdown(debitDD)

err := r.parseAccountDebitedDrawdown()

require.NotNil(t, err)
require.Contains(t, err.Error(), ErrNonAlphanumeric.Error())
expected := r.parseError(fieldError("Name", ErrNonAlphanumeric, "debitDD ®ame")).Error()
require.EqualError(t, err, expected)

_, err = r.Read()

require.NotNil(t, err)
require.Contains(t, err.Error(), ErrNonAlphanumeric.Error())
expected = r.parseError(fieldError("Name", ErrNonAlphanumeric, "debitDD ®ame")).Error()
require.EqualError(t, err, expected)
}

// TestAccountDebitedDrawdownTagError validates AccountDebitedDrawdown tag
Expand All @@ -181,6 +161,5 @@ func TestAccountDebitedDrawdownTagError(t *testing.T) {

err := debitDD.Validate()

require.NotNil(t, err)
require.Equal(t, fieldError("tag", ErrValidTagForType, debitDD.tag).Error(), err.Error())
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, debitDD.tag).Error())
}
33 changes: 10 additions & 23 deletions actualAmountPaid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ func TestActualAmountPaidAmountRequired(t *testing.T) {

err := aap.Validate()

require.NotNil(t, err)
require.Equal(t, fieldError("Amount", ErrFieldRequired).Error(), err.Error())
require.EqualError(t, err, fieldError("Amount", ErrFieldRequired).Error())
}

// TestActualAmountPaidCurrencyCodeRequired validates ActualAmountPaid CurrencyCode is required
Expand All @@ -40,8 +39,7 @@ func TestCurrencyCodeRequired(t *testing.T) {

err := aap.Validate()

require.NotNil(t, err)
require.Equal(t, fieldError("CurrencyCode", ErrFieldRequired).Error(), err.Error())
require.EqualError(t, err, fieldError("CurrencyCode", ErrFieldRequired).Error())
}

// TestActualAmountPaidAmountValid validates Amount
Expand All @@ -51,8 +49,7 @@ func TestActualAmountPaidAmountValid(t *testing.T) {

err := aap.Validate()

require.NotNil(t, err)
require.Equal(t, fieldError("Amount", ErrNonAmount, aap.RemittanceAmount.Amount).Error(), err.Error())
require.EqualError(t, err, fieldError("Amount", ErrNonAmount, aap.RemittanceAmount.Amount).Error())
}

// TestActualAmountPaidCurrencyCodeValid validates Amount
Expand All @@ -62,44 +59,35 @@ func TestActualAmountPaidCurrencyCodeValid(t *testing.T) {

err := aap.Validate()

require.NotNil(t, err)
require.Equal(t, fieldError("CurrencyCode", ErrNonCurrencyCode, aap.RemittanceAmount.CurrencyCode).Error(), err.Error())
require.EqualError(t, err, fieldError("CurrencyCode", ErrNonCurrencyCode, aap.RemittanceAmount.CurrencyCode).Error())
}

// TestParseActualAmountPaidWrongLength parses a wrong ActualAmountPaid record length
func TestParseActualAmountPaidWrongLength(t *testing.T) {
var line = "{8450}USD1234.56 "
r := NewReader(strings.NewReader(line))
r.line = line
fwm := new(FEDWireMessage)
aap := mockActualAmountPaid()
fwm.SetActualAmountPaid(aap)

err := r.parseActualAmountPaid()

require.NotNil(t, err)
expected := NewTagWrongLengthErr(28, len(r.line))
require.Contains(t, err.Error(), expected.Error())
require.EqualError(t, err, r.parseError(NewTagWrongLengthErr(28, len(r.line))).Error())
}

// TestParseActualAmountPaidReaderParseError parses a wrong ActualAmountPaid reader parse error
func TestParseActualAmountPaidReaderParseError(t *testing.T) {
var line = "{8450}USD1234.56Z "
r := NewReader(strings.NewReader(line))
r.line = line
fwm := new(FEDWireMessage)
aap := mockActualAmountPaid()
fwm.SetActualAmountPaid(aap)

err := r.parseActualAmountPaid()

require.NotNil(t, err)
require.Contains(t, err.Error(), ErrNonAmount.Error())
expected := r.parseError(fieldError("Amount", ErrNonAmount, "1234.56Z")).Error()
require.EqualError(t, err, expected)

_, err = r.Read()

require.NotNil(t, err)
require.Contains(t, err.Error(), ErrNonAmount.Error())
expected = r.parseError(fieldError("Amount", ErrNonAmount, "1234.56Z")).Error()
require.EqualError(t, err, expected)
}

// TestActualAmountPaidTagError validates ActualAmountPaid tag
Expand All @@ -109,6 +97,5 @@ func TestActualAmountPaidTagError(t *testing.T) {

err := aap.Validate()

require.NotNil(t, err)
require.Equal(t, fieldError("tag", ErrValidTagForType, aap.tag).Error(), err.Error())
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, aap.tag).Error())
}
Loading

0 comments on commit 5dd02e6

Please sign in to comment.