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

ref_converter_spec.rb « bitbucket_import « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 578b661d86b9fc0e458567a93214e8829fc95fc6 (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
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::BitbucketImport::RefConverter, feature_category: :importers do
  let_it_be(:project_identifier) { 'namespace/repo' }
  let_it_be(:project) { create(:project, import_source: project_identifier) }
  let(:path) { project.full_path }

  let(:ref_converter) { described_class.new(project) }

  shared_examples 'converts the ref correctly' do
    it 'converts the ref to a gitlab reference' do
      actual = ref_converter.convert_note(note)

      expect(actual).to eq(expected)
    end
  end

  context 'when the note has an issue ref' do
    let(:note) { "[https://bitbucket.org/namespace/repo/issues/1/first-issue](https://bitbucket.org/namespace/repo/issues/1/first-issue){: data-inline-card='' } " }
    let(:expected) { "[http://localhost/#{path}/-/issues/1/](http://localhost/#{path}/-/issues/1/)" }

    it_behaves_like 'converts the ref correctly'
  end

  context 'when the note has a pull request ref' do
    let(:note) { "[https://bitbucket.org/namespace/repo/pull-requests/7](https://bitbucket.org/namespace/repo/pull-requests/7){: data-inline-card='' } " }
    let(:expected) { "[http://localhost/#{path}/-/merge_requests/7](http://localhost/#{path}/-/merge_requests/7)" }

    it_behaves_like 'converts the ref correctly'
  end

  context 'when the note has a reference to a branch' do
    let(:note) { "[https://bitbucket.org/namespace/repo/src/master/](https://bitbucket.org/namespace/repo/src/master/){: data-inline-card='' } " }
    let(:expected) { "[http://localhost/#{path}/-/blob/master/](http://localhost/#{path}/-/blob/master/)" }

    it_behaves_like 'converts the ref correctly'
  end

  context 'when the note has a reference to a line in a file' do
    let(:note) do
      "[https://bitbucket.org/namespace/repo/src/0f16a22c21671421780980c9a7433eb8c986b9af/.gitignore#lines-6] \
      (https://bitbucket.org/namespace/repo/src/0f16a22c21671421780980c9a7433eb8c986b9af/.gitignore#lines-6) \
      {: data-inline-card='' }"
    end

    let(:expected) do
      "[http://localhost/#{path}/-/blob/0f16a22c21671421780980c9a7433eb8c986b9af/.gitignore#L6] \
      (http://localhost/#{path}/-/blob/0f16a22c21671421780980c9a7433eb8c986b9af/.gitignore#L6)"
    end

    it_behaves_like 'converts the ref correctly'
  end

  context 'when the note has a reference to a file' do
    let(:note) { "[https://bitbucket.org/namespace/repo/src/master/.gitignore](https://bitbucket.org/namespace/repo/src/master/.gitignore){: data-inline-card='' } " }
    let(:expected) { "[http://localhost/#{path}/-/blob/master/.gitignore](http://localhost/#{path}/-/blob/master/.gitignore)" }

    it_behaves_like 'converts the ref correctly'
  end

  context 'when the note does not have a ref' do
    let(:note) { 'Hello world' }
    let(:expected) { 'Hello world' }

    it_behaves_like 'converts the ref correctly'
  end
end