Commit cc758439 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'jj-allow-namespace-nested-attributes' into 'master'

Allow nested gitlab_subscription on namespace api

See merge request gitlab-org/gitlab!37397
parents b8aedf35 2b33f1cd
---
title: Allow nested gitlab_subscription on namespace api
merge_request: 37397
author: jejacks0n
type: changed
......@@ -36,6 +36,7 @@ module EE
resource :namespaces, requirements: ::API::API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
helpers do
params :gitlab_subscription_optional_attributes do
optional :start_date, type: Date, desc: 'The date when subscription was started'
optional :seats, type: Integer, desc: 'The number of seats purchased'
optional :max_seats_used, type: Integer, desc: 'The max number of active users detected in the last month'
optional :plan_code, type: String, desc: 'The code of the purchased plan'
......@@ -55,6 +56,9 @@ module EE
optional :extra_shared_runners_minutes_limit, type: Integer, desc: "Extra pipeline minutes for this namespace"
optional :additional_purchased_storage_size, type: Integer, desc: "Additional storage size for this namespace"
optional :additional_purchased_storage_ends_on, type: Date, desc: "End of subscription of the additional purchased storage"
optional :gitlab_subscription_attributes, type: Hash do
use :gitlab_subscription_optional_attributes
end
end
put ':id' do
authenticated_as_admin!
......@@ -74,9 +78,9 @@ module EE
success ::EE::API::Entities::GitlabSubscription
end
params do
requires :start_date, type: Date, desc: 'The date when subscription was started'
use :gitlab_subscription_optional_attributes
requires :start_date, type: Date, desc: 'The date when subscription was started'
end
post ":id/gitlab_subscription" do
authenticated_as_admin!
......@@ -107,8 +111,6 @@ module EE
success ::EE::API::Entities::GitlabSubscription
end
params do
optional :start_date, type: Date, desc: 'The date when subscription was started'
use :gitlab_subscription_optional_attributes
end
put ":id/gitlab_subscription" do
......
......@@ -209,6 +209,66 @@ RSpec.describe API::Namespaces do
expect(runners).to all(receive(:tick_runner_queue))
end
end
context "when passing attributes for gitlab_subscription" do
let(:gitlab_subscription) do
{
start_date: '2019-06-01',
end_date: '2020-06-01',
plan_code: 'gold',
seats: 20,
max_seats_used: 10,
auto_renew: true,
trial: true,
trial_ends_on: '2019-05-01',
trial_starts_on: '2019-06-01'
}
end
it "creates the gitlab_subscription record" do
expect(group1.gitlab_subscription).to be_nil
put api("/namespaces/#{group1.id}", admin), params: {
gitlab_subscription_attributes: gitlab_subscription
}
expect(group1.reload.gitlab_subscription).to have_attributes(
start_date: Date.parse(gitlab_subscription[:start_date]),
end_date: Date.parse(gitlab_subscription[:end_date]),
hosted_plan: instance_of(Plan),
seats: 20,
max_seats_used: 10,
auto_renew: true,
trial: true,
trial_starts_on: Date.parse(gitlab_subscription[:trial_starts_on]),
trial_ends_on: Date.parse(gitlab_subscription[:trial_ends_on])
)
end
it "updates the gitlab_subscription record" do
group1.create_gitlab_subscription!
put api("/namespaces/#{group1.id}", admin), params: {
gitlab_subscription_attributes: gitlab_subscription
}
expect(group1.reload.gitlab_subscription.reload.seats).to eq 20
end
context 'when params are invalid' do
it 'returns a 400 error' do
put api("/namespaces/#{group1.id}", admin), params: {
gitlab_subscription_attributes: { start_date: nil, seats: nil }
}
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq(
"gitlab_subscription.seats" => ["can't be blank"],
"gitlab_subscription.start_date" => ["can't be blank"]
)
end
end
end
end
describe 'POST :id/gitlab_subscription' do
......@@ -238,6 +298,12 @@ RSpec.describe API::Namespaces do
expect(response).to have_gitlab_http_status(:bad_request)
end
it 'fails when the record is invalid' do
do_post(admin, params.merge(start_date: nil))
expect(response).to have_gitlab_http_status(:bad_request)
end
it 'creates a subscription for the Group' do
do_post(admin, params)
......
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