Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/graphql')
-rw-r--r--spec/support/shared_examples/graphql/design_fields_shared_examples.rb5
-rw-r--r--spec/support/shared_examples/graphql/notes_on_noteables_shared_examples.rb57
2 files changed, 55 insertions, 7 deletions
diff --git a/spec/support/shared_examples/graphql/design_fields_shared_examples.rb b/spec/support/shared_examples/graphql/design_fields_shared_examples.rb
index efbcfaf0e91..aa3a1d78df8 100644
--- a/spec/support/shared_examples/graphql/design_fields_shared_examples.rb
+++ b/spec/support/shared_examples/graphql/design_fields_shared_examples.rb
@@ -32,7 +32,7 @@ RSpec.shared_examples 'a GraphQL type with design fields' do
let(:query) { GraphQL::Query.new(schema) }
let(:context) { query.context }
let(:field) { described_class.fields['image'] }
- let(:args) { GraphQL::Query::Arguments::NO_ARGS }
+ let(:args) { { parent: nil } }
let(:instance) { instantiate(object_id) }
let(:instance_b) { instantiate(object_id_b) }
@@ -42,13 +42,12 @@ RSpec.shared_examples 'a GraphQL type with design fields' do
end
def resolve_image(instance)
- field.resolve_field(instance, args, context)
+ field.resolve(instance, args, context)
end
before do
context[:current_user] = current_user
allow(Ability).to receive(:allowed?).with(current_user, :read_design, anything).and_return(true)
- allow(context).to receive(:parent).and_return(nil)
end
it 'resolves to the design image URL' do
diff --git a/spec/support/shared_examples/graphql/notes_on_noteables_shared_examples.rb b/spec/support/shared_examples/graphql/notes_on_noteables_shared_examples.rb
index 64f811771ec..799f82a9ec5 100644
--- a/spec/support/shared_examples/graphql/notes_on_noteables_shared_examples.rb
+++ b/spec/support/shared_examples/graphql/notes_on_noteables_shared_examples.rb
@@ -14,9 +14,21 @@ RSpec.shared_context 'exposing regular notes on a noteable in GraphQL' do
let(:user) { note.author }
context 'for regular notes' do
+ let!(:system_note) do
+ create(
+ :note,
+ system: true,
+ noteable: noteable,
+ project: (noteable.project if noteable.respond_to?(:project))
+ )
+ end
+
+ let(:filters) { "" }
+
let(:query) do
note_fields = <<~NOTES
- notes {
+ notes #{filters} {
+ count
edges {
node {
#{all_graphql_fields_for('Note', max_depth: 1)}
@@ -42,11 +54,12 @@ RSpec.shared_context 'exposing regular notes on a noteable in GraphQL' do
end
end
- it 'includes the note' do
+ it 'includes all notes' do
post_graphql(query, current_user: user)
- expect(noteable_data['notes']['edges'].first['node']['body'])
- .to eq(note.note)
+ expect(noteable_data['notes']['count']).to eq(2)
+ expect(noteable_data['notes']['edges'][0]['node']['body']).to eq(system_note.note)
+ expect(noteable_data['notes']['edges'][1]['node']['body']).to eq(note.note)
end
it 'avoids N+1 queries' do
@@ -69,6 +82,42 @@ RSpec.shared_context 'exposing regular notes on a noteable in GraphQL' do
expect { post_graphql(query, current_user: user) }.not_to exceed_query_limit(control)
expect_graphql_errors_to_be_empty
end
+
+ context 'when filter is provided' do
+ context 'when filter is set to ALL_NOTES' do
+ let(:filters) { "(filter: ALL_NOTES)" }
+
+ it 'returns all the notes' do
+ post_graphql(query, current_user: user)
+
+ expect(noteable_data['notes']['count']).to eq(2)
+ expect(noteable_data['notes']['edges'][0]['node']['body']).to eq(system_note.note)
+ expect(noteable_data['notes']['edges'][1]['node']['body']).to eq(note.note)
+ end
+ end
+
+ context 'when filter is set to ONLY_COMMENTS' do
+ let(:filters) { "(filter: ONLY_COMMENTS)" }
+
+ it 'returns only the comments' do
+ post_graphql(query, current_user: user)
+
+ expect(noteable_data['notes']['count']).to eq(1)
+ expect(noteable_data['notes']['edges'][0]['node']['body']).to eq(note.note)
+ end
+ end
+
+ context 'when filter is set to ONLY_ACTIVITY' do
+ let(:filters) { "(filter: ONLY_ACTIVITY)" }
+
+ it 'returns only the activity notes' do
+ post_graphql(query, current_user: user)
+
+ expect(noteable_data['notes']['count']).to eq(1)
+ expect(noteable_data['notes']['edges'][0]['node']['body']).to eq(system_note.note)
+ end
+ end
+ end
end
context "for discussions" do