2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Resolvers::ReleaseResolver do
|
2020-05-24 23:13:21 +05:30
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
let_it_be(:project) { create(:project, :private) }
|
|
|
|
let_it_be(:release) { create(:release, project: project) }
|
|
|
|
let_it_be(:developer) { create(:user) }
|
|
|
|
let_it_be(:public_user) { create(:user) }
|
|
|
|
|
|
|
|
let(:args) { { tag_name: release.tag } }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(developer)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#resolve' do
|
|
|
|
context 'when the user does not have access to the project' do
|
|
|
|
let(:current_user) { public_user }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(resolve_release).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user has full access to the project's releases" do
|
|
|
|
let(:current_user) { developer }
|
|
|
|
|
|
|
|
it 'returns the release associated with the specified tag' do
|
|
|
|
expect(resolve_release).to eq(release)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no tag_name argument was passed' do
|
|
|
|
let(:args) { {} }
|
|
|
|
|
|
|
|
it 'raises an error' do
|
2021-03-11 19:13:27 +05:30
|
|
|
expect { resolve_release }.to raise_error(ArgumentError)
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def resolve_release
|
|
|
|
context = { current_user: current_user }
|
|
|
|
resolve(described_class, obj: project, args: args, ctx: context)
|
|
|
|
end
|
|
|
|
end
|