File size: 2,804 Bytes
1f10f31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package config

import (
	"testing"

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

func TestTaxCodeConfigurationValidate(t *testing.T) {
	validBase := func() TaxCodeConfiguration {
		return TaxCodeConfiguration{
			Seeds: []TaxCodeSeed{
				{Key: "default", Name: "Provider default", DefaultInvoicing: true},
				{Key: "nontaxable", Name: "Nontaxable", DefaultCreditGrant: true, AppMappings: []TaxCodeAppMapping{
					{AppType: "stripe", TaxCode: "txcd_00000000"},
				}},
			},
		}
	}

	t.Run("Valid", func(t *testing.T) {
		require.NoError(t, validBase().Validate())
	})

	t.Run("EmptySeeds", func(t *testing.T) {
		err := TaxCodeConfiguration{}.Validate()
		assert.ErrorContains(t, err, "seeds must not be empty")
	})

	t.Run("EmptyKey", func(t *testing.T) {
		cfg := validBase()
		cfg.Seeds[0].Key = ""
		err := cfg.Validate()
		assert.ErrorContains(t, err, "key must not be empty")
	})

	t.Run("EmptyName", func(t *testing.T) {
		cfg := validBase()
		cfg.Seeds[0].Name = ""
		err := cfg.Validate()
		assert.ErrorContains(t, err, "name must not be empty")
	})

	t.Run("DuplicateKeys", func(t *testing.T) {
		cfg := validBase()
		cfg.Seeds[1].Key = cfg.Seeds[0].Key
		err := cfg.Validate()
		assert.ErrorContains(t, err, "duplicate key")
	})

	t.Run("NoDefaultInvoicing", func(t *testing.T) {
		cfg := validBase()
		cfg.Seeds[0].DefaultInvoicing = false
		err := cfg.Validate()
		assert.ErrorContains(t, err, "defaultInvoicing=true")
	})

	t.Run("MultipleDefaultInvoicing", func(t *testing.T) {
		cfg := validBase()
		cfg.Seeds[1].DefaultInvoicing = true
		err := cfg.Validate()
		assert.ErrorContains(t, err, "defaultInvoicing=true")
	})

	t.Run("NoDefaultCreditGrant", func(t *testing.T) {
		cfg := validBase()
		cfg.Seeds[1].DefaultCreditGrant = false
		err := cfg.Validate()
		assert.ErrorContains(t, err, "defaultCreditGrant=true")
	})

	t.Run("MultipleDefaultCreditGrant", func(t *testing.T) {
		cfg := validBase()
		cfg.Seeds[0].DefaultCreditGrant = true
		err := cfg.Validate()
		assert.ErrorContains(t, err, "defaultCreditGrant=true")
	})

	t.Run("SingleSeedCarriesBothFlags", func(t *testing.T) {
		// A single seed may carry both flags; this is legal.
		cfg := TaxCodeConfiguration{
			Seeds: []TaxCodeSeed{
				{Key: "all", Name: "All", DefaultInvoicing: true, DefaultCreditGrant: true},
			},
		}
		require.NoError(t, cfg.Validate())
	})

	t.Run("AppMappingEmptyAppType", func(t *testing.T) {
		cfg := validBase()
		cfg.Seeds[1].AppMappings[0].AppType = ""
		err := cfg.Validate()
		assert.ErrorContains(t, err, "appType must not be empty")
	})

	t.Run("AppMappingEmptyTaxCode", func(t *testing.T) {
		cfg := validBase()
		cfg.Seeds[1].AppMappings[0].TaxCode = ""
		err := cfg.Validate()
		assert.ErrorContains(t, err, "taxCode must not be empty")
	})
}