forked from lukemilby/lichess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_test.go
64 lines (54 loc) · 1.41 KB
/
account_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
package lichess
import (
"bytes"
"io/ioutil"
"net/http"
"testing"
"github.com/lukemilby/lichess/utils/mocks"
"github.com/stretchr/testify/assert"
)
func TestGetProfile(t *testing.T) {
setUp()
json := `{"username":"Georges","Profile":{"FirstName": "Bob" }}`
mocks.GetDoFunc = func(*http.Request) (*http.Response, error) {
r := ioutil.NopCloser(bytes.NewReader([]byte(json)))
return &http.Response{
StatusCode: 200,
Body: r,
}, nil
}
user, err := client.GetProfile()
assert.NotNil(t, user)
assert.Nil(t, err)
assert.EqualValues(t, "Georges", user.Username)
assert.EqualValues(t, "Bob", user.Profile.FirstName)
}
func TestGetEmail(t *testing.T) {
setUp()
json := `{"email":"[email protected]"}`
mocks.GetDoFunc = func(*http.Request) (*http.Response, error) {
r := ioutil.NopCloser(bytes.NewReader([]byte(json)))
return &http.Response{
StatusCode: 200,
Body: r,
}, nil
}
email, err := client.GetEmail()
assert.NotNil(t, email)
assert.Nil(t, err)
assert.EqualValues(t, "[email protected]", email.Email)
}
func TestSetKidModeStatus(t *testing.T) {
setUp()
json := `{"ok":true}`
mocks.GetDoFunc = func(*http.Request) (*http.Response, error) {
r := ioutil.NopCloser(bytes.NewReader([]byte(json)))
return &http.Response{
Body: r,
}, nil
}
status, err := client.SetKidModeStatus(true)
assert.NotNil(t, status)
assert.Nil(t, err)
assert.EqualValues(t, true, status.Ok)
}