Skip to content

Commit

Permalink
CV2-4985: add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy committed Jan 26, 2025
1 parent 28217c7 commit e987db9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/models/concerns/team_private.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ def get_dashboard_export_headers(ts, dashboard_type)
'Fact-Checks Created': { number_of_fact_checks_created: 'to_i' },
})
rates = ts.send('number_of_fact_checks_by_rating').keys
# Get the first element to fill the label and callback methods as other element will calling with empty callbacks
f_rate = rates.delete_at(0)
header.merge!({ "Claim & Fact-Checks (#{f_rate})": { number_of_fact_checks_by_rating: 'values' }})
rates.each{ |rate| header.merge!({"Claim & Fact-Checks (#{rate})": {}}) }
unless rates.blank?
# Get the first element to fill the label and callback methods as other element will calling with empty callbacks
f_rate = rates.delete_at(0)
header.merge!({ "Claim & Fact-Checks (#{f_rate})": { number_of_fact_checks_by_rating: 'values' }})
rates.each{ |rate| header.merge!({"Claim & Fact-Checks (#{rate})": {}}) }
end
top_items = { top_articles_tags: 'Top Article Tags', top_articles_sent: 'Top Fact-Checks Sent' }
end
unless top_items.blank?
Expand Down
1 change: 1 addition & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ def get_shorten_outgoing_urls
end

def get_dashboard_exported_data(filters, dashboard_type)
filters = filters.with_indifferent_access
ts = TeamStatistics.new(self, filters[:period], filters[:language], filters[:platform])
headers = get_dashboard_export_headers(ts, dashboard_type)
data = []
Expand Down
20 changes: 20 additions & 0 deletions test/models/team_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1315,4 +1315,24 @@ def setup
tn.destroy!
assert !t.get_shorten_outgoing_urls
end

test "should get dashboard data" do
setup_elasticsearch
RequestStore.store[:skip_cached_field_update] = false
team = create_team
pm = create_project_media team: team, channel: { main: CheckChannels::ChannelCodes::WHATSAPP }, disable_es_callbacks: false
pm2 = create_project_media team: team, channel: { main: CheckChannels::ChannelCodes::WHATSAPP }, disable_es_callbacks: false
create_tipline_request team: team.id, associated: pm, disable_es_callbacks: false
create_tipline_request team: team.id, associated: pm2, disable_es_callbacks: false
sleep 1
filters = { period: "past_week", platform: "whatsapp", language: "en" }
data = team.get_dashboard_exported_data(filters, 'tipline_dashboard')
assert_not_nil data
assert_equal data[0].length, data[1].length
cd = create_claim_description project_media: pm
fc = create_fact_check claim_description: cd, rating: 'in_progress'
data = team.get_dashboard_exported_data(filters, 'articles_dashboard')
assert_not_nil data
assert_equal data[0].length, data[1].length
end
end

0 comments on commit e987db9

Please sign in to comment.