summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/pipeline/chain/template_usage_spec.rb
blob: 8e0b032e68ca9f2c6fae147a6838f6a6fac5ee65 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Pipeline::Chain::TemplateUsage do
  let_it_be(:project) { create(:project) }
  let_it_be(:user) { create(:user) }

  let(:pipeline) { create(:ci_pipeline, project: project) }

  let(:command) do
    Gitlab::Ci::Pipeline::Chain::Command.new(project: project, current_user: user)
  end

  let(:step) { described_class.new(pipeline, command) }

  describe '#perform!' do
    subject(:perform) { step.perform! }

    it 'tracks the included templates' do
      expect(command).to(
        receive(:yaml_processor_result)
          .and_return(
            double(included_templates: %w(Template-1 Template-2))
          )
      )

      %w(Template-1 Template-2).each do |expected_template|
        expect(Gitlab::UsageDataCounters::CiTemplateUniqueCounter).to(
          receive(:track_unique_project_event)
            .with(project_id: project.id, template: expected_template, config_source: pipeline.config_source)
        )
      end

      perform
    end
  end
end