forked from l2x/dota2api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vanityUrl_test.go
37 lines (34 loc) · 996 Bytes
/
vanityUrl_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
package dota2api
import (
. "github.com/franela/goblin"
"io/ioutil"
"net/http"
"strings"
"testing"
)
const (
vanityUrlResponse = "{\"response\":{\"steamid\":\"42\",\"success\":1}}"
)
func TestDota2_ResolveVanityUrl(t *testing.T) {
g := Goblin(t)
mockClient := mockClient{}
api := LoadConfig(GetTestConfig())
api.client = &mockClient
g.Describe("api.GetHeroes", func() {
var id SteamId
var err error
g.It("Should call the correct URL", func() {
mockClient.DoFunc = func(req *http.Request) (*http.Response, error) {
g.Assert(req.URL.String()).Equal(api.getResolveVanityUrl() + "?key=keyTEST&vanityurl=vanityurl")
return &http.Response{StatusCode: 200, Body: ioutil.NopCloser(strings.NewReader(vanityUrlResponse))}, nil
}
id, err = api.ResolveVanityUrl(VanityUrl("vanityurl"))
})
g.It("Should return no error", func() {
g.Assert(err).IsNil()
})
g.It("Should return the correct SteamId", func() {
g.Assert(id).Equal(NewSteamIdFrom64(42))
})
})
}