debian-mirror-gitlab/spec/graphql/mutations/issues/set_severity_spec.rb

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

92 lines
2.5 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Mutations::Issues::SetSeverity do
2021-10-29 20:43:33 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:guest) { create(:user) }
let_it_be(:reporter) { create(:user) }
let_it_be(:issue) { create(:incident, project: project) }
2021-09-30 23:02:18 +05:30
2020-11-24 15:15:51 +05:30
let(:mutation) { described_class.new(object: nil, context: { current_user: user }, field: nil) }
2021-10-29 20:43:33 +05:30
specify { expect(described_class).to require_graphql_authorizations(:update_issue, :admin_issue) }
before_all do
project.add_guest(guest)
project.add_reporter(reporter)
end
2020-11-24 15:15:51 +05:30
describe '#resolve' do
2021-09-30 23:02:18 +05:30
let(:severity) { 'critical' }
2020-11-24 15:15:51 +05:30
2021-10-29 20:43:33 +05:30
subject(:resolve) do
mutation.resolve(
project_path: issue.project.full_path,
iid: issue.iid,
severity: severity
)
end
2020-11-24 15:15:51 +05:30
2021-10-29 20:43:33 +05:30
context 'as guest' do
let(:user) { guest }
2020-11-24 15:15:51 +05:30
2021-10-29 20:43:33 +05:30
it 'raises an error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
context 'and also author' do
let!(:issue) { create(:incident, project: project, author: user) }
it 'raises an error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
2020-11-24 15:15:51 +05:30
end
2021-10-29 20:43:33 +05:30
context 'and also assignee' do
let!(:issue) { create(:incident, project: project, assignee_ids: [user.id]) }
it 'raises an error' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
context 'as reporter' do
let(:user) { reporter }
2020-11-24 15:15:51 +05:30
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
2021-10-29 20:43:33 +05:30
let!(:issue) { create(:issue, project: project) }
2020-11-24 15:15:51 +05:30
2021-10-29 20:43:33 +05:30
it 'does not update the issue' do
2020-11-24 15:15:51 +05:30
expect { resolve }.not_to change { issue.updated_at }
end
end
end
end
end