debian-mirror-gitlab/spec/graphql/mutations/issues/set_severity_spec.rb
2020-11-24 15:15:51 +05:30

62 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Mutations::Issues::SetSeverity do
let_it_be(:user) { create(:user) }
let_it_be(:issue) { create(:incident) }
let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
specify { expect(described_class).to require_graphql_authorizations(:update_issue) }
describe '#resolve' do
let(:severity) { 'CRITICAL' }
let(:mutated_incident) { subject[:issue] }
subject(:resolve) { mutation.resolve(project_path: issue.project.full_path, iid: issue.iid, severity: severity) }
context 'when the user cannot update the issue' do
it 'raises an error' do
expect { resolve }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
context 'when the user can update the issue' do
before do
issue.project.add_developer(user)
end
context 'when issue type is incident' do
context 'when severity has a correct value' do
it 'updates severity' do
expect(resolve[:issue].severity).to eq('critical')
end
it 'returns no errors' do
expect(resolve[:errors]).to be_empty
end
end
context 'when severity has an unsuported value' do
let(:severity) { 'unsupported-severity' }
it 'sets severity to default' do
expect(resolve[:issue].severity).to eq(IssuableSeverity::DEFAULT)
end
it 'returns no errorsr' do
expect(resolve[:errors]).to be_empty
end
end
end
context 'when issue type is not incident' do
let!(:issue) { create(:issue) }
it 'does not updates the issue' do
expect { resolve }.not_to change { issue.updated_at }
end
end
end
end
end