2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-14 18:13:50 -06:00
|
|
|
RSpec.describe Admin::SearchLogsController do
|
2023-11-09 16:47:59 -06:00
|
|
|
fab!(:admin)
|
|
|
|
fab!(:moderator)
|
|
|
|
fab!(:user)
|
2017-11-14 18:13:50 -06:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
before { SearchLog.log(term: "ruby", search_type: :header, ip_address: "127.0.0.1") }
|
2017-11-14 18:13:50 -06:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
after { SearchLog.clear_debounce_cache! }
|
2018-04-22 21:00:37 -05:00
|
|
|
|
2022-07-27 05:21:10 -05:00
|
|
|
describe "#index" do
|
2022-11-02 22:42:44 -05:00
|
|
|
shared_examples "search logs accessible" do
|
|
|
|
it "returns search logs" do
|
2023-01-09 05:18:21 -06:00
|
|
|
get "/admin/logs/search_logs.json"
|
2017-11-14 18:13:50 -06:00
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
json = response.parsed_body
|
|
|
|
expect(json[0]["term"]).to eq("ruby")
|
|
|
|
expect(json[0]["searches"]).to eq(1)
|
|
|
|
expect(json[0]["ctr"]).to eq(0)
|
|
|
|
end
|
2017-11-14 18:13:50 -06:00
|
|
|
end
|
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
context "when logged in as an admin" do
|
|
|
|
before { sign_in(admin) }
|
|
|
|
|
|
|
|
include_examples "search logs accessible"
|
|
|
|
end
|
2017-11-14 18:13:50 -06:00
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
context "when logged in as a moderator" do
|
|
|
|
before { sign_in(moderator) }
|
2017-11-14 18:13:50 -06:00
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
include_examples "search logs accessible"
|
2017-11-14 18:13:50 -06:00
|
|
|
end
|
2022-10-31 07:02:26 -05:00
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
context "when logged in as a non-staff user" do
|
2023-01-09 05:18:21 -06:00
|
|
|
before { sign_in(user) }
|
2022-10-31 07:02:26 -05:00
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
it "denies access with a 404 response" do
|
|
|
|
get "/admin/logs/search_logs.json"
|
2022-10-31 07:02:26 -05:00
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
|
|
|
|
end
|
2022-10-31 07:02:26 -05:00
|
|
|
end
|
2017-11-14 18:13:50 -06:00
|
|
|
end
|
2017-12-19 20:41:31 -06:00
|
|
|
|
2022-07-27 05:21:10 -05:00
|
|
|
describe "#term" do
|
2022-11-02 22:42:44 -05:00
|
|
|
shared_examples "search log term accessible" do
|
|
|
|
it "returns search log term" do
|
2023-01-09 05:18:21 -06:00
|
|
|
get "/admin/logs/search_logs/term.json", params: { term: "ruby" }
|
2022-11-02 22:42:44 -05:00
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
json = response.parsed_body
|
2023-01-09 05:18:21 -06:00
|
|
|
expect(json["term"]["type"]).to eq("search_log_term")
|
|
|
|
expect(json["term"]["search_result"]).to be_present
|
2022-11-02 22:42:44 -05:00
|
|
|
end
|
2017-12-19 20:41:31 -06:00
|
|
|
end
|
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
context "when logged in as an admin" do
|
|
|
|
before { sign_in(admin) }
|
2019-03-28 20:48:20 -05:00
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
include_examples "search log term accessible"
|
2017-12-19 20:41:31 -06:00
|
|
|
end
|
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
context "when logged in as a moderator" do
|
|
|
|
before { sign_in(moderator) }
|
2017-12-19 20:41:31 -06:00
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
include_examples "search log term accessible"
|
2017-12-19 20:41:31 -06:00
|
|
|
end
|
2022-10-31 07:02:26 -05:00
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
context "when logged in as a non-staff user" do
|
2023-01-09 05:18:21 -06:00
|
|
|
before { sign_in(user) }
|
2022-10-31 07:02:26 -05:00
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
it "denies access with a 404 response" do
|
2023-01-09 05:18:21 -06:00
|
|
|
get "/admin/logs/search_logs/term.json", params: { term: "ruby" }
|
2022-10-31 07:02:26 -05:00
|
|
|
|
2022-11-02 22:42:44 -05:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
|
|
|
|
end
|
2022-10-31 07:02:26 -05:00
|
|
|
end
|
2017-12-19 20:41:31 -06:00
|
|
|
end
|
2017-11-14 18:13:50 -06:00
|
|
|
end
|