From 6f70af5e4210e8ea9a75b389717d07094520b549 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Fri, 4 Feb 2022 11:06:40 +0530 Subject: [PATCH] DEV: execute campaign refresh job only if stripe is configured. (#108) --- .../refresh_subscriptions_campaign_data.rb | 3 ++- ...efresh_subscriptions_campaign_data_spec.rb | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 spec/jobs/refresh_subscriptions_campaign_data_spec.rb diff --git a/app/jobs/scheduled/refresh_subscriptions_campaign_data.rb b/app/jobs/scheduled/refresh_subscriptions_campaign_data.rb index d691b60..46ef0a4 100644 --- a/app/jobs/scheduled/refresh_subscriptions_campaign_data.rb +++ b/app/jobs/scheduled/refresh_subscriptions_campaign_data.rb @@ -2,10 +2,11 @@ module ::Jobs class RefreshSubscriptionsCampaignData < ::Jobs::Scheduled + include ::DiscourseSubscriptions::Stripe every 30.minutes def execute(args) - return unless SiteSetting.discourse_subscriptions_campaign_enabled + return unless SiteSetting.discourse_subscriptions_campaign_enabled && is_stripe_configured? DiscourseSubscriptions::Campaign.new.refresh_data end end diff --git a/spec/jobs/refresh_subscriptions_campaign_data_spec.rb b/spec/jobs/refresh_subscriptions_campaign_data_spec.rb new file mode 100644 index 0000000..fd83234 --- /dev/null +++ b/spec/jobs/refresh_subscriptions_campaign_data_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Jobs::RefreshSubscriptionsCampaignData do + + before do + SiteSetting.discourse_subscriptions_campaign_enabled = true + end + + it 'should execute the job only if stripe is configured' do + DiscourseSubscriptions::Campaign.any_instance.expects(:refresh_data).once + described_class.new.execute({}) + + SiteSetting.discourse_subscriptions_public_key = "PUBLIC_KEY" + SiteSetting.discourse_subscriptions_secret_key = "SECRET_KEY" + described_class.new.execute({}) + end + +end