-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_meeting_test.go
61 lines (55 loc) · 1.71 KB
/
get_meeting_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
package whereby
import (
"bytes"
"errors"
"io/ioutil"
"net/http"
"testing"
)
func TestClient_GetMeeting(t *testing.T) {
t.Run("With valid request/response", func(t *testing.T) {
ctx, ccl := testContext(t)
defer ccl()
httpClient := &mockClient{DoFunc: func(req *http.Request) (*http.Response, error) {
body := `{"meetingId":"1","startDate":"2020-05-12T16:42:49Z","endDate":"2020-05-12T17:42:49Z","roomUrl":"http://example.com","hostRoomUrl":"http://example.com/host-room"}`
return &http.Response{
StatusCode: http.StatusCreated,
Body: ioutil.NopCloser(bytes.NewBufferString(body)),
ContentLength: int64(len(body)),
}, nil
}}
c := Client{
c: httpClient,
}
res, err := c.GetMeeting(ctx, "1")
if err != nil {
t.Errorf("want no err; got %v", err)
}
if res.MeetingID != "1" {
t.Errorf("res.MeetingID = %s; want %s", res.MeetingID, "1")
}
if got, want := res.HostURL, "http://example.com/host-room"; got != want {
t.Errorf("res.HostUrl = %s; want %s", got, want)
}
if got, want := res.MeetingID, "1"; got != want {
t.Errorf("res.MeetingID = %s; want %s", got, want)
}
})
t.Run("With invalid response", func(t *testing.T) {
ctx, ccl := testContext(t)
defer ccl()
httpClient := &mockClient{DoFunc: func(req *http.Request) (*http.Response, error) {
body := `{"meetingId":"1","startDate":"2020-05-12T16:42:49Z",`
return &http.Response{
StatusCode: http.StatusCreated,
Body: ioutil.NopCloser(bytes.NewBufferString(body)),
ContentLength: int64(len(body)),
}, errors.New("something went wrong")
}}
c := Client{c: httpClient}
_, err := c.GetMeeting(ctx, "1")
if err == nil {
t.Errorf("want err; got %v", err)
}
})
}