Commit f4736106 authored by Corinna Wiesner's avatar Corinna Wiesner

Fix broken tests affected by current license logic

With the new logic to find the current license some tests broke due to
using Timecop. The current code was not able to find a current license
because the usage of a past date was used for Timecop which was
before the license's start date. Therefore we set the license factory's
start date to 1970-01-01.
parent 05eae251
...@@ -19,8 +19,8 @@ FactoryBot.define do ...@@ -19,8 +19,8 @@ FactoryBot.define do
plan { License::STARTER_PLAN } plan { License::STARTER_PLAN }
end end
starts_at { Date.today - 1.month } starts_at { Date.new(1970, 1, 1) }
expires_at { Date.today + 11.months } expires_at { Date.current + 11.months }
block_changes_at { expires_at + 2.weeks } block_changes_at { expires_at + 2.weeks }
notify_users_at { expires_at } notify_users_at { expires_at }
notify_admins_at { expires_at } notify_admins_at { expires_at }
......
...@@ -102,7 +102,7 @@ describe HistoricalData do ...@@ -102,7 +102,7 @@ describe HistoricalData do
end end
context 'with data outside of the license period' do context 'with data outside of the license period' do
let!(:license) { create(:license) } let!(:license) { create(:license, starts_at: Date.current - 1.month) }
context 'with stats before the license period' do context 'with stats before the license period' do
before do before do
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
require "spec_helper" require "spec_helper"
describe License do describe License do
let(:gl_license) { build(:gitlab_license) } let(:gl_license) { build(:gitlab_license) }
let(:license) { build(:license, data: gl_license.export) } let(:license) { build(:license, data: gl_license.export) }
describe "Validation" do describe "Validation" do
describe "Valid license" do describe "Valid license" do
...@@ -116,7 +116,7 @@ describe License do ...@@ -116,7 +116,7 @@ describe License do
end end
context "after the license started" do context "after the license started" do
let(:date) { Date.today } let(:date) { Date.current }
it "is valid" do it "is valid" do
expect(license).to be_valid expect(license).to be_valid
...@@ -249,7 +249,7 @@ describe License do ...@@ -249,7 +249,7 @@ describe License do
describe 'downgrade' do describe 'downgrade' do
context 'when more users were added in previous period' do context 'when more users were added in previous period' do
before do before do
HistoricalData.create!(date: 6.months.ago, active_user_count: 15) HistoricalData.create!(date: described_class.current.starts_at - 6.months, active_user_count: 15)
set_restrictions(restricted_user_count: 5, previous_user_count: 10) set_restrictions(restricted_user_count: 5, previous_user_count: 10)
end end
...@@ -778,12 +778,14 @@ describe License do ...@@ -778,12 +778,14 @@ describe License do
end end
def set_restrictions(opts) def set_restrictions(opts)
date = described_class.current.starts_at
gl_license.restrictions = { gl_license.restrictions = {
active_user_count: opts[:restricted_user_count], active_user_count: opts[:restricted_user_count],
previous_user_count: opts[:previous_user_count], previous_user_count: opts[:previous_user_count],
trueup_quantity: opts[:trueup_quantity], trueup_quantity: opts[:trueup_quantity],
trueup_from: (Date.today - 1.year).to_s, trueup_from: (date - 1.year).to_s,
trueup_to: Date.today.to_s trueup_to: date.to_s
} }
end end
......
...@@ -32,7 +32,7 @@ describe API::License, api: true do ...@@ -32,7 +32,7 @@ describe API::License, api: true do
get api('/license', admin) get api('/license', admin)
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['user_limit']).to eq 0 expect(json_response['user_limit']).to eq 0
expect(Date.parse(json_response['starts_at'])).to eq Date.today - 1.month expect(Date.parse(json_response['starts_at'])).to eq Date.new(1970, 1, 1)
expect(Date.parse(json_response['expires_at'])).to eq Date.today + 11.months expect(Date.parse(json_response['expires_at'])).to eq Date.today + 11.months
expect(json_response['active_users']).to eq 1 expect(json_response['active_users']).to eq 1
expect(json_response['licensee']).not_to be_empty expect(json_response['licensee']).not_to be_empty
...@@ -51,7 +51,7 @@ describe API::License, api: true do ...@@ -51,7 +51,7 @@ describe API::License, api: true do
expect(response).to have_gitlab_http_status(:created) expect(response).to have_gitlab_http_status(:created)
expect(json_response['user_limit']).to eq 0 expect(json_response['user_limit']).to eq 0
expect(Date.parse(json_response['starts_at'])).to eq Date.today - 1.month expect(Date.parse(json_response['starts_at'])).to eq Date.new(1970, 1, 1)
expect(Date.parse(json_response['expires_at'])).to eq Date.today + 11.months expect(Date.parse(json_response['expires_at'])).to eq Date.today + 11.months
expect(json_response['active_users']).to eq 1 expect(json_response['active_users']).to eq 1
expect(json_response['licensee']).not_to be_empty expect(json_response['licensee']).not_to be_empty
......
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