2019-09-30 21:07:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.shared_examples 'a Note mutation that does not create a Note' do
|
|
|
|
it do
|
|
|
|
expect do
|
|
|
|
post_graphql_mutation(mutation, current_user: current_user)
|
|
|
|
end.not_to change { Note.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'a Note mutation that creates a Note' do
|
|
|
|
it do
|
|
|
|
expect do
|
|
|
|
post_graphql_mutation(mutation, current_user: current_user)
|
|
|
|
end.to change { Note.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'a Note mutation when the user does not have permission' do
|
|
|
|
it_behaves_like 'a Note mutation that does not create a Note'
|
|
|
|
|
|
|
|
it_behaves_like 'a mutation that returns top-level errors',
|
|
|
|
errors: ['The resource that you are attempting to access does not exist or you don\'t have permission to perform this action']
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'a Note mutation when there are active record validation errors' do |model: Note|
|
|
|
|
before do
|
|
|
|
expect_next_instance_of(model) do |note|
|
2020-01-01 13:55:28 +05:30
|
|
|
allow(note).to receive_message_chain(:errors, :empty?).and_return(true)
|
2019-09-30 21:07:59 +05:30
|
|
|
expect(note).to receive(:valid?).at_least(:once).and_return(false)
|
|
|
|
expect(note).to receive_message_chain(
|
|
|
|
:errors,
|
|
|
|
:full_messages
|
|
|
|
).and_return(['Error 1', 'Error 2'])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a Note mutation that does not create a Note'
|
|
|
|
|
|
|
|
it_behaves_like 'a mutation that returns errors in the response', errors: ['Error 1', 'Error 2']
|
|
|
|
|
|
|
|
it 'returns an empty Note' do
|
|
|
|
post_graphql_mutation(mutation, current_user: current_user)
|
|
|
|
|
|
|
|
expect(mutation_response).to have_key('note')
|
|
|
|
expect(mutation_response['note']).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'a Note mutation when the given resource id is not for a Noteable' do
|
|
|
|
let(:noteable) { create(:label, project: project) }
|
|
|
|
|
|
|
|
it_behaves_like 'a Note mutation that does not create a Note'
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it_behaves_like 'a mutation that returns top-level errors' do
|
|
|
|
let(:match_errors) { include(/ does not represent an instance of Noteable/) }
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
RSpec.shared_examples 'a Note mutation when the given resource id is not for a Note' do
|
|
|
|
let(:note) { create(:issue) }
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it_behaves_like 'a mutation that returns top-level errors' do
|
|
|
|
let(:match_errors) { include(/does not represent an instance of Note/) }
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
RSpec.shared_examples 'a Note mutation when there are rate limit validation errors' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(notes_create_limit: 3)
|
|
|
|
3.times { post_graphql_mutation(mutation, current_user: current_user) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a Note mutation that does not create a Note'
|
|
|
|
it_behaves_like 'a mutation that returns top-level errors',
|
|
|
|
errors: ['This endpoint has been requested too many times. Try again later.']
|
|
|
|
|
|
|
|
context 'when the user is in the allowlist' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(notes_create_limit_allowlist: ["#{current_user.username}"])
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a Note mutation that creates a Note'
|
|
|
|
end
|
|
|
|
end
|