-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtonicpow_test.go
150 lines (131 loc) · 4.34 KB
/
tonicpow_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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package tonicpow
import (
"encoding/json"
"fmt"
"net/http"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
)
const (
testAdvertiserID uint64 = 23
testAdvertiserName string = "TonicPow Test"
testAPIKey string = "TestAPIKey12345678987654321"
testAppID uint64 = 10
testCampaignID uint64 = 23
testCampaignTargetURL string = "https://tonicpow.com"
testConversionID uint64 = 99
testGoalID uint64 = 13
testGoalName string = "example_goal"
testRateCurrency string = "usd"
testShortCode string = "test_short_code"
testTncpwSession string = "TestSessionKey12345678987654321"
testTwitterID string = "22413277"
testUserID uint64 = 43
)
// TestVersion will test the method Version()
func TestVersion(t *testing.T) {
t.Parallel()
t.Run("get version", func(t *testing.T) {
ver := Version()
assert.Equal(t, version, ver)
})
}
// ExampleVersion example using Version()
//
// See more examples in /examples/
func ExampleVersion() {
fmt.Printf("version: %s", Version())
// Output:version: v0.8.0
}
// TestUserAgent will test the method UserAgent()
func TestUserAgent(t *testing.T) {
t.Parallel()
t.Run("get user agent", func(t *testing.T) {
agent := UserAgent()
assert.Equal(t, defaultUserAgent, agent)
})
}
// ExampleUserAgent example using UserAgent()
//
// See more examples in /examples/
func ExampleUserAgent() {
fmt.Printf("user agent: %s", UserAgent())
// Output:user agent: go-tonicpow: v0.8.0
}
// TestGetFeedType will test the method GetFeedType()
func TestGetFeedType(t *testing.T) {
t.Run("test valid cases", func(t *testing.T) {
assert.Equal(t, FeedTypeRSS, GetFeedType("rss"))
assert.Equal(t, FeedTypeJSON, GetFeedType("json"))
assert.Equal(t, FeedTypeAtom, GetFeedType("atom"))
assert.Equal(t, FeedTypeRSS, GetFeedType(""))
})
}
// TestEnvironment_Alias will test the method Alias()
func TestEnvironment_Alias(t *testing.T) {
assert.Equal(t, environmentStagingAlias, EnvironmentStaging.Alias())
assert.Equal(t, environmentDevelopmentAlias, EnvironmentDevelopment.Alias())
assert.Equal(t, environmentLiveAlias, EnvironmentLive.Alias())
e := Environment{}
assert.Equal(t, "", e.Alias())
}
// ExampleEnvironment_Alias example using Alias()
//
// See more examples in /examples/
func ExampleEnvironment_Alias() {
env := EnvironmentLive
fmt.Printf("name: %s alias: %s", env.Name(), env.Alias())
// Output:name: live alias: production
}
// TestEnvironment_Name will test the method Name()
func TestEnvironment_Name(t *testing.T) {
assert.Equal(t, environmentStagingName, EnvironmentStaging.Name())
assert.Equal(t, environmentDevelopmentName, EnvironmentDevelopment.Name())
assert.Equal(t, environmentLiveName, EnvironmentLive.Name())
e := Environment{}
assert.Equal(t, "", e.Name())
}
// ExampleEnvironment_Name example using Name()
//
// See more examples in /examples/
func ExampleEnvironment_Name() {
env := EnvironmentLive
fmt.Printf("name: %s alias: %s", env.Name(), env.Alias())
// Output:name: live alias: production
}
// TestEnvironment_URL will test the method URL()
func TestEnvironment_URL(t *testing.T) {
assert.Equal(t, stagingAPIURL, EnvironmentStaging.URL())
assert.Equal(t, developmentURL, EnvironmentDevelopment.URL())
assert.Equal(t, liveAPIURL, EnvironmentLive.URL())
e := Environment{}
assert.Equal(t, "", e.URL())
}
// ExampleEnvironment_URL example using URL()
//
// See more examples in /examples/
func ExampleEnvironment_URL() {
env := EnvironmentLive
fmt.Printf("name: %s url: %s", env.Name(), env.URL())
// Output:name: live url: https://api.tonicpow.com/v1
}
// mockResponseData is used for mocking the response
func mockResponseData(method, endpoint string, statusCode int, model interface{}) error {
httpmock.Reset()
if model != nil && model != "" {
data, err := json.Marshal(model)
if err != nil {
return err
}
httpmock.RegisterResponder(method, endpoint, httpmock.NewStringResponder(statusCode, string(data)))
} else {
httpmock.RegisterResponder(method, endpoint, httpmock.NewStringResponder(statusCode, ""))
}
return nil
}
// mockResponseFeed is used for mocking the response
func mockResponseFeed(endpoint string, statusCode int, feedResults string) {
httpmock.Reset()
httpmock.RegisterResponder(http.MethodGet, endpoint, httpmock.NewStringResponder(statusCode, feedResults))
}