2021-07-15 16:05:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-12-29 07:35:06 -05:00
|
|
|
require "rails_helper"
|
2021-07-15 16:05:27 -04:00
|
|
|
|
|
|
|
describe SiteSerializer do
|
2022-12-29 07:35:06 -05:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
2021-07-15 16:05:27 -04:00
|
|
|
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
|
|
|
|
2022-12-29 07:35:06 -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)
|
2021-07-15 16:05:27 -04:00
|
|
|
data = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
|
|
|
|
|
|
|
expect(data[:show_campaign_banner]).to be false
|
|
|
|
end
|
|
|
|
|
2022-12-29 07:35:06 -05:00
|
|
|
it "is true if the goal_met date is > 7 days old" do
|
|
|
|
Discourse.redis.set("subscriptions_goal_met_date", 1.days.ago)
|
2021-07-15 16:05:27 -04:00
|
|
|
data = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
|
|
|
|
|
|
|
expect(data[:show_campaign_banner]).to be true
|
|
|
|
end
|
|
|
|
|
2022-12-29 07:35:06 -05:00
|
|
|
it "fails gracefully if the goal_met date is invalid" do
|
|
|
|
Discourse.redis.set("subscriptions_goal_met_date", "bananas")
|
2021-07-15 16:05:27 -04:00
|
|
|
data = described_class.new(Site.new(guardian), scope: guardian, root: false).as_json
|
|
|
|
expect(data[:show_campaign_banner]).to be false
|
|
|
|
end
|
|
|
|
end
|