Commit 3a87d217 authored by Michael Lunøe's avatar Michael Lunøe Committed by Robert Speicher

Fix(subscribable banner): more explicit testing

This updates tests to be explicit about what needs
to be set in order to trigger different links in
the banner
parent 632b7768
...@@ -27,24 +27,52 @@ RSpec.describe "Admin views license" do ...@@ -27,24 +27,52 @@ RSpec.describe "Admin views license" do
context "when license is regular" do context "when license is regular" do
let_it_be(:license) { create(:license) } let_it_be(:license) { create(:license) }
let_it_be(:reference_date) { Date.parse('2020-01-22') }
before do context "when license is expired" do
visit(admin_license_path) let_it_be(:license) { build(:license, data: build(:gitlab_license, expires_at: reference_date - 1.day).export).save!(validate: false) }
end
context "when license expired" do it do
let_it_be(:license) { build(:license, data: build(:gitlab_license, expires_at: Date.yesterday).export).save!(validate: false) } travel_to(reference_date) do
visit(admin_license_path)
it { expect(page).to have_content("Your subscription expired!") } expect(page).to have_content("Your subscription expired!")
expect(page).to have_link 'Renew subscription', href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions"
end
end
context "when license blocks changes" do context "when license blocks changes" do
let_it_be(:license) { build(:license, data: build(:gitlab_license, expires_at: Date.yesterday, block_changes_at: Date.today).export).save!(validate: false) } let_it_be(:license) { build(:license, data: build(:gitlab_license, expires_at: reference_date - 1.week).export).save!(validate: false) }
it do
travel_to(reference_date) do
visit(admin_license_path)
it { expect(page).to have_content "You didn't renew your subscription so it was downgraded to the GitLab Core Plan" } expect(page).to have_content "You have 7 days to renew your subscription."
expect(page).to have_link 'Renew subscription', href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions"
end
end
end
context "when license blocks changes" do
let_it_be(:license) { build(:license, data: build(:gitlab_license, expires_at: reference_date - 4.weeks, block_changes_at: reference_date - 1.day).export).save!(validate: false) }
it do
travel_to(reference_date) do
visit(admin_license_path)
expect(page).to have_content "You didn't renew your subscription so it was downgraded to the GitLab Core Plan"
expect(page).to have_link 'Upgrade your plan', href: "#{EE::SUBSCRIPTIONS_URL}/subscriptions"
end
end
end end
end end
context "when viewing license history", :aggregate_failures do context "when viewing license history", :aggregate_failures do
before do
visit(admin_license_path)
end
it "shows licensee" do it "shows licensee" do
license_history = page.find("#license_history") license_history = page.find("#license_history")
......
...@@ -14,31 +14,15 @@ RSpec.describe 'layouts/header/_ee_subscribable_banner' do ...@@ -14,31 +14,15 @@ RSpec.describe 'layouts/header/_ee_subscribable_banner' do
end end
shared_examples 'displays the correct link' do shared_examples 'displays the correct link' do
context "when license will soon expire" do context "when license has expired" do
let(:license) { build(:gitlab_license, expires_at: Date.current + 5.days) } let(:license) { build(:gitlab_license, expires_at: Date.current - 1.week) }
it 'shows the renew plan link' do it 'shows the renew plan link' do
expect(rendered).to have_link 'Renew subscription', href: view.renew_subscription_path expect(rendered).to have_link 'Renew subscription', href: view.renew_subscription_path
end end
context "when license blocks changes" do context "when license blocks changes" do
let(:license) { build(:gitlab_license, expires_at: Date.current + 5.days, block_changes_at: Date.today) } let(:license) { build(:gitlab_license, expires_at: Date.current - 3.weeks) }
it 'shows the upgrade plan link' do
expect(rendered).to have_link 'Upgrade your plan', href: view.upgrade_subscription_path
end
end
end
context "when license expired" do
let(:license) { build(:gitlab_license, expires_at: Date.yesterday) }
it 'shows the renew plan link' do
expect(rendered).to have_link 'Renew subscription', href: view.renew_subscription_path
end
context "when license blocks changes" do
let(:license) { build(:gitlab_license, expires_at: Date.yesterday, block_changes_at: Date.today) }
it 'shows the upgrade plan link' do it 'shows the upgrade plan link' do
expect(rendered).to have_link 'Upgrade your plan', href: view.upgrade_subscription_path expect(rendered).to have_link 'Upgrade your plan', href: view.upgrade_subscription_path
......
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