discourse-subscriptions/spec/serializers/site_serializer_spec.rb

35 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "rails_helper"
describe SiteSerializer do
2024-03-06 08:51:25 -05:00
fab!(:user)
let(:guardian) { Guardian.new(user) }
before do
Discourse.redis.del("subscriptions_goal_met_date")
SiteSetting.discourse_subscriptions_enabled = true
SiteSetting.discourse_subscriptions_campaign_enabled = true
end
2024-01-16 11:51:44 -05:00
it "is false if the goal_met date is < 7 days old" do
Discourse.redis.set("subscriptions_goal_met_date", 10.days.ago)
data = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
expect(data[:show_campaign_banner]).to be false
end
it "is true if the goal_met date is > 7 days old" do
Discourse.redis.set("subscriptions_goal_met_date", 1.days.ago)
data = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
expect(data[:show_campaign_banner]).to be true
end
it "fails gracefully if the goal_met date is invalid" do
Discourse.redis.set("subscriptions_goal_met_date", "bananas")
data = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
expect(data[:show_campaign_banner]).to be false
end
end