debian-mirror-gitlab/spec/frontend/fixtures/jobs.rb

119 lines
4.5 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2022-08-13 15:12:31 +05:30
RSpec.describe 'Jobs (JavaScript fixtures)' do
include ApiHelpers
2017-08-17 22:00:37 +05:30
include JavaScriptFixturesHelpers
2022-08-13 15:12:31 +05:30
include GraphqlHelpers
2017-08-17 22:00:37 +05:30
2023-01-13 00:05:48 +05:30
let(:namespace) { create(:namespace, name: 'frontend-fixtures') }
2018-12-13 13:39:08 +05:30
let(:project) { create(:project, :repository, namespace: namespace, path: 'builds-project') }
2022-04-04 11:22:00 +05:30
let(:user) { project.first_owner }
2018-12-13 13:39:08 +05:30
let(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id) }
2022-08-13 15:12:31 +05:30
after do
remove_repository(project)
2018-12-13 13:39:08 +05:30
end
2017-08-17 22:00:37 +05:30
2022-08-13 15:12:31 +05:30
describe Projects::JobsController, type: :controller do
let!(:delayed) { create(:ci_build, :scheduled, pipeline: pipeline, name: 'delayed job') }
2017-08-17 22:00:37 +05:30
2022-08-13 15:12:31 +05:30
before do
sign_in(user)
end
2017-08-17 22:00:37 +05:30
2022-08-13 15:12:31 +05:30
it 'jobs/delayed.json' do
get :show, params: {
namespace_id: project.namespace.to_param,
project_id: project,
id: delayed.to_param
}, format: :json
expect(response).to be_successful
end
2018-03-17 18:26:18 +05:30
end
2022-08-13 15:12:31 +05:30
describe GraphQL::Query, type: :request do
let(:artifact) { create(:ci_job_artifact, file_type: :archive, file_format: :zip) }
let!(:build) { create(:ci_build, :success, name: 'build', pipeline: pipeline) }
let!(:cancelable) { create(:ci_build, :cancelable, name: 'cancelable', pipeline: pipeline) }
2023-04-23 21:23:45 +05:30
let!(:failed) { create(:ci_build, :failed, name: 'failed', pipeline: pipeline) }
2022-08-13 15:12:31 +05:30
let!(:created_by_tag) { create(:ci_build, :success, name: 'created_by_tag', tag: true, pipeline: pipeline) }
let!(:pending) { create(:ci_build, :pending, name: 'pending', pipeline: pipeline) }
let!(:playable) { create(:ci_build, :playable, name: 'playable', pipeline: pipeline) }
let!(:retryable) { create(:ci_build, :retryable, name: 'retryable', pipeline: pipeline) }
let!(:scheduled) { create(:ci_build, :scheduled, name: 'scheduled', pipeline: pipeline) }
let!(:with_artifact) { create(:ci_build, :success, name: 'with_artifact', job_artifacts: [artifact], pipeline: pipeline) }
let!(:with_coverage) { create(:ci_build, :success, name: 'with_coverage', coverage: 40.0, pipeline: pipeline) }
2023-07-09 08:55:56 +05:30
shared_examples 'graphql queries' do |path, jobs_query, skip_non_defaults = false|
2023-06-20 00:43:36 +05:30
let_it_be(:variables) { {} }
2023-07-09 08:55:56 +05:30
let_it_be(:success_path) { '' }
2022-08-13 15:12:31 +05:30
2023-06-20 00:43:36 +05:30
let_it_be(:query) do
get_graphql_query_as_string("#{path}/#{jobs_query}")
end
2022-08-13 15:12:31 +05:30
2023-06-20 00:43:36 +05:30
fixtures_path = 'graphql/jobs/'
2022-08-13 15:12:31 +05:30
2023-07-09 08:55:56 +05:30
it "#{fixtures_path}#{jobs_query}.json", :aggregate_failures do
2023-06-20 00:43:36 +05:30
post_graphql(query, current_user: user, variables: variables)
2022-08-13 15:12:31 +05:30
2023-07-09 08:55:56 +05:30
expect(graphql_data.dig(*success_path)).not_to be_nil
2023-06-20 00:43:36 +05:30
expect_graphql_errors_to_be_empty
end
2022-08-13 15:12:31 +05:30
2023-07-09 08:55:56 +05:30
context 'with non default fixtures', if: !skip_non_defaults do
it "#{fixtures_path}#{jobs_query}.as_guest.json" do
guest = create(:user)
project.add_guest(guest)
2022-08-13 15:12:31 +05:30
2023-07-09 08:55:56 +05:30
post_graphql(query, current_user: guest, variables: variables)
2022-08-13 15:12:31 +05:30
2023-07-09 08:55:56 +05:30
expect_graphql_errors_to_be_empty
end
2022-08-13 15:12:31 +05:30
2023-07-09 08:55:56 +05:30
it "#{fixtures_path}#{jobs_query}.paginated.json" do
post_graphql(query, current_user: user, variables: variables.merge({ first: 2 }))
2023-06-20 00:43:36 +05:30
2023-07-09 08:55:56 +05:30
expect_graphql_errors_to_be_empty
end
2023-06-20 00:43:36 +05:30
2023-07-09 08:55:56 +05:30
it "#{fixtures_path}#{jobs_query}.empty.json" do
post_graphql(query, current_user: user, variables: variables.merge({ first: 0 }))
2023-06-20 00:43:36 +05:30
2023-07-09 08:55:56 +05:30
expect_graphql_errors_to_be_empty
end
2023-06-20 00:43:36 +05:30
end
2022-08-13 15:12:31 +05:30
end
2023-06-20 00:43:36 +05:30
it_behaves_like 'graphql queries', 'jobs/components/table/graphql/queries', 'get_jobs.query.graphql' do
let(:variables) { { fullPath: 'frontend-fixtures/builds-project' } }
2023-07-09 08:55:56 +05:30
let(:success_path) { %w[project jobs] }
end
it_behaves_like 'graphql queries', 'jobs/components/table/graphql/queries', 'get_jobs_count.query.graphql', true do
let(:variables) { { fullPath: 'frontend-fixtures/builds-project' } }
let(:success_path) { %w[project jobs] }
2023-06-20 00:43:36 +05:30
end
2018-12-13 13:39:08 +05:30
2023-06-20 00:43:36 +05:30
it_behaves_like 'graphql queries', 'pages/admin/jobs/components/table/graphql/queries', 'get_all_jobs.query.graphql' do
let(:user) { create(:admin) }
2023-07-09 08:55:56 +05:30
let(:success_path) { 'jobs' }
2022-08-13 15:12:31 +05:30
end
2023-05-27 22:25:52 +05:30
2023-07-09 08:55:56 +05:30
it_behaves_like 'graphql queries', 'pages/admin/jobs/components/table/graphql/queries', 'get_cancelable_jobs_count.query.graphql', true do
let(:variables) { { statuses: %w[PENDING RUNNING] } }
let(:user) { create(:admin) }
let(:success_path) { %w[cancelable count] }
2023-05-27 22:25:52 +05:30
end
2023-07-09 08:55:56 +05:30
it_behaves_like 'graphql queries', 'pages/admin/jobs/components/table/graphql/queries', 'get_all_jobs_count.query.graphql', true do
let(:user) { create(:admin) }
let(:success_path) { 'jobs' }
2023-05-27 22:25:52 +05:30
end
end
2017-08-17 22:00:37 +05:30
end