2024-02-08 21:52:22 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe ApplicationController do
|
|
|
|
fab!(:user)
|
|
|
|
fab!(:admin)
|
|
|
|
|
|
|
|
def preloaded_json
|
|
|
|
JSON.parse(
|
|
|
|
Nokogiri::HTML5.fragment(response.body).css("div#data-preloaded").first["data-preloaded"],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.chat_enabled = true
|
|
|
|
SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when user is admin" do
|
2024-03-13 21:28:08 -04:00
|
|
|
it "has correctly loaded preloaded data for visiblePlugins" do
|
2024-02-08 21:52:22 -05:00
|
|
|
sign_in(admin)
|
|
|
|
get "/latest"
|
2024-03-13 21:28:08 -04:00
|
|
|
expect(JSON.parse(preloaded_json["visiblePlugins"])).to include(
|
|
|
|
{
|
|
|
|
"name" => "chat",
|
|
|
|
"admin_route" => {
|
|
|
|
"label" => "chat.admin.title",
|
|
|
|
"location" => "chat",
|
|
|
|
"use_new_show_route" => false,
|
|
|
|
},
|
|
|
|
"enabled" => true,
|
|
|
|
},
|
2024-02-08 21:52:22 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when user is not admin" do
|
2024-03-13 21:28:08 -04:00
|
|
|
it "does not include preloaded data for visiblePlugins" do
|
2024-02-08 21:52:22 -05:00
|
|
|
sign_in(user)
|
|
|
|
get "/latest"
|
2024-03-13 21:28:08 -04:00
|
|
|
expect(preloaded_json["visiblePlugins"]).to eq(nil)
|
2024-02-08 21:52:22 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|