Skip to content

Commit

Permalink
tag validation
Browse files Browse the repository at this point in the history
tag validation
  • Loading branch information
bkmoovio committed May 14, 2019
1 parent 0f2014c commit 452f63e
Show file tree
Hide file tree
Showing 119 changed files with 848 additions and 28 deletions.
5 changes: 4 additions & 1 deletion accountCreditedDrawdown.go
Expand Up @@ -58,7 +58,10 @@ func (creditDD *AccountCreditedDrawdown) Validate() error {
if err := creditDD.fieldInclusion(); err != nil {
return err
}
if err := creditDD.isNumeric(creditDD.DrawdownCreditAccountNumber); err != nil {
if creditDD.tag != TagAccountCreditedDrawdown {
return fieldError("tag", ErrValidTagForType, creditDD.tag)
}
if err := creditDD.isAlphanumeric(creditDD.DrawdownCreditAccountNumber); err != nil {
return fieldError("DrawdownCreditAccountNumber", err, creditDD.DrawdownCreditAccountNumber)
}
return nil
Expand Down
15 changes: 13 additions & 2 deletions accountCreditedDrawdown_test.go
Expand Up @@ -24,9 +24,9 @@ func TestMockAccountCreditedDrawdown(t *testing.T) {
// TestAccountCreditedDrawDownNumberAlphaNumeric validates AccountCreditedDrawdown is alphanumeric
func TestDrawdownCreditAccountNumberAlphaNumeric(t *testing.T) {
creditDD := mockAccountCreditedDrawdown()
creditDD.DrawdownCreditAccountNumber = "Z"
creditDD.DrawdownCreditAccountNumber = "®"
if err := creditDD.Validate(); err != nil {
if !base.Match(err, ErrNonNumeric) {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
Expand Down Expand Up @@ -80,3 +80,14 @@ func TestParseAccountCreditedDrawdownReaderParseError(t *testing.T) {
}
}
}

// TestAccountCreditedDrawdownTagError validates AccountCreditedDrawdown tag
func TestAccountCreditedDrawdownTagError(t *testing.T) {
creditDD := mockAccountCreditedDrawdown()
creditDD.tag = "{9999}"
if err := creditDD.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
3 changes: 3 additions & 0 deletions accountDebitedDrawdown.go
Expand Up @@ -73,6 +73,9 @@ func (debitDD *AccountDebitedDrawdown) Validate() error {
if err := debitDD.fieldInclusion(); err != nil {
return err
}
if debitDD.tag != TagAccountDebitedDrawdown {
return fieldError("tag", ErrValidTagForType, debitDD.tag)
}
if err := debitDD.isIdentificationCode(debitDD.IdentificationCode); err != nil {
return fieldError("IdentificationCode", err, debitDD.IdentificationCode)
}
Expand Down
11 changes: 11 additions & 0 deletions accountDebitedDrawdown_test.go
Expand Up @@ -173,3 +173,14 @@ func TestParseAccountDebitedDrawdownReaderParseError(t *testing.T) {
}
}
}

// TestAccountDebitedDrawdownTagError validates AccountDebitedDrawdown tag
func TestAccountDebitedDrawdownTagError(t *testing.T) {
debitDD := mockAccountDebitedDrawdown()
debitDD.tag = "{9999}"
if err := debitDD.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
3 changes: 3 additions & 0 deletions actualAmountPaid.go
Expand Up @@ -60,6 +60,9 @@ func (aap *ActualAmountPaid) Validate() error {
if err := aap.fieldInclusion(); err != nil {
return err
}
if aap.tag != TagActualAmountPaid {
return fieldError("tag", ErrValidTagForType, aap.tag)
}
if err := aap.isCurrencyCode(aap.RemittanceAmount.CurrencyCode); err != nil {
return fieldError("CurrencyCode", err, aap.RemittanceAmount.CurrencyCode)
}
Expand Down
11 changes: 11 additions & 0 deletions actualAmountPaid_test.go
Expand Up @@ -103,3 +103,14 @@ func TestParseActualAmountPaidReaderParseError(t *testing.T) {
}
}
}

// TestActualAmountPaidTagError validates ActualAmountPaid tag
func TestActualAmountPaidTagError(t *testing.T) {
aap := mockActualAmountPaid()
aap.tag = "{9999}"
if err := aap.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
3 changes: 3 additions & 0 deletions adjustment.go
Expand Up @@ -72,6 +72,9 @@ func (adj *Adjustment) Validate() error {
if err := adj.fieldInclusion(); err != nil {
return err
}
if adj.tag != TagAdjustment {
return fieldError("tag", ErrValidTagForType, adj.tag)
}
if err := adj.isAdjustmentReasonCode(adj.AdjustmentReasonCode); err != nil {
return fieldError("AdjustmentReasonCode", err, adj.AdjustmentReasonCode)
}
Expand Down
11 changes: 11 additions & 0 deletions adjustment_test.go
Expand Up @@ -150,3 +150,14 @@ func TestParseAdjustmentReaderParseError(t *testing.T) {
}
}
}

// TestAdjustmentTagError validates Adjustment tag
func TestAdjustmentTagError(t *testing.T) {
adj := mockAdjustment()
adj.tag = "{9999}"
if err := adj.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
4 changes: 3 additions & 1 deletion amount.go
Expand Up @@ -58,7 +58,9 @@ func (a *Amount) Validate() error {
if err := a.fieldInclusion(); err != nil {
return err
}
// ToDo: Amount cannot be all zero's except if SubType = 90
if a.tag != TagAmount {
return fieldError("tag", ErrValidTagForType, a.tag)
}
if err := a.isAmountImplied(a.Amount); err != nil {
return fieldError("Amount", err, a.Amount)
}
Expand Down
3 changes: 3 additions & 0 deletions amountNegotiatedDiscount.go
Expand Up @@ -60,6 +60,9 @@ func (nd *AmountNegotiatedDiscount) Validate() error {
if err := nd.fieldInclusion(); err != nil {
return err
}
if nd.tag != TagAmountNegotiatedDiscount {
return fieldError("tag", ErrValidTagForType, nd.tag)
}
if err := nd.isCurrencyCode(nd.RemittanceAmount.CurrencyCode); err != nil {
return fieldError("CurrencyCode", err, nd.RemittanceAmount.CurrencyCode)
}
Expand Down
11 changes: 11 additions & 0 deletions amountNegotiatedDiscount_test.go
Expand Up @@ -102,3 +102,14 @@ func TestParseAmountNegotiatedDiscountReaderParseError(t *testing.T) {
}
}
}

// TestAmountNegotiatedDiscountTagError validates AmountNegotiatedDiscount tag
func TestAmountNegotiatedDiscountTagError(t *testing.T) {
nd := mockAmountNegotiatedDiscount()
nd.tag = "{9999}"
if err := nd.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
11 changes: 11 additions & 0 deletions amount_test.go
Expand Up @@ -80,3 +80,14 @@ func TestParseAmountReaderParseError(t *testing.T) {
}
}
}

// TestAmountTagError validates Amount tag
func TestAmountTagError(t *testing.T) {
a := mockAmount()
a.tag = "{9999}"
if err := a.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
3 changes: 3 additions & 0 deletions beneficiary.go
Expand Up @@ -68,6 +68,9 @@ func (ben *Beneficiary) Validate() error {
if err := ben.fieldInclusion(); err != nil {
return err
}
if ben.tag != TagBeneficiary {
return fieldError("tag", ErrValidTagForType, ben.tag)
}
// Can be any Identification Code
if err := ben.isIdentificationCode(ben.Personal.IdentificationCode); err != nil {
return fieldError("IdentificationCode", err, ben.Personal.IdentificationCode)
Expand Down
3 changes: 3 additions & 0 deletions beneficiaryCustomer.go
Expand Up @@ -68,6 +68,9 @@ func (bc *BeneficiaryCustomer) Validate() error {
if err := bc.fieldInclusion(); err != nil {
return err
}
if bc.tag != TagBeneficiaryCustomer {
return fieldError("tag", ErrValidTagForType, bc.tag)
}
if err := bc.isAlphanumeric(bc.CoverPayment.SwiftFieldTag); err != nil {
return fieldError("SwiftFieldTag", err, bc.CoverPayment.SwiftFieldTag)
}
Expand Down
11 changes: 11 additions & 0 deletions beneficiaryCustomer_test.go
Expand Up @@ -140,3 +140,14 @@ func TestParseBeneficiaryCustomerReaderParseError(t *testing.T) {
}
}
}

// TestBeneficiaryCustomerTagError validates a BeneficiaryCustomer tag
func TestBeneficiaryCustomerTagError(t *testing.T) {
bc := mockBeneficiaryCustomer()
bc.tag = "{9999}"
if err := bc.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
3 changes: 3 additions & 0 deletions beneficiaryFI.go
Expand Up @@ -68,6 +68,9 @@ func (bfi *BeneficiaryFI) Validate() error {
if err := bfi.fieldInclusion(); err != nil {
return err
}
if bfi.tag != TagBeneficiaryFI {
return fieldError("tag", ErrValidTagForType, bfi.tag)
}
if err := bfi.isIdentificationCode(bfi.FinancialInstitution.IdentificationCode); err != nil {
return fieldError("IdentificationCode", err, bfi.FinancialInstitution.IdentificationCode)
}
Expand Down
11 changes: 11 additions & 0 deletions beneficiaryFI_test.go
Expand Up @@ -162,3 +162,14 @@ func TestParseBeneficiaryFIReaderParseError(t *testing.T) {
}
}
}

// TestBeneficiaryFITagError validates a BeneficiaryFI tag
func TestBeneficiaryFITagError(t *testing.T) {
bfi := mockBeneficiaryFI()
bfi.tag = "{9999}"
if err := bfi.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
3 changes: 3 additions & 0 deletions beneficiaryIntermediaryFI.go
Expand Up @@ -68,6 +68,9 @@ func (bifi *BeneficiaryIntermediaryFI) Validate() error {
if err := bifi.fieldInclusion(); err != nil {
return err
}
if bifi.tag != TagBeneficiaryIntermediaryFI {
return fieldError("tag", ErrValidTagForType, bifi.tag)
}
if err := bifi.isIdentificationCode(bifi.FinancialInstitution.IdentificationCode); err != nil {
return fieldError("IdentificationCode", err, bifi.FinancialInstitution.IdentificationCode)
}
Expand Down
11 changes: 11 additions & 0 deletions beneficiaryIntermediaryFI_test.go
Expand Up @@ -162,3 +162,14 @@ func TestParseBeneficiaryIntermediaryFIReaderParseError(t *testing.T) {
}
}
}

// TestBeneficiaryIntermediaryFITagError validates a BeneficiaryFI tag
func TestBeneficiaryIntermediaryFITagError(t *testing.T) {
bifi := mockBeneficiaryIntermediaryFI()
bifi.tag = "{9999}"
if err := bifi.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
12 changes: 3 additions & 9 deletions beneficiaryReference.go
Expand Up @@ -55,21 +55,15 @@ func (br *BeneficiaryReference) String() string {
// Validate performs WIRE format rule checks on BeneficiaryReference and returns an error if not Validated
// The first error encountered is returned and stops that parsing.
func (br *BeneficiaryReference) Validate() error {
/* if err := br.fieldInclusion(); err != nil {
return err
}*/
if br.tag != TagBeneficiaryReference {
return fieldError("tag", ErrValidTagForType, br.tag)
}
if err := br.isAlphanumeric(br.BeneficiaryReference); err != nil {
return fieldError("BeneficiaryReference", err, br.BeneficiaryReference)
}
return nil
}

// fieldInclusion validate mandatory fields. If fields are
// invalid the WIRE will return an error.
/*func (br *BeneficiaryReference) fieldInclusion() error {
return nil
}*/

// BeneficiaryReferenceField gets a string of the BeneficiaryReference field
func (br *BeneficiaryReference) BeneficiaryReferenceField() string {
return br.alphaField(br.BeneficiaryReference, 16)
Expand Down
11 changes: 11 additions & 0 deletions beneficiaryReference_test.go
Expand Up @@ -69,3 +69,14 @@ func TestParseBeneficiaryReferenceReaderParseError(t *testing.T) {
}
}
}

// TestBeneficiaryReferenceTagError validates a BeneficiaryReference tag
func TestBeneficiaryReferenceTagError(t *testing.T) {
br := mockBeneficiaryReference()
br.tag = "{9999}"
if err := br.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
11 changes: 11 additions & 0 deletions beneficiary_test.go
Expand Up @@ -151,3 +151,14 @@ func TestParseBeneficiaryReaderParseError(t *testing.T) {
}
}
}

// TestBeneficiaryTagError validates Beneficiary tag
func TestBeneficiaryTagError(t *testing.T) {
ben := mockBeneficiary()
ben.tag = "{9999}"
if err := ben.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
3 changes: 3 additions & 0 deletions businessFunctionCode.go
Expand Up @@ -64,6 +64,9 @@ func (bfc *BusinessFunctionCode) Validate() error {
if err := bfc.fieldInclusion(); err != nil {
return err
}
if bfc.tag != TagBusinessFunctionCode {
return fieldError("tag", ErrValidTagForType, bfc.tag)
}
if err := bfc.isBusinessFunctionCode(bfc.BusinessFunctionCode); err != nil {
return fieldError("BusinessFunctionCode", err, bfc.BusinessFunctionCode)
}
Expand Down
11 changes: 11 additions & 0 deletions businessFunctionCode_test.go
Expand Up @@ -79,3 +79,14 @@ func TestParseBusinessFunctionCodeReaderParseError(t *testing.T) {
}
}
}

// TestBusinessFunctionCodeTagError validates a BusinessFunctionCode tag
func TestBusinessFunctionCodeTagError(t *testing.T) {
bfc := mockBusinessFunctionCode()
bfc.tag = "{9999}"
if err := bfc.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
3 changes: 3 additions & 0 deletions charges.go
Expand Up @@ -79,6 +79,9 @@ func (c *Charges) String() string {
// Validate performs WIRE format rule checks on Charges and returns an error if not Validated
// The first error encountered is returned and stops that parsing.
func (c *Charges) Validate() error {
if c.tag != TagCharges {
return fieldError("tag", ErrValidTagForType, c.tag)
}
if err := c.isChargeDetails(c.ChargeDetails); err != nil {
return fieldError("ChargeDetails", ErrChargeDetails, c.ChargeDetails)
}
Expand Down
11 changes: 11 additions & 0 deletions charges_test.go
Expand Up @@ -192,3 +192,14 @@ func TestChargesAmountFour(t *testing.T) {
}
}
}

// TestChargesTagError validates a Charges tag
func TestChargesTagError(t *testing.T) {
c := mockCharges()
c.tag = "{9999}"
if err := c.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
3 changes: 3 additions & 0 deletions currencyInstructedAmount.go
Expand Up @@ -60,6 +60,9 @@ func (cia *CurrencyInstructedAmount) String() string {
// Validate performs WIRE format rule checks on CurrencyInstructedAmount and returns an error if not Validated
// The first error encountered is returned and stops that parsing.
func (cia *CurrencyInstructedAmount) Validate() error {
if cia.tag != TagCurrencyInstructedAmount {
return fieldError("tag", ErrValidTagForType, cia.tag)
}
if err := cia.isAlphanumeric(cia.SwiftFieldTag); err != nil {
return fieldError("SwiftFieldTag", err, cia.SwiftFieldTag)
}
Expand Down
11 changes: 11 additions & 0 deletions currencyInstructedAmount_test.go
Expand Up @@ -81,3 +81,14 @@ func TestParseCurrencyInstructedAmountReaderParseError(t *testing.T) {
}
}
}

// TestCurrencyInstructedAmountTagError validates a CurrencyInstructedAmount tag
func TestCurrencyInstructedAmountTagError(t *testing.T) {
cia := mockCurrencyInstructedAmount()
cia.tag = "{9999}"
if err := cia.Validate(); err != nil {
if !base.Match(err, ErrValidTagForType) {
t.Errorf("%T: %s", err, err)
}
}
}
3 changes: 3 additions & 0 deletions dateRemittanceDocument.go
Expand Up @@ -58,6 +58,9 @@ func (drd *DateRemittanceDocument) Validate() error {
if err := drd.fieldInclusion(); err != nil {
return err
}
if drd.tag != TagDateRemittanceDocument {
return fieldError("tag", ErrValidTagForType, drd.tag)
}
if err := drd.validateDate(drd.DateRemittanceDocument); err != nil {
return err
}
Expand Down

0 comments on commit 452f63e

Please sign in to comment.