diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-01 15:05:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-01 15:05:59 +0300 |
commit | 9e27f0d920cc3891fa7644c5cc0bc280c519fb20 (patch) | |
tree | 9784dd99270f2009159b19077412bf83d13123a4 /spec/lib/api | |
parent | 1bab0ba591263cd739af2d2c7c3f1b03678a59b6 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/api')
-rw-r--r-- | spec/lib/api/helpers/graphql_helpers_spec.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/lib/api/helpers/graphql_helpers_spec.rb b/spec/lib/api/helpers/graphql_helpers_spec.rb new file mode 100644 index 00000000000..c775ba6d5e8 --- /dev/null +++ b/spec/lib/api/helpers/graphql_helpers_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe API::Helpers::GraphqlHelpers do + describe 'run_graphql!' do + let(:query) { '{ metadata { version } }' } + + let(:graphql_helper) do + Class.new do + include API::Helpers::GraphqlHelpers + end.new + end + + context 'when transform function is provided' do + let(:result) { { 'data' => { 'metadata' => { 'version' => '1.0.0' } } } } + + before do + allow(GitlabSchema).to receive(:execute).and_return(result) + end + + it 'returns the expected result' do + expect( + graphql_helper.run_graphql!( + query: query, + transform: ->(result) { result.dig('data', 'metadata') } + ) + ).to eq({ 'version' => '1.0.0' }) + end + end + + context 'when a transform function is not provided' do + let(:result) { double('result') } + + before do + allow(GitlabSchema).to receive(:execute).and_return(result) + end + + it 'returns the expected result' do + expect(graphql_helper.run_graphql!(query: query)).to eq(result) + end + end + end +end |