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

composer_json_service_spec.rb « composer « packages « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 378016a6ffb37d93cf4a2d37099204d426fbf110 (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
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Packages::Composer::ComposerJsonService do
  describe '#execute' do
    let(:branch) { project.repository.find_branch('master') }
    let(:target) { branch.target }

    subject { described_class.new(project, target).execute }

    context 'with an existing file' do
      let(:project) { create(:project, :custom_repo, files: { 'composer.json' => json } ) }

      context 'with a valid file' do
        let(:json) { '{ "name": "package-name"}' }

        it 'returns the parsed json' do
          expect(subject).to eq({ 'name' => 'package-name' })
        end
      end

      context 'with an invalid file' do
        let(:json) { '{ name": "package-name"}' }

        it 'raises an error' do
          expect { subject }.to raise_error(described_class::InvalidJson, /Invalid/)
        end
      end
    end

    context 'without the composer.json file' do
      let(:project) { create(:project, :repository) }

      it 'raises an error' do
        expect { subject }.to raise_error(described_class::InvalidJson, /not found/)
      end
    end
  end
end