Commit f1929bf7 authored by Rubén Dávila's avatar Rubén Dávila

Fix query used to calculate number of users over license

The new query use the License period as the range date for the query.
With this change, customers will see a more accurate number on their
Dashboard for the Users Over License section.
parent d30fe518
......@@ -22,7 +22,9 @@ class HistoricalData < ApplicationRecord
end
def max_historical_user_count
HistoricalData.during(1.year.ago..Date.today).maximum(:active_user_count) || 0
exp_date = License.current&.expires_at || Date.today
HistoricalData.during(exp_date.ago(1.year)..exp_date).maximum(:active_user_count) || 0
end
end
end
---
title: Fix query used to calculate number of users over license
merge_request: 10556
author:
type: fixed
......@@ -76,4 +76,39 @@ describe HistoricalData do
end
end
end
describe '.max_historical_user_count with data outside of the license period' do
let!(:license) { create(:license) }
context 'with stats before the license period' do
before do
described_class.create!(date: license.starts_at.ago(2.days), active_user_count: 10)
end
it 'ignore those records' do
expect(described_class.max_historical_user_count).to eq(0)
end
end
context 'with stats after the license period' do
before do
described_class.create!(date: license.expires_at.in(2.days), active_user_count: 10)
end
it 'ignore those records' do
expect(described_class.max_historical_user_count).to eq(0)
end
end
context 'with stats inside license period' do
before do
described_class.create!(date: license.starts_at.in(2.days), active_user_count: 10)
described_class.create!(date: license.starts_at.in(5.days), active_user_count: 15)
end
it 'returns max value for active_user_count' do
expect(described_class.max_historical_user_count).to eq(15)
end
end
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