Commit 0e06171b authored by Josianne Hyson's avatar Josianne Hyson

Add check for skip_true_up in License validation

Skip the true up check for validating licenses that have the
`skip_true_up` flag set to `true`. Continue to validate true up figures
for licenses that do not have this flag at all, or have it set to
`false`. This allows us to bypass the true up validations for users that
have opted in to quarterly reconciliation and have been paying for
additional users each quarter.

Changelog: changed
Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/334115
EE: true

MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65793
parent 996ffa8e
......@@ -498,6 +498,8 @@ class License < ApplicationRecord
end
def validate_with_trueup?
return false if restricted_attr(:skip_true_up)
[restricted_attr(:trueup_quantity),
restricted_attr(:trueup_from),
restricted_attr(:trueup_to)].all?(&:present?)
......
......@@ -36,6 +36,34 @@ RSpec.describe License do
create(:historical_data, recorded_at: date, active_user_count: active_user_count)
end
context 'when skip_true_up is true on the license' do
it 'does not add errors for invalid true up' do
set_restrictions(restricted_user_count: 10, trueup_quantity: 8, skip_true_up: true)
expect(license).to be_valid
end
end
context 'when skip_true_up is false on the license' do
it 'adds errors for invalid true up figures' do
set_restrictions(restricted_user_count: 10, trueup_quantity: 8, skip_true_up: false)
expect(license).not_to be_valid
expect(license.errors.full_messages.to_sentence)
.to include 'You have applied a True-up for 8 users but you need one for 10 users'
end
end
context 'when skip_true_up is not present on the license' do
it 'adds errors for invalid true up figures' do
set_restrictions(restricted_user_count: 10, trueup_quantity: 8)
expect(license).not_to be_valid
expect(license.errors.full_messages.to_sentence)
.to include 'You have applied a True-up for 8 users but you need one for 10 users'
end
end
context 'when quantity is ok' do
before do
set_restrictions(restricted_user_count: 5, trueup_quantity: 10)
......@@ -1445,8 +1473,9 @@ RSpec.describe License do
previous_user_count: opts[:previous_user_count],
trueup_quantity: opts[:trueup_quantity],
trueup_from: (date - 1.year).to_s,
trueup_to: date.to_s
}
trueup_to: date.to_s,
skip_true_up: opts[:skip_true_up]
}.compact
end
describe '#paid?' 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