Commit 996ffa8e authored by Josianne Hyson's avatar Josianne Hyson

Refactor license validation specs

Prior to this change there were several different styles for declaring
the top level describe block in the License validation specs. This made
it difficult to easily see which validation is being tested where.

This commit re-groups the existing validation specs in this file to be
under a consistent title (the validation method name).

Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/334115
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65793
parent e70e3415
......@@ -5,28 +5,94 @@ require "spec_helper"
RSpec.describe License do
using RSpec::Parameterized::TableSyntax
subject(:license) { build(:license, data: gl_license.export) }
let(:gl_license) { build(:gitlab_license) }
let(:license) { build(:license, data: gl_license.export) }
describe "Validation" do
describe "Valid license" do
context "when the license is provided" do
it "is valid" do
describe 'validations' do
describe '#valid_license' do
context 'when the license is provided' do
it 'is valid' do
expect(license).to be_valid
end
end
context "when no license is provided" do
context 'when no license is provided' do
before do
license.data = nil
end
it "is invalid" do
it 'is invalid' do
expect(license).not_to be_valid
end
end
end
describe '#check_trueup' do
let(:active_user_count) { described_class.current.daily_billable_users_count + 10 }
let(:date) { described_class.current.starts_at }
before do
create(:historical_data, recorded_at: date, active_user_count: active_user_count)
end
context 'when quantity is ok' do
before do
set_restrictions(restricted_user_count: 5, trueup_quantity: 10)
end
it 'is valid' do
expect(license).to be_valid
end
context 'but active users exceeds restricted user count' do
it 'is invalid' do
create_list(:user, 6)
expect(license).not_to be_valid
end
end
end
context 'when quantity is wrong' do
it 'is invalid' do
set_restrictions(restricted_user_count: 5, trueup_quantity: 8)
expect(license).not_to be_valid
end
end
context 'when previous user count is not present' do
before do
set_restrictions(restricted_user_count: 5, trueup_quantity: 7)
end
it 'uses current active user count to calculate the expected true-up' do
create_list(:user, 3)
expect(license).to be_valid
end
context 'with wrong true-up quantity' do
it 'is invalid' do
create_list(:user, 2)
expect(license).not_to be_valid
end
end
end
context 'when previous user count is present' do
before do
set_restrictions(restricted_user_count: 5, trueup_quantity: 6, previous_user_count: 4)
end
it 'uses it to calculate the expected true-up' do
expect(license).to be_valid
end
end
end
describe '#check_users_limit' do
context 'for each plan' do
before do
......@@ -131,15 +197,14 @@ RSpec.describe License do
end
end
end
end
describe "Historical active user count" do
describe 'Historical active user count' do
let(:active_user_count) { described_class.current.daily_billable_users_count + 10 }
let(:date) { described_class.current.starts_at }
let!(:historical_data) { create(:historical_data, recorded_at: date, active_user_count: active_user_count) }
context "when there is no active user count restriction" do
it "is valid" do
context 'when there is no active user count restriction' do
it 'is valid' do
expect(license).to be_valid
end
end
......@@ -172,143 +237,86 @@ RSpec.describe License do
end
end
context "when the active user count restriction is exceeded" do
context 'when the active user count restriction is exceeded' do
before do
gl_license.restrictions = { active_user_count: active_user_count - 1 }
end
context "when the license started" do
it "is invalid" do
context 'when the license started' do
it 'is invalid' do
expect(license).not_to be_valid
end
end
context "after the license started" do
context 'after the license started' do
let(:date) { Date.current }
it "is valid" do
it 'is valid' do
expect(license).to be_valid
end
end
context "in the year before the license started" do
context 'in the year before the license started' do
let(:date) { described_class.current.starts_at - 6.months }
it "is invalid" do
it 'is invalid' do
expect(license).not_to be_valid
end
end
context "earlier than a year before the license started" do
context 'earlier than a year before the license started' do
let(:date) { described_class.current.starts_at - 2.years }
it "is valid" do
it 'is valid' do
expect(license).to be_valid
end
end
end
context "when the active user count restriction is not exceeded" do
context 'when the active user count restriction is not exceeded' do
before do
gl_license.restrictions = { active_user_count: active_user_count + 1 }
end
it "is valid" do
it 'is valid' do
expect(license).to be_valid
end
end
context "when the active user count is met exactly" do
it "is valid" do
context 'when the active user count is met exactly' do
it 'is valid' do
active_user_count = 100
gl_license.restrictions = { active_user_count: active_user_count }
expect(license).to be_valid
end
end
context 'with true-up info' do
context 'when quantity is ok' do
before do
set_restrictions(restricted_user_count: 5, trueup_quantity: 10)
end
it 'is valid' do
expect(license).to be_valid
end
context 'but active users exceeds restricted user count' do
it 'is invalid' do
create_list(:user, 6)
expect(license).not_to be_valid
end
end
end
context 'when quantity is wrong' do
it 'is invalid' do
set_restrictions(restricted_user_count: 5, trueup_quantity: 8)
expect(license).not_to be_valid
end
end
context 'when previous user count is not present' do
before do
set_restrictions(restricted_user_count: 5, trueup_quantity: 7)
end
it 'uses current active user count to calculate the expected true-up' do
create_list(:user, 3)
expect(license).to be_valid
end
context 'with wrong true-up quantity' do
it 'is invalid' do
create_list(:user, 2)
expect(license).not_to be_valid
end
end
end
context 'when previous user count is present' do
before do
set_restrictions(restricted_user_count: 5, trueup_quantity: 6, previous_user_count: 4)
end
it 'uses it to calculate the expected true-up' do
expect(license).to be_valid
end
end
end
end
describe "Not expired" do
describe '#not_expired' do
context "when the license doesn't expire" do
it "is valid" do
it 'is valid' do
expect(license).to be_valid
end
end
context "when the license has expired" do
context 'when the license has expired' do
before do
gl_license.expires_at = Date.yesterday
end
it "is invalid" do
it 'is invalid' do
expect(license).not_to be_valid
end
end
context "when the license has yet to expire" do
context 'when the license has yet to expire' do
before do
gl_license.expires_at = Date.tomorrow
end
it "is valid" do
it 'is valid' do
expect(license).to be_valid
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