diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-12 15:08:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-12 15:08:35 +0300 |
commit | 8ef107c43390ea9c9932afb55d1318e4716fbf3b (patch) | |
tree | ad35474f833e8da50107d8ca1e348f9a953c8d7c /spec | |
parent | e0df184fb182633972212cd62d6e3dc6e4bd0e62 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
9 files changed, 186 insertions, 36 deletions
diff --git a/spec/controllers/graphql_controller_spec.rb b/spec/controllers/graphql_controller_spec.rb index b1399835b45..b4a7e41ccd2 100644 --- a/spec/controllers/graphql_controller_spec.rb +++ b/spec/controllers/graphql_controller_spec.rb @@ -462,12 +462,13 @@ RSpec.describe GraphqlController, feature_category: :integrations do end it 'logs that it will try to hit the cache' do + expect(Gitlab::AppLogger).to receive(:info).with(message: "IntrospectionQueryCache hit") expect(Gitlab::AppLogger).to receive(:info).with( message: "IntrospectionQueryCache", - can_use_introspection_query_cache: true, + can_use_introspection_query_cache: "true", query: query.to_s, - variables: {}, - introspection_query_cache_key: ['introspection-query-cache', Gitlab.revision, false] + variables: "{}", + introspection_query_cache_key: "[\"introspection-query-cache\", \"#{Gitlab.revision}\", false]" ) post :execute, params: { query: query, operationName: 'IntrospectionQuery' } @@ -477,12 +478,13 @@ RSpec.describe GraphqlController, feature_category: :integrations do let(:query) { File.read(Rails.root.join('spec/fixtures/api/graphql/fake_introspection.graphql')) } it 'logs that it did not try to hit the cache' do + expect(Gitlab::AppLogger).to receive(:info).with(message: "IntrospectionQueryCache miss") expect(Gitlab::AppLogger).to receive(:info).with( message: "IntrospectionQueryCache", - can_use_introspection_query_cache: false, + can_use_introspection_query_cache: "false", query: query.to_s, - variables: {}, - introspection_query_cache_key: ['introspection-query-cache', Gitlab.revision, false] + variables: "{}", + introspection_query_cache_key: "[\"introspection-query-cache\", \"#{Gitlab.revision}\", false]" ) post :execute, params: { query: query, operationName: 'IntrospectionQuery' } diff --git a/spec/features/groups/new_group_page_spec.rb b/spec/features/groups/new_group_page_spec.rb index a73dbf998c3..c3731565ddf 100644 --- a/spec/features/groups/new_group_page_spec.rb +++ b/spec/features/groups/new_group_page_spec.rb @@ -11,24 +11,6 @@ RSpec.describe 'New group page', :js, feature_category: :groups_and_projects do sign_in(user) end - describe 'new top level group alert' do - context 'when a user visits the new group page' do - it 'shows the new top level group alert' do - visit new_group_path(anchor: 'create-group-pane') - - expect(page).to have_selector('[data-testid="new-top-level-alert"]') - end - end - - context 'when a user visits the new sub group page' do - it 'does not show the new top level group alert' do - visit new_group_path(parent_id: parent_group.id, anchor: 'create-group-pane') - - expect(page).not_to have_selector('[data-testid="new-top-level-alert"]') - end - end - end - describe 'sidebar' do context 'in the current navigation' do before do diff --git a/spec/frontend/sentry/index_spec.js b/spec/frontend/sentry/index_spec.js index aa19bb03cda..3130e01cc9e 100644 --- a/spec/frontend/sentry/index_spec.js +++ b/spec/frontend/sentry/index_spec.js @@ -4,6 +4,7 @@ import LegacySentryConfig from '~/sentry/legacy_sentry_config'; import SentryConfig from '~/sentry/sentry_config'; describe('Sentry init', () => { + const version = '1.0.0'; const dsn = 'https://123@sentry.gitlab.test/123'; const environment = 'test'; const currentUserId = '1'; @@ -13,6 +14,7 @@ describe('Sentry init', () => { beforeEach(() => { window.gon = { + version, sentry_dsn: dsn, sentry_environment: environment, current_user_id: currentUserId, @@ -42,7 +44,7 @@ describe('Sentry init', () => { currentUserId, allowUrls: [gitlabUrl, 'webpack-internal://'], environment, - release: revision, + release: version, tags: { revision, feature_category: featureCategory, diff --git a/spec/frontend/vue_shared/new_namespace/new_namespace_page_spec.js b/spec/frontend/vue_shared/new_namespace/new_namespace_page_spec.js index b87ae8a232f..1ee6f2cfff3 100644 --- a/spec/frontend/vue_shared/new_namespace/new_namespace_page_spec.js +++ b/spec/frontend/vue_shared/new_namespace/new_namespace_page_spec.js @@ -4,6 +4,7 @@ import { nextTick } from 'vue'; import LegacyContainer from '~/vue_shared/new_namespace/components/legacy_container.vue'; import WelcomePage from '~/vue_shared/new_namespace/components/welcome.vue'; import NewNamespacePage from '~/vue_shared/new_namespace/new_namespace_page.vue'; +import NewTopLevelGroupAlert from '~/groups/components/new_top_level_group_alert.vue'; import SuperSidebarToggle from '~/super_sidebar/components/super_sidebar_toggle.vue'; import { sidebarState } from '~/super_sidebar/constants'; @@ -14,6 +15,7 @@ describe('Experimental new namespace creation app', () => { const findWelcomePage = () => wrapper.findComponent(WelcomePage); const findLegacyContainer = () => wrapper.findComponent(LegacyContainer); const findBreadcrumb = () => wrapper.findComponent(GlBreadcrumb); + const findNewTopLevelGroupAlert = () => wrapper.findComponent(NewTopLevelGroupAlert); const findSuperSidebarToggle = () => wrapper.findComponent(SuperSidebarToggle); const DEFAULT_PROPS = { @@ -33,6 +35,9 @@ describe('Experimental new namespace creation app', () => { ...DEFAULT_PROPS, ...propsData, }, + stubs: { + NewTopLevelGroupAlert, + }, }); }; @@ -125,4 +130,39 @@ describe('Experimental new namespace creation app', () => { expect(findSuperSidebarToggle().exists()).toBe(isToggleVisible); }); }); + + describe('top level group alert', () => { + beforeEach(() => { + window.location.hash = `#${DEFAULT_PROPS.panels[0].name}`; + }); + + describe('when self-managed', () => { + it('does not render alert', () => { + createComponent(); + + expect(findNewTopLevelGroupAlert().exists()).toBe(false); + }); + }); + + describe('when on .com', () => { + it('does not render alert', () => { + createComponent({ propsData: { isSaas: true } }); + + expect(findNewTopLevelGroupAlert().exists()).toBe(false); + }); + + describe('when empty parent group name', () => { + it('renders alert', () => { + createComponent({ + propsData: { + isSaas: true, + panels: [{ ...DEFAULT_PROPS.panels[0], detailProps: { parentGroupName: '' } }], + }, + }); + + expect(findNewTopLevelGroupAlert().exists()).toBe(true); + }); + }); + }); + }); }); diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb index f66f9a8a58e..bdcf0ef57ee 100644 --- a/spec/helpers/groups_helper_spec.rb +++ b/spec/helpers/groups_helper_spec.rb @@ -437,7 +437,8 @@ RSpec.describe GroupsHelper do expect(subgroup_creation_data(subgroup)).to eq({ import_existing_group_path: '/groups/new#import-group-pane', parent_group_name: name, - parent_group_url: group_url(group) + parent_group_url: group_url(group), + is_saas: 'false' }) end end @@ -447,7 +448,8 @@ RSpec.describe GroupsHelper do expect(subgroup_creation_data(group)).to eq({ import_existing_group_path: '/groups/new#import-group-pane', parent_group_name: nil, - parent_group_url: nil + parent_group_url: nil, + is_saas: 'false' }) end end diff --git a/spec/lib/gitlab/background_migration/mark_duplicate_npm_packages_for_destruction_spec.rb b/spec/lib/gitlab/background_migration/mark_duplicate_npm_packages_for_destruction_spec.rb new file mode 100644 index 00000000000..05a19b7973c --- /dev/null +++ b/spec/lib/gitlab/background_migration/mark_duplicate_npm_packages_for_destruction_spec.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::MarkDuplicateNpmPackagesForDestruction, schema: 20230524201454, feature_category: :package_registry do # rubocop:disable Layout/LineLength + describe '#perform' do + let(:projects_table) { table(:projects) } + let(:namespaces_table) { table(:namespaces) } + let(:packages_table) { table(:packages_packages) } + + let!(:namespace) do + namespaces_table.create!(name: 'project', path: 'project', type: 'Project') + end + + let!(:project) do + projects_table.create!( + namespace_id: namespace.id, + name: 'project', + path: 'project', + project_namespace_id: namespace.id + ) + end + + let!(:package_1) do + packages_table.create!( + project_id: project.id, + name: 'test1', + version: '1.0.0', + package_type: described_class::NPM_PACKAGE_TYPE + ) + end + + let!(:package_2) do + packages_table.create!( + project_id: project.id, + name: 'test2', + version: '1.0.0', + package_type: described_class::NPM_PACKAGE_TYPE + ) + end + + let!(:package_3) do + packages_table.create!( + project_id: project.id, + name: 'test3', + version: '1.0.0', + package_type: described_class::NPM_PACKAGE_TYPE + ) + end + + let(:migration) do + described_class.new( + start_id: projects_table.minimum(:id), + end_id: projects_table.maximum(:id), + batch_table: :packages_packages, + batch_column: :project_id, + sub_batch_size: 10, + pause_ms: 0, + connection: ApplicationRecord.connection + ) + end + + before do + # create a duplicated package without triggering model validation errors + package_2.update_column(:name, package_1.name) + package_3.update_column(:name, package_1.name) + end + + it 'marks duplicate npm packages for destruction', :aggregate_failures do + packages_marked_for_destruction = described_class::Package + .where(status: described_class::PENDING_DESTRUCTION_STATUS) + + expect { migration.perform } + .to change { packages_marked_for_destruction.count }.from(0).to(2) + expect(package_3.reload.status).not_to eq(described_class::PENDING_DESTRUCTION_STATUS) + end + end +end diff --git a/spec/lib/gitlab/gon_helper_spec.rb b/spec/lib/gitlab/gon_helper_spec.rb index 6e8997d51c3..1135cfc22ac 100644 --- a/spec/lib/gitlab/gon_helper_spec.rb +++ b/spec/lib/gitlab/gon_helper_spec.rb @@ -6,10 +6,6 @@ RSpec.describe Gitlab::GonHelper do let(:helper) do Class.new do include Gitlab::GonHelper - - def current_user - nil - end end.new end @@ -18,6 +14,7 @@ RSpec.describe Gitlab::GonHelper do let(:https) { true } before do + allow(helper).to receive(:current_user).and_return(nil) allow(helper).to receive(:gon).and_return(gon) stub_config_setting(https: https) end @@ -40,6 +37,24 @@ RSpec.describe Gitlab::GonHelper do end end + it 'sets no GitLab version' do + expect(gon).not_to receive(:version=) + + helper.add_gon_variables + end + + context 'when user is logged in' do + before do + allow(helper).to receive(:current_user).and_return(build_stubbed(:user)) + end + + it 'sets GitLab version' do + expect(gon).to receive(:version=).with(Gitlab::VERSION) + + helper.add_gon_variables + end + end + context 'when sentry is configured' do let(:clientside_dsn) { 'https://xxx@sentry.example.com/1' } let(:environment) { 'staging' } diff --git a/spec/migrations/20230524201454_queue_mark_duplicate_npm_packages_for_destruction_spec.rb b/spec/migrations/20230524201454_queue_mark_duplicate_npm_packages_for_destruction_spec.rb new file mode 100644 index 00000000000..639c84e9bec --- /dev/null +++ b/spec/migrations/20230524201454_queue_mark_duplicate_npm_packages_for_destruction_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe QueueMarkDuplicateNpmPackagesForDestruction, feature_category: :package_registry do + let!(:batched_migration) { described_class::MIGRATION } + + it 'schedules a new batched migration' do + reversible_migration do |migration| + migration.before -> { + expect(batched_migration).not_to have_scheduled_batched_migration + } + + migration.after -> { + expect(batched_migration).to have_scheduled_batched_migration( + table_name: :packages_packages, + column_name: :project_id, + interval: described_class::DELAY_INTERVAL, + batch_size: described_class::BATCH_SIZE, + batch_class_name: described_class::BATCH_CLASS_NAME, + sub_batch_size: described_class::SUB_BATCH_SIZE + ) + } + end + end +end diff --git a/spec/models/integrations/hangouts_chat_spec.rb b/spec/models/integrations/hangouts_chat_spec.rb index 1ebf2ec3005..bcb80768ffb 100644 --- a/spec/models/integrations/hangouts_chat_spec.rb +++ b/spec/models/integrations/hangouts_chat_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Integrations::HangoutsChat do +RSpec.describe Integrations::HangoutsChat, feature_category: :integrations do it_behaves_like "chat integration", "Hangouts Chat" do let(:client) { HangoutsChat::Sender } let(:client_arguments) { webhook_url } @@ -46,25 +46,27 @@ RSpec.describe Integrations::HangoutsChat do end context 'with issue events' do - let(:issues_sample_data) { create(:issue, project: project).to_hook_data(user) } + let_it_be(:issue) { create(:issue, project: project) } + let(:issues_sample_data) { issue.to_hook_data(user) } it "adds thread key for issue events" do expect(chat_integration.execute(issues_sample_data)).to be(true) expect(WebMock).to have_requested(:post, webhook_url) - .with(query: hash_including({ "threadKey" => /issue .*?/ })) + .with(query: hash_including({ "threadKey" => /issue #{project.full_name}##{issue.iid}/ })) .once end end context 'with merge events' do - let(:merge_sample_data) { create(:merge_request, source_project: project).to_hook_data(user) } + let_it_be(:merge_request) { create(:merge_request, source_project: project) } + let(:merge_sample_data) { merge_request.to_hook_data(user) } it "adds thread key for merge events" do expect(chat_integration.execute(merge_sample_data)).to be(true) expect(WebMock).to have_requested(:post, webhook_url) - .with(query: hash_including({ "threadKey" => /merge request .*?/ })) + .with(query: hash_including({ "threadKey" => /merge request #{project.full_name}!#{merge_request.iid}/ })) .once end end |