2019-09-04 21:01:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe API::Issues, feature_category: :team_planning do
|
2020-03-13 15:44:24 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:owner) { create(:owner) }
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
let_it_be(:guest) { create(:user) }
|
|
|
|
let_it_be(:author) { create(:author) }
|
|
|
|
let_it_be(:assignee) { create(:assignee) }
|
|
|
|
let(:admin) { create(:user, :admin) }
|
2019-09-04 21:01:54 +05:30
|
|
|
let(:issue_title) { 'foo' }
|
|
|
|
let(:issue_description) { 'closed' }
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
let_it_be(:project, reload: true) do
|
|
|
|
create(:project, :public, creator_id: owner.id, namespace: owner.namespace)
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
let!(:closed_issue) do
|
|
|
|
create :closed_issue,
|
|
|
|
author: user,
|
|
|
|
assignees: [user],
|
|
|
|
project: project,
|
|
|
|
state: :closed,
|
|
|
|
milestone: milestone,
|
|
|
|
created_at: generate(:past_time),
|
|
|
|
updated_at: 3.hours.ago,
|
|
|
|
closed_at: 1.hour.ago
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
let!(:confidential_issue) do
|
|
|
|
create :issue,
|
|
|
|
:confidential,
|
|
|
|
project: project,
|
|
|
|
author: author,
|
|
|
|
assignees: [assignee],
|
|
|
|
created_at: generate(:past_time),
|
|
|
|
updated_at: 2.hours.ago
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
let!(:issue) do
|
|
|
|
create :issue,
|
|
|
|
author: user,
|
|
|
|
assignees: [user],
|
|
|
|
project: project,
|
|
|
|
milestone: milestone,
|
|
|
|
created_at: generate(:past_time),
|
|
|
|
updated_at: 1.hour.ago,
|
|
|
|
title: issue_title,
|
|
|
|
description: issue_description
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
let_it_be(:label) do
|
2019-09-04 21:01:54 +05:30
|
|
|
create(:label, title: 'label', color: '#FFAABB', project: project)
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
let!(:label_link) { create(:label_link, label: label, target: issue) }
|
|
|
|
let(:milestone) { create(:milestone, title: '1.0.0', project: project) }
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
let_it_be(:empty_milestone) do
|
2019-09-04 21:01:54 +05:30
|
|
|
create(:milestone, title: '2.0.0', project: project)
|
|
|
|
end
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
let!(:note) { create(:note_on_issue, author: user, project: project, noteable: issue) }
|
2019-09-04 21:01:54 +05:30
|
|
|
let(:no_milestone_title) { 'None' }
|
|
|
|
let(:any_milestone_title) { 'Any' }
|
2020-06-23 00:09:42 +05:30
|
|
|
let(:updated_title) { 'updated title' }
|
|
|
|
let(:issue_path) { "/projects/#{project.id}/issues/#{issue.iid}" }
|
|
|
|
let(:api_for_user) { api(issue_path, user) }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
before_all do
|
2019-09-04 21:01:54 +05:30
|
|
|
project.add_reporter(user)
|
|
|
|
project.add_guest(guest)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_licensed_features(multiple_issue_assignees: false, issue_weights: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /projects/:id/issues/:issue_iid to update only title' do
|
2023-06-20 00:43:36 +05:30
|
|
|
it_behaves_like 'PUT request permissions for admin mode' do
|
|
|
|
let(:path) { "/projects/#{project.id}/issues/#{confidential_issue.iid}" }
|
|
|
|
let(:params) { { title: updated_title } }
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'updates a project issue', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { title: updated_title }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response['title']).to eq(updated_title)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 error if issue iid not found' do
|
2023-06-20 00:43:36 +05:30
|
|
|
put api("/projects/#{project.id}/issues/#{non_existing_record_id}", user), params: { title: updated_title }
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 error if issue id is used instead of the iid' do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user), params: { title: updated_title }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows special label names' do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user,
|
2019-09-04 21:01:54 +05:30
|
|
|
params: {
|
2020-06-23 00:09:42 +05:30
|
|
|
title: updated_title,
|
2019-09-04 21:01:54 +05:30
|
|
|
labels: 'label, label?, label&foo, ?, &'
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'allows special label names with labels param as array', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user,
|
2019-09-04 21:01:54 +05:30
|
|
|
params: {
|
2020-06-23 00:09:42 +05:30
|
|
|
title: updated_title,
|
2019-09-04 21:01:54 +05:30
|
|
|
labels: ['label', 'label?', 'label&foo, ?, &']
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(json_response['labels']).to contain_exactly('label', 'label?', 'label&foo', '?', '&')
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'confidential issues' do
|
2020-06-23 00:09:42 +05:30
|
|
|
let(:confidential_issue_path) { "/projects/#{project.id}/issues/#{confidential_issue.iid}" }
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it 'returns 403 for non project members' do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api(confidential_issue_path, non_member), params: { title: updated_title }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 403 for project members with guest role' do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api(confidential_issue_path, guest), params: { title: updated_title }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'updates a confidential issue for project members', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api(confidential_issue_path, user), params: { title: updated_title }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(json_response['title']).to eq(updated_title)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'updates a confidential issue for author', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api(confidential_issue_path, author), params: { title: updated_title }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(json_response['title']).to eq(updated_title)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'updates a confidential issue for admin', :aggregate_failures do
|
|
|
|
put api(confidential_issue_path, admin, admin_mode: true), params: { title: updated_title }
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(json_response['title']).to eq(updated_title)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'sets an issue to confidential', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { confidential: true }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['confidential']).to be_truthy
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'makes a confidential issue public', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api(confidential_issue_path, user), params: { confidential: false }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['confidential']).to be_falsy
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'does not update a confidential issue with wrong confidential flag', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api(confidential_issue_path, user), params: { confidential: 'foo' }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['error']).to eq('confidential is invalid')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /projects/:id/issues/:issue_iid with spam filtering' do
|
2020-05-24 23:13:21 +05:30
|
|
|
include_context 'includes Spam constants'
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def update_issue
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: params
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
let(:params) do
|
|
|
|
{
|
2020-06-23 00:09:42 +05:30
|
|
|
title: updated_title,
|
2019-09-04 21:01:54 +05:30
|
|
|
description: 'content here',
|
|
|
|
labels: 'label, label2'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
before do
|
2020-05-24 23:13:21 +05:30
|
|
|
expect_next_instance_of(Spam::SpamActionService) do |spam_service|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(spam_service).to receive_messages(check_for_spam?: true)
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
allow_next_instance_of(Spam::AkismetService) do |akismet_service|
|
|
|
|
allow(akismet_service).to receive(:spam?).and_return(true)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
context 'when allow_possible_spam application setting is false' do
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'does not update a project issue' do
|
|
|
|
expect { update_issue }.not_to change { issue.reload.title }
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'returns correct status and message', :aggregate_failures do
|
2019-12-21 20:55:43 +05:30
|
|
|
update_issue
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(json_response['message']['base']).to match_array([/issue has been recognized as spam/])
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new spam log entry' do
|
|
|
|
expect { update_issue }
|
2020-06-23 00:09:42 +05:30
|
|
|
.to log_spam(title: updated_title, description: 'content here', user_id: user.id, noteable_type: 'Issue')
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
context 'when allow_possible_spam application setting is true' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(allow_possible_spam: true)
|
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
it 'updates a project issue' do
|
|
|
|
expect { update_issue }.to change { issue.reload.title }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns correct status and message' do
|
|
|
|
update_issue
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new spam log entry' do
|
|
|
|
expect { update_issue }
|
2020-06-23 00:09:42 +05:30
|
|
|
.to log_spam(title: updated_title, description: 'content here', user_id: user.id, noteable_type: 'Issue')
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /projects/:id/issues/:issue_iid to update assignee' do
|
|
|
|
context 'support for deprecated assignee_id' do
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'removes assignee', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { assignee_id: 0 }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['assignee']).to be_nil
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'updates an issue with new assignee', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { assignee_id: user2.id }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['assignee']['name']).to eq(user2.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'removes assignee', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { assignee_ids: [0] }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['assignees']).to be_empty
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'updates an issue with new assignee', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { assignee_ids: [user2.id] }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['assignees'].first['name']).to eq(user2.name)
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
context 'single assignee restrictions', :aggregate_failures do
|
2019-09-04 21:01:54 +05:30
|
|
|
it 'updates an issue with several assignees but only one has been applied' do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { assignee_ids: [user2.id, guest.id] }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['assignees'].size).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /projects/:id/issues/:issue_iid to update labels' do
|
|
|
|
let!(:label) { create(:label, title: 'dummy', project: project) }
|
|
|
|
let!(:label_link) { create(:label_link, label: label, target: issue) }
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'adds relevant labels', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { add_labels: '1, 2' }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response['labels']).to contain_exactly(label.title, '1', '2')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'removes' do
|
|
|
|
let!(:label2) { create(:label, title: 'a-label', project: project) }
|
|
|
|
let!(:label_link2) { create(:label_link, label: label2, target: issue) }
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'removes relevant labels', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { remove_labels: label2.title }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response['labels']).to eq([label.title])
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'removes all labels', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { remove_labels: "#{label.title}, #{label2.title}" }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response['labels']).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'does not update labels if not present', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { title: updated_title }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['labels']).to eq([label.title])
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'removes all labels and touches the record', :aggregate_failures do
|
2022-05-07 20:08:51 +05:30
|
|
|
travel_to(2.minutes.from_now) do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { labels: '' }
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['labels']).to eq([])
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(json_response['updated_at']).to be > Time.current
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'removes all labels and touches the record with labels param as array', :aggregate_failures do
|
2022-05-07 20:08:51 +05:30
|
|
|
travel_to(2.minutes.from_now) do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { labels: [''] }
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['labels']).to eq([])
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(json_response['updated_at']).to be > Time.current
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'updates labels and touches the record', :aggregate_failures do
|
2022-05-07 20:08:51 +05:30
|
|
|
travel_to(2.minutes.from_now) do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { labels: 'foo,bar' }
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(json_response['labels']).to contain_exactly('foo', 'bar')
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(json_response['updated_at']).to be > Time.current
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'updates labels and touches the record with labels param as array', :aggregate_failures do
|
2022-05-07 20:08:51 +05:30
|
|
|
travel_to(2.minutes.from_now) do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { labels: %w(foo bar) }
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['labels']).to include 'foo'
|
|
|
|
expect(json_response['labels']).to include 'bar'
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(json_response['updated_at']).to be > Time.current
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'allows special label names', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { labels: 'label:foo, label-bar,label_bar,label/bar,label?bar,label&bar,?,&' }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(json_response['labels']).to contain_exactly('label:foo', 'label-bar', 'label_bar', 'label/bar', 'label?bar', 'label&bar', '?', '&')
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'allows special label names with labels param as array', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { labels: ['label:foo', 'label-bar', 'label_bar', 'label/bar,label?bar,label&bar,?,&'] }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(json_response['labels']).to contain_exactly('label:foo', 'label-bar', 'label_bar', 'label/bar', 'label?bar', 'label&bar', '?', '&')
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'returns 400 if title is too long', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { title: 'g' * 256 }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(json_response['message']['title']).to eq(['is too long (maximum is 255 characters)'])
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /projects/:id/issues/:issue_iid to update state and label' do
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'updates a project issue', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { labels: 'label2', state_event: 'close' }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(json_response['labels']).to contain_exactly('label2')
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['state']).to eq 'closed'
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'reopens a project isssue', :aggregate_failures do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api(issue_path, user), params: { state_event: 'reopen' }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['state']).to eq 'opened'
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
describe 'PUT /projects/:id/issues/:issue_iid to update updated_at param' do
|
|
|
|
context 'when reporter makes request' do
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'accepts the update date to be set', :aggregate_failures do
|
2019-09-04 21:01:54 +05:30
|
|
|
update_time = 2.weeks.ago
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { title: 'some new title', updated_at: update_time }
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(json_response['title']).to eq('some new title')
|
2020-04-08 14:13:33 +05:30
|
|
|
expect(Time.parse(json_response['updated_at'])).not_to be_like_time(update_time)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when admin or owner makes the request' do
|
2020-06-23 00:09:42 +05:30
|
|
|
let(:api_for_owner) { api(issue_path, owner) }
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
it 'not allow to set null for updated_at' do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_owner, params: { updated_at: nil }
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'not allow to set blank for updated_at' do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_owner, params: { updated_at: '' }
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'not allow to set invalid format for updated_at' do
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_owner, params: { updated_at: 'invalid-format' }
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:bad_request)
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'accepts the update date to be set', :aggregate_failures do
|
2020-04-08 14:13:33 +05:30
|
|
|
update_time = 2.weeks.ago
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_owner, params: { title: 'some new title', updated_at: update_time }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-06-23 00:09:42 +05:30
|
|
|
expect(json_response['title']).to eq('some new title')
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(Time.parse(json_response['updated_at'])).to be_like_time(update_time)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /projects/:id/issues/:issue_iid to update due date' do
|
2023-05-27 22:25:52 +05:30
|
|
|
it 'creates a new project issue', :aggregate_failures do
|
2019-09-04 21:01:54 +05:30
|
|
|
due_date = 2.weeks.from_now.strftime('%Y-%m-%d')
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
put api_for_user, params: { due_date: due_date }
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2019-09-04 21:01:54 +05:30
|
|
|
expect(json_response['due_date']).to eq(due_date)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|