Skip to content

Commit

Permalink
Added Invoice Tests and Updated Validation
Browse files Browse the repository at this point in the history
  • Loading branch information
apardods committed Nov 26, 2024
1 parent b47d4f6 commit 496b504
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
7 changes: 2 additions & 5 deletions addons/es/verifactu/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ func validateInvoicePreceding(val any) error {
return nil
}
return validation.ValidateStruct(p,
validation.Field(&p.IssueDate, validation.Required),
validation.Field(&p.Series, validation.Required),
validation.Field(&p.Ext,
tax.ExtensionsRequires(ExtKeyDocType),
validation.Skip,
validation.Field(&p.IssueDate,
validation.Required,
),
)

Check warning on line 96 in addons/es/verifactu/invoice.go

View check run for this annotation

Codecov / codecov/patch

addons/es/verifactu/invoice.go#L92-L96

Added lines #L92 - L96 were not covered by tests
}
Expand Down
28 changes: 16 additions & 12 deletions addons/es/verifactu/invoice_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package verifactu

import (
"fmt"
"testing"

"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/cal"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/num"
"github.com/invopop/gobl/org"
"github.com/invopop/gobl/tax"

"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -44,6 +45,13 @@ func TestInvoiceValidation(t *testing.T) {
require.ErrorContains(t, err, "es-verifactu-doc-type: required")
})

t.Run("no customer", func(t *testing.T) {
inv := testInvoiceStandard(t)
inv.Customer = nil
require.NoError(t, inv.Calculate())
require.NoError(t, inv.Validate())
})

t.Run("correction invoice requires preceding", func(t *testing.T) {
inv := testInvoiceStandard(t)
inv.Type = bill.InvoiceTypeCreditNote
Expand All @@ -53,14 +61,12 @@ func TestInvoiceValidation(t *testing.T) {
t.Run("correction invoice with preceding", func(t *testing.T) {
inv := testInvoiceStandard(t)
inv.Type = bill.InvoiceTypeCreditNote
inv.Tax.Ext[ExtKeyDocType] = "R1"
d := cal.MakeDate(2024, 1, 1)
inv.Preceding = []*org.DocumentRef{
{
Series: "ABC",
Code: "122",
Ext: tax.Extensions{
ExtKeyDocType: "F1",
},
Series: "ABC",
Code: "122",
IssueDate: &d,
},
}
require.NoError(t, inv.Calculate())
Expand All @@ -71,6 +77,9 @@ func TestInvoiceValidation(t *testing.T) {
func assertValidationError(t *testing.T, inv *bill.Invoice, expected string) {
require.NoError(t, inv.Calculate())
err := inv.Validate()
if inv.Preceding != nil {
fmt.Println(inv.Preceding[0].IssueDate)
}
require.ErrorContains(t, err, expected)
}

Expand Down Expand Up @@ -118,10 +127,5 @@ func testInvoiceStandard(t *testing.T) *bill.Invoice {
Text: "This is a test invoice",
},
},
Tax: &bill.Tax{
Ext: tax.Extensions{
ExtKeyDocType: "F1",
},
},
}
}

0 comments on commit 496b504

Please sign in to comment.