2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Admin::DashboardController do
|
2013-07-08 10:25:38 +08:00
|
|
|
before do
|
2013-08-03 06:31:25 +08:00
|
|
|
AdminDashboardData.stubs(:fetch_cached_stats).returns(reports: [])
|
2013-07-03 23:06:07 +08:00
|
|
|
Jobs::VersionCheck.any_instance.stubs(:execute).returns(true)
|
2013-07-08 10:25:38 +08:00
|
|
|
end
|
2013-03-15 06:26:12 +08:00
|
|
|
|
|
|
|
it "is a subclass of AdminController" do
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(Admin::DashboardController < Admin::AdminController).to eq(true)
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'while logged in as an admin' do
|
2019-05-07 11:12:20 +08:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2013-03-15 06:26:12 +08:00
|
|
|
|
2021-01-22 23:09:02 +08:00
|
|
|
def populate_new_features
|
|
|
|
sample_features = [
|
|
|
|
{ "id" => "1", "emoji" => "🤾", "title" => "Cool Beans", "description" => "Now beans are included", "created_at" => Time.zone.now - 40.minutes },
|
|
|
|
{ "id" => "2", "emoji" => "🙈", "title" => "Fancy Legumes", "description" => "Legumes too!", "created_at" => Time.zone.now - 20.minutes }
|
|
|
|
]
|
|
|
|
|
|
|
|
Discourse.redis.set('new_features', MultiJson.dump(sample_features))
|
|
|
|
end
|
|
|
|
|
2018-06-11 12:47:42 +08:00
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#index' do
|
2022-07-28 00:14:14 +08:00
|
|
|
context 'when version checking is enabled' do
|
2013-03-15 06:26:12 +08:00
|
|
|
before do
|
2017-07-07 14:09:14 +08:00
|
|
|
SiteSetting.version_checks = true
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns discourse version info' do
|
2018-06-11 12:47:42 +08:00
|
|
|
get "/admin/dashboard.json"
|
2017-08-31 12:06:56 +08:00
|
|
|
|
2018-06-07 16:11:09 +08:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 23:04:12 +08:00
|
|
|
expect(response.parsed_body['version_check']).to be_present
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-28 00:14:14 +08:00
|
|
|
context 'when version checking is disabled' do
|
2013-03-15 06:26:12 +08:00
|
|
|
before do
|
2017-07-07 14:09:14 +08:00
|
|
|
SiteSetting.version_checks = false
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return discourse version info' do
|
2018-06-11 12:47:42 +08:00
|
|
|
get "/admin/dashboard.json"
|
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 23:04:12 +08:00
|
|
|
json = response.parsed_body
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(json['version_check']).not_to be_present
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-30 03:48:26 +08:00
|
|
|
|
2018-06-11 12:47:42 +08:00
|
|
|
describe '#problems' do
|
2013-03-30 03:48:26 +08:00
|
|
|
context 'when there are no problems' do
|
|
|
|
before do
|
|
|
|
AdminDashboardData.stubs(:fetch_problems).returns([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty array' do
|
2018-06-11 12:47:42 +08:00
|
|
|
get "/admin/dashboard/problems.json"
|
2017-08-31 12:06:56 +08:00
|
|
|
|
2018-06-07 16:11:09 +08:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 23:04:12 +08:00
|
|
|
json = response.parsed_body
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(json['problems'].size).to eq(0)
|
2013-03-30 03:48:26 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are problems' do
|
|
|
|
before do
|
|
|
|
AdminDashboardData.stubs(:fetch_problems).returns(['Not enough awesome', 'Too much sass'])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an array of strings' do
|
2018-06-11 12:47:42 +08:00
|
|
|
get "/admin/dashboard/problems.json"
|
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 23:04:12 +08:00
|
|
|
json = response.parsed_body
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(json['problems'].size).to eq(2)
|
|
|
|
expect(json['problems'][0]).to be_a(String)
|
|
|
|
expect(json['problems'][1]).to be_a(String)
|
2013-03-30 03:48:26 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-01-22 23:09:02 +08:00
|
|
|
|
|
|
|
describe '#new_features' do
|
|
|
|
before do
|
|
|
|
Discourse.redis.del "new_features_last_seen_user_#{admin.id}"
|
|
|
|
Discourse.redis.del "new_features"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is empty by default' do
|
|
|
|
get "/admin/dashboard/new-features.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
json = response.parsed_body
|
|
|
|
expect(json['new_features']).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fails gracefully for invalid JSON' do
|
|
|
|
Discourse.redis.set("new_features", "INVALID JSON")
|
|
|
|
get "/admin/dashboard/new-features.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
json = response.parsed_body
|
|
|
|
expect(json['new_features']).to eq(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes new features when available' do
|
|
|
|
populate_new_features
|
|
|
|
|
|
|
|
get "/admin/dashboard/new-features.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
json = response.parsed_body
|
|
|
|
|
|
|
|
expect(json['new_features'].length).to eq(2)
|
|
|
|
expect(json['new_features'][0]["emoji"]).to eq("🙈")
|
|
|
|
expect(json['new_features'][0]["title"]).to eq("Fancy Legumes")
|
2021-02-11 02:12:04 +08:00
|
|
|
expect(json['has_unseen_features']).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'passes unseen feature state' do
|
|
|
|
populate_new_features
|
|
|
|
DiscourseUpdates.mark_new_features_as_seen(admin.id)
|
|
|
|
|
|
|
|
get "/admin/dashboard/new-features.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
json = response.parsed_body
|
|
|
|
|
|
|
|
expect(json['has_unseen_features']).to eq(false)
|
2021-01-22 23:09:02 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#mark_new_features_as_seen' do
|
|
|
|
it 'resets last seen for a given user' do
|
|
|
|
populate_new_features
|
|
|
|
put "/admin/dashboard/mark-new-features-as-seen.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(DiscourseUpdates.new_features_last_seen(admin.id)).not_to eq(nil)
|
2021-02-11 02:12:04 +08:00
|
|
|
expect(DiscourseUpdates.has_unseen_features?(admin.id)).to eq(false)
|
2021-01-22 23:09:02 +08:00
|
|
|
end
|
|
|
|
end
|
2013-03-15 06:26:12 +08:00
|
|
|
end
|
2013-07-08 10:25:38 +08:00
|
|
|
end
|