2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe UserActionsController do
|
2022-02-22 05:02:04 -06:00
|
|
|
describe "GET index" do
|
|
|
|
subject(:user_actions) { get "/user_actions.json", params: params }
|
2013-05-26 19:22:37 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
context "when 'username' is not specified" do
|
|
|
|
let(:params) { {} }
|
2013-05-26 20:02:58 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
it "fails" do
|
|
|
|
user_actions
|
|
|
|
expect(response).to have_http_status :bad_request
|
|
|
|
end
|
|
|
|
end
|
2013-05-26 19:22:37 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
context "when 'username' is specified" do
|
|
|
|
let(:username) { post.user.username }
|
|
|
|
let(:params) { { username: username } }
|
|
|
|
let(:actions) { response.parsed_body["user_actions"] }
|
|
|
|
let(:post) { create_post }
|
2013-05-26 19:22:37 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
before { UserActionManager.enable }
|
2015-04-21 13:36:46 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
it "renders list correctly" do
|
|
|
|
user_actions
|
|
|
|
expect(response).to have_http_status :ok
|
|
|
|
expect(actions.first).to include "acting_name" => post.user.name, "post_number" => 1
|
|
|
|
expect(actions.first).not_to include "email"
|
|
|
|
end
|
2019-01-15 20:40:16 -06:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
context "when 'acting_username' is provided" do
|
|
|
|
let(:user) { Fabricate(:user) }
|
2019-01-15 20:40:16 -06:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
before do
|
|
|
|
PostActionNotifier.enable
|
|
|
|
PostActionCreator.like(user, post)
|
|
|
|
params[:acting_username] = user.username
|
|
|
|
end
|
2019-01-15 20:40:16 -06:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
it "filters its results" do
|
|
|
|
user_actions
|
|
|
|
expect(response).to have_http_status :ok
|
|
|
|
expect(actions.first).to include "acting_username" => user.username
|
|
|
|
end
|
|
|
|
end
|
2019-01-15 20:40:16 -06:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
context "when user's profile is hidden" do
|
|
|
|
fab!(:post) { Fabricate(:post) }
|
2019-01-15 20:40:16 -06:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
before { post.user.user_option.update_column(:hide_profile_and_presence, true) }
|
2019-01-15 20:40:16 -06:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
context "when `allow_users_to_hide_profile` is disabled" do
|
|
|
|
before { SiteSetting.allow_users_to_hide_profile = false }
|
2019-01-15 20:40:16 -06:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
it "succeeds" do
|
|
|
|
user_actions
|
|
|
|
expect(response).to have_http_status :ok
|
|
|
|
end
|
|
|
|
end
|
2020-10-09 16:18:44 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
context "when `allow_users_to_hide_profile` is enabled" do
|
|
|
|
it "returns a 404" do
|
|
|
|
user_actions
|
|
|
|
expect(response).to have_http_status :not_found
|
|
|
|
end
|
|
|
|
end
|
2020-10-09 16:18:44 -05:00
|
|
|
end
|
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
context "when checking other users' activity" do
|
|
|
|
fab!(:another_user) { Fabricate(:user) }
|
2020-10-09 16:18:44 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
context "when user is anonymous" do
|
|
|
|
UserAction.private_types.each do |action_type|
|
|
|
|
action_name = UserAction.types.key(action_type)
|
|
|
|
it "cannot list other users' actions of type: #{action_name}" do
|
|
|
|
list_and_check(action_type, 404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when user is logged in" do
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
2020-10-09 16:18:44 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
before { sign_in(user) }
|
2021-09-29 07:24:28 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
UserAction.private_types.each do |action_type|
|
|
|
|
action_name = UserAction.types.key(action_type)
|
|
|
|
it "cannot list other users' actions of type: #{action_name}" do
|
|
|
|
list_and_check(action_type, 404)
|
|
|
|
end
|
|
|
|
end
|
2021-09-29 07:24:28 -05:00
|
|
|
end
|
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
context "when user is a moderator" do
|
|
|
|
fab!(:moderator) { Fabricate(:moderator) }
|
2021-09-29 07:24:28 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
before { sign_in(moderator) }
|
|
|
|
|
|
|
|
UserAction.private_types.each do |action_type|
|
|
|
|
action_name = UserAction.types.key(action_type)
|
|
|
|
it "cannot list other users' actions of type: #{action_name}" do
|
|
|
|
list_and_check(action_type, 404)
|
|
|
|
end
|
|
|
|
end
|
2021-09-29 07:24:28 -05:00
|
|
|
end
|
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
context "when user is an admin" do
|
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2021-09-29 07:24:28 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
before { sign_in(admin) }
|
|
|
|
|
|
|
|
UserAction.private_types.each do |action_type|
|
|
|
|
action_name = UserAction.types.key(action_type)
|
|
|
|
it "can list other users' actions of type: #{action_name}" do
|
|
|
|
list_and_check(action_type, 200)
|
|
|
|
end
|
|
|
|
end
|
2021-09-29 07:24:28 -05:00
|
|
|
end
|
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
def list_and_check(action_type, expected_response)
|
|
|
|
get "/user_actions.json", params: { filter: action_type, username: another_user.username }
|
2021-09-29 07:24:28 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
expect(response.status).to eq(expected_response)
|
2021-09-29 07:24:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
context "when bad data is provided" do
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
2021-09-29 07:24:28 -05:00
|
|
|
|
2022-02-22 05:02:04 -06:00
|
|
|
let(:params) { { filter: filter, username: username, offset: offset, limit: limit } }
|
|
|
|
let(:filter) { "1,2" }
|
|
|
|
let(:username) { user.username }
|
|
|
|
let(:offset) { "0" }
|
|
|
|
let(:limit) { "10" }
|
|
|
|
|
|
|
|
%i[filter username offset limit].each do |parameter|
|
|
|
|
context "when providing bad data for '#{parameter}'" do
|
|
|
|
let(parameter) { { bad: "data" } }
|
|
|
|
|
|
|
|
it "doesn't raise an error" do
|
|
|
|
user_actions
|
|
|
|
expect(response).not_to have_http_status :error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-09-29 07:24:28 -05:00
|
|
|
end
|
|
|
|
end
|
2013-05-26 19:22:37 -05:00
|
|
|
end
|
|
|
|
end
|