From c7ebad17fa39584f92a6d317dc2f465990fe088d Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 15 Sep 2021 13:18:26 -0500 Subject: [PATCH] Helper to fetch customer's vcard-temp --- lib/customer.rb | 8 +++++++- test/test_customer.rb | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/customer.rb b/lib/customer.rb index 160013041ccc17f883b8d5e38836de75ce53a033..4cd6619deb2fe947319c7ceda6c26fb4a212dd6e 100644 --- a/lib/customer.rb +++ b/lib/customer.rb @@ -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 diff --git a/test/test_customer.rb b/test/test_customer.rb index defcb2d9b1fc15c7432bc28078a40f885092f156..212bb24688e8b81b721822524e66dfb843a112ed 100644 --- a/test/test_customer.rb +++ b/test/test_customer.rb @@ -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|