-
Notifications
You must be signed in to change notification settings - Fork 79
/
tag_api_test.go
69 lines (60 loc) · 1.89 KB
/
tag_api_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
package intercom
import (
"io/ioutil"
"testing"
)
type TestTagHTTPClient struct {
TestHTTPClient
t *testing.T
fixtureFilename string
expectedURI string
}
func TestAPIListTag(t *testing.T) {
http := TestTagHTTPClient{t: t, fixtureFilename: "fixtures/tags.json", expectedURI: "/tags"}
api := TagAPI{httpClient: &http}
tagList, _ := api.list()
if tagList.Tags[0].ID != "51313" {
t.Errorf("Tag list should start with tag 51313, but had %s", tagList.Tags[0].ID)
}
}
func TestAPITagSave(t *testing.T) {
http := TestTagHTTPClient{t: t, fixtureFilename: "fixtures/tag.json", expectedURI: "/tags"}
api := TagAPI{httpClient: &http}
tag := Tag{ID: "60218", Name: "My Tag"}
savedTag, _ := api.save(&tag)
if savedTag.ID != "60218" {
t.Errorf("Expected saved tag with ID 60218, got %s", savedTag.ID)
}
}
func TestAPITagDelete(t *testing.T) {
http := TestTagHTTPClient{t: t, expectedURI: "/tags/6"}
api := TagAPI{httpClient: &http}
api.delete("6")
}
func TestAPITagTagging(t *testing.T) {
http := TestTagHTTPClient{t: t, fixtureFilename: "fixtures/tag.json", expectedURI: "/tags"}
api := TagAPI{httpClient: &http}
taggingList := TaggingList{Name: "My Tag", Users: []Tagging{Tagging{UserID: "2345"}}}
savedTag, _ := api.tag(&taggingList)
if savedTag.ID != "60218" {
t.Errorf("Expected saved tag with ID 60218, got %s", savedTag.ID)
}
}
func (t TestTagHTTPClient) Get(uri string, params interface{}) ([]byte, error) {
if uri != t.expectedURI {
t.t.Errorf("Wrong endpoint called")
}
return ioutil.ReadFile(t.fixtureFilename)
}
func (t TestTagHTTPClient) Post(uri string, body interface{}) ([]byte, error) {
if uri != t.expectedURI {
t.t.Errorf("Wrong endpoint called")
}
return ioutil.ReadFile(t.fixtureFilename)
}
func (t TestTagHTTPClient) Delete(uri string, body interface{}) ([]byte, error) {
if uri != t.expectedURI {
t.t.Errorf("Wrong endpoint called")
}
return nil, nil
}