diff options
author | Nick Thomas <nick@gitlab.com> | 2017-08-16 16:04:41 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-06-05 21:47:42 +0300 |
commit | 9c6c17cbcdb8bf8185fc1b873dcfd08f723e4df5 (patch) | |
tree | 624dba30e87ed0ea39afa0535d92c37c7718daef /spec/controllers | |
parent | 67dc43db2f30095cce7fe01d7f475d084be936e8 (diff) |
Add a minimal GraphQL API
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/graphql_controller_spec.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/controllers/graphql_controller_spec.rb b/spec/controllers/graphql_controller_spec.rb new file mode 100644 index 00000000000..d6689dbc3c6 --- /dev/null +++ b/spec/controllers/graphql_controller_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe GraphqlController do + describe 'execute' do + before do + sign_in(user) if user + + run_test_query! + end + + subject { query_response } + + context 'graphql is disabled by feature flag' do + let(:user) { nil } + + before do + stub_feature_flags(graphql: false) + end + + it 'returns 404' do + run_test_query! + + expect(response).to have_gitlab_http_status(404) + end + end + + context 'signed out' do + let(:user) { nil } + + it 'runs the query with current_user: nil' do + is_expected.to eq('echo' => 'nil says: test success') + end + end + + context 'signed in' do + let(:user) { create(:user, username: 'Simon') } + + it 'runs the query with current_user set' do + is_expected.to eq('echo' => '"Simon" says: test success') + end + end + end + + # Chosen to exercise all the moving parts in GraphqlController#execute + def run_test_query! + query = <<~QUERY + query Echo($text: String) { + echo(text: $text) + } + QUERY + + post :execute, query: query, operationName: 'Echo', variables: { 'text' => 'test success' } + end + + def query_response + json_response['data'] + end +end |