discourse/spec/jobs/call_discourse_hub_spec.rb
David Taylor de973de2b6
FIX: Handle boolean values in version check response (#38786)
Since our update to redis gem v5.x in March 2025, the CallDiscourseHub
job has been raising an error because it fails to store
`TrueClass`/`FalseClass` values which are returned from the API. This
means that new-version emails were not sent.

We don't have any need to store the `critical: true|false` values, so
this commit slices the response to only include the strings we need. It
also adds a spec which would've caught the error.
2026-03-23 15:39:38 +00:00

49 lines
1.5 KiB
Ruby

# frozen_string_literal: true
RSpec.describe Jobs::CallDiscourseHub do
describe "#execute" do
context "when `include_in_discourse_discover setting` enabled" do
it "calls `discover_enrollment` method in DiscourseHub" do
SiteSetting.version_checks = false
SiteSetting.include_in_discourse_discover = true
DiscourseHub.stubs(:discover_enrollment).returns(true)
described_class.new.execute({})
end
end
context "when version_checks enabled" do
before do
SiteSetting.version_checks = true
SiteSetting.include_in_discourse_discover = false
end
it "stores missing versions from the hub response" do
DiscourseHub.stubs(:discourse_version_check).returns(
{
"latestVersion" => "2026.3.1",
"criticalUpdates" => false,
"missingVersionsCount" => 2,
"versions" => [
{ "version" => "2026.3.1", "notes" => "Latest release", "critical" => true },
{ "version" => "2026.2.5", "notes" => "Security patch", "critical" => false },
],
},
)
described_class.new.execute({})
expect(DiscourseUpdates).to have_attributes(
latest_version: "2026.3.1",
missing_versions_count: 2,
missing_versions:
contain_exactly(
{ "version" => "2026.3.1", "notes" => "Latest release" },
{ "version" => "2026.2.5", "notes" => "Security patch" },
),
)
end
end
end
end