usage_data_spec.rb 2.6 KB
Newer Older
1 2 3
require 'spec_helper'

describe Gitlab::UsageData do
4 5
  let(:projects) { create_list(:project, 3) }
  let!(:board) { create(:board, project: projects[0]) }
6 7

  describe '#data' do
8 9 10 11 12 13 14 15 16
    before do
      create(:jira_service, project: projects[0])
      create(:jira_service, project: projects[1])
      create(:prometheus_service, project: projects[1])
      create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true)
      create(:service, project: projects[1], type: 'SlackService', active: true)
      create(:service, project: projects[2], type: 'SlackService', active: true)
    end

17
    subject { described_class.data }
18 19 20 21 22 23

    it "gathers usage data" do
      expect(subject.keys).to match_array(%i(
        active_user_count
        counts
        recorded_at
Z
Z.J. van de Weg 已提交
24
        mattermost_enabled
S
Sean McGivern 已提交
25
        edition
26 27
        version
        uuid
S
Sean McGivern 已提交
28
        hostname
29 30 31 32 33 34 35
      ))
    end

    it "gathers usage counts" do
      count_data = subject[:counts]

      expect(count_data[:boards]).to eq(1)
36
      expect(count_data[:projects]).to eq(3)
37 38 39 40

      expect(count_data.keys).to match_array(%i(
        boards
        ci_builds
41 42
        ci_internal_pipelines
        ci_external_pipelines
43 44
        ci_runners
        ci_triggers
45
        ci_pipeline_schedules
46 47 48
        deploy_keys
        deployments
        environments
49
        in_review_folder
50 51 52 53 54 55 56 57 58
        groups
        issues
        keys
        labels
        lfs_objects
        merge_requests
        milestones
        notes
        projects
59
        projects_imported_from_github
60 61 62
        projects_jira_active
        projects_slack_notifications_active
        projects_slack_slash_active
63
        projects_prometheus_active
64 65 66 67 68
        pages_domains
        protected_branches
        releases
        snippets
        todos
R
Robert Speicher 已提交
69
        uploads
70 71 72
        web_hooks
      ))
    end
73 74 75 76 77 78 79 80 81 82

    it 'gathers projects data correctly' do
      count_data = subject[:counts]

      expect(count_data[:projects]).to eq(3)
      expect(count_data[:projects_prometheus_active]).to eq(1)
      expect(count_data[:projects_jira_active]).to eq(2)
      expect(count_data[:projects_slack_notifications_active]).to eq(2)
      expect(count_data[:projects_slack_slash_active]).to eq(1)
    end
83 84 85
  end

  describe '#license_usage_data' do
86
    subject { described_class.license_usage_data }
87 88

    it "gathers license data" do
89
      expect(subject[:uuid]).to eq(current_application_settings.uuid)
90 91 92 93 94 95
      expect(subject[:version]).to eq(Gitlab::VERSION)
      expect(subject[:active_user_count]).to eq(User.active.count)
      expect(subject[:recorded_at]).to be_a(Time)
    end
  end
end