diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-18 23:02:30 +0300 |
commit | 41fe97390ceddf945f3d967b8fdb3de4c66b7dea (patch) | |
tree | 9c8d89a8624828992f06d892cd2f43818ff5dcc8 /spec/graphql/mutations/saved_replies/create_spec.rb | |
parent | 0804d2dc31052fb45a1efecedc8e06ce9bc32862 (diff) |
Add latest changes from gitlab-org/gitlab@14-9-stable-eev14.9.0-rc42
Diffstat (limited to 'spec/graphql/mutations/saved_replies/create_spec.rb')
-rw-r--r-- | spec/graphql/mutations/saved_replies/create_spec.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/graphql/mutations/saved_replies/create_spec.rb b/spec/graphql/mutations/saved_replies/create_spec.rb new file mode 100644 index 00000000000..5141c537b06 --- /dev/null +++ b/spec/graphql/mutations/saved_replies/create_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Mutations::SavedReplies::Create do + let_it_be(:current_user) { create(:user) } + + let(:mutation) { described_class.new(object: nil, context: { current_user: current_user }, field: nil) } + + let(:mutation_arguments) { { name: 'save_reply_name', content: 'Save Reply Content' } } + + describe '#resolve' do + subject(:resolve) do + mutation.resolve(**mutation_arguments) + end + + context 'when feature is disabled' do + before do + stub_feature_flags(saved_replies: false) + end + + it 'raises Gitlab::Graphql::Errors::ResourceNotAvailable' do + expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled') + end + end + + context 'when feature is enabled for current user' do + before do + stub_feature_flags(saved_replies: current_user) + end + + context 'when service fails to create a new saved reply' do + let(:mutation_arguments) { { name: '', content: '' } } + + it { expect(subject[:saved_reply]).to be_nil } + it { expect(subject[:errors]).to match_array(["Content can't be blank", "Name can't be blank", "Name can contain only lowercase letters, digits, '_' and '-'. Must start with a letter, and cannot end with '-' or '_'"]) } + end + + context 'when service successfully creates a new saved reply' do + it { expect(subject[:saved_reply].name).to eq(mutation_arguments[:name]) } + it { expect(subject[:saved_reply].content).to eq(mutation_arguments[:content]) } + it { expect(subject[:errors]).to be_empty } + end + end + end +end |