debian-mirror-gitlab/spec/graphql/mutations/labels/create_spec.rb

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

83 lines
2.1 KiB
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Mutations::Labels::Create do
let_it_be(:user) { create(:user) }
let(:attributes) do
{
title: 'new title',
description: 'A new label'
}
end
let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
let(:mutated_label) { subject[:label] }
shared_examples 'create labels mutation' do
describe '#resolve' do
subject { mutation.resolve(attributes.merge(extra_params)) }
context 'when the user does not have permission to create a label' do
before do
parent.add_guest(user)
end
it 'raises an error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
context 'when the user can create a label' do
before do
parent.add_developer(user)
end
it 'creates label with correct values' do
expect(mutated_label).to have_attributes(attributes)
end
end
end
end
specify { expect(described_class).to require_graphql_authorizations(:admin_label) }
context 'when creating a project label' do
let_it_be(:parent) { create(:project) }
2021-09-30 23:02:18 +05:30
2021-01-29 00:20:46 +05:30
let(:extra_params) { { project_path: parent.full_path } }
it_behaves_like 'create labels mutation'
end
context 'when creating a group label' do
let_it_be(:parent) { create(:group) }
2021-09-30 23:02:18 +05:30
2021-01-29 00:20:46 +05:30
let(:extra_params) { { group_path: parent.full_path } }
it_behaves_like 'create labels mutation'
end
describe '#ready?' do
2021-02-22 17:27:13 +05:30
subject { mutation.ready?(**attributes.merge(extra_params)) }
2021-01-29 00:20:46 +05:30
context 'when passing both project_path and group_path' do
let(:extra_params) { { project_path: 'foo', group_path: 'bar' } }
it 'raises an argument error' do
expect { subject }
.to raise_error(Gitlab::Graphql::Errors::ArgumentError, /Exactly one of/)
end
end
context 'when passing only project_path or group_path' do
let(:extra_params) { { project_path: 'foo' } }
it 'does not raise an error' do
expect { subject }.not_to raise_error
end
end
end
end