-
Notifications
You must be signed in to change notification settings - Fork 2
/
preferencecenter_test.go
58 lines (46 loc) · 1.65 KB
/
preferencecenter_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
package braze_test
import (
"context"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/dietdoctor/go-braze"
"github.com/stretchr/testify/assert"
)
func TestPreferencesServerCreateURL(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/preference_center/v1/foo/url/bar", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "Bearer key", r.Header.Get("Authorization"))
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
w.WriteHeader(http.StatusCreated)
w.Write([]byte(`{"preference_center_url":"https://foo"}`))
})
srv := httptest.NewServer(mux)
defer srv.Close()
url, _ := url.Parse(srv.URL)
client, err := braze.NewClient(braze.APIKey("key"), braze.BaseURL(url))
assert.NoError(t, err)
resp, err := client.PreferenceCenter().CreateURL(context.Background(), &braze.PreferenceCenterCreateURLRequest{
PreferenceCenterID: "foo",
UserID: "bar",
})
assert.NoError(t, err)
assert.Equal(t, "https://foo", resp.URL)
}
func TestPreferencesServerCreateURLInternalServerError(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/preference_center/v1/foo/url/bar", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "Bearer key", r.Header.Get("Authorization"))
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
w.WriteHeader(http.StatusInternalServerError)
})
srv := httptest.NewServer(mux)
defer srv.Close()
url, _ := url.Parse(srv.URL)
client, err := braze.NewClient(braze.APIKey("key"), braze.BaseURL(url))
assert.NoError(t, err)
resp, err := client.PreferenceCenter().CreateURL(context.Background(), nil)
assert.Error(t, err)
assert.Nil(t, resp)
}