Commit 94360ae0 authored by Michael Lunøe's avatar Michael Lunøe Committed by Markus Koller

Revert "Merge branch '323357-mlunoe-subscription-plans-service' into 'master'"

This reverts commit 636c36aa, reversing
changes made to ce6ed97f.
parent c765eb69
......@@ -8,7 +8,6 @@ module SubscriptionsHelper
setup_for_company: (current_user.setup_for_company == true).to_s,
full_name: current_user.name,
available_plans: subscription_available_plans.to_json,
ci_minutes_plans: ci_minutes_plans.to_json,
plan_id: params[:plan_id],
namespace_id: params[:namespace_id],
new_user: new_user?.to_s,
......@@ -44,26 +43,6 @@ module SubscriptionsHelper
plans_data.reject { |plan_data| plan_data[:deprecated] }
end
def ci_minutes_plans
return if ::Feature.disabled?(:new_route_ci_minutes_purchase, default_enabled: :yaml)
strong_memoize(:ci_minutes_plans) do
fields = %w[
name
code
active
free
price_per_month
price_per_year
features
about_page_href
hide_deprecated_card
]
Gitlab::SubscriptionPortal::Client.plan_data("CI_1000_MINUTES_PLAN", fields)[:plans]
end
end
def present_groups(groups)
groups.map do |namespace|
{
......
......@@ -57,7 +57,7 @@ module Gitlab
}
GQL
response = execute_graphql_query({ query: query })[:data]
response = execute_graphql_query({ query: query }).dig(:data)
if response['errors'].blank?
eligible = response.dig('data', 'subscription', 'eoaStarterBronzeEligible')
......@@ -75,31 +75,6 @@ module Gitlab
end
end
def plan_data(plan_tags, fields)
query = <<~GQL
query($tags: [PlanTag!]) {
plans(planTags: $tags) {
deprecated
#{(fields - ['deprecated']).map { |field| "#{field}: #{field.to_s.camelize(:lower)}" }.join(" ")}
}
}
GQL
response = execute_graphql_query({ query: query, variables: { tags: plan_tags } })[:data]
if response['errors'].present?
track_error(query, response)
return error
end
{
success: true,
plans: response.dig('data', 'plans')
.reject { |plan| plan['deprecated'] }
}
end
def subscription_last_term(namespace_id)
return error('Must provide a namespace ID') unless namespace_id
......
......@@ -3,17 +3,13 @@
require 'spec_helper'
RSpec.describe 'Subscriptions Content Security Policy' do
include SubscriptionPortalHelpers
subject { response_headers['Content-Security-Policy'] }
let_it_be(:default_csp_values) { "'self' https://some-cdn.test" }
let_it_be(:zuora_url) { 'https://*.zuora.com' }
let(:plan_tags) { 'CI_1000_MINUTES_PLAN' }
before do
stub_request(:get, /.*gitlab_plans.*/).to_return(status: 200, body: "{}")
stub_plan_data_request(plan_tags)
expect_next_instance_of(SubscriptionsController) do |controller|
expect(controller).to receive(:current_content_security_policy).and_return(csp)
......
......@@ -3,8 +3,6 @@
require 'spec_helper'
RSpec.describe SubscriptionsHelper do
include SubscriptionPortalHelpers
using RSpec::Parameterized::TableSyntax
let_it_be(:free_plan) do
......@@ -25,15 +23,12 @@ RSpec.describe SubscriptionsHelper do
[free_plan, bronze_plan]
end
let(:plan_tags) { 'CI_1000_MINUTES_PLAN' }
before do
stub_feature_flags(hide_deprecated_billing_plans: false)
allow(helper).to receive(:params).and_return(plan_id: 'bronze_id', namespace_id: nil)
allow_next_instance_of(GitlabSubscriptions::FetchSubscriptionPlansService) do |instance|
allow(instance).to receive(:execute).and_return(raw_plan_data)
end
stub_plan_data_request(plan_tags)
end
describe '#subscription_data' do
......@@ -53,7 +48,6 @@ RSpec.describe SubscriptionsHelper do
it { is_expected.to include(setup_for_company: 'false') }
it { is_expected.to include(full_name: 'First Last') }
it { is_expected.to include(available_plans: '[{"id":"bronze_id","code":"bronze","price_per_year":48.0,"name":"Bronze Plan"}]') }
it { is_expected.to include(ci_minutes_plans: '[{"name":"1000 CI minutes pack","code":"ci_minutes","active":true,"deprecated":false,"free":null,"price_per_month":0.8333333333333334,"price_per_year":10,"features":null,"about_page_href":null,"hide_deprecated_card":false}]') }
it { is_expected.to include(plan_id: 'bronze_id') }
it { is_expected.to include(namespace_id: group.id.to_s) }
it { is_expected.to include(group_data: %Q{[{"id":#{group.id},"name":"My Namespace","users":2,"guests":1}]}) }
......@@ -111,14 +105,6 @@ RSpec.describe SubscriptionsHelper do
it { is_expected.to include(available_plans: '[]') }
end
end
context 'when ff new_route_ci_minutes_purchase is disabled' do
before do
stub_feature_flags(new_route_ci_minutes_purchase: false)
end
it { is_expected.not_to include(ci_minutes_plans: '[{"name":"1000 CI minutes pack","code":"ci_minutes","active":true,"deprecated":false,"free":null,"price_per_month":0.8333333333333334,"price_per_year":10,"features":null,"about_page_href":null,"hide_deprecated_card":false}]') }
end
end
describe '#plan_title' do
......
......@@ -3,8 +3,6 @@
require 'spec_helper'
RSpec.describe Gitlab::SubscriptionPortal::Clients::Graphql do
include SubscriptionPortalHelpers
let(:client) { Gitlab::SubscriptionPortal::Client }
describe '#activate' do
......@@ -134,63 +132,6 @@ RSpec.describe Gitlab::SubscriptionPortal::Clients::Graphql do
end
end
describe '#plan_data' do
let(:plan_tags) { 'CI_1000_MINUTES_PLAN' }
subject(:plan_data) { client.plan_data(plan_tags, stubbed_plan_data_query_fields) }
context 'when the response contains errors' do
before do
expect(client).to receive(:execute_graphql_query).and_return(response)
end
let(:response) do
{
success: true,
data: {
'errors' => [{ 'message' => 'this will be ignored' }]
}
}
end
it 'logs an error and returns a failure' do
expect(Gitlab::ErrorTracking)
.to receive(:track_and_raise_for_dev_exception)
.with(
a_kind_of(Gitlab::SubscriptionPortal::Client::ResponseError),
query: include(*stubbed_plan_data_query_fields_camelized), response: response[:data])
expect(plan_data).to eq({ success: false })
end
end
context 'when the response does not contain errors' do
before do
allow(client).to receive(:execute_graphql_query).and_return({ data: Gitlab::Json.parse(stubbed_plan_data_response_body) })
end
it 'filters out the deprecated plans' do
expect(plan_data).to match({
success: true,
plans: contain_exactly(include('deprecated' => false))
})
end
context 'when plans is an empty array' do
before do
allow(client).to receive(:execute_graphql_query).and_return({
success: true,
data: { "data" => { "plans" => [] } }
})
end
it 'returns the correct response' do
expect(plan_data).to eq({ success: true, plans: [] })
end
end
end
end
describe '#subscription_last_term' do
let(:query) do
<<~GQL
......
......@@ -21,24 +21,6 @@ module SubscriptionPortalHelpers
)
end
def stub_plan_data_request(plan_tags)
stub_full_request("#{EE::SUBSCRIPTIONS_URL}/graphql", method: :post)
.with(
body: include(*plan_tags, *stubbed_plan_data_query_fields_camelized),
headers: {
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'X-Admin-Email' => EE::SUBSCRIPTION_PORTAL_ADMIN_EMAIL,
'X-Admin-Token' => EE::SUBSCRIPTION_PORTAL_ADMIN_TOKEN
}
)
.to_return(
status: 200,
headers: { 'Content-Type' => 'application/json' },
body: stubbed_plan_data_response_body
)
end
private
def stubbed_eoa_eligibility_response_body(eligible, free_upgrade_plan_id, assisted_upgrade_plan_id)
......@@ -52,55 +34,4 @@ module SubscriptionPortalHelpers
}
}.to_json
end
def stubbed_plan_data_query_fields
%w[
name
code
active
free
price_per_month
price_per_year
features
about_page_href
hide_deprecated_card
]
end
def stubbed_plan_data_query_fields_camelized
stubbed_plan_data_query_fields.map { |field| field.to_s.camelize(:lower) }
end
def stubbed_plan_data_response_body
{
"data": {
"plans": [
{
"name": "1000 CI minutes pack",
"code": "ci_minutes",
"active": true,
"deprecated": false,
"free": nil,
"price_per_month": 0.8333333333333334,
"price_per_year": 10,
"features": nil,
"about_page_href": nil,
"hide_deprecated_card": false
},
{
"name": "Deprecated 1000 CI minutes pack",
"code": "deprecated_ci_minutes",
"active": true,
"deprecated": true,
"free": nil,
"price_per_month": 1,
"price_per_year": 12,
"features": nil,
"about_page_href": nil,
"hide_deprecated_card": false
}
]
}
}.to_json
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