diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/factories | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/factories')
45 files changed, 399 insertions, 45 deletions
diff --git a/spec/factories/atlassian_identities.rb b/spec/factories/atlassian_identities.rb new file mode 100644 index 00000000000..698cf4ae7ad --- /dev/null +++ b/spec/factories/atlassian_identities.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :atlassian_identity, class: 'Atlassian::Identity' do + extern_uid { generate(:username) } + user { create(:user) } + expires_at { 2.weeks.from_now } + token { SecureRandom.alphanumeric(1254) } + refresh_token { SecureRandom.alphanumeric(45) } + end +end diff --git a/spec/factories/audit_events.rb b/spec/factories/audit_events.rb index 38414400282..5497648273c 100644 --- a/spec/factories/audit_events.rb +++ b/spec/factories/audit_events.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true FactoryBot.define do - factory :audit_event, class: 'SecurityEvent', aliases: [:user_audit_event] do + factory :audit_event, class: 'AuditEvent', aliases: [:user_audit_event] do user transient { target_user { create(:user) } } @@ -36,7 +36,7 @@ FactoryBot.define do ip_address { IPAddr.new '127.0.0.1' } details do { - change: 'packges_enabled', + change: 'packages_enabled', from: true, to: false, author_name: user.name, diff --git a/spec/factories/ci/bridge.rb b/spec/factories/ci/bridge.rb index 4c1d5f07a42..5a33a30921b 100644 --- a/spec/factories/ci/bridge.rb +++ b/spec/factories/ci/bridge.rb @@ -53,5 +53,14 @@ FactoryBot.define do finished status { 'failed' } end + + trait :skipped do + started + status { 'skipped' } + end + + trait :strategy_depend do + options { { trigger: { strategy: 'depend' } } } + end end end diff --git a/spec/factories/ci/build_pending_states.rb b/spec/factories/ci/build_pending_states.rb new file mode 100644 index 00000000000..765b7f005b9 --- /dev/null +++ b/spec/factories/ci/build_pending_states.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ci_build_pending_state, class: 'Ci::BuildPendingState' do + build factory: :ci_build + trace_checksum { 'crc32:12345678' } + state { 'success' } + end +end diff --git a/spec/factories/ci/pipeline_artifacts.rb b/spec/factories/ci/pipeline_artifacts.rb index ecfd1e79e78..fa33609dd6c 100644 --- a/spec/factories/ci/pipeline_artifacts.rb +++ b/spec/factories/ci/pipeline_artifacts.rb @@ -6,12 +6,33 @@ FactoryBot.define do project { pipeline.project } file_type { :code_coverage } file_format { :raw } - file_store { Ci::PipelineArtifact::FILE_STORE_SUPPORTED.first } + file_store { ObjectStorage::SUPPORTED_STORES.first } size { 1.megabytes } after(:build) do |artifact, _evaluator| artifact.file = fixture_file_upload( Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage.json'), 'application/json') end + + trait :with_multibyte_characters do + size { { "utf8" => "✓" }.to_json.bytesize } + after(:build) do |artifact, _evaluator| + artifact.file = CarrierWaveStringFile.new_file( + file_content: { "utf8" => "✓" }.to_json, + filename: 'filename', + content_type: 'application/json' + ) + end + end + + trait :with_code_coverage_with_multiple_files do + after(:build) do |artifact, _evaluator| + artifact.file = fixture_file_upload( + Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage_with_multiple_files.json'), 'application/json' + ) + end + + size { file.size } + end end end diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb index 2790be8b70d..6174bfbfbb7 100644 --- a/spec/factories/ci/pipelines.rb +++ b/spec/factories/ci/pipelines.rb @@ -121,6 +121,12 @@ FactoryBot.define do end end + trait :with_coverage_report_artifact do + after(:build) do |pipeline, evaluator| + pipeline.pipeline_artifacts << build(:ci_pipeline_artifact, pipeline: pipeline, project: pipeline.project) + end + end + trait :with_terraform_reports do status { :success } diff --git a/spec/factories/ci_platform_metrics.rb b/spec/factories/ci_platform_metrics.rb new file mode 100644 index 00000000000..478f9715021 --- /dev/null +++ b/spec/factories/ci_platform_metrics.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ci_platform_metric do + recorded_at { Time.zone.now } + platform_target { generate(:title) } + count { SecureRandom.random_number(100) } + end +end diff --git a/spec/factories/clusters/kubernetes_namespaces.rb b/spec/factories/clusters/kubernetes_namespaces.rb index c820bf4da60..efcb3abcb90 100644 --- a/spec/factories/clusters/kubernetes_namespaces.rb +++ b/spec/factories/clusters/kubernetes_namespaces.rb @@ -10,15 +10,18 @@ FactoryBot.define do if cluster.project_type? cluster_project = cluster.cluster_project - kubernetes_namespace.project = cluster_project.project + kubernetes_namespace.project = cluster_project&.project kubernetes_namespace.cluster_project = cluster_project end - kubernetes_namespace.namespace ||= - Gitlab::Kubernetes::DefaultNamespace.new( - cluster, - project: kubernetes_namespace.project - ).from_environment_slug(kubernetes_namespace.environment&.slug) + if kubernetes_namespace.project + kubernetes_namespace.namespace ||= + Gitlab::Kubernetes::DefaultNamespace.new( + cluster, + project: kubernetes_namespace.project + ).from_environment_slug(kubernetes_namespace.environment&.slug) + end + kubernetes_namespace.service_account_name ||= "#{kubernetes_namespace.namespace}-service-account" end diff --git a/spec/factories/clusters/providers/aws.rb b/spec/factories/clusters/providers/aws.rb index 2c54300e606..497181de89a 100644 --- a/spec/factories/clusters/providers/aws.rb +++ b/spec/factories/clusters/providers/aws.rb @@ -4,6 +4,7 @@ FactoryBot.define do factory :cluster_provider_aws, class: 'Clusters::Providers::Aws' do association :cluster, platform_type: :kubernetes, provider_type: :aws + kubernetes_version { '1.16' } role_arn { 'arn:aws:iam::123456789012:role/role-name' } vpc_id { 'vpc-00000000000000000' } subnet_ids { %w(subnet-00000000000000000 subnet-11111111111111111) } diff --git a/spec/factories/dev_ops_score_metrics.rb b/spec/factories/dev_ops_report_metrics.rb index 1d1f1a2c39e..808c70c2499 100644 --- a/spec/factories/dev_ops_score_metrics.rb +++ b/spec/factories/dev_ops_report_metrics.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true FactoryBot.define do - factory :dev_ops_score_metric, class: 'DevOpsScore::Metric' do + factory :dev_ops_report_metric, class: 'DevOpsReport::Metric' do leader_issues { 9.256 } instance_issues { 1.234 } percentage_issues { 13.331 } diff --git a/spec/factories/diff_position.rb b/spec/factories/diff_position.rb index 685272acf5c..0185c4ce156 100644 --- a/spec/factories/diff_position.rb +++ b/spec/factories/diff_position.rb @@ -53,7 +53,10 @@ FactoryBot.define do factory :image_diff_position do position_type { 'image' } x { 1 } - y { 1 } + # Fix: + # NoMethodError: undefined method `end_line=' for nil:NilClass + # from /usr/lib/ruby/2.6.0/psych/tree_builder.rb:133:in `set_end_location' + add_attribute(:y) { 1 } width { 10 } height { 10 } end diff --git a/spec/factories/draft_note.rb b/spec/factories/draft_note.rb index 24563dc92b7..67a3377a39f 100644 --- a/spec/factories/draft_note.rb +++ b/spec/factories/draft_note.rb @@ -25,7 +25,7 @@ FactoryBot.define do factory :draft_note_on_discussion, traits: [:on_discussion] trait :on_discussion do - discussion_id { create(:discussion_note_on_merge_request, noteable: merge_request, project: project).discussion_id } + discussion_id { association(:discussion_note_on_merge_request, noteable: merge_request, project: project).discussion_id } end end end diff --git a/spec/factories/file_uploaders.rb b/spec/factories/file_uploaders.rb index dc888fdd535..f7ceb800f14 100644 --- a/spec/factories/file_uploaders.rb +++ b/spec/factories/file_uploaders.rb @@ -14,7 +14,7 @@ FactoryBot.define do end after(:build) do |uploader, evaluator| - uploader.store!(evaluator.file) + uploader.store!(evaluator.file) if evaluator.project&.persisted? end initialize_with do diff --git a/spec/factories/group_members.rb b/spec/factories/group_members.rb index 3c9d469f23c..37ddbc09616 100644 --- a/spec/factories/group_members.rb +++ b/spec/factories/group_members.rb @@ -3,7 +3,7 @@ FactoryBot.define do factory :group_member do access_level { GroupMember::OWNER } - group + source { association(:group) } user trait(:guest) { access_level { GroupMember::GUEST } } @@ -28,5 +28,11 @@ FactoryBot.define do trait :blocked do after(:build) { |group_member, _| group_member.user.block! } end + + trait :minimal_access do + to_create { |instance| instance.save!(validate: false) } + + access_level { GroupMember::MINIMAL_ACCESS } + end end end diff --git a/spec/factories/instance_statistics/measurement.rb b/spec/factories/instance_statistics/measurement.rb new file mode 100644 index 00000000000..fb180c23214 --- /dev/null +++ b/spec/factories/instance_statistics/measurement.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :instance_statistics_measurement, class: 'Analytics::InstanceStatistics::Measurement' do + recorded_at { Time.now } + identifier { :projects } + count { 1_000 } + + trait :project_count do + identifier { :projects } + end + + trait :group_count do + identifier { :groups } + end + end +end diff --git a/spec/factories/issuable_severity.rb b/spec/factories/issuable_severity.rb new file mode 100644 index 00000000000..10ce58f7944 --- /dev/null +++ b/spec/factories/issuable_severity.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :issuable_severity do + association :issue, factory: :incident + end +end diff --git a/spec/factories/issue_links.rb b/spec/factories/issue_links.rb new file mode 100644 index 00000000000..884e4dfac08 --- /dev/null +++ b/spec/factories/issue_links.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :issue_link do + source factory: :issue + target factory: :issue + end +end diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index 99fe2ef9c0a..90e43b9e22c 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -26,6 +26,12 @@ FactoryBot.define do closed_at { Time.now } end + trait :with_alert do + after(:create) do |issue| + create(:alert_management_alert, project: issue.project, issue: issue) + end + end + after(:build) do |issue, evaluator| issue.state_id = Issue.available_states[evaluator.state] end @@ -46,5 +52,9 @@ FactoryBot.define do factory :incident do issue_type { :incident } end + + factory :quality_test_case do + issue_type { :test_case } + end end end diff --git a/spec/factories/jira_connect_installation.rb b/spec/factories/jira_connect_installation.rb new file mode 100644 index 00000000000..2e3202c662c --- /dev/null +++ b/spec/factories/jira_connect_installation.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :jira_connect_installation do + sequence(:client_key) { |n| "atlassian-client-key-#{n}" } + shared_secret { 'jrNarHaRYaumMvfV3UnYpwt8' } + base_url { 'https://sample.atlassian.net' } + end +end diff --git a/spec/factories/jira_connect_subscription.rb b/spec/factories/jira_connect_subscription.rb new file mode 100644 index 00000000000..e22b277f190 --- /dev/null +++ b/spec/factories/jira_connect_subscription.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :jira_connect_subscription do + association :installation, factory: :jira_connect_installation + association :namespace, factory: :group + end +end diff --git a/spec/factories/labels.rb b/spec/factories/labels.rb index 6725b571f19..a9a9416c48b 100644 --- a/spec/factories/labels.rb +++ b/spec/factories/labels.rb @@ -18,6 +18,13 @@ FactoryBot.define do title { "#{prefix}::#{generate(:label_title)}" } end + trait :incident do + properties = IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES + title { properties.fetch(:title) } + description { properties.fetch(:description) } + color { properties.fetch(:color) } + end + factory :label, traits: [:base_label], class: 'ProjectLabel' do project diff --git a/spec/factories/merge_request_diffs.rb b/spec/factories/merge_request_diffs.rb index 0c4c3244af5..fdb7f52f3bd 100644 --- a/spec/factories/merge_request_diffs.rb +++ b/spec/factories/merge_request_diffs.rb @@ -2,12 +2,26 @@ FactoryBot.define do factory :merge_request_diff do - association :merge_request + merge_request do + build(:merge_request) do |merge_request| + # MergeRequest should not create a MergeRequestDiff in the callback + allow(merge_request).to receive(:ensure_merge_request_diff) + end + end + state { :collected } commits_count { 1 } base_commit_sha { Digest::SHA1.hexdigest(SecureRandom.hex) } head_commit_sha { Digest::SHA1.hexdigest(SecureRandom.hex) } start_commit_sha { Digest::SHA1.hexdigest(SecureRandom.hex) } + + trait :external do + external_diff { fixture_file_upload("spec/fixtures/doc_sample.txt", "plain/txt") } + stored_externally { true } + importing { true } # this avoids setting the state to 'empty' + end + + factory :external_merge_request_diff, traits: [:external] end end diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index af6e88f73b1..6836d5d71f0 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -169,7 +169,7 @@ FactoryBot.define do merge_request.head_pipeline = build( :ci_pipeline, :success, - :with_coverage_reports, + :with_coverage_report_artifact, project: merge_request.source_project, ref: merge_request.source_branch, sha: merge_request.diff_head_sha) diff --git a/spec/factories/metrics/users_starred_dasboards.rb b/spec/factories/metrics/users_starred_dashboards.rb index 06fe7735e9a..06fe7735e9a 100644 --- a/spec/factories/metrics/users_starred_dasboards.rb +++ b/spec/factories/metrics/users_starred_dashboards.rb diff --git a/spec/factories/operations/feature_flag_scopes.rb b/spec/factories/operations/feature_flag_scopes.rb new file mode 100644 index 00000000000..a98c397b8b5 --- /dev/null +++ b/spec/factories/operations/feature_flag_scopes.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :operations_feature_flag_scope, class: 'Operations::FeatureFlagScope' do + association :feature_flag, factory: :operations_feature_flag + active { true } + strategies { [{ name: "default", parameters: {} }] } + sequence(:environment_scope) { |n| "review/patch-#{n}" } + end +end diff --git a/spec/factories/operations/feature_flags.rb b/spec/factories/operations/feature_flags.rb new file mode 100644 index 00000000000..7e43d38a04f --- /dev/null +++ b/spec/factories/operations/feature_flags.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :operations_feature_flag, class: 'Operations::FeatureFlag' do + sequence(:name) { |n| "feature_flag_#{n}" } + project + active { true } + + trait :legacy_flag do + version { Operations::FeatureFlag.versions['legacy_flag'] } + end + + trait :new_version_flag do + version { Operations::FeatureFlag.versions['new_version_flag'] } + end + end +end diff --git a/spec/factories/operations/feature_flags/scope.rb b/spec/factories/operations/feature_flags/scope.rb new file mode 100644 index 00000000000..ef0097c6d08 --- /dev/null +++ b/spec/factories/operations/feature_flags/scope.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :operations_scope, class: 'Operations::FeatureFlags::Scope' do + association :strategy, factory: :operations_strategy + sequence(:environment_scope) { |n| "review/patch-#{n}" } + end +end diff --git a/spec/factories/operations/feature_flags/strategy.rb b/spec/factories/operations/feature_flags/strategy.rb new file mode 100644 index 00000000000..bdb5d9f0f3c --- /dev/null +++ b/spec/factories/operations/feature_flags/strategy.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :operations_strategy, class: 'Operations::FeatureFlags::Strategy' do + association :feature_flag, factory: :operations_feature_flag + name { "default" } + parameters { {} } + end +end diff --git a/spec/factories/operations/feature_flags/user_list.rb b/spec/factories/operations/feature_flags/user_list.rb new file mode 100644 index 00000000000..e87598f0d7c --- /dev/null +++ b/spec/factories/operations/feature_flags/user_list.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :operations_feature_flag_user_list, class: 'Operations::FeatureFlags::UserList' do + association :project, factory: :project + name { 'My User List' } + user_xids { 'user1,user2,user3' } + end +end diff --git a/spec/factories/operations/feature_flags_clients.rb b/spec/factories/operations/feature_flags_clients.rb new file mode 100644 index 00000000000..ca9a28dcfed --- /dev/null +++ b/spec/factories/operations/feature_flags_clients.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :operations_feature_flags_client, class: 'Operations::FeatureFlagsClient' do + project + end +end diff --git a/spec/factories/packages.rb b/spec/factories/packages.rb index a7902f6f105..52b2a32cd3b 100644 --- a/spec/factories/packages.rb +++ b/spec/factories/packages.rb @@ -2,6 +2,7 @@ FactoryBot.define do factory :package, class: 'Packages::Package' do project + creator { project&.creator } name { 'my/company/app/my-app' } sequence(:version) { |n| "1.#{n}-SNAPSHOT" } package_type { :maven } @@ -56,14 +57,20 @@ FactoryBot.define do end factory :pypi_package do - pypi_metadatum - sequence(:name) { |n| "pypi-package-#{n}"} sequence(:version) { |n| "1.0.#{n}" } package_type { :pypi } - after :create do |package| + transient do + without_loaded_metadatum { false } + end + + after :create do |package, evaluator| create :package_file, :pypi, package: package, file_name: "#{package.name}-#{package.version}.tar.gz" + + unless evaluator.without_loaded_metadatum + create :pypi_metadatum, package: package + end end end @@ -115,6 +122,12 @@ FactoryBot.define do conan_metadatum { build(:conan_metadatum, package: nil) } end end + + factory :generic_package do + sequence(:name) { |n| "generic-package-#{n}" } + version { '1.0.0' } + package_type { :generic } + end end factory :composer_metadatum, class: 'Packages::Composer::Metadatum' do @@ -297,7 +310,7 @@ FactoryBot.define do end factory :pypi_metadatum, class: 'Packages::Pypi::Metadatum' do - association :package, package_type: :pypi + package { create(:pypi_package, without_loaded_metadatum: true) } required_python { '>=2.7' } end diff --git a/spec/factories/pages_deployments.rb b/spec/factories/pages_deployments.rb new file mode 100644 index 00000000000..1bea003d683 --- /dev/null +++ b/spec/factories/pages_deployments.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :pages_deployment, class: 'PagesDeployment' do + project + file_store { ObjectStorage::SUPPORTED_STORES.first } + size { 1.megabytes } + + # TODO: replace with proper file uploaded in https://gitlab.com/gitlab-org/gitlab/-/issues/245295 + file { "dummy string" } + end +end diff --git a/spec/factories/plan_limits.rb b/spec/factories/plan_limits.rb index 4aea09618d0..ae892307193 100644 --- a/spec/factories/plan_limits.rb +++ b/spec/factories/plan_limits.rb @@ -7,5 +7,14 @@ FactoryBot.define do trait :default_plan do plan factory: :default_plan end + + trait :with_package_file_sizes do + conan_max_file_size { 100 } + maven_max_file_size { 100 } + npm_max_file_size { 100 } + nuget_max_file_size { 100 } + pypi_max_file_size { 100 } + generic_packages_max_file_size { 100 } + end end end diff --git a/spec/factories/project_feature_usage.rb b/spec/factories/project_feature_usage.rb new file mode 100644 index 00000000000..8265ea04392 --- /dev/null +++ b/spec/factories/project_feature_usage.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :project_feature_usage do + project + + trait :dvcs_cloud do + jira_dvcs_cloud_last_sync_at { Time.current } + end + + trait :dvcs_server do + jira_dvcs_server_last_sync_at { Time.current } + end + end +end diff --git a/spec/factories/project_members.rb b/spec/factories/project_members.rb index e7004937be3..0c2ffac4112 100644 --- a/spec/factories/project_members.rb +++ b/spec/factories/project_members.rb @@ -3,7 +3,7 @@ FactoryBot.define do factory :project_member do user - project + source { association(:project) } maintainer trait(:guest) { access_level { ProjectMember::GUEST } } diff --git a/spec/factories/project_statistics.rb b/spec/factories/project_statistics.rb index 78e80a92b3a..ea003b67db0 100644 --- a/spec/factories/project_statistics.rb +++ b/spec/factories/project_statistics.rb @@ -22,6 +22,7 @@ FactoryBot.define do project_statistics.build_artifacts_size = evaluator.size_multiplier * 4 project_statistics.packages_size = evaluator.size_multiplier * 5 project_statistics.snippets_size = evaluator.size_multiplier * 6 + project_statistics.pipeline_artifacts_size = evaluator.size_multiplier * 7 end end end diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb index 328b7f9a229..e3411e4f925 100644 --- a/spec/factories/projects.rb +++ b/spec/factories/projects.rb @@ -3,8 +3,6 @@ require_relative '../support/helpers/test_env' FactoryBot.define do - PAGES_ACCESS_LEVEL_SCHEMA_VERSION ||= 20180423204600 - # Project without repository # # Project does not have bare repository. @@ -42,7 +40,7 @@ FactoryBot.define do forward_deployment_enabled { nil } end - after(:create) do |project, evaluator| + before(:create) do |project, evaluator| # Builds and MRs can't have higher visibility level than repository access level. builds_access_level = [evaluator.builds_access_level, evaluator.repository_access_level].min merge_requests_access_level = [evaluator.merge_requests_access_level, evaluator.repository_access_level].min @@ -54,15 +52,14 @@ FactoryBot.define do issues_access_level: evaluator.issues_access_level, forking_access_level: evaluator.forking_access_level, merge_requests_access_level: merge_requests_access_level, - repository_access_level: evaluator.repository_access_level + repository_access_level: evaluator.repository_access_level, + pages_access_level: evaluator.pages_access_level } - if ActiveRecord::Migrator.current_version >= PAGES_ACCESS_LEVEL_SCHEMA_VERSION - hash.store("pages_access_level", evaluator.pages_access_level) - end - - project.project_feature.update!(hash) + project.build_project_feature(hash) + end + after(:create) do |project, evaluator| # Normally the class Projects::CreateService is used for creating # projects, and this class takes care of making sure the owner and current # user have access to the project. Our specs don't use said service class, @@ -114,6 +111,18 @@ FactoryBot.define do import_status { :failed } end + trait :jira_dvcs_cloud do + before(:create) do |project| + create(:project_feature_usage, :dvcs_cloud, project: project) + end + end + + trait :jira_dvcs_server do + before(:create) do |project| + create(:project_feature_usage, :dvcs_server, project: project) + end + end + trait :archived do archived { true } end @@ -383,6 +392,12 @@ FactoryBot.define do end end + factory :ewm_project, parent: :project do + has_external_issue_tracker { true } + + ewm_service + end + factory :project_with_design, parent: :project do after(:create) do |project| issue = create(:issue, project: project) diff --git a/spec/factories/resource_iteration_event.rb b/spec/factories/resource_iteration_event.rb deleted file mode 100644 index 85e7320f7a7..00000000000 --- a/spec/factories/resource_iteration_event.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.define do - factory :resource_iteration_event do - issue { merge_request.nil? ? create(:issue) : nil } - merge_request { nil } - iteration - action { :add } - user { issue&.author || merge_request&.author || create(:user) } - end -end diff --git a/spec/factories/services.rb b/spec/factories/services.rb index 7fbf6f16dc7..9056fd97f13 100644 --- a/spec/factories/services.rb +++ b/spec/factories/services.rb @@ -116,6 +116,12 @@ FactoryBot.define do issue_tracker end + factory :ewm_service do + project + active { true } + issue_tracker + end + trait :issue_tracker do transient do create_data { true } diff --git a/spec/factories/snippet_repositories.rb b/spec/factories/snippet_repositories.rb index 1f9e68514bb..c3a6bc3ae31 100644 --- a/spec/factories/snippet_repositories.rb +++ b/spec/factories/snippet_repositories.rb @@ -8,5 +8,13 @@ FactoryBot.define do snippet_repository.shard_name = snippet_repository.snippet.repository_storage snippet_repository.disk_path = snippet_repository.snippet.disk_path end + + trait(:checksummed) do + verification_checksum { 'abc' } + end + + trait(:checksum_failure) do + verification_failure { 'Could not calculate the checksum' } + end end end diff --git a/spec/factories/terraform/state.rb b/spec/factories/terraform/state.rb index 46784581180..9decc89ef39 100644 --- a/spec/factories/terraform/state.rb +++ b/spec/factories/terraform/state.rb @@ -7,6 +7,7 @@ FactoryBot.define do sequence(:name) { |n| "state-#{n}" } trait :with_file do + versioning_enabled { false } file { fixture_file_upload('spec/fixtures/terraform/terraform.tfstate', 'application/json') } end @@ -15,5 +16,24 @@ FactoryBot.define do locked_at { Time.current } locked_by_user { create(:user) } end + + trait(:checksummed) do + with_file + verification_checksum { 'abc' } + end + + trait(:checksum_failure) do + with_file + verification_failure { 'Could not calculate the checksum' } + end + + trait :with_version do + after(:create) do |state| + create(:terraform_state_version, :with_file, terraform_state: state) + end + end + + # Remove with https://gitlab.com/gitlab-org/gitlab/-/issues/235108 + factory :legacy_terraform_state, parent: :terraform_state, traits: [:with_file] end end diff --git a/spec/factories/terraform/state_version.rb b/spec/factories/terraform/state_version.rb new file mode 100644 index 00000000000..d1bd78215e3 --- /dev/null +++ b/spec/factories/terraform/state_version.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :terraform_state_version, class: 'Terraform::StateVersion' do + terraform_state factory: :terraform_state + created_by_user factory: :user + + sequence(:version) + file { fixture_file_upload('spec/fixtures/terraform/terraform.tfstate', 'application/json') } + end +end diff --git a/spec/factories/usage_data.rb b/spec/factories/usage_data.rb index d2b8fd94aca..5b20205a235 100644 --- a/spec/factories/usage_data.rb +++ b/spec/factories/usage_data.rb @@ -51,12 +51,11 @@ FactoryBot.define do create(:protected_branch, name: 'main', project: projects[0]) # Incident Labeled Issues - incident_label_attrs = IncidentManagement::CreateIncidentLabelService::LABEL_PROPERTIES - incident_label = create(:label, project: projects[0], **incident_label_attrs) + incident_label = create(:label, :incident, project: projects[0]) create(:labeled_issue, project: projects[0], labels: [incident_label]) incident_group = create(:group) - incident_label_scoped_to_project = create(:label, project: projects[1], **incident_label_attrs) - incident_label_scoped_to_group = create(:group_label, group: incident_group, **incident_label_attrs) + incident_label_scoped_to_project = create(:label, :incident, project: projects[1]) + incident_label_scoped_to_group = create(:group_label, :incident, group: incident_group) create(:labeled_issue, project: projects[1], labels: [incident_label_scoped_to_project]) create(:labeled_issue, project: projects[1], labels: [incident_label_scoped_to_group]) @@ -65,6 +64,10 @@ FactoryBot.define do create(:alert_management_alert, issue: alert_bot_issues[0], project: projects[0]) create(:self_managed_prometheus_alert_event, related_issues: [issues[1]], project: projects[0]) + # Kubernetes agents + create(:cluster_agent, project: projects[0]) + create(:cluster_agent_token, agent: create(:cluster_agent, project: projects[1]) ) + # Enabled clusters gcp_cluster = create(:cluster_provider_gcp, :created).cluster create(:cluster_provider_aws, :created) @@ -94,6 +97,11 @@ FactoryBot.define do create(:grafana_integration, project: projects[1], enabled: true) create(:grafana_integration, project: projects[2], enabled: false) + create(:package, project: projects[0]) + create(:package, project: projects[0]) + create(:package, project: projects[1]) + create(:package, created_at: 2.months.ago, project: projects[1]) + ProjectFeature.first.update_attribute('repository_access_level', 0) # Create fresh & a month (28-days SMAU) old data diff --git a/spec/factories/users.rb b/spec/factories/users.rb index 7e121b10632..1a8c5d7e40c 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -81,6 +81,14 @@ FactoryBot.define do end end + trait :two_factor_via_webauthn do + transient { registrations_count { 5 } } + + after(:create) do |user, evaluator| + create_list(:webauthn_registration, evaluator.registrations_count, user: user) + end + end + trait :readme do project_view { :readme } end @@ -128,6 +136,16 @@ FactoryBot.define do end end + factory :atlassian_user do + transient do + extern_uid { generate(:username) } + end + + after(:create) do |user, evaluator| + create(:atlassian_identity, user: user, extern_uid: evaluator.extern_uid) + end + end + factory :admin, traits: [:admin] end end diff --git a/spec/factories/webauthn_registrations.rb b/spec/factories/webauthn_registrations.rb new file mode 100644 index 00000000000..ac803885244 --- /dev/null +++ b/spec/factories/webauthn_registrations.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :webauthn_registration do + credential_xid { SecureRandom.base64(88) } + public_key { SecureRandom.base64(103) } + name { FFaker::BaconIpsum.characters(10) } + counter { 1 } + user + end +end |