Commit c67779e3 authored by Corinna Wiesner's avatar Corinna Wiesner

Refactor CustomersDot url

Move remaining urls for CustomersDot into methods in
Gitlab::SubscriptionPortal and refactor all specs for that class.
parent b52f21df
......@@ -3,7 +3,7 @@ class Admin::InstanceReviewController < Admin::ApplicationController
feature_category :devops_reports
def index
redirect_to("#{::Gitlab::SubscriptionPortal::SUBSCRIPTIONS_URL}/instance_review?#{instance_review_params}")
redirect_to("#{Gitlab::SubscriptionPortal.subscriptions_instance_review_url}?#{instance_review_params}")
end
def instance_review_params
......
......@@ -7,10 +7,8 @@ module CustomersDot
feature_category :purchase
BASE_URL = Gitlab::SubscriptionPortal::SUBSCRIPTIONS_URL
def graphql
response = Gitlab::HTTP.post("#{BASE_URL}/graphql",
response = Gitlab::HTTP.post(EE::SUBSCRIPTIONS_GRAPHQL_URL,
body: request.raw_post,
headers: forward_headers
)
......
......@@ -43,7 +43,7 @@ module BillingPlansHelper
add_seats_href: add_seats_url(namespace),
plan_upgrade_href: plan_upgrade_url(namespace, plan),
plan_renew_href: plan_renew_url(namespace),
customer_portal_url: "#{EE::SUBSCRIPTIONS_URL}/subscriptions",
customer_portal_url: EE::SUBSCRIPTIONS_MANAGE_URL,
billable_seats_href: billable_seats_href(namespace),
plan_name: plan&.name,
free_personal_namespace: namespace.free_personal?.to_s
......@@ -147,19 +147,19 @@ module BillingPlansHelper
def add_seats_url(group)
return unless group
"#{EE::SUBSCRIPTIONS_URL}/gitlab/namespaces/#{group.id}/extra_seats"
::Gitlab::SubscriptionPortal.add_extra_seats_url(group.id)
end
def plan_upgrade_url(group, plan)
return unless group && plan&.id
"#{EE::SUBSCRIPTIONS_URL}/gitlab/namespaces/#{group.id}/upgrade/#{plan.id}"
::Gitlab::SubscriptionPortal.upgrade_subscription_url(group.id, plan.id)
end
def plan_renew_url(group)
return unless group
"#{EE::SUBSCRIPTIONS_URL}/gitlab/namespaces/#{group.id}/renew"
::Gitlab::SubscriptionPortal.renew_subscription_url(group.id)
end
def billable_seats_href(namespace)
......
......@@ -24,11 +24,11 @@ module EE
def renew_subscription_path
return plan_renew_url(current_namespace) if decorated_subscription
"#{EE::SUBSCRIPTIONS_URL}/subscriptions"
SUBSCRIPTIONS_MANAGE_URL
end
def upgrade_subscription_path
"#{EE::SUBSCRIPTIONS_URL}/subscriptions"
SUBSCRIPTIONS_MANAGE_URL
end
def link_to_button_style(path:, track_property:)
......
# frozen_string_literal: true
module GitlabSubscriptions
class FetchSubscriptionPlansService
URL = "#{EE::SUBSCRIPTIONS_URL}/gitlab_plans"
def initialize(plan:, namespace_id: nil)
@plan = plan
@namespace_id = namespace_id
......@@ -16,7 +14,7 @@ module GitlabSubscriptions
def send_request
response = Gitlab::HTTP.get(
URL,
EE::SUBSCRIPTIONS_GITLAB_PLANS_URL,
allow_local_requests: true,
query: { plan: @plan, namespace_id: @namespace_id },
headers: { 'Accept' => 'application/json' }
......
......@@ -24,7 +24,7 @@
= s_('Promotions|When you have a lot of issues, it can be hard to get an overview. By adding a weight to your issues, you can get a better idea of the effort, cost, required time, or value of each, and so better manage them.')
%p
- if Gitlab::CurrentSettings.should_check_namespace_plan?
- subscription_link_url = "#{EE::SUBSCRIPTIONS_URL}/plans"
- subscription_link_url = EE::SUBSCRIPTIONS_PLANS_URL
- subscription_link_start = '<a href="%{url}" target="_blank" class="btn-link tr-issue-weights-bronze-features-cta">'.html_safe % { url: subscription_link_url }
= s_("Promotions|See the other features in the %{subscription_link_start}Premium plan%{subscription_link_end}").html_safe % { subscription_link_start: subscription_link_start, subscription_link_end: '</a>'.html_safe }
- else
......
......@@ -8,6 +8,7 @@ module EE
SUBSCRIPTIONS_MORE_STORAGE_URL = ::Gitlab::SubscriptionPortal.subscriptions_more_storage_url.freeze
SUBSCRIPTIONS_MANAGE_URL = ::Gitlab::SubscriptionPortal.subscriptions_manage_url.freeze
SUBSCRIPTIONS_PLANS_URL = ::Gitlab::SubscriptionPortal.subscriptions_plans_url.freeze
SUBSCRIPTIONS_GITLAB_PLANS_URL = ::Gitlab::SubscriptionPortal.subscriptions_gitlab_plans_url.freeze
SUBSCRIPTION_PORTAL_ADMIN_EMAIL = ::Gitlab::SubscriptionPortal.subscription_portal_admin_email.freeze
SUBSCRIPTION_PORTAL_ADMIN_TOKEN = ::Gitlab::SubscriptionPortal.subscription_portal_admin_token.freeze
CUSTOMER_SUPPORT_URL = ::Gitlab::Saas.customer_support_url.freeze
......
......@@ -24,7 +24,7 @@ RSpec.describe 'Billings > Extend / Reactivate Trial', :js do
stub_ee_application_setting(should_check_namespace_plan: true)
stub_feature_flags(allow_extend_reactivate_trial: true)
stub_billing_plans(nil)
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?plan=#{plan.name}&namespace_id=#{group.id}")
stub_full_request("#{EE::SUBSCRIPTIONS_GITLAB_PLANS_URL}?plan=#{plan.name}&namespace_id=#{group.id}")
.to_return(status: 200, body: plans_data.to_json)
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/trials/extend_reactivate_trial", method: :put)
.to_return(status: 200)
......
......@@ -20,7 +20,7 @@ RSpec.describe 'Billings > Qrtly Reconciliation Alert', :js do
before do
stub_ee_application_setting(should_check_namespace_plan: true)
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?plan=#{plan.name}&namespace_id=#{namespace.id}")
stub_full_request("#{EE::SUBSCRIPTIONS_GITLAB_PLANS_URL}?plan=#{plan.name}&namespace_id=#{namespace.id}")
.to_return(status: 200, body: plans_data.to_json)
sign_in(user)
end
......
......@@ -58,7 +58,7 @@ RSpec.describe 'Groups > Billing', :js do
expect(page).to have_content("#{group.name} is currently using the Free Plan")
within subscription_table do
expect(page).to have_content("start date #{formatted_date(subscription.start_date)}")
expect(page).to have_link("Upgrade", href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions")
expect(page).to have_link("Upgrade", href: EE::SUBSCRIPTIONS_MANAGE_URL)
expect(page).not_to have_link("Manage")
end
end
......@@ -85,7 +85,7 @@ RSpec.describe 'Groups > Billing', :js do
within subscription_table do
expect(page).to have_content("start date #{formatted_date(subscription.start_date)}")
expect(page).to have_link("Upgrade", href: upgrade_url)
expect(page).to have_link("Manage", href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions")
expect(page).to have_link("Manage", href: EE::SUBSCRIPTIONS_MANAGE_URL)
expect(page).to have_link("Add seats", href: extra_seats_url)
expect(page).to have_link("Renew", href: renew_url)
expect(page).to have_link("See usage", href: group_usage_quotas_path(group, anchor: 'seats-quota-tab'))
......@@ -122,7 +122,7 @@ RSpec.describe 'Groups > Billing', :js do
expect(page).to have_content("#{group.name} is currently using the Bronze Plan")
within subscription_table do
expect(page).not_to have_link("Upgrade")
expect(page).to have_link("Manage", href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions")
expect(page).to have_link("Manage", href: EE::SUBSCRIPTIONS_MANAGE_URL)
end
end
end
......
......@@ -12,7 +12,7 @@ RSpec.describe 'Welcome screen', :js do
before do
group.add_owner(user)
gitlab_sign_in(user)
stub_request(:get, "#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?plan=free&namespace_id=")
stub_request(:get, "#{EE::SUBSCRIPTIONS_GITLAB_PLANS_URL}?plan=free&namespace_id=")
.to_return(status: 200, body: '{}', headers: {})
visit edit_subscriptions_group_path(group.path, params)
......
......@@ -7,7 +7,7 @@ RSpec.describe BillingPlansHelper do
describe '#subscription_plan_data_attributes' do
let(:group) { build(:group) }
let(:customer_portal_url) { "#{EE::SUBSCRIPTIONS_URL}/subscriptions" }
let(:customer_portal_url) { EE::SUBSCRIPTIONS_MANAGE_URL }
let(:add_seats_href) { "#{EE::SUBSCRIPTIONS_URL}/gitlab/namespaces/#{group.id}/extra_seats" }
let(:plan_renew_href) { "#{EE::SUBSCRIPTIONS_URL}/gitlab/namespaces/#{group.id}/renew" }
let(:billable_seats_href) { helper.group_usage_quotas_path(group, anchor: 'seats-quota-tab') }
......
......@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe CustomersDot::ProxyController, type: :request do
describe 'POST graphql' do
let_it_be(:customers_dot) { "#{Gitlab::SubscriptionPortal::SUBSCRIPTIONS_URL}/graphql" }
let_it_be(:customers_dot) { ::EE::SUBSCRIPTIONS_GRAPHQL_URL }
let_it_be(:default_headers) { { 'Content-Type' => 'application/json' } }
shared_examples 'customersdot proxy' do
......
......@@ -6,7 +6,7 @@ RSpec.describe GitlabSubscriptions::FetchSubscriptionPlansService do
describe '#execute' do
subject(:execute_service) { described_class.new(plan: plan).execute }
let(:endpoint_url) { "#{EE::SUBSCRIPTIONS_URL}/gitlab_plans" }
let(:endpoint_url) { EE::SUBSCRIPTIONS_GITLAB_PLANS_URL }
let(:plan) { 'bronze' }
let(:response_mock) { double(body: [{ 'foo' => 'bar' }].to_json) }
......
......@@ -4,7 +4,7 @@ module SubscriptionPortalHelpers
include StubRequests
def stub_eoa_eligibility_request(namespace_id, eligible = false, free_upgrade_plan_id = nil, assisted_upgrade_plan_id = nil)
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/graphql", method: :post)
stub_full_request(EE::SUBSCRIPTIONS_GRAPHQL_URL, method: :post)
.with(
body: "{\"query\":\"{\\n subscription(namespaceId: \\\"#{namespace_id}\\\") {\\n eoaStarterBronzeEligible\\n assistedUpgradePlanId\\n freeUpgradePlanId\\n }\\n}\\n\"}",
headers: {
......@@ -28,7 +28,7 @@ module SubscriptionPortalHelpers
end
def stub_billing_plans(namespace_id, plan = 'free', plans_data = nil, raise_error: nil)
stub = stub_full_request("#{EE::SUBSCRIPTIONS_URL}/gitlab_plans?namespace_id=#{namespace_id}&plan=#{plan}")
stub = stub_full_request("#{EE::SUBSCRIPTIONS_GITLAB_PLANS_URL}?namespace_id=#{namespace_id}&plan=#{plan}")
.with(headers: { 'Accept' => 'application/json' })
if raise_error
stub.to_raise(raise_error)
......
......@@ -38,6 +38,26 @@ module Gitlab
"#{self.subscriptions_url}/plans"
end
def self.subscriptions_gitlab_plans_url
"#{self.subscriptions_url}/gitlab_plans"
end
def self.subscriptions_instance_review_url
"#{self.subscriptions_url}/instance_review"
end
def self.add_extra_seats_url(group_id)
"#{self.subscriptions_url}/gitlab/namespaces/#{group_id}/extra_seats"
end
def self.upgrade_subscription_url(group_id, plan_id)
"#{self.subscriptions_url}/gitlab/namespaces/#{group_id}/upgrade/#{plan_id}"
end
def self.renew_subscription_url(group_id)
"#{self.subscriptions_url}/gitlab/namespaces/#{group_id}/renew"
end
def self.subscription_portal_admin_email
ENV.fetch('SUBSCRIPTION_PORTAL_ADMIN_EMAIL', 'gl_com_api@gitlab.com')
end
......
......@@ -6,7 +6,7 @@ RSpec.describe Admin::InstanceReviewController do
include UsageDataHelpers
let(:admin) { create(:admin) }
let(:subscriptions_url) { ::Gitlab::SubscriptionPortal::SUBSCRIPTIONS_URL }
let(:subscriptions_instance_review_url) { Gitlab::SubscriptionPortal.subscriptions_instance_review_url }
before do
sign_in(admin)
......@@ -44,7 +44,7 @@ RSpec.describe Admin::InstanceReviewController do
notes_count: 0
} }.to_query
expect(response).to redirect_to("#{subscriptions_url}/instance_review?#{params}")
expect(response).to redirect_to("#{subscriptions_instance_review_url}?#{params}")
end
end
......@@ -61,7 +61,7 @@ RSpec.describe Admin::InstanceReviewController do
version: ::Gitlab::VERSION
} }.to_query
expect(response).to redirect_to("#{subscriptions_url}/instance_review?#{params}")
expect(response).to redirect_to("#{subscriptions_instance_review_url}?#{params}")
end
end
end
......
......@@ -5,23 +5,88 @@ require 'spec_helper'
RSpec.describe ::Gitlab::SubscriptionPortal do
using RSpec::Parameterized::TableSyntax
where(:method_name, :test, :development, :result) do
:default_subscriptions_url | false | false | 'https://customers.gitlab.com'
:default_subscriptions_url | false | true | 'https://customers.stg.gitlab.com'
:default_subscriptions_url | true | false | 'https://customers.stg.gitlab.com'
:payment_form_url | false | false | 'https://customers.gitlab.com/payment_forms/cc_validation'
:payment_form_url | false | true | 'https://customers.stg.gitlab.com/payment_forms/cc_validation'
:payment_form_url | true | false | 'https://customers.stg.gitlab.com/payment_forms/cc_validation'
let(:env_value) { nil }
before do
stub_env('CUSTOMER_PORTAL_URL', env_value)
end
with_them do
subject { described_class.method(method_name).call }
describe '.default_subscriptions_url' do
where(:test, :development, :result) do
false | false | 'https://customers.gitlab.com'
false | true | 'https://customers.stg.gitlab.com'
true | false | 'https://customers.stg.gitlab.com'
end
before do
allow(Rails).to receive_message_chain(:env, :test?).and_return(test)
allow(Rails).to receive_message_chain(:env, :development?).and_return(development)
end
it { is_expected.to eq(result) }
with_them do
subject { described_class.default_subscriptions_url }
it { is_expected.to eq(result) }
end
end
describe '.subscriptions_url' do
subject { described_class.subscriptions_url }
context 'when CUSTOMER_PORTAL_URL ENV is unset' do
it { is_expected.to eq('https://customers.stg.gitlab.com') }
end
context 'when CUSTOMER_PORTAL_URL ENV is set' do
let(:env_value) { 'https://customers.example.com' }
it { is_expected.to eq(env_value) }
end
end
context 'url methods' do
where(:method_name, :result) do
:default_subscriptions_url | 'https://customers.stg.gitlab.com'
:payment_form_url | 'https://customers.stg.gitlab.com/payment_forms/cc_validation'
:subscriptions_graphql_url | 'https://customers.stg.gitlab.com/graphql'
:subscriptions_more_minutes_url | 'https://customers.stg.gitlab.com/buy_pipeline_minutes'
:subscriptions_more_storage_url | 'https://customers.stg.gitlab.com/buy_storage'
:subscriptions_manage_url | 'https://customers.stg.gitlab.com/subscriptions'
:subscriptions_plans_url | 'https://customers.stg.gitlab.com/plans'
:subscriptions_instance_review_url | 'https://customers.stg.gitlab.com/instance_review'
:subscriptions_gitlab_plans_url | 'https://customers.stg.gitlab.com/gitlab_plans'
:subscriptions_comparison_url | 'https://about.gitlab.com/pricing/gitlab-com/feature-comparison'
end
with_them do
subject { described_class.send(method_name) }
it { is_expected.to eq(result) }
end
end
describe '.self.add_extra_seats_url' do
subject { described_class.add_extra_seats_url(group_id) }
let(:group_id) { 153 }
it { is_expected.to eq("https://customers.stg.gitlab.com/gitlab/namespaces/#{group_id}/extra_seats") }
end
describe '.self.upgrade_subscription_url' do
subject { described_class.upgrade_subscription_url(group_id, plan_id) }
let(:group_id) { 153 }
let(:plan_id) { 5 }
it { is_expected.to eq("https://customers.stg.gitlab.com/gitlab/namespaces/#{group_id}/upgrade/#{plan_id}") }
end
describe '.self.renew_subscription_url' do
subject { described_class.renew_subscription_url(group_id) }
let(:group_id) { 153 }
it { is_expected.to eq("https://customers.stg.gitlab.com/gitlab/namespaces/#{group_id}/renew") }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment