M lib/customer.rb => lib/customer.rb +7 -1
@@ 67,13 67,19 @@ class Customer
stanza = stanza.dup
stanza.to = jid.with(resource: stanza.to&.resource)
stanza.from = stanza.from.with(domain: CONFIG[:component][:jid])
- BLATHER << stanza
+ block_given? ? yield(stanza) : (BLATHER << stanza)
end
def stanza_from(stanza)
BLATHER << @sgx.stanza(stanza)
end
+ def fetch_vcard_temp(from_tel=nil)
+ iq = Blather::Stanza::Iq::Vcard.new(:get)
+ iq.from = Blather::JID.new(from_tel, CONFIG[:component][:jid])
+ stanza_to(iq, &IQ_MANAGER.method(:write)).then(&:vcard)
+ end
+
def sip_account
SipAccount.find(customer_id)
end
M test/test_customer.rb => test/test_customer.rb +13 -0
@@ 8,6 8,7 @@ Customer::BRAINTREE = Minitest::Mock.new
Customer::ELECTRUM = Minitest::Mock.new
Customer::REDIS = Minitest::Mock.new
Customer::DB = Minitest::Mock.new
+Customer::IQ_MANAGER = Minitest::Mock.new
CustomerPlan::DB = Minitest::Mock.new
CustomerUsage::REDIS = Minitest::Mock.new
CustomerUsage::DB = Minitest::Mock.new
@@ 109,6 110,18 @@ class CustomerTest < Minitest::Test
Customer::BLATHER.verify
end
+ def test_fetch_vcard_temp
+ result = Blather::Stanza::Iq::Vcard.new(:result)
+ result.vcard["FN"] = "name"
+ Customer::IQ_MANAGER.expect(
+ :method,
+ ->(*) { EMPromise.resolve(result) },
+ [:write]
+ )
+ assert_equal "name", customer.fetch_vcard_temp("+15551234567").sync["FN"]
+ end
+ em :test_fetch_vcard_temp
+
def test_customer_usage_report
report_for = (Date.today..(Date.today - 1))
report_for.first.downto(report_for.last).each.with_index do |day, idx|