summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/requests/api
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/requests/api')
-rw-r--r--spec/support/shared_examples/requests/api/composer_packages_shared_examples.rb4
-rw-r--r--spec/support/shared_examples/requests/api/container_repositories_shared_examples.rb90
-rw-r--r--spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb2
-rw-r--r--spec/support/shared_examples/requests/api/issuable_participants_examples.rb30
-rw-r--r--spec/support/shared_examples/requests/api/notes_shared_examples.rb79
5 files changed, 129 insertions, 76 deletions
diff --git a/spec/support/shared_examples/requests/api/composer_packages_shared_examples.rb b/spec/support/shared_examples/requests/api/composer_packages_shared_examples.rb
index 9f4fdcf7ba1..dc2c4f890b1 100644
--- a/spec/support/shared_examples/requests/api/composer_packages_shared_examples.rb
+++ b/spec/support/shared_examples/requests/api/composer_packages_shared_examples.rb
@@ -163,11 +163,11 @@ RSpec.shared_examples 'rejects Composer access with unknown project id' do
let(:project) { double(id: non_existing_record_id) }
context 'as anonymous' do
- it_behaves_like 'process Composer api request', :anonymous, :not_found
+ it_behaves_like 'process Composer api request', :anonymous, :unauthorized
end
context 'as authenticated user' do
- subject { get api(url), headers: basic_auth_header(user.username, personal_access_token.token) }
+ subject { get api(url), params: params, headers: basic_auth_header(user.username, personal_access_token.token) }
it_behaves_like 'process Composer api request', :anonymous, :not_found
end
diff --git a/spec/support/shared_examples/requests/api/container_repositories_shared_examples.rb b/spec/support/shared_examples/requests/api/container_repositories_shared_examples.rb
index e1e75be2494..c1eccafa987 100644
--- a/spec/support/shared_examples/requests/api/container_repositories_shared_examples.rb
+++ b/spec/support/shared_examples/requests/api/container_repositories_shared_examples.rb
@@ -116,3 +116,93 @@ RSpec.shared_examples 'not hitting graphql network errors with the container reg
expect_graphql_errors_to_be_empty
end
end
+
+RSpec.shared_examples 'reconciling migration_state' do
+ shared_examples 'enforcing states coherence to' do |expected_migration_state|
+ it 'leaves the repository in the expected migration_state' do
+ expect(repository.gitlab_api_client).not_to receive(:pre_import_repository)
+ expect(repository.gitlab_api_client).not_to receive(:import_repository)
+
+ subject
+
+ expect(repository.reload.migration_state).to eq(expected_migration_state)
+ end
+ end
+
+ shared_examples 'retrying the pre_import' do
+ it 'retries the pre_import' do
+ expect(repository).to receive(:migration_pre_import).and_return(:ok)
+
+ expect { subject }.to change { repository.reload.migration_state }.to('pre_importing')
+ end
+ end
+
+ shared_examples 'retrying the import' do
+ it 'retries the import' do
+ expect(repository).to receive(:migration_import).and_return(:ok)
+
+ expect { subject }.to change { repository.reload.migration_state }.to('importing')
+ end
+ end
+
+ context 'native response' do
+ let(:status) { 'native' }
+
+ it 'finishes the import' do
+ expect { subject }
+ .to change { repository.reload.migration_state }.to('import_done')
+ .and change { repository.reload.migration_skipped_reason }.to('native_import')
+ end
+ end
+
+ context 'import_in_progress response' do
+ let(:status) { 'import_in_progress' }
+
+ it_behaves_like 'enforcing states coherence to', 'importing'
+ end
+
+ context 'import_complete response' do
+ let(:status) { 'import_complete' }
+
+ it 'finishes the import' do
+ expect { subject }.to change { repository.reload.migration_state }.to('import_done')
+ end
+ end
+
+ context 'import_failed response' do
+ let(:status) { 'import_failed' }
+
+ it_behaves_like 'retrying the import'
+ end
+
+ context 'pre_import_in_progress response' do
+ let(:status) { 'pre_import_in_progress' }
+
+ it_behaves_like 'enforcing states coherence to', 'pre_importing'
+ end
+
+ context 'pre_import_complete response' do
+ let(:status) { 'pre_import_complete' }
+
+ it 'finishes the pre_import and starts the import' do
+ expect(repository).to receive(:finish_pre_import).and_call_original
+ expect(repository).to receive(:migration_import).and_return(:ok)
+
+ expect { subject }.to change { repository.reload.migration_state }.to('importing')
+ end
+ end
+
+ context 'pre_import_failed response' do
+ let(:status) { 'pre_import_failed' }
+
+ it_behaves_like 'retrying the pre_import'
+ end
+
+ %w[pre_import_canceled import_canceled].each do |canceled_status|
+ context "#{canceled_status} response" do
+ let(:status) { canceled_status }
+
+ it_behaves_like 'enforcing states coherence to', 'import_skipped'
+ end
+ end
+end
diff --git a/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb b/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb
index 01ed6c26576..da9d254039b 100644
--- a/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb
+++ b/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb
@@ -54,11 +54,13 @@ RSpec.shared_examples 'group and project boards query' do
end
context 'when using default sorting' do
+ # rubocop:disable RSpec/VariableName
let!(:board_B) { create(:board, resource_parent: board_parent, name: 'B') }
let!(:board_C) { create(:board, resource_parent: board_parent, name: 'C') }
let!(:board_a) { create(:board, resource_parent: board_parent, name: 'a') }
let!(:board_A) { create(:board, resource_parent: board_parent, name: 'A') }
let(:boards) { [board_a, board_A, board_B, board_C] }
+ # rubocop:enable RSpec/VariableName
context 'when ascending' do
it_behaves_like 'sorted paginated query' do
diff --git a/spec/support/shared_examples/requests/api/issuable_participants_examples.rb b/spec/support/shared_examples/requests/api/issuable_participants_examples.rb
index c5e5803c0a7..673d7741017 100644
--- a/spec/support/shared_examples/requests/api/issuable_participants_examples.rb
+++ b/spec/support/shared_examples/requests/api/issuable_participants_examples.rb
@@ -28,34 +28,4 @@ RSpec.shared_examples 'issuable participants endpoint' do
expect(response).to have_gitlab_http_status(:not_found)
end
-
- context 'with a confidential note' do
- let!(:note) do
- create(
- :note,
- :confidential,
- project: project,
- noteable: entity,
- author: create(:user)
- )
- end
-
- it 'returns a full list of participants' do
- get api("/projects/#{project.id}/#{area}/#{entity.iid}/participants", user)
-
- expect(response).to have_gitlab_http_status(:ok)
- participant_ids = json_response.map { |el| el['id'] }
- expect(participant_ids).to match_array([entity.author_id, note.author_id])
- end
-
- context 'when user cannot see a confidential note' do
- it 'returns a limited list of participants' do
- get api("/projects/#{project.id}/#{area}/#{entity.iid}/participants", create(:user))
-
- expect(response).to have_gitlab_http_status(:ok)
- participant_ids = json_response.map { |el| el['id'] }
- expect(participant_ids).to match_array([entity.author_id])
- end
- end
- end
end
diff --git a/spec/support/shared_examples/requests/api/notes_shared_examples.rb b/spec/support/shared_examples/requests/api/notes_shared_examples.rb
index 2a157f6e855..e7e30665b08 100644
--- a/spec/support/shared_examples/requests/api/notes_shared_examples.rb
+++ b/spec/support/shared_examples/requests/api/notes_shared_examples.rb
@@ -142,15 +142,6 @@ RSpec.shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
expect(json_response['author']['username']).to eq(user.username)
end
- it "creates a confidential note if confidential is set to true" do
- post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user), params: { body: 'hi!', confidential: true }
-
- expect(response).to have_gitlab_http_status(:created)
- expect(json_response['body']).to eq('hi!')
- expect(json_response['confidential']).to be_truthy
- expect(json_response['author']['username']).to eq(user.username)
- end
-
it "returns a 400 bad request error if body not given" do
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user)
@@ -306,52 +297,31 @@ RSpec.shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
end
describe "PUT /#{parent_type}/:id/#{noteable_type}/:noteable_id/notes/:note_id" do
- let(:params) { { body: 'Hello!', confidential: false } }
+ let(:params) { { body: 'Hello!' } }
subject do
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes/#{note.id}", user), params: params
end
- context 'when eveything is ok' do
- before do
- note.update!(confidential: true)
- end
+ context 'when only body param is present' do
+ let(:params) { { body: 'Hello!' } }
- context 'with multiple params present' do
- before do
- subject
- end
-
- it 'returns modified note' do
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['body']).to eq('Hello!')
- expect(json_response['confidential']).to be_falsey
- end
-
- it 'updates the note' do
- expect(note.reload.note).to eq('Hello!')
- expect(note.confidential).to be_falsey
- end
- end
-
- context 'when only body param is present' do
- let(:params) { { body: 'Hello!' } }
-
- it 'updates only the note text' do
- expect { subject }.not_to change { note.reload.confidential }
+ it 'updates the note text' do
+ subject
- expect(note.note).to eq('Hello!')
- end
+ expect(note.reload.note).to eq('Hello!')
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response['body']).to eq('Hello!')
end
+ end
- context 'when only confidential param is present' do
- let(:params) { { confidential: false } }
+ context 'when confidential param is present' do
+ let(:params) { { confidential: true } }
- it 'updates only the note text' do
- expect { subject }.not_to change { note.reload.note }
+ it 'does not allow to change confidentiality' do
+ expect { subject }.not_to change { note.reload.note }
- expect(note.confidential).to be_falsey
- end
+ expect(response).to have_gitlab_http_status(:bad_request)
end
end
@@ -393,3 +363,24 @@ RSpec.shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
end
end
end
+
+RSpec.shared_examples 'noteable API with confidential notes' do |parent_type, noteable_type, id_name|
+ it_behaves_like 'noteable API', parent_type, noteable_type, id_name
+
+ describe "POST /#{parent_type}/:id/#{noteable_type}/:noteable_id/notes" do
+ let(:params) { { body: 'hi!' } }
+
+ subject do
+ post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user), params: params
+ end
+
+ it "creates a confidential note if confidential is set to true" do
+ post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user), params: params.merge(confidential: true)
+
+ expect(response).to have_gitlab_http_status(:created)
+ expect(json_response['body']).to eq('hi!')
+ expect(json_response['confidential']).to be_truthy
+ expect(json_response['author']['username']).to eq(user.username)
+ end
+ end
+end