-
Notifications
You must be signed in to change notification settings - Fork 3
/
content_test.go
116 lines (92 loc) · 3.24 KB
/
content_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
108
109
110
111
112
113
114
115
116
package lytics
import (
"testing"
"github.com/bmizerany/assert"
"github.com/jarcoal/httpmock"
"github.com/lytics/go-lytics/mock"
)
func TestGetUserContentRecommendation(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterContentMocks()
filter := &RecommendationFilter{
Limit: 1,
Shuffle: false,
Topics: []string{"mock", "test"},
Visited: false,
}
client := NewLytics(mock.MockApiKey, nil)
recs, err := client.GetUserContentRecommendation("user_id", mock.MockUserID, filter)
assert.Equal(t, err, nil)
assert.Equal(t, len(recs), 1)
assert.Equal(t, recs[0].Url, "www.testwebsite.com/some/url")
assert.Equal(t, recs[0].Confidence, 0.8328074038765564)
}
func TestGetSegmentContentRecommendation(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterContentMocks()
filter := &RecommendationFilter{
Limit: 1,
Rank: "popular",
}
client := NewLytics(mock.MockApiKey, nil)
recs, err := client.GetSegmentContentRecommendation(mock.MockSegmentID1, filter)
assert.Equal(t, err, nil)
assert.Equal(t, len(recs), 1)
assert.Equal(t, recs[0].Url, "www.testwebsite.com/some/url")
assert.Equal(t, recs[0].Confidence, 0.8328074038765564)
}
func TestGetDocuments(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterContentMocks()
client := NewLytics(mock.MockApiKey, nil)
docs, err := client.GetDocuments([]string{}, 1)
assert.Equal(t, err, nil)
assert.Equal(t, len(docs.Urls), 1)
assert.Equal(t, docs.Total, 5000)
assert.Equal(t, docs.Urls[0].Url, "www.testwebsite.com/some/url")
urls := []string{"www.testwebsite.com/some/url", "www.testwebsite.com/path/to/my-article"}
docs, err = client.GetDocuments(urls, 0)
assert.Equal(t, err, nil)
assert.Equal(t, len(docs.Urls), 2)
assert.Equal(t, docs.Urls[0].Url, "www.testwebsite.com/some/url")
assert.Equal(t, docs.Urls[1].Url, "www.testwebsite.com/path/to/my-article")
}
func TestGetTopicSummary(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterContentMocks()
client := NewLytics(mock.MockApiKey, nil)
topicSummary, err := client.GetTopicSummary(mock.MockTopicID, 0)
assert.Equal(t, err, nil)
assert.Equal(t, topicSummary.Docs.Total, 1)
assert.Equal(t, topicSummary.Topics.Present, 7890)
assert.Equal(t, topicSummary.Topics.HighBucket, 351)
}
func TestGetContentTaxonomy(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterContentMocks()
client := NewLytics(mock.MockApiKey, nil)
taxonomy, err := client.GetContentTaxonomy()
assert.Equal(t, err, nil)
assert.Equal(t, taxonomy.DocCount, 438)
assert.Equal(t, taxonomy.Nodes[0].Name, "marketing technology")
assert.Equal(t, taxonomy.Nodes[1].Count, 1)
}
func TestGetTopicRollups(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
mock.RegisterContentMocks()
client := NewLytics(mock.MockApiKey, nil)
rollups, err := client.GetTopicRollups()
assert.Equal(t, err, nil)
assert.Equal(t, len(rollups), 2)
assert.Equal(t, rollups[0].Label, "Marketing")
assert.Equal(t, len(rollups[0].Topics), 3)
assert.Equal(t, rollups[0].AcctId, mock.MockAccountID)
assert.Equal(t, rollups[1].Label, "Data science")
assert.Equal(t, rollups[1].Topics[0].Label, "Data")
}