-
Notifications
You must be signed in to change notification settings - Fork 12
/
user_test.go
31 lines (26 loc) · 926 Bytes
/
user_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
package reddit
import (
"fmt"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"testing"
)
func TestIsUsernameAvailable(t *testing.T) {
url := fmt.Sprintf("%s/api/username_available.json?user=GovSchwarzenegger", baseURL)
httpmock.Activate()
httpmock.RegisterResponder("GET", url, httpmock.NewStringResponder(200, "false"))
defer httpmock.DeactivateAndReset()
client := NoAuthClient
isUsernameAvailable, err := client.IsUsernameAvailable("GovSchwarzenegger")
assert.NoError(t, err)
assert.Equal(t, isUsernameAvailable, false)
}
func TestGetUserInfo(t *testing.T) {
url := fmt.Sprintf("%s/user/GovSchwarzenegger/about.json", baseURL)
mockResponseFromFile(url, "test_data/user/user_info.json")
defer httpmock.DeactivateAndReset()
client := NoAuthClient
userInfo, err := client.GetUserInfo("GovSchwarzenegger")
assert.NoError(t, err)
assert.Equal(t, userInfo.Name, "GovSchwarzenegger")
}