debian-mirror-gitlab/spec/helpers/storage_helper_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

150 lines
5.8 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
require "spec_helper"
2017-08-17 22:00:37 +05:30
2020-07-28 23:09:34 +05:30
RSpec.describe StorageHelper do
2018-11-08 19:23:39 +05:30
describe "#storage_counter" do
it "formats bytes to one decimal place" do
expect(helper.storage_counter(1.23.megabytes)).to eq("1.2 MB")
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
it "does not add decimals for sizes < 1 MB" do
expect(helper.storage_counter(23.5.kilobytes)).to eq("24 KB")
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
it "does not add decimals for zeroes" do
expect(helper.storage_counter(2.megabytes)).to eq("2 MB")
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
it "uses commas as thousands separator" do
2019-02-15 15:39:39 +05:30
expect(helper.storage_counter(100_000_000_000_000_000_000_000)).to eq("86,736.2 EB")
2017-08-17 22:00:37 +05:30
end
end
2019-07-31 22:56:46 +05:30
describe "#storage_counters_details" do
2020-11-24 15:15:51 +05:30
let_it_be(:namespace) { create(:namespace) }
let_it_be(:project) do
2019-07-31 22:56:46 +05:30
create(:project,
namespace: namespace,
statistics: build(:project_statistics,
2021-12-11 22:18:48 +05:30
namespace: namespace,
repository_size: 10.kilobytes,
wiki_size: 10.bytes,
lfs_objects_size: 20.gigabytes,
build_artifacts_size: 30.megabytes,
pipeline_artifacts_size: 11.megabytes,
snippets_size: 40.megabytes,
packages_size: 12.megabytes,
uploads_size: 15.megabytes))
2019-07-31 22:56:46 +05:30
end
2021-12-11 22:18:48 +05:30
let(:message) { 'Repository: 10 KB / Wikis: 10 Bytes / Build Artifacts: 30 MB / Pipeline Artifacts: 11 MB / LFS: 20 GB / Snippets: 40 MB / Packages: 12 MB / Uploads: 15 MB' }
2019-07-31 22:56:46 +05:30
it 'works on ProjectStatistics' do
expect(helper.storage_counters_details(project.statistics)).to eq(message)
end
it 'works on Namespace.with_statistics' do
namespace_stats = Namespace.with_statistics.find(project.namespace.id)
expect(helper.storage_counters_details(namespace_stats)).to eq(message)
end
end
2022-04-04 11:22:00 +05:30
describe "storage_enforcement_banner" do
let_it_be_with_refind(:current_user) { create(:user) }
let_it_be(:free_group) { create(:group) }
let_it_be(:paid_group) { create(:group) }
before do
2022-05-07 20:08:51 +05:30
allow(helper).to receive(:can?).with(current_user, :admin_namespace, free_group).and_return(true)
allow(helper).to receive(:can?).with(current_user, :admin_namespace, paid_group).and_return(true)
2022-04-04 11:22:00 +05:30
allow(helper).to receive(:current_user) { current_user }
allow(Gitlab).to receive(:com?).and_return(true)
allow(paid_group).to receive(:paid?).and_return(true)
end
describe "#storage_enforcement_banner_info" do
it 'returns nil when namespace is not free' do
2022-05-07 20:08:51 +05:30
expect(helper.storage_enforcement_banner_info(paid_group)).to be(nil)
2022-04-04 11:22:00 +05:30
end
it 'returns nil when storage_enforcement_date is not set' do
allow(free_group).to receive(:storage_enforcement_date).and_return(nil)
2022-05-07 20:08:51 +05:30
expect(helper.storage_enforcement_banner_info(free_group)).to be(nil)
2022-04-04 11:22:00 +05:30
end
2022-05-07 20:08:51 +05:30
describe 'when storage_enforcement_date is set' do
let_it_be(:storage_enforcement_date) { Date.today + 30 }
before do
allow(free_group).to receive(:storage_enforcement_date).and_return(storage_enforcement_date)
end
it 'returns nil when current_user do not have access usage quotas page' do
allow(helper).to receive(:can?).with(current_user, :admin_namespace, free_group).and_return(false)
expect(helper.storage_enforcement_banner_info(free_group)).to be(nil)
end
it 'returns a hash when current_user can access usage quotas page' do
expect(helper.storage_enforcement_banner_info(free_group)).to eql({
text: "From #{storage_enforcement_date} storage limits will apply to this namespace. View and manage your usage in <strong>Group settings &gt; Usage quotas</strong>.",
variant: 'warning',
callouts_feature_name: 'storage_enforcement_banner_second_enforcement_threshold',
callouts_path: '/-/users/group_callouts',
learn_more_link: '<a rel="noopener noreferrer" target="_blank" href="/help//">Learn more.</a>'
})
end
2022-04-04 11:22:00 +05:30
end
context 'when storage_enforcement_date is set and dismissed callout exists' do
before do
create(:group_callout,
user: current_user,
group_id: free_group.id,
feature_name: 'storage_enforcement_banner_second_enforcement_threshold')
storage_enforcement_date = Date.today + 30
allow(free_group).to receive(:storage_enforcement_date).and_return(storage_enforcement_date)
end
2022-05-07 20:08:51 +05:30
it { expect(helper.storage_enforcement_banner_info(free_group)).to be(nil) }
2022-04-04 11:22:00 +05:30
end
context 'callouts_feature_name' do
let(:days_from_now) { 45 }
subject do
storage_enforcement_date = Date.today + days_from_now
allow(free_group).to receive(:storage_enforcement_date).and_return(storage_enforcement_date)
2022-05-07 20:08:51 +05:30
helper.storage_enforcement_banner_info(free_group)[:callouts_feature_name]
2022-04-04 11:22:00 +05:30
end
it 'returns first callouts_feature_name' do
is_expected.to eq('storage_enforcement_banner_first_enforcement_threshold')
end
context 'returns second callouts_feature_name' do
let(:days_from_now) { 20 }
it { is_expected.to eq('storage_enforcement_banner_second_enforcement_threshold') }
end
context 'returns third callouts_feature_name' do
let(:days_from_now) { 13 }
it { is_expected.to eq('storage_enforcement_banner_third_enforcement_threshold') }
end
context 'returns fourth callouts_feature_name' do
let(:days_from_now) { 3 }
it { is_expected.to eq('storage_enforcement_banner_fourth_enforcement_threshold') }
end
end
end
end
2017-08-17 22:00:37 +05:30
end