diff options
Diffstat (limited to 'spec/requests/api/graphql/project/job_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/project/job_spec.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/project/job_spec.rb b/spec/requests/api/graphql/project/job_spec.rb new file mode 100644 index 00000000000..6edd4cf753f --- /dev/null +++ b/spec/requests/api/graphql/project/job_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Query.project.job' do + include GraphqlHelpers + + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + + let(:job) { create(:ci_build, project: project, name: 'GQL test job') } + + let(:query) do + <<~QUERY + { + project(fullPath: "#{project.full_path}") { + job(id: "#{job.to_global_id}") { + name + } + } + } + QUERY + end + + context 'when the user can read jobs on the project' do + before do + project.add_developer(user) + end + + it 'returns the job that matches the given ID' do + post_graphql(query, current_user: user) + + expect(graphql_data.dig('project', 'job', 'name')).to eq('GQL test job') + end + + context 'when no job matches the given ID' do + let(:job) { create(:ci_build, project: create(:project), name: 'Job from another project') } + + it 'returns null' do + post_graphql(query, current_user: user) + + expect(graphql_data.dig('project', 'job')).to be_nil + end + end + end + + context 'when the user cannot read jobs on the project' do + it 'returns null' do + post_graphql(query, current_user: user) + + expect(graphql_data.dig('project', 'job')).to be_nil + end + end +end |