Skip to content

Commit

Permalink
Fix Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
apardods committed Nov 22, 2024
1 parent 52b07e5 commit b47d4f6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 55 deletions.
13 changes: 6 additions & 7 deletions addons/es/verifactu/invoice_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package verifactu_test
package verifactu

import (
"testing"

"github.com/invopop/gobl/addons/es/verifactu"
"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/cbc"
"github.com/invopop/gobl/num"
Expand Down Expand Up @@ -54,13 +53,13 @@ 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[verifactu.ExtKeyDocType] = "R1"
inv.Tax.Ext[ExtKeyDocType] = "R1"
inv.Preceding = []*org.DocumentRef{
{
Series: "ABC",
Code: "122",
Ext: tax.Extensions{
verifactu.ExtKeyDocType: "F1",
ExtKeyDocType: "F1",
},
},
}
Expand All @@ -78,7 +77,7 @@ func assertValidationError(t *testing.T, inv *bill.Invoice, expected string) {
func testInvoiceStandard(t *testing.T) *bill.Invoice {
t.Helper()
return &bill.Invoice{
Addons: tax.WithAddons(verifactu.V1),
Addons: tax.WithAddons(V1),
Code: "123",
Supplier: &org.Party{
Name: "Test Supplier",
Expand Down Expand Up @@ -107,7 +106,7 @@ func testInvoiceStandard(t *testing.T) *bill.Invoice {
Category: "VAT",
Rate: "exempt",
Ext: tax.Extensions{
verifactu.ExtKeyTaxClassification: "E1",
ExtKeyTaxClassification: "E1",
},
},
},
Expand All @@ -121,7 +120,7 @@ func testInvoiceStandard(t *testing.T) *bill.Invoice {
},
Tax: &bill.Tax{
Ext: tax.Extensions{
verifactu.ExtKeyDocType: "F1",
ExtKeyDocType: "F1",
},
},
}
Expand Down
101 changes: 53 additions & 48 deletions addons/es/verifactu/scenarios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,59 @@ package verifactu

import (
"testing"

"github.com/invopop/gobl/bill"
"github.com/invopop/gobl/tax"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestScenarios(t *testing.T) {
tests := []struct {
name string
scenario string
tags []string
want bool
}{
{
name: "standard invoice",
scenario: "standard",
tags: []string{},
want: true,
},
{
name: "simplified invoice",
scenario: "simplified",
tags: []string{"simplified"},
want: true,
},
{
name: "corrective invoice",
scenario: "corrective",
tags: []string{"corrective"},
want: true,
},
{
name: "invalid scenario",
scenario: "invalid",
tags: []string{},
want: false,
},
{
name: "simplified with wrong tags",
scenario: "simplified",
tags: []string{"corrective"},
want: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ValidateScenario(tt.scenario, tt.tags)
if got != tt.want {
t.Errorf("ValidateScenario(%v, %v) = %v, want %v",
tt.scenario, tt.tags, got, tt.want)
}
})
}
func TestInvoiceDocumentScenarios(t *testing.T) {

t.Run("with addon", func(t *testing.T) {
i := testInvoiceStandard(t)
require.NoError(t, i.Calculate())
assert.Equal(t, i.Tax.Ext[ExtKeyDocType].String(), "F1")
})

t.Run("simplified invoice", func(t *testing.T) {
i := testInvoiceStandard(t)
i.SetTags(tax.TagSimplified)
require.NoError(t, i.Calculate())
assert.Len(t, i.Notes, 1)
assert.Equal(t, i.Tax.Ext[ExtKeyDocType].String(), "F2")
})

t.Run("substitution invoice", func(t *testing.T) {
i := testInvoiceStandard(t)
i.SetTags(TagSubstitution)
require.NoError(t, i.Calculate())
assert.Len(t, i.Notes, 1)
assert.Equal(t, i.Tax.Ext[ExtKeyDocType].String(), "F3")
})

t.Run("credit note", func(t *testing.T) {
i := testInvoiceStandard(t)
i.Type = bill.InvoiceTypeCreditNote
require.NoError(t, i.Calculate())
assert.Len(t, i.Notes, 1)
assert.Equal(t, i.Tax.Ext[ExtKeyDocType].String(), "R1")
})

t.Run("corrective", func(t *testing.T) {
i := testInvoiceStandard(t)
i.Type = bill.InvoiceTypeCorrective
require.NoError(t, i.Calculate())
assert.Len(t, i.Notes, 1)
assert.Equal(t, i.Tax.Ext[ExtKeyDocType].String(), "R1")
})

t.Run("simplified credit note", func(t *testing.T) {
i := testInvoiceStandard(t)
i.Type = bill.InvoiceTypeCreditNote
i.SetTags(tax.TagSimplified)
require.NoError(t, i.Calculate())
assert.Len(t, i.Notes, 1)
assert.Equal(t, i.Tax.Ext[ExtKeyDocType].String(), "R5")
})
}

0 comments on commit b47d4f6

Please sign in to comment.