blob: 67c2d1348f7cb7e14cd17ab3e5f5633da5663f87 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Mutations::SavedReplies::Update do
let_it_be(:current_user) { create(:user) }
let_it_be(:saved_reply) { create(:saved_reply, user: current_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(id: saved_reply.to_global_id, **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 update 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 updates the 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
|