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
110
111
112
113
114
115
116
117
# frozen_string_literal: true
require "test_helper"
require "bandwidth_tn_order"
class BandwidthTNOrderTest < Minitest::Test
def test_for_received
order = BandwidthTNOrder.for(BandwidthIris::Order.new(
order_status: "RECEIVED"
))
assert_kind_of BandwidthTNOrder::Received, order
end
def test_for_complete
order = BandwidthTNOrder.for(BandwidthIris::Order.new(
order_status: "COMPLETE"
))
assert_kind_of BandwidthTNOrder::Complete, order
end
def test_for_failed
order = BandwidthTNOrder.for(BandwidthIris::Order.new(
order_status: "FAILED"
))
assert_kind_of BandwidthTNOrder::Failed, order
end
def test_for_unknown
order = BandwidthTNOrder.for(BandwidthIris::Order.new(
order_status: "randOmgarBagE"
))
assert_kind_of BandwidthTNOrder, order
assert_equal :randomgarbage, order.status
end
def test_poll
order = BandwidthTNOrder.new(BandwidthIris::Order.new)
assert_raises { order.poll.sync }
end
em :test_poll
class TestReceived < Minitest::Test
def setup
@order = BandwidthTNOrder::Received.new(
BandwidthIris::Order.new(id: "oid")
)
end
def test_poll
req = stub_request(
:get,
"https://dashboard.bandwidth.com/v1.0/accounts//orders/oid"
).to_return(status: 200, body: <<~RESPONSE)
<OrderResponse>
<OrderStatus>COMPLETE</OrderStatus>
<CompletedNumbers>
<TelephoneNumber>
<FullNumber>5555550000</FullNumber>
</TelephoneNumber>
</CompletedNumbers>
</OrderResponse>
RESPONSE
stub_request(
:post,
"https://api.catapult.inetwork.com/v1/users/catapult_user/phoneNumbers"
).with(
body: open(__dir__ + "/data/catapult_import_body.json").read.chomp,
headers: {
"Authorization" => "Basic Y2F0YXB1bHRfdG9rZW46Y2F0YXB1bHRfc2VjcmV0",
"Content-Type" => "application/json"
}
).to_return(status: 200)
@order.poll.sync
assert_requested req
end
em :test_poll
end
class TestComplete < Minitest::Test
def setup
@order = BandwidthTNOrder::Complete.new(BandwidthIris::Order.new(
completed_numbers: {
telephone_number: { full_number: "5555550000" }
}
))
end
def test_poll
req = stub_request(
:post,
"https://api.catapult.inetwork.com/v1/users/catapult_user/phoneNumbers"
).with(
body: open(__dir__ + "/data/catapult_import_body.json").read.chomp,
headers: {
"Authorization" => "Basic Y2F0YXB1bHRfdG9rZW46Y2F0YXB1bHRfc2VjcmV0",
"Content-Type" => "application/json"
}
).to_return(status: 200)
assert_equal @order, @order.poll.sync
assert_requested req
end
em :test_poll
end
class TestFailed < Minitest::Test
def setup
@order = BandwidthTNOrder::Failed.new(
BandwidthIris::Order.new(id: "oid")
)
end
def test_poll
assert_raises { @order.poll.sync }
end
em :test_poll
end
end