This repository has been archived by the owner on Mar 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
80 lines (66 loc) · 2.12 KB
/
client_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
package auth
import (
"net/http"
"testing"
"fmt"
"time"
"github.com/branch-app/branch-mono-go/domain/auth"
"github.com/stretchr/testify/assert"
"gopkg.in/h2non/gock.v1"
)
func TestNewClient(t *testing.T) {
key := "test_key"
baseURL := "http://svc-auth.branch/"
client := NewClient(baseURL, key)
options := client.jsonClient.Options()
assert.Equal(t, fmt.Sprintf("bearer %s", key), options.Headers["Authorization"])
assert.Equal(t, baseURL, client.jsonClient.BaseURL())
}
func TestGetHalo4Token(t *testing.T) {
defer gock.Off()
client := NewClient("http://svc-auth.branch/", "test_key")
time, _ := time.Parse("May 5, 2017 at 9:42pm (UTC)", "2017-05-13T09:42:42Z")
json := auth.Halo4Token{
SpartanToken: "test_spartan_token",
AnalyticsToken: "test_analytics_token",
ExpiresAt: time,
Gamertag: "Program",
}
gock.New("http://svc-auth.branch/").
Post("/1/2017-05-13/get_halo4_token").
Reply(http.StatusOK).
JSON(json)
gock.InterceptClient(client.jsonClient.HTTPClient)
token, err := client.GetHalo4Token()
assert.Nil(t, err)
assert.Equal(t, json.SpartanToken, token.SpartanToken)
assert.Equal(t, json.AnalyticsToken, token.AnalyticsToken)
assert.Equal(t, json.ExpiresAt, token.ExpiresAt)
assert.Equal(t, json.Gamertag, token.Gamertag)
assert.True(t, gock.IsDone())
}
func TestGetXboxLiveToken(t *testing.T) {
defer gock.Off()
client := NewClient("http://svc-auth.branch/", "test_key")
time, _ := time.Parse("May 5, 2017 at 9:42pm (UTC)", "2017-05-13T09:42:42Z")
json := auth.XboxLiveToken{
ExpiresAt: time,
Gamertag: "Program",
Token: "test_token",
UserHash: "test_hash",
XUID: "test_xuid",
}
gock.New("http://svc-auth.branch/").
Post("/1/2017-05-13/get_xboxlive_token").
Reply(http.StatusOK).
JSON(json)
gock.InterceptClient(client.jsonClient.HTTPClient)
token, err := client.GetXboxLiveToken()
assert.Nil(t, err)
assert.Equal(t, json.ExpiresAt, token.ExpiresAt)
assert.Equal(t, json.Gamertag, token.Gamertag)
assert.Equal(t, json.Token, token.Token)
assert.Equal(t, json.UserHash, token.UserHash)
assert.Equal(t, json.XUID, token.XUID)
assert.True(t, gock.IsDone())
}