Add three reports (#14338)

* Add report top_users_by_received_likes

* Add report top_users_by_received_likes_from_inferior_trust_level

* Add report top_users_by_likes_received_from_a_variety_of_people

* Add test to report_top_users_by_received_likes

* add top_users_by_likes_received_from_a_variety_of_people report test

* add top_users_by_likes_received_from_inferior_trust_level report tests
This commit is contained in:
Michelle Bueno Saquetim Vendrame
2021-12-02 17:11:55 +00:00
committed by GitHub
parent 2f04a9b9fb
commit 9b5836aa1d
7 changed files with 401 additions and 0 deletions

View File

@ -1325,4 +1325,108 @@ describe Report do
end
end
end
describe 'top_users_by_likes_received' do
let(:report) { Report.find('top_users_by_likes_received') }
include_examples 'no data'
context 'with data' do
before do
user_1 = Fabricate(:user, username: "jonah")
user_2 = Fabricate(:user, username: "jake")
user_3 = Fabricate(:user, username: "john")
3.times { UserAction.create!(user_id: user_1.id, action_type: UserAction::WAS_LIKED) }
9.times { UserAction.create!(user_id: user_2.id, action_type: UserAction::WAS_LIKED) }
6.times { UserAction.create!(user_id: user_3.id, action_type: UserAction::WAS_LIKED) }
end
it "with category filtering" do
report = Report.find('top_users_by_likes_received')
expect(report.data.length).to eq(3)
expect(report.data[0][:username]).to eq("jake")
expect(report.data[1][:username]).to eq("john")
expect(report.data[2][:username]).to eq("jonah")
end
end
end
describe 'top_users_by_likes_received_from_a_variety_of_people' do
let(:report) { Report.find('top_users_by_likes_received_from_a_variety_of_people') }
include_examples 'no data'
context 'with data' do
before do
user_1 = Fabricate(:user, username: "jonah")
user_2 = Fabricate(:user, username: "jake")
user_3 = Fabricate(:user, username: "john")
user_4 = Fabricate(:user, username: "joseph")
user_5 = Fabricate(:user, username: "joanne")
user_6 = Fabricate(:user, username: "jerome")
topic_1 = Fabricate(:topic, user: user_1)
topic_2 = Fabricate(:topic, user: user_2)
topic_3 = Fabricate(:topic, user: user_3)
post_1 = Fabricate(:post, topic: topic_1, user: user_1)
post_2 = Fabricate(:post, topic: topic_2, user: user_2)
post_3 = Fabricate(:post, topic: topic_3, user: user_3)
3.times { UserAction.create!(user_id: user_4.id, target_post_id: post_1.id, action_type: UserAction::LIKE) }
6.times { UserAction.create!(user_id: user_5.id, target_post_id: post_2.id, action_type: UserAction::LIKE) }
9.times { UserAction.create!(user_id: user_6.id, target_post_id: post_3.id, action_type: UserAction::LIKE) }
end
it "with category filtering" do
report = Report.find('top_users_by_likes_received_from_a_variety_of_people')
expect(report.data.length).to eq(3)
expect(report.data[0][:username]).to eq("jonah")
expect(report.data[1][:username]).to eq("jake")
expect(report.data[2][:username]).to eq("john")
end
end
end
describe 'top_users_by_likes_received_from_inferior_trust_level' do
let(:report) { Report.find('top_users_by_likes_received_from_inferior_trust_level') }
include_examples 'no data'
context 'with data' do
before do
user_1 = Fabricate(:user, username: "jonah", trust_level: 2)
user_2 = Fabricate(:user, username: "jake", trust_level: 2)
user_3 = Fabricate(:user, username: "john", trust_level: 2)
user_4 = Fabricate(:user, username: "joseph", trust_level: 1)
user_5 = Fabricate(:user, username: "joanne", trust_level: 1)
user_6 = Fabricate(:user, username: "jerome", trust_level: 2)
topic_1 = Fabricate(:topic, user: user_1)
topic_2 = Fabricate(:topic, user: user_2)
topic_3 = Fabricate(:topic, user: user_3)
post_1 = Fabricate(:post, topic: topic_1, user: user_1)
post_2 = Fabricate(:post, topic: topic_2, user: user_2)
post_3 = Fabricate(:post, topic: topic_3, user: user_3)
3.times { UserAction.create!(user_id: user_4.id, target_post_id: post_1.id, action_type: UserAction::LIKE) }
6.times { UserAction.create!(user_id: user_5.id, target_post_id: post_2.id, action_type: UserAction::LIKE) }
9.times { UserAction.create!(user_id: user_6.id, target_post_id: post_3.id, action_type: UserAction::LIKE) }
end
it "with category filtering" do
report = Report.find('top_users_by_likes_received_from_inferior_trust_level')
expect(report.data.length).to eq(2)
expect(report.data[0][:username]).to eq("jake")
expect(report.data[1][:username]).to eq("jonah")
end
end
end
end