2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-03-14 18:26:12 -04:00
|
|
|
|
|
|
|
describe Admin::DashboardController do
|
2013-07-07 22:25:38 -04:00
|
|
|
before do
|
2013-08-02 18:31:25 -04:00
|
|
|
AdminDashboardData.stubs(:fetch_cached_stats).returns(reports: [])
|
2013-07-03 11:06:07 -04:00
|
|
|
Jobs::VersionCheck.any_instance.stubs(:execute).returns(true)
|
2013-07-07 22:25:38 -04:00
|
|
|
end
|
2013-03-14 18:26:12 -04:00
|
|
|
|
|
|
|
it "is a subclass of AdminController" do
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(Admin::DashboardController < Admin::AdminController).to eq(true)
|
2013-03-14 18:26:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'while logged in as an admin' do
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2013-03-14 18:26:12 -04:00
|
|
|
|
2018-06-11 00:47:42 -04:00
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#index' do
|
2013-03-14 18:26:12 -04:00
|
|
|
context 'version checking is enabled' do
|
|
|
|
before do
|
2017-07-07 02:09:14 -04:00
|
|
|
SiteSetting.version_checks = true
|
2013-03-14 18:26:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns discourse version info' do
|
2018-06-11 00:47:42 -04:00
|
|
|
get "/admin/dashboard.json"
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 11:04:12 -04:00
|
|
|
expect(response.parsed_body['version_check']).to be_present
|
2013-03-14 18:26:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'version checking is disabled' do
|
|
|
|
before do
|
2017-07-07 02:09:14 -04:00
|
|
|
SiteSetting.version_checks = false
|
2013-03-14 18:26:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return discourse version info' do
|
2018-06-11 00:47:42 -04:00
|
|
|
get "/admin/dashboard.json"
|
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 11:04:12 -04:00
|
|
|
json = response.parsed_body
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(json['version_check']).not_to be_present
|
2013-03-14 18:26:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-29 15:48:26 -04:00
|
|
|
|
2018-06-11 00:47:42 -04:00
|
|
|
describe '#problems' do
|
2013-03-29 15:48:26 -04: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 00:47:42 -04:00
|
|
|
get "/admin/dashboard/problems.json"
|
2017-08-31 00:06:56 -04:00
|
|
|
|
2018-06-07 04:11:09 -04:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 11:04:12 -04:00
|
|
|
json = response.parsed_body
|
2015-01-09 12:04:02 -05:00
|
|
|
expect(json['problems'].size).to eq(0)
|
2013-03-29 15:48:26 -04: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 00:47:42 -04:00
|
|
|
get "/admin/dashboard/problems.json"
|
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 11:04:12 -04:00
|
|
|
json = response.parsed_body
|
2015-01-09 12:04:02 -05: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-29 15:48:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-03-14 18:26:12 -04:00
|
|
|
end
|
2013-07-07 22:25:38 -04:00
|
|
|
end
|