Skip to content

Commit

Permalink
Ticket CV2-3948: Fixing how number of tipline newsletters delivered a…
Browse files Browse the repository at this point in the history
…re calculated
  • Loading branch information
caiosba committed Nov 18, 2023
1 parent 462fe74 commit c92330a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/check_statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def get_statistics(start_date, end_date, team_id, platform, language, tracing_at

CheckTracer.in_span('CheckStatistics#newsletters_delivered', attributes: tracing_attributes) do
# Number of newsletters effectively delivered, accounting for user errors for each platform
statistics[:newsletters_delivered] = TiplineMessage.where(created_at: start_date..end_date, team_id: team_id, platform: platform_name, language: language, direction: 'outgoing', event: 'newsletter').count
statistics[:newsletters_delivered] = TiplineMessage.where(created_at: start_date..end_date, team_id: team_id, platform: platform_name, language: language, direction: 'outgoing', state: 'delivered', event: 'newsletter').count
end

CheckTracer.in_span('CheckStatistics#whatsapp_conversations', attributes: tracing_attributes) do
Expand Down
8 changes: 8 additions & 0 deletions test/lib/check_statistics_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,12 @@ def teardown
WebMock.stub_request(:get, @url).to_return(status: 400, body: { error: 'Error' }.to_json)
assert_nil CheckStatistics.number_of_whatsapp_conversations(create_team.id, @from, @to)
end

test 'should calculate number of delivered newsletters' do
WebMock.stub_request(:get, /graph\.facebook\.com/).to_return(status: 400, body: { error: 'Error' }.to_json)
create_tipline_message team_id: @team.id, event: 'newsletter', direction: :outgoing, state: 'sent'
create_tipline_message team_id: @team.id, event: 'newsletter', direction: :outgoing, state: 'delivered'
data = CheckStatistics.get_statistics(Time.now.yesterday, Time.now.tomorrow, @team.id, 'whatsapp', 'en')
assert_equal 1, data[:newsletters_delivered]
end
end

0 comments on commit c92330a

Please sign in to comment.