-
Notifications
You must be signed in to change notification settings - Fork 82
/
object_test.go
67 lines (60 loc) · 1.42 KB
/
object_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
package notionapi_test
import (
"encoding/json"
"reflect"
"testing"
"github.com/jomei/notionapi"
)
func TestDate(t *testing.T) {
t.Run(".UnmarshalText", func(t *testing.T) {
var d notionapi.Date
t.Run("OK datetime with timezone", func(t *testing.T) {
data := []byte("1987-02-13T00:00:00.000+01:00")
err := d.UnmarshalText(data)
if err != nil {
t.Fatal(err)
}
})
t.Run("OK date", func(t *testing.T) {
data := []byte("1985-01-02")
err := d.UnmarshalText(data)
if err != nil {
t.Fatal(err)
}
})
t.Run("NOK", func(t *testing.T) {
data := []byte("1985")
err := d.UnmarshalText(data)
if err == nil {
t.Fatalf("expected an error, got none")
}
})
})
}
func TestColor_MarshalText(t *testing.T) {
type Foo struct {
Test notionapi.Color `json:"test"`
}
t.Run("marshall to color if color is not empty", func(t *testing.T) {
f := Foo{Test: notionapi.ColorGreen}
r, err := json.Marshal(f)
if err != nil {
t.Fatal(err)
}
want := []byte(`{"test":"green"}`)
if !reflect.DeepEqual(r, want) {
t.Errorf("Color.MarshallText error() got = %v, want %v", r, want)
}
})
t.Run("marshall to default color if color is empty", func(t *testing.T) {
f := Foo{}
r, err := json.Marshal(f)
if err != nil {
t.Fatal(err)
}
want := []byte(`{"test":"default"}`)
if !reflect.DeepEqual(r, want) {
t.Errorf("Color.MarshallText error() got = %v, want %v", r, want)
}
})
}