1# frozen_string_literal: true
2
3require "admin_command"
4
5BackendSgx::IQ_MANAGER = Minitest::Mock.new
6Customer::BLATHER = Minitest::Mock.new
7AdminActionRepo::REDIS = Minitest::Mock.new
8
9class AdminCommandTest < Minitest::Test
10 def admin_command(tel="+15556667777")
11 sgx = Minitest::Mock.new(OpenStruct.new(
12 registered?: OpenStruct.new(phone: tel)
13 ))
14 [sgx, AdminCommand.new(customer(sgx: sgx), CustomerRepo.new)]
15 end
16
17 def test_action_cancel_account
18 sgx, admin = admin_command
19
20 Customer::BLATHER.expect(
21 :<<,
22 EMPromise.resolve(nil),
23 [
24 Matching.new do |m|
25 assert_equal "Your JMP account has been cancelled.", m.body
26 assert_equal "test@example.net", m.to.to_s
27 assert_equal "notify_from@component", m.from.to_s
28 end
29 ]
30 )
31
32 Customer::BLATHER.expect(
33 :<<,
34 EMPromise.resolve(nil),
35 [
36 Matching.new do |iq|
37 assert iq.remove?
38 assert_equal "test@example.net", iq.to.to_s
39 assert_equal "component", iq.from.to_s
40 end
41 ]
42 )
43
44 sgx.expect(:deregister!, EMPromise.resolve(nil))
45
46 stub_request(
47 :post,
48 "https://dashboard.bandwidth.com/v1.0/accounts//disconnects"
49 ).with(
50 body: {
51 name: "test",
52 DisconnectTelephoneNumberOrderType: {
53 TelephoneNumberList: {
54 TelephoneNumber: "5556667777"
55 }
56 }
57 }.to_xml(indent: 0, root: "DisconnectTelephoneNumberOrder")
58 ).to_return(status: 200, body: "")
59
60 admin.action_cancel_account.sync
61
62 assert_mock sgx
63 assert_mock BackendSgx::IQ_MANAGER
64 assert_mock Customer::BLATHER
65 end
66 em :test_action_cancel_account
67
68 def test_action_cancel_account_keep_number
69 sgx, admin = admin_command("+15566667777")
70
71 Customer::BLATHER.expect(
72 :<<,
73 EMPromise.resolve(nil),
74 [
75 Matching.new do |m|
76 assert_equal "Your JMP account has been cancelled.", m.body
77 assert_equal "test@example.net", m.to.to_s
78 assert_equal "notify_from@component", m.from.to_s
79 end
80 ]
81 )
82
83 Customer::BLATHER.expect(
84 :<<,
85 EMPromise.resolve(nil),
86 [
87 Matching.new do |iq|
88 assert iq.remove?
89 assert_equal "test@example.net", iq.to.to_s
90 assert_equal "component", iq.from.to_s
91 end
92 ]
93 )
94
95 sgx.expect(:deregister!, EMPromise.resolve(nil))
96
97 stub_request(
98 :post,
99 "https://dashboard.bandwidth.com/v1.0/accounts/moveto/moveTns"
100 ).with(
101 body: {
102 CustomerOrderId: "test",
103 SourceAccountId: "test_bw_account",
104 SiteId: "movetosite",
105 SipPeerId: "movetopeer",
106 TelephoneNumbers: { TelephoneNumber: "5566667777" }
107 }.to_xml(indent: 0, root: "MoveTnsOrder")
108 ).to_return(status: 200, body: "")
109
110 admin.action_cancel_account.sync
111
112 assert_mock sgx
113 assert_mock BackendSgx::IQ_MANAGER
114 assert_mock Customer::BLATHER
115 end
116 em :test_action_cancel_account_keep_number
117end