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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# frozen_string_literal: true
require "test_helper"
require "sip_account"
class SipAccount
attr_reader :password
end
class SipAccountTest < Minitest::Test
def setup
@sip = SipAccount.new(
BandwidthIris::SipCredential.new(
user_name: "12345",
realm: "sip.example.com",
http_voice_v2_app_id: "sipappid"
)
).with(password: "old password")
end
def test_with_random_password
new_sip = @sip.with_random_password
refute_equal @sip.password, new_sip.password
refute_empty new_sip.password
assert_kind_of String, new_sip.password
end
def test_form
form = @sip.form
assert_equal "12345", form.field("username").value
assert_equal "old password", form.field("password").value
assert_equal "sip.example.com", form.field("server").value
end
def test_put
put = stub_request(
:put,
"https://dashboard.bandwidth.com/v1.0/accounts//sipcredentials/12345"
).with(
body: {
Hash1: "73b05bcaf9096438c978aecff5f7cc45",
Hash1b: "2b7fe68f6337ef4db29e752684a18db4",
Realm: "sip.example.com",
HttpVoiceV2AppId: "sipappid"
}.to_xml(indent: 0, root: "SipCredential"),
headers: {
"Authorization" => "Basic Og=="
}
).to_return(
status: 201,
headers: { "Location" => "http://example.com/endpoint" }
)
new_sip = @sip.put
assert_equal "12345", new_sip.username
assert_requested put
end
em :test_put
def test_put_fail
stub_request(
:put,
"https://dashboard.bandwidth.com/v1.0/accounts//sipcredentials/12345"
).to_return(status: 400)
assert_raises(BandwidthIris::Errors::GenericError) { @sip.put }
end
em :test_put_fail
class NewTest < Minitest::Test
def setup
@sip = SipAccount.new(
BandwidthIris::SipCredential.new(
user_name: "12345",
realm: "sip.example.com",
http_voice_v2_app_id: "sipappid"
)
).with(password: "old password")
end
def test_with_random_password
new_sip = @sip.with_random_password
refute_equal @sip.password, new_sip.password
refute_empty new_sip.password
assert_kind_of String, new_sip.password
end
def test_put
post = stub_request(
:put,
"https://dashboard.bandwidth.com/v1.0/accounts//sipcredentials/12345"
).with(
body: {
Hash1: "73b05bcaf9096438c978aecff5f7cc45",
Hash1b: "2b7fe68f6337ef4db29e752684a18db4",
Realm: "sip.example.com",
HttpVoiceV2AppId: "sipappid"
}.to_xml(indent: 0, root: "SipCredential"),
headers: {
"Authorization" => "Basic Og=="
}
).to_return(status: 201)
new_sip = @sip.put
assert_equal "12345", new_sip.username
assert_requested post
end
em :test_put
end
end