2020-11-30 22:20:10 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-12-04 08:06:33 +01:00
|
|
|
if ENV['SIMPLECOV']
|
|
|
|
require 'simplecov'
|
2019-12-09 09:14:31 +01:00
|
|
|
|
2020-12-04 08:06:33 +01:00
|
|
|
SimpleCov.start do
|
|
|
|
root "plugins/discourse-custom-wizard"
|
|
|
|
track_files "plugins/discourse-custom-wizard/**/*.rb"
|
2021-05-17 09:57:09 +02:00
|
|
|
add_filter { |src| src.filename =~ /(\/spec\/|\/db\/|plugin\.rb|api|gems)/ }
|
2021-03-11 06:38:12 +01:00
|
|
|
SimpleCov.minimum_coverage 80
|
2020-12-04 08:06:33 +01:00
|
|
|
end
|
2020-11-30 22:20:10 +01:00
|
|
|
end
|
|
|
|
|
2021-08-12 16:26:17 +02:00
|
|
|
require 'oj'
|
|
|
|
Oj.default_options = Oj.default_options.merge(cache_str: -1)
|
|
|
|
|
2021-03-11 06:38:12 +01:00
|
|
|
require 'rails_helper'
|
2021-10-05 11:07:20 +02:00
|
|
|
require 'webmock/rspec'
|
2021-09-07 14:06:13 +02:00
|
|
|
|
|
|
|
def get_wizard_fixture(path)
|
|
|
|
JSON.parse(
|
|
|
|
File.open(
|
|
|
|
"#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/#{path}.json"
|
|
|
|
).read
|
|
|
|
).with_indifferent_access
|
|
|
|
end
|
|
|
|
|
2021-09-24 11:58:42 +02:00
|
|
|
def authenticate_subscription
|
|
|
|
CustomWizard::Subscription::Authentication.any_instance.stubs(:active?).returns(true)
|
2021-09-07 14:06:13 +02:00
|
|
|
end
|
|
|
|
|
2021-09-14 05:33:16 +02:00
|
|
|
def enable_subscription
|
2021-09-24 11:58:42 +02:00
|
|
|
CustomWizard::Subscription.any_instance.stubs(:subscribed?).returns(true)
|
2021-09-07 14:06:13 +02:00
|
|
|
end
|
|
|
|
|
2021-09-24 11:58:42 +02:00
|
|
|
def disable_subscription
|
|
|
|
CustomWizard::Subscription.any_instance.stubs(:subscribed?).returns(false)
|
2021-09-07 14:06:13 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def valid_subscription
|
|
|
|
{
|
|
|
|
product_id: "prod_CBTNpi3fqWWkq0",
|
|
|
|
price_id: "price_id",
|
|
|
|
price_nickname: "business"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def invalid_subscription
|
|
|
|
{
|
|
|
|
product_id: "prod_CBTNpi3fqWWkq0",
|
|
|
|
price_id: "price_id"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def stub_subscription_request(status, subscription)
|
2021-09-24 11:58:42 +02:00
|
|
|
authenticate_subscription
|
|
|
|
sub = CustomWizard::Subscription.new
|
|
|
|
stub_request(:get, "https://#{sub.server}/subscription-server/user-subscriptions/#{sub.subscription_type}/#{sub.client_name}").to_return(status: status, body: { subscriptions: [subscription] }.to_json)
|
2021-09-07 14:06:13 +02:00
|
|
|
end
|