summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/dependency_linker/composer_json_linker_spec.rb
blob: 0ebd8994636935b41b8f9a699264377c2e373905 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
require 'rails_helper'

describe Gitlab::DependencyLinker::ComposerJsonLinker do
  describe '.support?' do
    it 'supports composer.json' do
      expect(described_class.support?('composer.json')).to be_truthy
    end

    it 'does not support other files' do
      expect(described_class.support?('composer.json.example')).to be_falsey
    end
  end

  describe '#link' do
    let(:file_name) { "composer.json" }

    let(:file_content) do
      <<-CONTENT.strip_heredoc
        {
          "name": "laravel/laravel",
          "homepage": "https://laravel.com/",
          "description": "The Laravel Framework.",
          "keywords": ["framework", "laravel"],
          "license": "MIT",
          "type": "project",
          "repositories": [
            {
              "type": "git",
              "url": "https://github.com/laravel/laravel.git"
            }
          ],
          "require": {
            "php": ">=5.5.9",
            "laravel/framework": "5.2.*"
          },
          "require-dev": {
            "fzaninotto/faker": "~1.4",
            "mockery/mockery": "0.9.*",
            "phpunit/phpunit": "~4.0",
            "symfony/css-selector": "2.8.*|3.0.*",
            "symfony/dom-crawler": "2.8.*|3.0.*"
          }
        }
      CONTENT
    end

    subject { Gitlab::Highlight.highlight(file_name, file_content) }

    def link(name, url)
      %{<a href="#{url}" rel="nofollow noreferrer noopener" target="_blank">#{name}</a>}
    end

    it 'does not link the module name' do
      expect(subject).not_to include(link('laravel/laravel', 'https://packagist.org/packages/laravel/laravel'))
    end

    it 'links the homepage' do
      expect(subject).to include(link('https://laravel.com/', 'https://laravel.com/'))
    end

    it 'links the repository URL' do
      expect(subject).to include(link('https://github.com/laravel/laravel.git', 'https://github.com/laravel/laravel.git'))
    end

    it 'links the license' do
      expect(subject).to include(link('MIT', 'http://choosealicense.com/licenses/mit/'))
    end

    it 'links dependencies' do
      expect(subject).to include(link('laravel/framework', 'https://packagist.org/packages/laravel/framework'))
      expect(subject).to include(link('fzaninotto/faker', 'https://packagist.org/packages/fzaninotto/faker'))
      expect(subject).to include(link('mockery/mockery', 'https://packagist.org/packages/mockery/mockery'))
      expect(subject).to include(link('phpunit/phpunit', 'https://packagist.org/packages/phpunit/phpunit'))
      expect(subject).to include(link('symfony/css-selector', 'https://packagist.org/packages/symfony/css-selector'))
      expect(subject).to include(link('symfony/dom-crawler', 'https://packagist.org/packages/symfony/dom-crawler'))
    end

    it 'does not link core dependencies' do
      expect(subject).not_to include(link('php', 'https://packagist.org/packages/php'))
    end
  end
end