Commit 77bea357 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'blackst0ne-replace-spinach-admin-license.feature' into 'master'

Replace the `admin/license.feature` spinach test with an rspec analog

See merge request gitlab-org/gitlab-ee!5477
parents 60039b36 3a1ffbf6
---
title: 'Replace the `admin/license.feature` spinach test with an rspec analog'
merge_request: 5477
author: "@blackst0ne"
type: other
require 'spec_helper'
feature "License Admin" do
before do
sign_in(create(:admin))
end
describe '#show' do
it 'shows a valid license' do
visit admin_license_path
expect(page).to have_content('Your license is valid')
page.within '.license-panel' do
expect(page).to have_content('Unlimited')
end
end
describe 'limited users' do
let!(:license) { create(:license, data: build(:gitlab_license, restrictions: { active_user_count: 2000 }).export) }
it 'shows panel counts' do
visit admin_license_path
page.within '.license-panel' do
expect(page).to have_content('2,000')
end
end
end
context 'with a trial license' do
let!(:license) { create(:license, trial: true) }
it 'shows expiration duration with license type' do
visit admin_license_path
page.within '.js-license-info-panel' do
expect(page).to have_content('Expires: Free trial will expire in')
end
end
end
context 'with a regular license' do
let!(:license) { create(:license) }
it 'shows only expiration duration' do
visit admin_license_path
page.within '.js-license-info-panel' do
expect(page).not_to have_content('Expires: Free trial will expire in')
end
end
end
context 'with an expired trial license' do
let!(:license) { create(:license, trial: true, expired: true) }
it 'does not mention blocking of changes' do
visit admin_license_path
page.within '.gitlab-ee-license-banner' do
expect(page).to have_content('Your trial license expired on')
expect(page).not_to have_content('Pushing code and creation of issues and merge requests has been disabled')
end
end
end
context 'when license key is provided in the query string' do
let(:license) { build(:license, data: build(:gitlab_license, restrictions: { active_user_count: 2000 }).export) }
before do
License.destroy_all
end
it 'shows the modal to install the license' do
visit admin_license_path(trial_key: license.data)
page.within '#modal-upload-trial-license' do
expect(page).to have_content('Your trial license was issued')
expect(page).to have_button('Install license')
end
end
it 'can install the license' do
visit admin_license_path(trial_key: license.data)
click_button 'Install license'
expect(page).to have_content('The license was successfully uploaded and is now active')
end
end
end
end
require "spec_helper"
describe "Admin uploads license" do
set(:admin) { create(:admin) }
before do
sign_in(admin)
end
context "when license key is provided in the query string" do
set(:license) { build(:license, data: build(:gitlab_license, restrictions: { active_user_count: 2000 }).export) }
before do
License.destroy_all
visit(admin_license_path(trial_key: license.data))
end
it "installs license" do
page.within("#modal-upload-trial-license") do
expect(page).to have_content("Your trial license was issued").and have_button("Install license")
end
click_button("Install license")
expect(page).to have_content("The license was successfully uploaded and is now active")
end
end
context "uploading license" do
before do
visit(new_admin_license_path)
File.write(path, license.export)
end
context "when license is valid" do
set(:license) { build(:gitlab_license) }
set(:path) { Rails.root.join("tmp/valid_license.gitlab-license") }
it "uploads license" do
attach_and_upload(path)
expect(page).to have_content("The license was successfully uploaded and is now active.")
.and have_content(license.licensee.values.first)
end
end
context "when license is invalid" do
set(:license) { build(:gitlab_license, expires_at: Date.yesterday) }
set(:path) { Rails.root.join("tmp/invalid_license.gitlab-license") }
it "doesn't upload license" do
attach_and_upload(path)
expect(page).to have_content("This license has already expired.")
end
end
end
private
def attach_and_upload(path)
attach_file("license_data_file", path)
click_button("Upload license")
end
end
require "spec_helper"
describe "Admin views license" do
set(:admin) { create(:admin) }
before do
sign_in(admin)
end
context "when license is valid" do
before do
visit(admin_license_path)
end
it "shows license" do
expect(page).to have_content("Your license is valid")
page.within(".license-panel") do
expect(page).to have_content("Unlimited")
end
end
end
context "when license is trial" do
set(:license) { create(:license, trial: true) }
before do
visit(admin_license_path)
end
it "shows expiration duration with license type" do
page.within(".js-license-info-panel") do
expect(page).to have_content("Expires: Free trial will expire in")
end
end
context "when license is expired" do
set(:license) { create(:license, trial: true, expired: true) }
it "does not mention blocking of changes" do
page.within(".gitlab-ee-license-banner") do
expect(page).to have_content("Your trial license expired on")
.and have_no_content("Pushing code and creation of issues and merge requests has been disabled")
end
end
end
end
context "when license is regular" do
set(:license) { create(:license) }
before do
visit(admin_license_path)
end
it "shows only expiration duration" do
expect(page).to have_content(license.licensee.values.first)
page.within(".js-license-info-panel") do
expect(page).not_to have_content("Expires: Free trial will expire in")
end
end
context "when license expired" do
set(:license) { build(:license, data: build(:gitlab_license, expires_at: Date.yesterday).export).save(validate: false) }
it { expect(page).to have_content("Your license expired") }
context "when license blocks changes" do
set(:license) { build(:license, data: build(:gitlab_license, expires_at: Date.yesterday, block_changes_at: Date.today).export).save(validate: false) }
it { expect(page).to have_content "Pushing code and creation of issues and merge requests has been disabled." }
end
end
context "when viewing license history" do
set(:license) { create(:license) }
it "shows licensee" do
license_history = page.find("#license_history")
License.previous.each do |license|
expect(license_history).to have_content(license.licensee.values.first)
end
end
end
end
context "with limited users" do
set(:license) { create(:license, data: build(:gitlab_license, restrictions: { active_user_count: 2000 }).export) }
before do
visit(admin_license_path)
end
it "shows panel counts" do
page.within(".license-panel") do
expect(page).to have_content("2,000")
end
end
end
end
@admin
Feature: Admin license
Background:
Given I sign in as an admin
Scenario: Viewing current license
Given there is a license
And I visit admin license page
Then I should see to whom the license is licensed
Scenario: Viewing expired license
Given there is a license
And the current license is expired
And I visit admin license page
Then I should see a warning telling me the license has expired
Scenario: Viewing license that blocks changes
Given there is a license
And the current license is expired
And the current license blocks changes
And I visit admin license page
Then I should see a warning telling me code pushes have been disabled
Scenario: Viewing license history
Given there is a license
And there are multiple licenses
And I visit admin license page
Then I should see to whom the licenses were licensed
Scenario: Uploading valid license
Given I visit admin upload license page
And I upload a valid license
Then I should see a notice telling me the license was uploaded
And I should see to whom the license is licensed
Scenario: Uploading invalid license
Given I visit admin upload license page
Then I upload an invalid license
Then I should see a warning telling me it's invalid
class Spinach::Features::AdminLicense < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
step 'I should see to whom the license is licensed' do
expect(page).to have_content(license.licensee.values.first)
end
step 'there is a license' do
create(:license)
end
step 'there is no license' do
License.destroy_all
end
step 'I should be redirected to the license upload page' do
expect(current_path).to eq(new_admin_license_path)
end
step 'the current license is expired' do
build(:license, data: build(:gitlab_license, expires_at: Date.yesterday).export).save(validate: false)
end
step 'I should see a warning telling me the license has expired' do
expect(page).to have_content "Your license expired"
end
step 'the current license blocks changes' do
build(:license, data: build(:gitlab_license, expires_at: Date.yesterday, block_changes_at: Date.today).export).save(validate: false)
end
step 'I should see a warning telling me code pushes have been disabled' do
expect(page).to have_content "Pushing code and creation of issues and merge requests has been disabled."
end
step 'there are multiple licenses' do
create(:license)
create(:license)
end
step 'I should see to whom the licenses were licensed' do
license_history = page.find("#license_history")
License.previous.each do |license|
expect(license_history).to have_content(license.licensee.values.first)
end
end
step 'I visit admin upload license page' do
visit new_admin_license_path
end
step 'I upload a valid license' do
path = Rails.root.join("tmp/valid_license.gitlab-license")
license = build(:gitlab_license)
File.write(path, license.export)
attach_file 'license_data_file', path
click_button "Upload license"
end
step 'I should see a notice telling me the license was uploaded' do
expect(page).to have_content "The license was successfully uploaded and is now active."
end
step 'I upload an invalid license' do
path = Rails.root.join("tmp/invalid_license.gitlab-license")
license = build(:gitlab_license, expires_at: Date.yesterday)
File.write(path, license.export)
attach_file 'license_data_file', path
click_button "Upload license"
end
step "I should see a warning telling me it's invalid" do
expect(page).to have_content "This license has already expired."
end
def license
License.reset_current
License.current
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