2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe UserActionsController do
|
2022-02-22 06:02:04 -05:00
|
|
|
describe "GET index" do
|
|
|
|
subject(:user_actions) { get "/user_actions.json", params: params }
|
2013-05-26 20:22:37 -04:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
context "when 'username' is not specified" do
|
|
|
|
let(:params) { {} }
|
2013-05-26 21:02:58 -04:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
it "fails" do
|
|
|
|
user_actions
|
|
|
|
expect(response).to have_http_status :bad_request
|
|
|
|
end
|
|
|
|
end
|
2013-05-26 20:22:37 -04:00
|
|
|
|
2022-02-22 06:02:04 -05: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 20:22:37 -04:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
before do
|
|
|
|
UserActionManager.enable
|
|
|
|
end
|
2015-04-21 14:36:46 -04:00
|
|
|
|
2022-02-22 06:02:04 -05: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 21:40:16 -05:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
context "when 'acting_username' is provided" do
|
|
|
|
let(:user) { Fabricate(:user) }
|
2019-01-15 21:40:16 -05:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
before do
|
|
|
|
PostActionNotifier.enable
|
|
|
|
PostActionCreator.like(user, post)
|
|
|
|
params[:acting_username] = user.username
|
|
|
|
end
|
2019-01-15 21:40:16 -05:00
|
|
|
|
2022-02-22 06:02:04 -05: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 21:40:16 -05:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
context "when user's profile is hidden" do
|
|
|
|
fab!(:post) { Fabricate(:post) }
|
2019-01-15 21:40:16 -05:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
before do
|
|
|
|
post.user.user_option.update_column(:hide_profile_and_presence, true)
|
|
|
|
end
|
2019-01-15 21:40:16 -05:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
context "when `allow_users_to_hide_profile` is disabled" do
|
|
|
|
before do
|
|
|
|
SiteSetting.allow_users_to_hide_profile = false
|
|
|
|
end
|
2019-01-15 21:40:16 -05:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
it "succeeds" do
|
|
|
|
user_actions
|
|
|
|
expect(response).to have_http_status :ok
|
|
|
|
end
|
|
|
|
end
|
2020-10-09 17:18:44 -04:00
|
|
|
|
2022-02-22 06:02:04 -05: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 17:18:44 -04:00
|
|
|
end
|
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
context "when checking other users' activity" do
|
|
|
|
fab!(:another_user) { Fabricate(:user) }
|
2020-10-09 17:18:44 -04:00
|
|
|
|
2022-02-22 06:02:04 -05: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 17:18:44 -04:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2021-09-29 08:24:28 -04:00
|
|
|
|
2022-02-22 06:02:04 -05: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 08:24:28 -04:00
|
|
|
end
|
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
context "when user is a moderator" do
|
|
|
|
fab!(:moderator) { Fabricate(:moderator) }
|
2021-09-29 08:24:28 -04:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
before do
|
|
|
|
sign_in(moderator)
|
|
|
|
end
|
|
|
|
|
|
|
|
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 08:24:28 -04:00
|
|
|
end
|
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
context "when user is an admin" do
|
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2021-09-29 08:24:28 -04:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
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 08:24:28 -04:00
|
|
|
end
|
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
def list_and_check(action_type, expected_response)
|
|
|
|
get "/user_actions.json", params: {
|
|
|
|
filter: action_type,
|
|
|
|
username: another_user.username
|
|
|
|
}
|
2021-09-29 08:24:28 -04:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
expect(response.status).to eq(expected_response)
|
2021-09-29 08:24:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
context "when bad data is provided" do
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
2021-09-29 08:24:28 -04:00
|
|
|
|
2022-02-22 06:02:04 -05:00
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
filter: filter,
|
|
|
|
username: username,
|
|
|
|
offset: offset,
|
|
|
|
limit: limit
|
|
|
|
}
|
|
|
|
end
|
|
|
|
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 08:24:28 -04:00
|
|
|
end
|
|
|
|
end
|
2013-05-26 20:22:37 -04:00
|
|
|
end
|
|
|
|
end
|