Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-09-06 09:10:18 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-09-06 09:10:18 +0300
commit5947e68ac310a25614438df36149b27b0654eb5c (patch)
tree05d34230936ffcd2e4fecbf2c1b76b15e6ffaa00 /spec
parent091f92820381bde259de3d33571ee5102d54cb01 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin/topics_controller_spec.rb2
-rw-r--r--spec/frontend/issues/show/components/incidents/timeline_events_item_spec.js6
-rw-r--r--spec/frontend/issues/show/components/incidents/timeline_events_list_spec.js2
-rw-r--r--spec/frontend/issues/show/components/incidents/timeline_events_tab_spec.js4
-rw-r--r--spec/requests/api/topics_spec.rb62
-rw-r--r--spec/services/topics/merge_service_spec.rb10
6 files changed, 75 insertions, 11 deletions
diff --git a/spec/controllers/admin/topics_controller_spec.rb b/spec/controllers/admin/topics_controller_spec.rb
index 87093e0263b..111fdcc3be6 100644
--- a/spec/controllers/admin/topics_controller_spec.rb
+++ b/spec/controllers/admin/topics_controller_spec.rb
@@ -194,7 +194,7 @@ RSpec.describe Admin::TopicsController do
end
it 'renders a 400 error for identical topic ids' do
- post :merge, params: { source_topic_id: topic, target_topic_id: topic.id }
+ post :merge, params: { source_topic_id: topic.id, target_topic_id: topic.id }
expect(response).to have_gitlab_http_status(:bad_request)
expect { topic.reload }.not_to raise_error
diff --git a/spec/frontend/issues/show/components/incidents/timeline_events_item_spec.js b/spec/frontend/issues/show/components/incidents/timeline_events_item_spec.js
index edbbc9f8f4e..28223e92ade 100644
--- a/spec/frontend/issues/show/components/incidents/timeline_events_item_spec.js
+++ b/spec/frontend/issues/show/components/incidents/timeline_events_item_spec.js
@@ -19,7 +19,7 @@ describe('IncidentTimelineEventList', () => {
...propsData,
},
provide: {
- canUpdate: false,
+ canUpdateTimelineEvent: false,
...provide,
},
});
@@ -81,14 +81,14 @@ describe('IncidentTimelineEventList', () => {
});
it('shows dropdown and delete item when user has update permission', () => {
- mountComponent({ provide: { canUpdate: true } });
+ mountComponent({ provide: { canUpdateTimelineEvent: true } });
expect(findDropdown().exists()).toBe(true);
expect(findDeleteButton().exists()).toBe(true);
});
it('triggers a delete when the delete button is clicked', async () => {
- mountComponent({ provide: { canUpdate: true } });
+ mountComponent({ provide: { canUpdateTimelineEvent: true } });
findDeleteButton().trigger('click');
diff --git a/spec/frontend/issues/show/components/incidents/timeline_events_list_spec.js b/spec/frontend/issues/show/components/incidents/timeline_events_list_spec.js
index 18bd91f0465..549b819fa19 100644
--- a/spec/frontend/issues/show/components/incidents/timeline_events_list_spec.js
+++ b/spec/frontend/issues/show/components/incidents/timeline_events_list_spec.js
@@ -52,7 +52,7 @@ describe('IncidentTimelineEventList', () => {
provide: {
fullPath: 'group/project',
issuableId: '1',
- canUpdate: true,
+ canUpdateTimelineEvent: true,
},
apolloProvider,
});
diff --git a/spec/frontend/issues/show/components/incidents/timeline_events_tab_spec.js b/spec/frontend/issues/show/components/incidents/timeline_events_tab_spec.js
index f260b803b7a..5bac1d6e7ad 100644
--- a/spec/frontend/issues/show/components/incidents/timeline_events_tab_spec.js
+++ b/spec/frontend/issues/show/components/incidents/timeline_events_tab_spec.js
@@ -36,7 +36,7 @@ describe('TimelineEventsTab', () => {
provide: {
fullPath: 'group/project',
issuableId: '1',
- canUpdate: true,
+ canUpdateTimelineEvent: true,
...provide,
},
apolloProvider: mockApollo,
@@ -136,7 +136,7 @@ describe('TimelineEventsTab', () => {
it('should not show a button when user cannot update', () => {
mountComponent({
mockApollo: createMockApolloProvider(emptyResponse),
- provide: { canUpdate: false },
+ provide: { canUpdateTimelineEvent: false },
});
expect(findAddEventButton().exists()).toBe(false);
diff --git a/spec/requests/api/topics_spec.rb b/spec/requests/api/topics_spec.rb
index 72221e3fb6a..1ad6f876fab 100644
--- a/spec/requests/api/topics_spec.rb
+++ b/spec/requests/api/topics_spec.rb
@@ -317,4 +317,66 @@ RSpec.describe API::Topics do
end
end
end
+
+ describe 'POST /topics/merge', :aggregate_failures do
+ context 'as administrator' do
+ let_it_be(:api_url) { api('/topics/merge', admin) }
+
+ it 'merge topics' do
+ post api_url, params: { source_topic_id: topic_3.id, target_topic_id: topic_2.id }
+
+ expect(response).to have_gitlab_http_status(:created)
+ expect { topic_2.reload }.not_to raise_error
+ expect { topic_3.reload }.to raise_error(ActiveRecord::RecordNotFound)
+ expect(json_response['id']).to eq(topic_2.id)
+ expect(json_response['total_projects_count']).to eq(topic_2.total_projects_count)
+ end
+
+ it 'returns 404 for non existing source topic id' do
+ post api_url, params: { source_topic_id: non_existing_record_id, target_topic_id: topic_2.id }
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+
+ it 'returns 404 for non existing target topic id' do
+ post api_url, params: { source_topic_id: topic_3.id, target_topic_id: non_existing_record_id }
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+
+ it 'returns 400 for identical topic ids' do
+ post api_url, params: { source_topic_id: topic_2.id, target_topic_id: topic_2.id }
+
+ expect(response).to have_gitlab_http_status(:bad_request)
+ expect(json_response['message']).to eql('The source topic and the target topic are identical.')
+ end
+
+ it 'returns 400 if merge failed' do
+ allow_next_found_instance_of(Projects::Topic) do |topic|
+ allow(topic).to receive(:destroy!).and_raise(ActiveRecord::RecordNotDestroyed)
+ end
+
+ post api_url, params: { source_topic_id: topic_3.id, target_topic_id: topic_2.id }
+
+ expect(response).to have_gitlab_http_status(:bad_request)
+ expect(json_response['message']).to eql('Topics could not be merged!')
+ end
+ end
+
+ context 'as normal user' do
+ it 'returns 403 Forbidden' do
+ post api('/topics/merge', user), params: { source_topic_id: topic_3.id, target_topic_id: topic_2.id }
+
+ expect(response).to have_gitlab_http_status(:forbidden)
+ end
+ end
+
+ context 'as anonymous' do
+ it 'returns 401 Unauthorized' do
+ post api('/topics/merge'), params: { source_topic_id: topic_3.id, target_topic_id: topic_2.id }
+
+ expect(response).to have_gitlab_http_status(:unauthorized)
+ end
+ end
+ end
end
diff --git a/spec/services/topics/merge_service_spec.rb b/spec/services/topics/merge_service_spec.rb
index 971917eb8e9..eef31817aa8 100644
--- a/spec/services/topics/merge_service_spec.rb
+++ b/spec/services/topics/merge_service_spec.rb
@@ -30,7 +30,9 @@ RSpec.describe Topics::MergeService do
it 'reverts previous changes' do
allow(source_topic.reload).to receive(:destroy!).and_raise(ActiveRecord::RecordNotDestroyed)
- expect { subject }.to raise_error(ActiveRecord::RecordNotDestroyed)
+ response = subject
+ expect(response).to be_error
+ expect(response.message).to eq('Topics could not be merged!')
expect(source_topic.projects).to contain_exactly(project_1, project_2, project_4)
expect(target_topic.projects).to contain_exactly(project_3, project_4)
@@ -50,9 +52,9 @@ RSpec.describe Topics::MergeService do
with_them do
it 'raises correct error' do
- expect { subject }.to raise_error(ArgumentError) do |error|
- expect(error.message).to eq(expected_message)
- end
+ response = subject
+ expect(response).to be_error
+ expect(response.message).to eq(expected_message)
end
end
end