summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/code_navigation_path_spec.rb
blob: 938a2f821fd856febb090e8c9281ba4f5375d11a (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
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::CodeNavigationPath do
  context 'when there is an artifact with code navigation data' do
    let_it_be(:project) { create(:project, :repository) }
    let_it_be(:sha) { project.repository.commits('master', limit: 5).last.id }
    let_it_be(:pipeline) { create(:ci_pipeline, project: project, sha: sha) }
    let_it_be(:job) { create(:ci_build, pipeline: pipeline) }
    let_it_be(:artifact) { create(:ci_job_artifact, :lsif, job: job) }

    let(:commit_sha) { sha }
    let(:path) { 'lib/app.rb' }

    subject { described_class.new(project, commit_sha).full_json_path_for(path) }

    context 'when a pipeline exist for a sha' do
      it 'returns path to a file in the artifact' do
        expect(subject).to eq("/#{project.full_path}/-/jobs/#{job.id}/artifacts/raw/lsif/#{path}.json?file_type=lsif")
      end
    end

    context 'when a pipeline exist for the latest commits' do
      let(:commit_sha) { project.commit.id }

      it 'returns path to a file in the artifact' do
        expect(subject).to eq("/#{project.full_path}/-/jobs/#{job.id}/artifacts/raw/lsif/#{path}.json?file_type=lsif")
      end
    end

    context 'when code_navigation feature is disabled' do
      before do
        stub_feature_flags(code_navigation: false)
      end

      it 'returns nil' do
        expect(subject).to be_nil
      end
    end
  end
end