diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/support/shared_examples/requests/api/notes_shared_examples.rb | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/support/shared_examples/requests/api/notes_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/requests/api/notes_shared_examples.rb | 79 |
1 files changed, 35 insertions, 44 deletions
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 |