Skip to content

Commit

Permalink
Simplfy addon validations and improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cavalle committed Oct 25, 2024
1 parent 745a7b8 commit e3f6a2a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
4 changes: 4 additions & 0 deletions addons/br/nfse/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
)

func validateInvoice(inv *bill.Invoice) error {
if inv == nil {
return nil
}

return validation.ValidateStruct(inv,
validation.Field(&inv.Charges,
validation.Empty.Error("not supported by nfse"),
Expand Down
4 changes: 4 additions & 0 deletions addons/br/nfse/invoices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func TestInvoicesValidation(t *testing.T) {
name: "valid invoice",
inv: &bill.Invoice{},
},
{
name: "nil invoice",
inv: nil,
},
{
name: "charges present",
inv: &bill.Invoice{
Expand Down
3 changes: 1 addition & 2 deletions addons/br/nfse/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"github.com/invopop/validation"
)

func validateItem(value any) error {
item, _ := value.(*org.Item)
func validateItem(item *org.Item) error {
if item == nil {
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions addons/br/nfse/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func TestItemValidation(t *testing.T) {
},
},
},
{
name: "nil item",
item: nil,
},
{
name: "missing extensions",
item: &org.Item{},
Expand All @@ -44,10 +48,6 @@ func TestItemValidation(t *testing.T) {
},
err: "ext: (br-nfse-service: required.).",
},
{
name: "nil",
item: nil,
},
}

addon := tax.AddonForKey(nfse.V1)
Expand Down
3 changes: 1 addition & 2 deletions addons/br/nfse/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"github.com/invopop/validation"
)

func validateLine(value any) error {
line, _ := value.(*bill.Line)
func validateLine(line *bill.Line) error {
if line == nil {
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions addons/br/nfse/line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func TestLineValidation(t *testing.T) {
},
},
},
{
name: "nil line",
line: nil,
},
{
name: "missing taxes",
line: &bill.Line{},
Expand Down

0 comments on commit e3f6a2a

Please sign in to comment.