Skip to content

Commit

Permalink
Merge pull request #193 from bloomcredit/8744
Browse files Browse the repository at this point in the history
fix: add validation for account status, account type, and special comment code
  • Loading branch information
adamdecaf committed May 15, 2024
2 parents 32f15e4 + 79f5a68 commit f38d0b2
Show file tree
Hide file tree
Showing 3 changed files with 390 additions and 0 deletions.
100 changes: 100 additions & 0 deletions pkg/lib/base_segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,56 @@ func (r *BaseSegment) ValidateDateBirth() error {
return nil
}

// validation of account status
func (r *BaseSegment) ValidateAccountStatus() error {
switch r.AccountStatus {
case AccountStatusDF, AccountStatusDA, AccountStatus11, AccountStatus61, AccountStatus62,
AccountStatus63, AccountStatus64, AccountStatus71, AccountStatus78, AccountStatus80,
AccountStatus82, AccountStatus83, AccountStatus84, AccountStatus93, AccountStatus96,
AccountStatus97, AccountStatus05, AccountStatus13, AccountStatus65, AccountStatus88,
AccountStatus89, AccountStatus94, AccountStatus95:
return nil
}
return utils.NewErrInvalidValueOfField("account status", "base segment")
}

// validation of account type
func (r *BaseSegment) ValidateAccountType() error {
switch r.AccountType {
case AccountType00, AccountType01, AccountType02, AccountType03, AccountType04, AccountType05, AccountType06,
AccountType07, AccountType08, AccountType0A, AccountType0C, AccountType0F, AccountType0G, AccountType10,
AccountType11, AccountType12, AccountType13, AccountType15, AccountType17, AccountType18, AccountType19,
AccountType20, AccountType25, AccountType26, AccountType29, AccountType2A, AccountType2C, AccountType37,
AccountType3A, AccountType43, AccountType47, AccountType48, AccountType4D, AccountType50, AccountType5A,
AccountType5B, AccountType65, AccountType66, AccountType67, AccountType68, AccountType69, AccountType6A,
AccountType6B, AccountType6D, AccountType70, AccountType71, AccountType72, AccountType73, AccountType74,
AccountType75, AccountType77, AccountType7A, AccountType7B, AccountType89, AccountType8A, AccountType8B,
AccountType90, AccountType91, AccountType92, AccountType93, AccountType95, AccountType9A, AccountType9B:
return nil
}
return utils.NewErrInvalidValueOfField("account type", "base segment")
}

// validation of special comment
func (r *BaseSegment) ValidateSpecialComment() error {
switch r.SpecialComment {
case SpecialCommentCodeBlank, SpecialCommentCodeB, SpecialCommentCodeC, SpecialCommentCodeH, SpecialCommentCodeI,
SpecialCommentCodeM, SpecialCommentCodeO, SpecialCommentCodeS, SpecialCommentCodeV, SpecialCommentCodeAB,
SpecialCommentCodeAC, SpecialCommentCodeAH, SpecialCommentCodeAI, SpecialCommentCodeAM, SpecialCommentCodeAN,
SpecialCommentCodeAO, SpecialCommentCodeAP, SpecialCommentCodeAS, SpecialCommentCodeAT, SpecialCommentCodeAU,
SpecialCommentCodeAV, SpecialCommentCodeAW, SpecialCommentCodeAX, SpecialCommentCodeAZ, SpecialCommentCodeBA,
SpecialCommentCodeBB, SpecialCommentCodeBC, SpecialCommentCodeBD, SpecialCommentCodeBE, SpecialCommentCodeBF,
SpecialCommentCodeBG, SpecialCommentCodeBH, SpecialCommentCodeBI, SpecialCommentCodeBJ, SpecialCommentCodeBK,
SpecialCommentCodeBL, SpecialCommentCodeBN, SpecialCommentCodeBO, SpecialCommentCodeBP, SpecialCommentCodeBS,
SpecialCommentCodeBT, SpecialCommentCodeCH, SpecialCommentCodeCI, SpecialCommentCodeCJ, SpecialCommentCodeCK,
SpecialCommentCodeCL, SpecialCommentCodeCM, SpecialCommentCodeCN, SpecialCommentCodeCO, SpecialCommentCodeCP,
SpecialCommentCodeCS, SpecialCommentCodeDE:

return nil
}
return utils.NewErrInvalidValueOfField("special comment", "base segment")
}

// Name returns name of packed base segment
func (r *PackedBaseSegment) Name() string {
return PackedBaseSegmentName
Expand Down Expand Up @@ -1378,6 +1428,56 @@ func (r *PackedBaseSegment) ValidateDateBirth() error {
return nil
}

// validation of account status
func (r *PackedBaseSegment) ValidateAccountStatus() error {
switch r.AccountStatus {
case AccountStatusDF, AccountStatusDA, AccountStatus11, AccountStatus61, AccountStatus62,
AccountStatus63, AccountStatus64, AccountStatus71, AccountStatus78, AccountStatus80,
AccountStatus82, AccountStatus83, AccountStatus84, AccountStatus93, AccountStatus96,
AccountStatus97, AccountStatus05, AccountStatus13, AccountStatus65, AccountStatus88,
AccountStatus89, AccountStatus94, AccountStatus95:
return nil
}
return utils.NewErrInvalidValueOfField("account status", "packed base segment")
}

// validation of account type
func (r *PackedBaseSegment) ValidateAccountType() error {
switch r.AccountType {
case AccountType00, AccountType01, AccountType02, AccountType03, AccountType04, AccountType05, AccountType06,
AccountType07, AccountType08, AccountType0A, AccountType0C, AccountType0F, AccountType0G, AccountType10,
AccountType11, AccountType12, AccountType13, AccountType15, AccountType17, AccountType18, AccountType19,
AccountType20, AccountType25, AccountType26, AccountType29, AccountType2A, AccountType2C, AccountType37,
AccountType3A, AccountType43, AccountType47, AccountType48, AccountType4D, AccountType50, AccountType5A,
AccountType5B, AccountType65, AccountType66, AccountType67, AccountType68, AccountType69, AccountType6A,
AccountType6B, AccountType6D, AccountType70, AccountType71, AccountType72, AccountType73, AccountType74,
AccountType75, AccountType77, AccountType7A, AccountType7B, AccountType89, AccountType8A, AccountType8B,
AccountType90, AccountType91, AccountType92, AccountType93, AccountType95, AccountType9A, AccountType9B:
return nil
}
return utils.NewErrInvalidValueOfField("account type", "packed base segment")
}

// validation of special comment
func (r *PackedBaseSegment) ValidateSpecialComment() error {
switch r.SpecialComment {
case SpecialCommentCodeBlank, SpecialCommentCodeB, SpecialCommentCodeC, SpecialCommentCodeH, SpecialCommentCodeI,
SpecialCommentCodeM, SpecialCommentCodeO, SpecialCommentCodeS, SpecialCommentCodeV, SpecialCommentCodeAB,
SpecialCommentCodeAC, SpecialCommentCodeAH, SpecialCommentCodeAI, SpecialCommentCodeAM, SpecialCommentCodeAN,
SpecialCommentCodeAO, SpecialCommentCodeAP, SpecialCommentCodeAS, SpecialCommentCodeAT, SpecialCommentCodeAU,
SpecialCommentCodeAV, SpecialCommentCodeAW, SpecialCommentCodeAX, SpecialCommentCodeAZ, SpecialCommentCodeBA,
SpecialCommentCodeBB, SpecialCommentCodeBC, SpecialCommentCodeBD, SpecialCommentCodeBE, SpecialCommentCodeBF,
SpecialCommentCodeBG, SpecialCommentCodeBH, SpecialCommentCodeBI, SpecialCommentCodeBJ, SpecialCommentCodeBK,
SpecialCommentCodeBL, SpecialCommentCodeBN, SpecialCommentCodeBO, SpecialCommentCodeBP, SpecialCommentCodeBS,
SpecialCommentCodeBT, SpecialCommentCodeCH, SpecialCommentCodeCI, SpecialCommentCodeCJ, SpecialCommentCodeCK,
SpecialCommentCodeCL, SpecialCommentCodeCM, SpecialCommentCodeCN, SpecialCommentCodeCO, SpecialCommentCodeCP,
SpecialCommentCodeCS, SpecialCommentCodeDE:

return nil
}
return utils.NewErrInvalidValueOfField("special comment", "packed base segment")
}

func readApplicableSegments(record []byte, f Record) (int, error) {
var segment Segment
offset := 0
Expand Down
60 changes: 60 additions & 0 deletions pkg/lib/base_segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,46 @@ func (t *SegmentTest) TestBaseSegmentWithDateBirth(c *check.C) {
c.Assert(err, check.Not(check.IsNil))
}

func (t *SegmentTest) TestBaseSegmentWithInvalidAccountStatus(c *check.C) {
segment := &BaseSegment{}
_, err := segment.Parse(t.sampleBaseSegment)
c.Assert(err, check.IsNil)
segment.AccountStatus = "FF"
err = segment.Validate()
c.Assert(err, check.Not(check.IsNil))
c.Assert(err.Error(), check.DeepEquals, "account status in base segment has an invalid value")
}

func (t *SegmentTest) TestPackedBaseSegmentWithInvalidAccountStatus(c *check.C) {
segment := &PackedBaseSegment{}
_, err := segment.Parse(t.samplePackedBaseSegment)
c.Assert(err, check.IsNil)
segment.AccountStatus = "FF"
err = segment.Validate()
c.Assert(err, check.Not(check.IsNil))
c.Assert(err.Error(), check.DeepEquals, "account status in packed base segment has an invalid value")
}

func (t *SegmentTest) TestBaseSegmentWithInvalidAccountType(c *check.C) {
segment := &BaseSegment{}
_, err := segment.Parse(t.sampleBaseSegment)
c.Assert(err, check.IsNil)
segment.AccountType = "FF"
err = segment.Validate()
c.Assert(err, check.Not(check.IsNil))
c.Assert(err.Error(), check.DeepEquals, "account type in base segment has an invalid value")
}

func (t *SegmentTest) TestPackedBaseSegmentWithInvalidAccountType(c *check.C) {
segment := &PackedBaseSegment{}
_, err := segment.Parse(t.samplePackedBaseSegment)
c.Assert(err, check.IsNil)
segment.AccountType = "FF"
err = segment.Validate()
c.Assert(err, check.Not(check.IsNil))
c.Assert(err.Error(), check.DeepEquals, "account type in packed base segment has an invalid value")
}

func (t *SegmentTest) TestPackedBaseSegmentWithSocialSecurityNumber(c *check.C) {
segment := &PackedBaseSegment{}
_, err := segment.Parse(t.samplePackedBaseSegment)
Expand Down Expand Up @@ -426,3 +466,23 @@ func (t *SegmentTest) TestPackedBaseSegmentWithDateBirth(c *check.C) {
err = segment.Validate()
c.Assert(err, check.Not(check.IsNil))
}

func (t *SegmentTest) TestBaseSegmentWithInvalidSpecialComment(c *check.C) {
segment := &BaseSegment{}
_, err := segment.Parse(t.sampleBaseSegment)
c.Assert(err, check.IsNil)
segment.SpecialComment = "FF"
err = segment.Validate()
c.Assert(err, check.Not(check.IsNil))
c.Assert(err.Error(), check.DeepEquals, "special comment in base segment has an invalid value")
}

func (t *SegmentTest) TestPackedBaseSegmentWithInvalidSpecialComment(c *check.C) {
segment := &PackedBaseSegment{}
_, err := segment.Parse(t.samplePackedBaseSegment)
c.Assert(err, check.IsNil)
segment.SpecialComment = "FF"
err = segment.Validate()
c.Assert(err, check.Not(check.IsNil))
c.Assert(err.Error(), check.DeepEquals, "special comment in packed base segment has an invalid value")
}
Loading

0 comments on commit f38d0b2

Please sign in to comment.