FIX: Support version in new feature payload (#11841)

Followup to 4f01ca87e3
This commit is contained in:
Penar Musaraj 2021-01-25 16:30:43 -05:00 committed by GitHub
parent 363dca5ddc
commit 568bad75c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -131,6 +131,10 @@ module DiscourseUpdates
entries.select! { |item| Time.zone.parse(item["created_at"]) > last_seen }
end
entries.select! do |item|
item["discourse_version"].nil? || Discourse.has_needed_version?(Discourse::VERSION::STRING, item["discourse_version"]) rescue nil
end
entries.sort { |item| Time.zone.parse(item["created_at"]) }
end

View File

@ -211,5 +211,25 @@ describe DiscourseUpdates do
expect(result.length).to eq(1)
expect(result[0]["title"]).to eq("Brand New Item")
end
it 'correctly shows features by Discourse version' do
features_with_versions = [
{ "emoji" => "🤾", "title" => "Bells", "created_at" => 40.minutes.ago },
{ "emoji" => "🙈", "title" => "Whistles", "created_at" => 20.minutes.ago, discourse_version: "2.6.0.beta1" },
{ "emoji" => "🙈", "title" => "Confetti", "created_at" => 15.minutes.ago, discourse_version: "2.7.0.beta2" },
{ "emoji" => "🤾", "title" => "Not shown yet", "created_at" => 10.minutes.ago, discourse_version: "2.7.0.beta5" },
{ "emoji" => "🤾", "title" => "Not shown yet (beta < stable)", "created_at" => 10.minutes.ago, discourse_version: "2.7.0" },
{ "emoji" => "🤾", "title" => "Ignore invalid version", "created_at" => 10.minutes.ago, discourse_version: "invalid-version" },
]
Discourse.redis.set('new_features', MultiJson.dump(features_with_versions))
DiscourseUpdates.stubs(:last_installed_version).returns("2.7.0.beta2")
result = DiscourseUpdates.unseen_new_features(admin.id)
expect(result.length).to eq(3)
expect(result[0]["title"]).to eq("Confetti")
expect(result[1]["title"]).to eq("Whistles")
expect(result[2]["title"]).to eq("Bells")
end
end
end