-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsiat_test.go
More file actions
58 lines (50 loc) · 1.25 KB
/
siat_test.go
File metadata and controls
58 lines (50 loc) · 1.25 KB
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
package siat_test
import (
"testing"
"github.com/ron86i/go-siat"
"github.com/ron86i/go-siat/pkg/models"
"github.com/stretchr/testify/assert"
)
func TestMap_ToJSON(t *testing.T) {
m := siat.Map{"key": "value", "num": 123}
jsonStr, err := m.ToJSON()
assert.NoError(t, err)
assert.Contains(t, jsonStr, `"key":"value"`)
assert.Contains(t, jsonStr, `"num":123`)
}
func TestMap_Sum(t *testing.T) {
m := siat.Map{
"a": float64(10.5),
"b": 20,
"c": int64(30),
"d": "not a number",
}
sum := m.Sum()
assert.Equal(t, 60.5, sum)
}
func TestMap_ToStruct(t *testing.T) {
m := siat.Map{"name": "Juan", "age": 30}
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
}
var p Person
err := m.ToStruct(&p)
assert.NoError(t, err)
assert.Equal(t, "Juan", p.Name)
assert.Equal(t, 30, p.Age)
}
func TestNew(t *testing.T) {
t.Run("Valid BaseUrl", func(t *testing.T) {
services, err := siat.New("https://pilotosiatservicios.impuestos.gob.bo/v2", nil)
assert.NoError(t, err)
assert.NotNil(t, services)
})
models.Codigos().NewCuisBuilder().Build()
t.Run("Empty BaseUrl", func(t *testing.T) {
services, err := siat.New("", nil)
assert.Error(t, err)
assert.Nil(t, services)
assert.Equal(t, "baseUrl is empty", err.Error())
})
}