Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-03-03 03:12:53 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-03 03:12:53 +0300
commita77c9fccd057514a8b78a10642779f54a22f3f76 (patch)
tree5746326ff4e1e25f01af2062454f90bdc3f57d35 /spec
parenta88ffaad9f9f321a71657ac0aca4d947f5bc6a5b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/users/show_spec.rb34
-rw-r--r--spec/frontend/profile/components/followers_tab_spec.js21
-rw-r--r--spec/frontend/profile/components/following_tab_spec.js21
-rw-r--r--spec/helpers/users_helper_spec.rb4
-rw-r--r--spec/lib/gitlab/usage/metrics/instrumentations/count_bulk_imports_entities_metric_spec.rb119
-rw-r--r--spec/migrations/20230221214519_remove_incorrectly_onboarded_namespaces_from_onboarding_progress_spec.rb59
-rw-r--r--spec/support/stub_dot_com_check.rb27
-rw-r--r--spec/tooling/danger/stable_branch_spec.rb39
8 files changed, 274 insertions, 50 deletions
diff --git a/spec/features/users/show_spec.rb b/spec/features/users/show_spec.rb
index 88b2d918976..9aef3ed7cd6 100644
--- a/spec/features/users/show_spec.rb
+++ b/spec/features/users/show_spec.rb
@@ -149,7 +149,7 @@ RSpec.describe 'User page', feature_category: :user_profile do
end
end
- context 'follow/unfollow and followers/following' do
+ context 'follow/unfollow and followers/following', :js do
let_it_be(:followee) { create(:user) }
let_it_be(:follower) { create(:user) }
@@ -159,21 +159,33 @@ RSpec.describe 'User page', feature_category: :user_profile do
expect(page).not_to have_button(text: 'Follow', class: 'gl-button')
end
- it 'shows 0 followers and 0 following' do
- subject
+ shared_examples 'follower tabs with count badges' do
+ it 'shows 0 followers and 0 following' do
+ subject
+
+ expect(page).to have_content('Followers 0')
+ expect(page).to have_content('Following 0')
+ end
+
+ it 'shows 1 followers and 1 following' do
+ follower.follow(user)
+ user.follow(followee)
- expect(page).to have_content('0 followers')
- expect(page).to have_content('0 following')
+ subject
+
+ expect(page).to have_content('Followers 1')
+ expect(page).to have_content('Following 1')
+ end
end
- it 'shows 1 followers and 1 following' do
- follower.follow(user)
- user.follow(followee)
+ it_behaves_like 'follower tabs with count badges'
- subject
+ context 'with profile_tabs_vue feature flag disabled' do
+ before_all do
+ stub_feature_flags(profile_tabs_vue: false)
+ end
- expect(page).to have_content('1 follower')
- expect(page).to have_content('1 following')
+ it_behaves_like 'follower tabs with count badges'
end
it 'does show button to follow' do
diff --git a/spec/frontend/profile/components/followers_tab_spec.js b/spec/frontend/profile/components/followers_tab_spec.js
index 4af428c4e0c..9cc5bdea9be 100644
--- a/spec/frontend/profile/components/followers_tab_spec.js
+++ b/spec/frontend/profile/components/followers_tab_spec.js
@@ -1,4 +1,4 @@
-import { GlTab } from '@gitlab/ui';
+import { GlBadge, GlTab } from '@gitlab/ui';
import { s__ } from '~/locale';
import FollowersTab from '~/profile/components/followers_tab.vue';
@@ -8,12 +8,25 @@ describe('FollowersTab', () => {
let wrapper;
const createComponent = () => {
- wrapper = shallowMountExtended(FollowersTab);
+ wrapper = shallowMountExtended(FollowersTab, {
+ provide: {
+ followers: 2,
+ },
+ });
};
- it('renders `GlTab` and sets `title` prop', () => {
+ it('renders `GlTab` and sets title', () => {
createComponent();
- expect(wrapper.findComponent(GlTab).attributes('title')).toBe(s__('UserProfile|Followers'));
+ expect(wrapper.findComponent(GlTab).element.textContent).toContain(
+ s__('UserProfile|Followers'),
+ );
+ });
+
+ it('renders `GlBadge`, sets size and content', () => {
+ createComponent();
+
+ expect(wrapper.findComponent(GlBadge).attributes('size')).toBe('sm');
+ expect(wrapper.findComponent(GlBadge).element.textContent).toBe('2');
});
});
diff --git a/spec/frontend/profile/components/following_tab_spec.js b/spec/frontend/profile/components/following_tab_spec.js
index 75123274ccb..c9d56360c3e 100644
--- a/spec/frontend/profile/components/following_tab_spec.js
+++ b/spec/frontend/profile/components/following_tab_spec.js
@@ -1,4 +1,4 @@
-import { GlTab } from '@gitlab/ui';
+import { GlBadge, GlTab } from '@gitlab/ui';
import { s__ } from '~/locale';
import FollowingTab from '~/profile/components/following_tab.vue';
@@ -8,12 +8,25 @@ describe('FollowingTab', () => {
let wrapper;
const createComponent = () => {
- wrapper = shallowMountExtended(FollowingTab);
+ wrapper = shallowMountExtended(FollowingTab, {
+ provide: {
+ followees: 3,
+ },
+ });
};
- it('renders `GlTab` and sets `title` prop', () => {
+ it('renders `GlTab` and sets title', () => {
createComponent();
- expect(wrapper.findComponent(GlTab).attributes('title')).toBe(s__('UserProfile|Following'));
+ expect(wrapper.findComponent(GlTab).element.textContent).toContain(
+ s__('UserProfile|Following'),
+ );
+ });
+
+ it('renders `GlBadge`, sets size and content', () => {
+ createComponent();
+
+ expect(wrapper.findComponent(GlBadge).attributes('size')).toBe('sm');
+ expect(wrapper.findComponent(GlBadge).element.textContent).toBe('3');
});
});
diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb
index 83afeb77bad..41161188388 100644
--- a/spec/helpers/users_helper_spec.rb
+++ b/spec/helpers/users_helper_spec.rb
@@ -482,10 +482,14 @@ RSpec.describe UsersHelper do
describe '#user_profile_tabs_app_data' do
before do
allow(helper).to receive(:user_calendar_path).with(user, :json).and_return('/users/root/calendar.json')
+ allow(user).to receive_message_chain(:followers, :count).and_return(2)
+ allow(user).to receive_message_chain(:followees, :count).and_return(3)
end
it 'returns expected hash' do
expect(helper.user_profile_tabs_app_data(user)).to eq({
+ followees: 3,
+ followers: 2,
user_calendar_path: '/users/root/calendar.json',
utc_offset: 0
})
diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/count_bulk_imports_entities_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/count_bulk_imports_entities_metric_spec.rb
index ce15d44b1e1..317929f77e6 100644
--- a/spec/lib/gitlab/usage/metrics/instrumentations/count_bulk_imports_entities_metric_spec.rb
+++ b/spec/lib/gitlab/usage/metrics/instrumentations/count_bulk_imports_entities_metric_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountBulkImportsEntitiesMetric do
+RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountBulkImportsEntitiesMetric, feature_category: :importers do
let_it_be(:user) { create(:user) }
let_it_be(:bulk_import_projects) do
create_list(:bulk_import_entity, 2, source_type: 'project_entity', created_at: 3.weeks.ago, status: 2)
@@ -163,4 +163,121 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountBulkImportsEntitie
options: { status: 2, source_type: 'project_entity' }
end
end
+
+ context 'with has_failures: true' do
+ before(:all) do
+ create_list(:bulk_import_entity, 3, :project_entity, :finished, created_at: 3.weeks.ago, has_failures: true)
+ create_list(:bulk_import_entity, 2, :project_entity, :finished, created_at: 2.months.ago, has_failures: true)
+ create_list(:bulk_import_entity, 3, :group_entity, :finished, created_at: 3.weeks.ago, has_failures: true)
+ create_list(:bulk_import_entity, 2, :group_entity, :finished, created_at: 2.months.ago, has_failures: true)
+ end
+
+ context 'with all time frame' do
+ context 'with project entity' do
+ let(:expected_value) { 5 }
+ let(:expected_query) do
+ "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\" " \
+ "WHERE \"bulk_import_entities\".\"source_type\" = 1 AND \"bulk_import_entities\".\"status\" = 2 " \
+ "AND \"bulk_import_entities\".\"has_failures\" = TRUE"
+ end
+
+ it_behaves_like 'a correct instrumented metric value and query',
+ time_frame: 'all',
+ options: { status: 2, source_type: 'project_entity', has_failures: true }
+ end
+
+ context 'with group entity' do
+ let(:expected_value) { 5 }
+ let(:expected_query) do
+ "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\" " \
+ "WHERE \"bulk_import_entities\".\"source_type\" = 0 AND \"bulk_import_entities\".\"status\" = 2 " \
+ "AND \"bulk_import_entities\".\"has_failures\" = TRUE"
+ end
+
+ it_behaves_like 'a correct instrumented metric value and query',
+ time_frame: 'all',
+ options: { status: 2, source_type: 'group_entity', has_failures: true }
+ end
+ end
+
+ context 'for 28d time frame' do
+ let(:expected_value) { 3 }
+ let(:start) { 30.days.ago.to_s(:db) }
+ let(:finish) { 2.days.ago.to_s(:db) }
+ let(:expected_query) do
+ "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\" " \
+ "WHERE \"bulk_import_entities\".\"created_at\" BETWEEN '#{start}' AND '#{finish}' " \
+ "AND \"bulk_import_entities\".\"source_type\" = 1 AND \"bulk_import_entities\".\"status\" = 2 " \
+ "AND \"bulk_import_entities\".\"has_failures\" = TRUE"
+ end
+
+ it_behaves_like 'a correct instrumented metric value and query',
+ time_frame: '28d',
+ options: { status: 2, source_type: 'project_entity', has_failures: true }
+ end
+ end
+
+ context 'with has_failures: false' do
+ context 'with all time frame' do
+ context 'with project entity' do
+ let(:expected_value) { 3 }
+ let(:expected_query) do
+ "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\" " \
+ "WHERE \"bulk_import_entities\".\"source_type\" = 1 AND \"bulk_import_entities\".\"status\" = 2 " \
+ "AND \"bulk_import_entities\".\"has_failures\" = FALSE"
+ end
+
+ it_behaves_like 'a correct instrumented metric value and query',
+ time_frame: 'all',
+ options: { status: 2, source_type: 'project_entity', has_failures: false }
+ end
+
+ context 'with group entity' do
+ let(:expected_value) { 2 }
+ let(:expected_query) do
+ "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\" " \
+ "WHERE \"bulk_import_entities\".\"source_type\" = 0 AND \"bulk_import_entities\".\"status\" = 2 " \
+ "AND \"bulk_import_entities\".\"has_failures\" = FALSE"
+ end
+
+ it_behaves_like 'a correct instrumented metric value and query',
+ time_frame: 'all',
+ options: { status: 2, source_type: 'group_entity', has_failures: false }
+ end
+ end
+
+ context 'for 28d time frame' do
+ context 'with project entity' do
+ let(:expected_value) { 2 }
+ let(:start) { 30.days.ago.to_s(:db) }
+ let(:finish) { 2.days.ago.to_s(:db) }
+ let(:expected_query) do
+ "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\" " \
+ "WHERE \"bulk_import_entities\".\"created_at\" BETWEEN '#{start}' AND '#{finish}' " \
+ "AND \"bulk_import_entities\".\"source_type\" = 1 AND \"bulk_import_entities\".\"status\" = 2 " \
+ "AND \"bulk_import_entities\".\"has_failures\" = FALSE"
+ end
+
+ it_behaves_like 'a correct instrumented metric value and query',
+ time_frame: '28d',
+ options: { status: 2, source_type: 'project_entity', has_failures: false }
+ end
+
+ context 'with group entity' do
+ let(:expected_value) { 2 }
+ let(:start) { 30.days.ago.to_s(:db) }
+ let(:finish) { 2.days.ago.to_s(:db) }
+ let(:expected_query) do
+ "SELECT COUNT(\"bulk_import_entities\".\"id\") FROM \"bulk_import_entities\" " \
+ "WHERE \"bulk_import_entities\".\"created_at\" BETWEEN '#{start}' AND '#{finish}' " \
+ "AND \"bulk_import_entities\".\"source_type\" = 0 AND \"bulk_import_entities\".\"status\" = 2 " \
+ "AND \"bulk_import_entities\".\"has_failures\" = FALSE"
+ end
+
+ it_behaves_like 'a correct instrumented metric value and query',
+ time_frame: '28d',
+ options: { status: 2, source_type: 'group_entity', has_failures: false }
+ end
+ end
+ end
end
diff --git a/spec/migrations/20230221214519_remove_incorrectly_onboarded_namespaces_from_onboarding_progress_spec.rb b/spec/migrations/20230221214519_remove_incorrectly_onboarded_namespaces_from_onboarding_progress_spec.rb
new file mode 100644
index 00000000000..be49a3e919d
--- /dev/null
+++ b/spec/migrations/20230221214519_remove_incorrectly_onboarded_namespaces_from_onboarding_progress_spec.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe RemoveIncorrectlyOnboardedNamespacesFromOnboardingProgress, feature_category: :onboarding do
+ let(:onboarding_progresses) { table(:onboarding_progresses) }
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+
+ # namespace to keep with name Learn Gitlab
+ let(:namespace1) { namespaces.create!(name: 'namespace1', type: 'Group', path: 'namespace1') }
+ let!(:onboard_keep_1) { onboarding_progresses.create!(namespace_id: namespace1.id) }
+ let!(:proj1) do
+ proj_namespace = namespaces.create!(name: 'proj1', path: 'proj1', type: 'Project', parent_id: namespace1.id)
+ projects.create!(name: 'project', namespace_id: namespace1.id, project_namespace_id: proj_namespace.id)
+ end
+
+ let!(:learn_gitlab) do
+ proj_namespace = namespaces.create!(name: 'projlg1', path: 'projlg1', type: 'Project', parent_id: namespace1.id)
+ projects.create!(name: 'Learn GitLab', namespace_id: namespace1.id, project_namespace_id: proj_namespace.id)
+ end
+
+ # namespace to keep with name Learn GitLab - Ultimate trial
+ let(:namespace2) { namespaces.create!(name: 'namespace2', type: 'Group', path: 'namespace2') }
+ let!(:onboard_keep_2) { onboarding_progresses.create!(namespace_id: namespace2.id) }
+ let!(:proj2) do
+ proj_namespace = namespaces.create!(name: 'proj2', path: 'proj2', type: 'Project', parent_id: namespace2.id)
+ projects.create!(name: 'project', namespace_id: namespace2.id, project_namespace_id: proj_namespace.id)
+ end
+
+ let!(:learn_gitlab2) do
+ proj_namespace = namespaces.create!(name: 'projlg2', path: 'projlg2', type: 'Project', parent_id: namespace2.id)
+ projects.create!(
+ name: 'Learn GitLab - Ultimate trial',
+ namespace_id: namespace2.id,
+ project_namespace_id: proj_namespace.id
+ )
+ end
+
+ # namespace to remove without learn gitlab project
+ let(:namespace3) { namespaces.create!(name: 'namespace3', type: 'Group', path: 'namespace3') }
+ let!(:onboarding_to_delete) { onboarding_progresses.create!(namespace_id: namespace3.id) }
+ let!(:proj3) do
+ proj_namespace = namespaces.create!(name: 'proj3', path: 'proj3', type: 'Project', parent_id: namespace3.id)
+ projects.create!(name: 'project', namespace_id: namespace3.id, project_namespace_id: proj_namespace.id)
+ end
+
+ # namespace to remove without any projects
+ let(:namespace4) { namespaces.create!(name: 'namespace4', type: 'Group', path: 'namespace4') }
+ let!(:onboarding_to_delete_without_project) { onboarding_progresses.create!(namespace_id: namespace4.id) }
+
+ describe '#up' do
+ it 'deletes the onboarding for namespaces without learn gitlab' do
+ expect { migrate! }.to change { onboarding_progresses.count }.by(-2)
+ expect(onboarding_progresses.all).to contain_exactly(onboard_keep_1, onboard_keep_2)
+ end
+ end
+end
diff --git a/spec/support/stub_dot_com_check.rb b/spec/support/stub_dot_com_check.rb
index 178cf2577ef..6934b33d111 100644
--- a/spec/support/stub_dot_com_check.rb
+++ b/spec/support/stub_dot_com_check.rb
@@ -1,17 +1,20 @@
# frozen_string_literal: true
RSpec.configure do |config|
- config.before(:context, :saas) do
- # Ensure Gitlab.com? returns true during context.
- # This is needed for let_it_be which is shared across examples,
- # therefore the value must be changed in before_all,
- # but RSpec prevent stubbing method calls in before_all,
- # therefore we have to resort to temporarily swap url value.
- @_original_gitlab_url = Gitlab.config.gitlab['url']
- Gitlab.config.gitlab['url'] = Gitlab::Saas.com_url
- end
- config.after(:context, :saas) do
- # Swap back original value
- Gitlab.config.gitlab['url'] = @_original_gitlab_url
+ %i[saas saas_registration].each do |metadata|
+ config.before(:context, metadata) do
+ # Ensure Gitlab.com? returns true during context.
+ # This is needed for let_it_be which is shared across examples,
+ # therefore the value must be changed in before_all,
+ # but RSpec prevent stubbing method calls in before_all,
+ # therefore we have to resort to temporarily swap url value.
+ @_original_gitlab_url = Gitlab.config.gitlab['url']
+ Gitlab.config.gitlab['url'] = Gitlab::Saas.com_url
+ end
+
+ config.after(:context, metadata) do
+ # Swap back original value
+ Gitlab.config.gitlab['url'] = @_original_gitlab_url
+ end
end
end
diff --git a/spec/tooling/danger/stable_branch_spec.rb b/spec/tooling/danger/stable_branch_spec.rb
index a0c628b0add..1bfa62b2379 100644
--- a/spec/tooling/danger/stable_branch_spec.rb
+++ b/spec/tooling/danger/stable_branch_spec.rb
@@ -92,11 +92,19 @@ RSpec.describe Tooling::Danger::StableBranch, feature_category: :delivery do
let(:pipeline_bridges_response) do
[
- { 'name' => 'e2e:package-and-test',
- 'status' => 'success' }
+ {
+ 'name' => 'e2e:package-and-test',
+ 'status' => 'success',
+ 'downstream_pipeline' => {
+ 'id' => '123',
+ 'status' => package_and_qa_state
+ }
+ }
]
end
+ let(:package_and_qa_state) { 'success' }
+
let(:parsed_response) do
[
{ 'version' => '15.1.1' },
@@ -176,31 +184,26 @@ RSpec.describe Tooling::Danger::StableBranch, feature_category: :delivery do
end
context 'when package-and-test job is in manual state' do
- described_class::FAILING_PACKAGE_AND_TEST_STATUSES.each do |status|
- let(:pipeline_bridges_response) do
- [
- { 'name' => 'e2e:package-and-test',
- 'status' => status }
- ]
- end
+ let(:package_and_qa_state) { 'manual' }
- it_behaves_like 'with a failure', described_class::NEEDS_PACKAGE_AND_TEST_MESSAGE
- it_behaves_like 'bypassing when flaky test or docs only'
- end
+ it_behaves_like 'with a failure', described_class::NEEDS_PACKAGE_AND_TEST_MESSAGE
+ it_behaves_like 'bypassing when flaky test or docs only'
end
context 'when package-and-test job is in a non-successful state' do
- let(:pipeline_bridges_response) do
- [
- { 'name' => 'e2e:package-and-test',
- 'status' => 'running' }
- ]
- end
+ let(:package_and_qa_state) { 'running' }
it_behaves_like 'with a warning', described_class::WARN_PACKAGE_AND_TEST_MESSAGE
it_behaves_like 'bypassing when flaky test or docs only'
end
+ context 'when package-and-test job is canceled' do
+ let(:package_and_qa_state) { 'canceled' }
+
+ it_behaves_like 'with a failure', described_class::NEEDS_PACKAGE_AND_TEST_MESSAGE
+ it_behaves_like 'bypassing when flaky test or docs only'
+ end
+
context 'when no pipeline is found' do
before do
allow(gitlab_gem_client).to receive(:mr_json).and_return({})