File: group_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (70 lines) | stat: -rw-r--r-- 2,503 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe API::Entities::Group, feature_category: :groups_and_projects do
  let_it_be(:group) do
    base_group = create(:group) do |g|
      create(:project_statistics, namespace_id: g.id)
      create(:namespace_root_storage_statistics, namespace_id: g.id)
    end
    Group.with_statistics.find(base_group.id)
  end

  subject(:json) { described_class.new(group, options).as_json }

  context 'with statistics' do
    let(:options) { { with_custom_attributes: true, statistics: true } }

    it 'returns expected data' do
      expect(json.keys).to(
        include(
          :organization_id, :path, :description, :visibility, :share_with_group_lock,
          :require_two_factor_authentication, :two_factor_grace_period, :project_creation_level, :auto_devops_enabled,
          :subgroup_creation_level, :emails_disabled, :emails_enabled, :lfs_enabled, :default_branch_protection,
          :default_branch_protection_defaults, :avatar_url, :request_access_enabled, :full_name, :full_path,
          :created_at, :parent_id, :organization_id, :shared_runners_setting, :custom_attributes, :statistics,
          :default_branch, :root_storage_statistics
        )
      )
    end

    context 'on a sub-group' do
      let(:subgroup) do
        subgroup = create(:group, parent: group, path: "#{group.path}-subgroup") do |g|
          create(:project_statistics, namespace_id: g.id)
        end
        Group.with_statistics.find(subgroup.id)
      end

      subject(:json) { described_class.new(subgroup, options).as_json }

      it 'does not expose root storage statistics' do
        expect(json.keys).not_to(include(:root_storage_statistics))
      end
    end

    context 'on a group without root storage statistics' do
      let(:group_without_root_storage_statistics) do
        base_group = create(:group) do |g|
          create(:project_statistics, namespace_id: g.id)
        end
        Group.with_statistics.find(base_group.id)
      end

      subject(:json) { described_class.new(group_without_root_storage_statistics, options).as_json }

      it 'returns nil for root storage statistics' do
        expect(json[:root_storage_statistics]).to be_nil
      end
    end
  end

  context 'without statistics' do
    let(:options) { { with_custom_attributes: true, statistics: false } }

    it 'does not expose statistics' do
      expect(json.keys).not_to(include(:statistics, :root_storage_statistics))
    end
  end
end