Include only incoming/outgoing messages in reporting (#429)
* Skip activity messages from reporting * Makes reportable? as access list for reporting
This commit is contained in:
parent
18bf1a9e62
commit
cc180b77ce
3 changed files with 48 additions and 5 deletions
|
@ -25,10 +25,10 @@ class ReportingListener < BaseListener
|
||||||
|
|
||||||
def message_created(event)
|
def message_created(event)
|
||||||
message, account, timestamp = extract_message_and_account(event)
|
message, account, timestamp = extract_message_and_account(event)
|
||||||
if message.outgoing?
|
|
||||||
::Reports::UpdateAccountIdentity.new(account, timestamp).incr_outgoing_messages_count
|
return unless message.reportable?
|
||||||
else
|
|
||||||
::Reports::UpdateAccountIdentity.new(account, timestamp).incr_incoming_messages_count
|
identity = ::Reports::UpdateAccountIdentity.new(account, timestamp)
|
||||||
end
|
message.outgoing? ? identity.incr_outgoing_messages_count : identity.incr_incoming_messages_count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -66,6 +66,10 @@ class Message < ApplicationRecord
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reportable?
|
||||||
|
incoming? || outgoing?
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def dispatch_event
|
def dispatch_event
|
||||||
|
|
39
spec/listeners/reporting_listener_spec.rb
Normal file
39
spec/listeners/reporting_listener_spec.rb
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
describe ReportingListener do
|
||||||
|
let(:listener) { described_class.instance }
|
||||||
|
let!(:account) { create(:account) }
|
||||||
|
let(:report_identity) { Reports::UpdateAccountIdentity.new(account, Time.zone.now) }
|
||||||
|
let!(:user) { create(:user, account: account) }
|
||||||
|
let!(:inbox) { create(:inbox, account: account) }
|
||||||
|
let!(:conversation) { create(:conversation, account: account, inbox: inbox, assignee: user) }
|
||||||
|
|
||||||
|
describe '#message_created' do
|
||||||
|
let(:event_name) { :'conversation.created' }
|
||||||
|
|
||||||
|
context 'when user activity message' do
|
||||||
|
it 'does not increment messages count' do
|
||||||
|
activity_message = create(:message, message_type: 'activity', account: account, inbox: inbox, conversation: conversation)
|
||||||
|
event = Events::Base.new(event_name, Time.zone.now, message: activity_message)
|
||||||
|
|
||||||
|
allow(Reports::UpdateAccountIdentity).to receive(:new).and_return(report_identity)
|
||||||
|
allow(report_identity).to receive(:incr_outgoing_messages_count).exactly(0).times
|
||||||
|
allow(report_identity).to receive(:incr_incoming_messages_count).exactly(0).times
|
||||||
|
|
||||||
|
listener.message_created(event)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when user conversation message' do
|
||||||
|
it 'increments messages count' do
|
||||||
|
conversation_message = create(:message, message_type: 'outgoing', account: account, inbox: inbox, conversation: conversation)
|
||||||
|
event = Events::Base.new(event_name, Time.zone.now, message: conversation_message)
|
||||||
|
|
||||||
|
allow(Reports::UpdateAccountIdentity).to receive(:new).and_return(report_identity)
|
||||||
|
allow(report_identity).to receive(:incr_outgoing_messages_count).once
|
||||||
|
allow(report_identity).to receive(:incr_incoming_messages_count).exactly(0).times
|
||||||
|
|
||||||
|
listener.message_created(event)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue