discourse/spec/requests/admin/search_logs_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

87 lines
2.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-11-15 08:13:50 +08:00
RSpec.describe Admin::SearchLogsController do
fab!(:admin)
fab!(:moderator)
fab!(:user)
2017-11-15 08:13:50 +08:00
before { SearchLog.log(term: "ruby", search_type: :header, ip_address: "127.0.0.1") }
2017-11-15 08:13:50 +08:00
after { SearchLog.clear_debounce_cache! }
describe "#index" do
shared_examples "search logs accessible" do
it "returns search logs" do
get "/admin/logs/search_logs.json"
2017-11-15 08:13:50 +08: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-15 08:13:50 +08:00
end
context "when logged in as an admin" do
before { sign_in(admin) }
include_examples "search logs accessible"
end
2017-11-15 08:13:50 +08:00
context "when logged in as a moderator" do
before { sign_in(moderator) }
2017-11-15 08:13:50 +08:00
include_examples "search logs accessible"
2017-11-15 08:13:50 +08:00
end
context "when logged in as a non-staff user" do
before { sign_in(user) }
it "denies access with a 404 response" do
get "/admin/logs/search_logs.json"
expect(response.status).to eq(404)
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
end
end
2017-11-15 08:13:50 +08:00
end
describe "#term" do
shared_examples "search log term accessible" do
it "returns search log term" do
get "/admin/logs/search_logs/term.json", params: { term: "ruby" }
expect(response.status).to eq(200)
json = response.parsed_body
expect(json["term"]["type"]).to eq("search_log_term")
expect(json["term"]["search_result"]).to be_present
end
end
context "when logged in as an admin" do
before { sign_in(admin) }
include_examples "search log term accessible"
end
context "when logged in as a moderator" do
before { sign_in(moderator) }
include_examples "search log term accessible"
end
context "when logged in as a non-staff user" do
before { sign_in(user) }
it "denies access with a 404 response" do
get "/admin/logs/search_logs/term.json", params: { term: "ruby" }
expect(response.status).to eq(404)
expect(response.parsed_body["errors"]).to include(I18n.t("not_found"))
end
end
end
2017-11-15 08:13:50 +08:00
end