# frozen_string_literal: true
require "admin_command"
BackendSgx::IQ_MANAGER = Minitest::Mock.new
Customer::BLATHER = Minitest::Mock.new
AdminActionRepo::REDIS = Minitest::Mock.new
class AdminCommandTest < Minitest::Test
def admin_command(tel="+15556667777")
sgx = Minitest::Mock.new(OpenStruct.new(
registered?: OpenStruct.new(phone: tel)
))
[sgx, AdminCommand.new(customer(sgx: sgx), CustomerRepo.new)]
end
def test_action_cancel_account
sgx, admin = admin_command
Customer::BLATHER.expect(
:<<,
EMPromise.resolve(nil),
[
Matching.new do |m|
assert_equal "Your JMP account has been cancelled.", m.body
assert_equal "test@example.net", m.to.to_s
assert_equal "notify_from@component", m.from.to_s
end
]
)
Customer::BLATHER.expect(
:<<,
EMPromise.resolve(nil),
[
Matching.new do |iq|
assert iq.remove?
assert_equal "test@example.net", iq.to.to_s
assert_equal "component", iq.from.to_s
end
]
)
sgx.expect(:deregister!, EMPromise.resolve(nil))
stub_request(
:post,
"https://dashboard.bandwidth.com/v1.0/accounts//disconnects"
).with(
body: {
name: "test",
DisconnectTelephoneNumberOrderType: {
TelephoneNumberList: {
TelephoneNumber: "5556667777"
}
}
}.to_xml(indent: 0, root: "DisconnectTelephoneNumberOrder")
).to_return(status: 200, body: "")
admin.action_cancel_account.sync
assert_mock sgx
assert_mock BackendSgx::IQ_MANAGER
assert_mock Customer::BLATHER
end
em :test_action_cancel_account
def test_action_cancel_account_keep_number
sgx, admin = admin_command("+15566667777")
Customer::BLATHER.expect(
:<<,
EMPromise.resolve(nil),
[
Matching.new do |m|
assert_equal "Your JMP account has been cancelled.", m.body
assert_equal "test@example.net", m.to.to_s
assert_equal "notify_from@component", m.from.to_s
end
]
)
Customer::BLATHER.expect(
:<<,
EMPromise.resolve(nil),
[
Matching.new do |iq|
assert iq.remove?
assert_equal "test@example.net", iq.to.to_s
assert_equal "component", iq.from.to_s
end
]
)
sgx.expect(:deregister!, EMPromise.resolve(nil))
stub_request(
:post,
"https://dashboard.bandwidth.com/v1.0/accounts/moveto/moveTns"
).with(
body: {
CustomerOrderId: "test",
SourceAccountId: "test_bw_account",
SiteId: "movetosite",
SipPeerId: "movetopeer",
TelephoneNumbers: { TelephoneNumber: "5566667777" }
}.to_xml(indent: 0, root: "MoveTnsOrder")
).to_return(status: 200, body: "")
admin.action_cancel_account.sync
assert_mock sgx
assert_mock BackendSgx::IQ_MANAGER
assert_mock Customer::BLATHER
end
em :test_action_cancel_account_keep_number
end