summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/monitor/demo_projects_spec.rb
blob: 262c78eb62ede2dc57c86c7ce77ea26fd6a31ca2 (plain)
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Monitor::DemoProjects do
  describe '#primary_keys' do
    subject { described_class.primary_keys }

    it 'fetches primary_keys when on gitlab.com' do
      allow(Gitlab).to receive(:com?).and_return(true)
      allow(Gitlab).to receive(:staging?).and_return(false)

      expect(subject).to eq(Gitlab::Monitor::DemoProjects::DOT_COM_IDS)
    end

    it 'fetches primary_keys when on staging' do
      allow(Gitlab).to receive(:com?).and_return(true)
      allow(Gitlab).to receive(:staging?).and_return(true)

      expect(subject).to eq(Gitlab::Monitor::DemoProjects::STAGING_IDS)
    end

    it 'fetches all keys when in the dev or test env' do
      project = create(:project)
      allow(Gitlab).to receive(:dev_or_test_env?).and_return(true)

      expect(subject).to eq([project.id])
    end

    it 'falls back on empty array' do
      stub_config_setting(url: 'https://helloworld')
      allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)

      expect(subject).to eq([])
    end
  end
end