debian-mirror-gitlab/spec/services/packages/composer/composer_json_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe Packages::Composer::ComposerJsonService, feature_category: :package_registry do
2020-07-28 23:09:34 +05:30
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
2023-01-13 00:05:48 +05:30
let(:project) { create(:project, :custom_repo, files: { 'composer.json' => json }) }
2020-07-28 23:09:34 +05:30
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
2021-01-03 14:25:43 +05:30
expect { subject }.to raise_error(described_class::InvalidJson, /Invalid/)
2020-07-28 23:09:34 +05:30
end
end
end
context 'without the composer.json file' do
let(:project) { create(:project, :repository) }
it 'raises an error' do
2021-01-03 14:25:43 +05:30
expect { subject }.to raise_error(described_class::InvalidJson, /not found/)
2020-07-28 23:09:34 +05:30
end
end
end
end