Welcome to mirror list, hosted at ThFree Co, Russian Federation.

require_verification_for_namespace_creation_experiment_spec.rb « experiments « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 87417fe1637dd15d158a607a5dac63ba5e9f70c3 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe RequireVerificationForNamespaceCreationExperiment, :experiment do
  subject(:experiment) { described_class.new(user: user) }

  let_it_be(:user) { create(:user) }

  describe '#candidate?' do
    context 'when experiment subject is candidate' do
      before do
        stub_experiments(require_verification_for_namespace_creation: :candidate)
      end

      it 'returns true' do
        expect(experiment.candidate?).to eq(true)
      end
    end

    context 'when experiment subject is control' do
      before do
        stub_experiments(require_verification_for_namespace_creation: :control)
      end

      it 'returns false' do
        expect(experiment.candidate?).to eq(false)
      end
    end
  end

  describe '#record_conversion' do
    let_it_be(:namespace) { create(:namespace) }

    context 'when should_track? is false' do
      before do
        allow(experiment).to receive(:should_track?).and_return(false)
      end

      it 'does not record a conversion event' do
        expect(experiment.publish_to_database).to be_nil
        expect(experiment.record_conversion(namespace)).to be_nil
      end
    end

    context 'when should_track? is true' do
      before do
        allow(experiment).to receive(:should_track?).and_return(true)
      end

      it 'records a conversion event' do
        experiment_subject = experiment.publish_to_database

        expect { experiment.record_conversion(namespace) }.to change { experiment_subject.reload.converted_at }.from(nil)
          .and change { experiment_subject.context }.to include('namespace_id' => namespace.id)
      end
    end
  end
end