discourse/spec/services/problem_check/s3_cdn_spec.rb
Ted Johansson ea5c3a3bdc
DEV: Move non scheduled problem checks to classes (#26122)
In AdminDashboardData we have a bunch of problem checks implemented as methods on that class. This PR absolves it of the responsibility by promoting each of those checks to a first class ProblemCheck. This way each of them can have their own priority and arbitrary functionality can be isolated in its own class.

Think "extract class" refactoring over and over. Since they were all moved we can also get rid of the @@problem_syms class variable which was basically the old version of the registry now replaced by ProblemCheck.realtime.

In addition AdminDashboardData::Problem value object has been entirely replaced with the new ProblemCheck::Problem (with compatible API).

Lastly, I added some RSpec matchers to simplify testing of problem checks and provide helpful error messages when assertions fail.
2024-03-14 10:55:01 +08:00

43 lines
1.3 KiB
Ruby

# frozen_string_literal: true
RSpec.describe ProblemCheck::S3Cdn do
subject(:check) { described_class.new }
describe ".call" do
before do
GlobalSetting.stubs(use_s3?: globally_enabled)
SiteSetting.stubs(enable_s3_uploads?: locally_enabled)
SiteSetting::Upload.stubs(s3_cdn_url: cdn_url)
end
context "when S3 uploads are enabled" do
let(:globally_enabled) { false }
let(:locally_enabled) { true }
context "when CDN URL is configured" do
let(:cdn_url) { "https://cdn.codinghorror.com" }
it { expect(check).to be_chill_about_it }
end
context "when CDN URL is not configured" do
let(:cdn_url) { nil }
it do
expect(check).to have_a_problem.with_priority("low").with_message(
'The server is configured to upload files to S3, but there is no S3 CDN configured. This can lead to expensive S3 costs and slower site performance. <a href="https://meta.discourse.org/t/-/148916" target="_blank">See "Using Object Storage for Uploads" to learn more</a>.',
)
end
end
end
context "when S3 uploads are disabled" do
let(:globally_enabled) { false }
let(:locally_enabled) { false }
let(:cdn_url) { nil }
it { expect(check).to be_chill_about_it }
end
end
end