debian-mirror-gitlab/spec/requests/api/graphql/mutations/issues/create_spec.rb

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

91 lines
2.8 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Create an issue' do
include GraphqlHelpers
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:assignee1) { create(:user) }
let_it_be(:assignee2) { create(:user) }
let_it_be(:project_label1) { create(:label, project: project) }
let_it_be(:project_label2) { create(:label, project: project) }
let_it_be(:milestone) { create(:milestone, project: project) }
let_it_be(:new_label1) { FFaker::Lorem.word }
let_it_be(:new_label2) { FFaker::Lorem.word }
let(:input) do
{
'title' => 'new title',
'description' => 'new description',
'confidential' => true,
2021-06-08 01:23:25 +05:30
'dueDate' => Date.tomorrow.strftime('%Y-%m-%d'),
'type' => 'ISSUE'
2021-01-03 14:25:43 +05:30
}
end
let(:mutation) { graphql_mutation(:createIssue, input.merge('projectPath' => project.full_path, 'locked' => true)) }
let(:mutation_response) { graphql_mutation_response(:create_issue) }
context 'the user is not allowed to create an issue' do
it_behaves_like 'a mutation that returns a top-level access error'
end
context 'when user has permissions to create an issue' do
before do
project.add_developer(current_user)
end
2021-06-08 01:23:25 +05:30
it 'creates the issue' do
2021-11-11 11:23:49 +05:30
expect do
post_graphql_mutation(mutation, current_user: current_user)
end.to change(Issue, :count).by(1)
2021-01-03 14:25:43 +05:30
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']).to include(input)
expect(mutation_response['issue']).to include('discussionLocked' => true)
2021-11-11 11:23:49 +05:30
expect(Issue.last.work_item_type.base_type).to eq('issue')
2021-01-03 14:25:43 +05:30
end
2021-12-11 22:18:48 +05:30
it_behaves_like 'has spam protection' do
let(:mutation_class) { ::Mutations::Issues::Create }
end
2022-04-04 11:22:00 +05:30
2022-08-13 15:12:31 +05:30
context 'when creating an issue of type TASK' do
before do
input['type'] = 'TASK'
end
2023-01-13 00:05:48 +05:30
it 'creates an issue with TASK type' do
expect do
post_graphql_mutation(mutation, current_user: current_user)
end.to change(Issue, :count).by(1)
2022-08-13 15:12:31 +05:30
2023-01-13 00:05:48 +05:30
created_issue = Issue.last
2022-08-13 15:12:31 +05:30
2023-01-13 00:05:48 +05:30
expect(created_issue.work_item_type.base_type).to eq('task')
expect(created_issue.issue_type).to eq('task')
2022-08-13 15:12:31 +05:30
end
end
2022-04-04 11:22:00 +05:30
context 'when position params are provided' do
let(:existing_issue) { create(:issue, project: project, relative_position: 50) }
before do
input.merge!(
move_after_id: existing_issue.to_global_id.to_s
)
end
it 'sets the correct position' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['issue']['relativePosition']).to be < existing_issue.relative_position
end
end
2021-01-03 14:25:43 +05:30
end
end