This repository has been archived by the owner on Aug 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
call_test.go
68 lines (52 loc) · 1.56 KB
/
call_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
package twiliogo
import (
"encoding/json"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
var testCall = Call{
Sid: "testsid",
ParentCallSid: "",
DateCreated: "2013-05-11",
DateUpdated: "2013-05-11",
AccountSid: "AC3TestAccount",
To: "+15555555555",
From: "+16666666666",
PhoneNumberSid: "",
Status: "queued",
StartTime: "5:00",
EndTime: "6:00",
Duration: "5",
Price: "4",
PriceUnit: "dollars",
Direction: "outbound-api",
AnsweredBy: "",
ForwardedFrom: "",
CallerName: "",
Uri: "/2010-04-01/Accounts/AC3TestAccount/Calls/testsid.json",
}
func TestNewCall(t *testing.T) {
client := new(MockClient)
callJson, _ := json.Marshal(testCall)
params := url.Values{}
params.Set("From", "6666666666")
params.Set("To", "5555555555")
params.Set("Url", "http://callback.com")
client.On("post", params, "/Calls.json").Return(callJson, nil)
call, err := NewCall(client, "6666666666", "5555555555", Callback("http://callback.com"))
client.Mock.AssertExpectations(t)
if assert.Nil(t, err, "Error unmarshaling call") {
assert.Equal(t, call.Sid, "testsid", "Call malformed")
}
}
func TestGetCall(t *testing.T) {
client := new(MockClient)
callJson, _ := json.Marshal(testCall)
client.On("get", url.Values{}, "/Calls/testsid.json").Return(callJson, nil)
call, err := GetCall(client, "testsid")
client.Mock.AssertExpectations(t)
if assert.Nil(t, err, "Error unmarshaling call") {
assert.Equal(t, call.Sid, "testsid", "Call malformed")
}
}