@@ -7,7 +7,6 @@ BackendSgx::IQ_MANAGER = Minitest::Mock.new
AdminAction::LaunchSnikket::IQ_MANAGER = Minitest::Mock.new
Customer::BLATHER = Minitest::Mock.new
AdminActionRepo::REDIS = Minitest::Mock.new
-DB = FakeDB.new
class AdminCommandTest < Minitest::Test
def admin_command(tel="+15556667777")
@@ -16,9 +15,79 @@ class AdminCommandTest < Minitest::Test
))
[
sgx,
- AdminCommand.new(customer(sgx: sgx), CustomerRepo.new, Snikket::Repo.new)
+ AdminCommand.new(
+ customer(sgx: sgx),
+ CustomerRepo.new(db: FakeDB.new),
+ AdminActionRepo.new,
+ Snikket::Repo.new(db: FakeDB.new)
+ )
+ ]
+ end
+
+ def test_no_user
+ q_form = Blather::Stanza::Iq::Command.new
+ q_form.action = :complete
+ q_form.form.fields = [
+ { var: "q", value: "testuser" }
]
+
+ customer_repo = Minitest::Mock.new
+
+ result = execute_command {
+ customer_repo.expect(
+ :find_by_format,
+ EMPromise.resolve(OpenStruct.new(
+ customer_id: "testuser",
+ billing_customer_id: "testuser",
+ balance: 0.to_d,
+ jid: Blather::JID.new("test@example.com"),
+ tndetails: {}
+ )),
+ ["testuser"]
+ )
+
+ customer_repo.expect(
+ :find_by_format,
+ EMPromise.resolve(nil),
+ [Blather::JID]
+ )
+
+ customer_repo.expect(
+ :find_by_format,
+ EMPromise.resolve(nil),
+ [ProxiedJID]
+ )
+
+ TrustLevelRepo::REDIS.expect(
+ :get,
+ EMPromise.resolve("Customer"),
+ ["jmp_customer_trust_level-testuser"]
+ )
+
+ TrustLevelRepo::DB.expect(
+ :query_one,
+ EMPromise.resolve({ settled_amount: 0 }),
+ [String, "testuser"], default: {}
+ )
+
+ Command::COMMAND_MANAGER.expect(
+ :write,
+ EMPromise.resolve(q_form),
+ [Matching.new do |iq|
+ assert_equal :form, iq.form.type
+ assert iq.form.field("q")
+ end]
+ )
+
+ AdminCommand.for(nil, customer_repo).start.catch { |e| e }
+ }
+
+ assert result.stanza.completed?
+ assert_mock customer_repo
+ assert_mock Command::COMMAND_MANAGER
+ assert_mock TrustLevelRepo::REDIS
end
+ em :test_no_user
def test_action_launch_snikket
sgx, admin = admin_command