Commit 614e2c10 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'fix-trial-start-billing-members' into 'master'

Fix namespace billing page incorrectly accessing billable members

See merge request gitlab-org/gitlab!49677
parents 1bb4b4af 4e6d7554
...@@ -26,12 +26,14 @@ export default { ...@@ -26,12 +26,14 @@ export default {
default: false, default: false,
}, },
}, },
inject: ['billableSeatsHref'], inject: ['billableSeatsHref', 'isGroup'],
computed: { computed: {
...mapState(['hasBillableGroupMembers']), ...mapState(['hasBillableGroupMembers']),
}, },
created() { created() {
this.fetchHasBillableGroupMembers(); if (this.isGroup) {
this.fetchHasBillableGroupMembers();
}
}, },
methods: { methods: {
...mapActions(['fetchHasBillableGroupMembers']), ...mapActions(['fetchHasBillableGroupMembers']),
......
...@@ -16,6 +16,7 @@ export default (containerId = 'js-billing-plans') => { ...@@ -16,6 +16,7 @@ export default (containerId = 'js-billing-plans') => {
namespaceId, namespaceId,
namespaceName, namespaceName,
addSeatsHref, addSeatsHref,
isGroup,
planUpgradeHref, planUpgradeHref,
planRenewHref, planRenewHref,
customerPortalUrl, customerPortalUrl,
...@@ -29,6 +30,7 @@ export default (containerId = 'js-billing-plans') => { ...@@ -29,6 +30,7 @@ export default (containerId = 'js-billing-plans') => {
namespaceId, namespaceId,
namespaceName, namespaceName,
addSeatsHref, addSeatsHref,
isGroup,
planUpgradeHref, planUpgradeHref,
planRenewHref, planRenewHref,
customerPortalUrl, customerPortalUrl,
......
...@@ -9,17 +9,18 @@ module BillingPlansHelper ...@@ -9,17 +9,18 @@ module BillingPlansHelper
number_to_currency(value, unit: '$', strip_insignificant_zeros: true, format: "%u%n") number_to_currency(value, unit: '$', strip_insignificant_zeros: true, format: "%u%n")
end end
def subscription_plan_data_attributes(group, plan) def subscription_plan_data_attributes(namespace, plan)
return {} unless group return {} unless namespace
{ {
namespace_id: group.id, namespace_id: namespace.id,
namespace_name: group.name, namespace_name: namespace.name,
add_seats_href: add_seats_url(group), is_group: namespace.group?,
plan_upgrade_href: plan_upgrade_url(group, plan), add_seats_href: add_seats_url(namespace),
plan_renew_href: plan_renew_url(group), 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_URL}/subscriptions",
billable_seats_href: billable_seats_href(group) billable_seats_href: billable_seats_href(namespace)
} }
end end
......
...@@ -39,7 +39,11 @@ describe('subscription table row', () => { ...@@ -39,7 +39,11 @@ describe('subscription table row', () => {
const defaultProps = { header: HEADER, columns: COLUMNS }; const defaultProps = { header: HEADER, columns: COLUMNS };
const createComponent = ({ props = {}, billableSeatsHref = BILLABLE_SEATS_URL } = {}) => { const createComponent = ({
props = {},
billableSeatsHref = BILLABLE_SEATS_URL,
isGroup = true,
} = {}) => {
if (wrapper) { if (wrapper) {
throw new Error('wrapper already exists!'); throw new Error('wrapper already exists!');
} }
...@@ -51,6 +55,7 @@ describe('subscription table row', () => { ...@@ -51,6 +55,7 @@ describe('subscription table row', () => {
}, },
provide: { provide: {
billableSeatsHref, billableSeatsHref,
isGroup,
}, },
store, store,
localVue, localVue,
...@@ -86,13 +91,21 @@ describe('subscription table row', () => { ...@@ -86,13 +91,21 @@ describe('subscription table row', () => {
.at(0) .at(0)
.find('[data-testid="seats-usage-button"]'); .find('[data-testid="seats-usage-button"]');
describe('default', () => { describe('dispatched actions', () => {
beforeEach(() => { it('dispatches action when created if namespace is group', () => {
createComponent(); createComponent();
expect(store.dispatch).toHaveBeenCalledWith('fetchHasBillableGroupMembers');
}); });
it('dispatches correct actions when created', () => { it('does not dispatch action when created if namespace is not group', () => {
expect(store.dispatch).toHaveBeenCalledWith('fetchHasBillableGroupMembers'); createComponent({ isGroup: false });
expect(store.dispatch).not.toHaveBeenCalledWith('fetchHasBillableGroupMembers');
});
});
describe('default', () => {
beforeEach(() => {
createComponent();
}); });
it(`should render one header cell and ${COLUMNS.length} visible columns in total`, () => { it(`should render one header cell and ${COLUMNS.length} visible columns in total`, () => {
......
...@@ -21,6 +21,7 @@ RSpec.describe BillingPlansHelper do ...@@ -21,6 +21,7 @@ RSpec.describe BillingPlansHelper do
expect(helper.subscription_plan_data_attributes(group, plan)) expect(helper.subscription_plan_data_attributes(group, plan))
.to eq(namespace_id: group.id, .to eq(namespace_id: group.id,
namespace_name: group.name, namespace_name: group.name,
is_group: true,
add_seats_href: add_seats_href, add_seats_href: add_seats_href,
plan_upgrade_href: upgrade_href, plan_upgrade_href: upgrade_href,
plan_renew_href: renew_href, plan_renew_href: renew_href,
...@@ -48,6 +49,7 @@ RSpec.describe BillingPlansHelper do ...@@ -48,6 +49,7 @@ RSpec.describe BillingPlansHelper do
expect(helper.subscription_plan_data_attributes(group, plan)) expect(helper.subscription_plan_data_attributes(group, plan))
.to eq(namespace_id: group.id, .to eq(namespace_id: group.id,
namespace_name: group.name, namespace_name: group.name,
is_group: true,
customer_portal_url: customer_portal_url, customer_portal_url: customer_portal_url,
billable_seats_href: billable_seats_href, billable_seats_href: billable_seats_href,
add_seats_href: add_seats_href, add_seats_href: add_seats_href,
...@@ -55,18 +57,28 @@ RSpec.describe BillingPlansHelper do ...@@ -55,18 +57,28 @@ RSpec.describe BillingPlansHelper do
plan_upgrade_href: nil) plan_upgrade_href: nil)
end end
end end
context 'when namespace is passed in' do
it 'returns false for is_group' do
namespace = build(:namespace)
result = helper.subscription_plan_data_attributes(namespace, plan)
expect(result).to include(is_group: false)
end
end
end end
describe '#use_new_purchase_flow?' do describe '#use_new_purchase_flow?' do
where type: ['Group', nil], where type: ['Group', nil],
plan: Plan.all_plans, plan: Plan.all_plans,
trial_active: [true, false] trial_active: [true, false]
with_them do with_them do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:namespace) do let(:namespace) do
create :namespace, type: type, create :namespace, type: type,
gitlab_subscription: create(:gitlab_subscription, hosted_plan: create("#{plan}_plan".to_sym)) gitlab_subscription: create(:gitlab_subscription, hosted_plan: create("#{plan}_plan".to_sym))
end end
before do before do
......
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