-
Notifications
You must be signed in to change notification settings - Fork 1
/
common_test.go
107 lines (85 loc) · 2 KB
/
common_test.go
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
105
106
107
package toshl_test
import (
"encoding/json"
"testing"
toshl "github.com/andreagrandi/toshl-go"
"github.com/stretchr/testify/assert"
)
func TestCommonCurrencyDecode(t *testing.T) {
var currency toshl.Currency
currencyJSON := []byte(`{
"code": "USD",
"rate": 1,
"fixed": false
}`)
err := json.Unmarshal(currencyJSON, ¤cy)
if err != nil {
t.Errorf("Cannot decode Currency JSON")
}
assert.Nil(t, err)
}
func TestCommonCurrencyDecodeError(t *testing.T) {
var currency toshl.Currency
currencyJSON := []byte(`{
"code": 1,
"rate": "fsdfa",
"fixed": false
}`)
err := json.Unmarshal(currencyJSON, ¤cy)
assert.NotNil(t, err)
}
func TestCommonMedianDecode(t *testing.T) {
var median toshl.Median
medianJSON := []byte(`{
"expenses": 55,
"incomes": 1300
}`)
err := json.Unmarshal(medianJSON, &median)
if err != nil {
t.Errorf("Cannot decode Median JSON")
}
assert.Nil(t, err)
}
func TestCommonMedianDecodeError(t *testing.T) {
var median toshl.Median
medianJSON := []byte(`{
"expenses": "abc",
"incomes": 1300
}`)
err := json.Unmarshal(medianJSON, &median)
assert.NotNil(t, err)
}
func TestCommonGoalDecode(t *testing.T) {
var goal toshl.Goal
goalJSON := []byte(`{
"amount": 63570,
"start": "2013-07-01",
"end": "2015-07-01"
}`)
err := json.Unmarshal(goalJSON, &goal)
if err != nil {
t.Errorf("Cannot decode Goal JSON")
}
assert.Nil(t, err)
}
func TestCommonGoalDecodeError(t *testing.T) {
var goal toshl.Goal
goalJSON := []byte(`{
"amount": "abcd",
"start": "2013-07-01",
"end": "2015-07-01"
}`)
err := json.Unmarshal(goalJSON, &goal)
assert.NotNil(t, err)
}
func TestCommonRecurrenceDecode(t *testing.T) {
var recurrence toshl.Recurrence
recurrenceJSON := []byte(`{
"frequency": "monthly",
"interval": 1,
"start": "2012-06-01",
"iteration": 4
}`)
err := json.Unmarshal(recurrenceJSON, &recurrence)
assert.Nil(t, err)
}