diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-11 18:08:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-11 18:08:21 +0300 |
commit | ed94a4dd903dc4d20cbc1bce330b9c1b7a5f7fbf (patch) | |
tree | e77f48da26680f6e949604cab506cf137515b05c /spec | |
parent | fc0afaf7da2156e91e615662272811eee56d034a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
12 files changed, 144 insertions, 74 deletions
diff --git a/spec/frontend/boards/board_list_helper.js b/spec/frontend/boards/board_list_helper.js index af5509fd2e9..1ba546f24a8 100644 --- a/spec/frontend/boards/board_list_helper.js +++ b/spec/frontend/boards/board_list_helper.js @@ -86,7 +86,6 @@ export default function createComponent({ apolloProvider: fakeApollo, store, propsData: { - disabled: false, list, boardItems: [issue], canAdminList: true, @@ -104,6 +103,7 @@ export default function createComponent({ isEpicBoard: false, isGroupBoard: false, isProjectBoard: true, + disabled: false, ...provide, }, stubs, diff --git a/spec/frontend/boards/board_list_spec.js b/spec/frontend/boards/board_list_spec.js index 34c0504143c..abe8c230bd8 100644 --- a/spec/frontend/boards/board_list_spec.js +++ b/spec/frontend/boards/board_list_spec.js @@ -267,7 +267,7 @@ describe('Board list component', () => { describe('when dragging is not allowed', () => { beforeEach(() => { wrapper = createComponent({ - componentProps: { + provide: { disabled: true, }, }); diff --git a/spec/frontend/boards/components/board_app_spec.js b/spec/frontend/boards/components/board_app_spec.js index c209f2f82e6..872a67a71fb 100644 --- a/spec/frontend/boards/components/board_app_spec.js +++ b/spec/frontend/boards/components/board_app_spec.js @@ -23,11 +23,10 @@ describe('BoardApp', () => { }); }; - const createComponent = ({ provide = { disabled: true } } = {}) => { + const createComponent = () => { wrapper = shallowMount(BoardApp, { store, provide: { - ...provide, fullBoardId: 'gid://gitlab/Board/1', }, }); diff --git a/spec/frontend/boards/components/board_card_spec.js b/spec/frontend/boards/components/board_card_spec.js index cd3882dc9ee..f8ad7c468c1 100644 --- a/spec/frontend/boards/components/board_card_spec.js +++ b/spec/frontend/boards/components/board_card_spec.js @@ -49,7 +49,6 @@ describe('Board card', () => { propsData: { list: mockLabelList, item, - disabled: false, index: 0, ...propsData, }, @@ -61,6 +60,7 @@ describe('Board card', () => { issuableType: 'issue', isProjectBoard: false, isGroupBoard: true, + disabled: false, ...provide, }, }); diff --git a/spec/frontend/boards/components/board_column_spec.js b/spec/frontend/boards/components/board_column_spec.js index c13f7caba76..d34e228a2d7 100644 --- a/spec/frontend/boards/components/board_column_spec.js +++ b/spec/frontend/boards/components/board_column_spec.js @@ -34,7 +34,6 @@ describe('Board Column Component', () => { wrapper = shallowMount(BoardColumn, { store, propsData: { - disabled: false, list: listMock, }, }); diff --git a/spec/frontend/boards/components/board_content_spec.js b/spec/frontend/boards/components/board_content_spec.js index 98f66ed804a..97596c86198 100644 --- a/spec/frontend/boards/components/board_content_spec.js +++ b/spec/frontend/boards/components/board_content_spec.js @@ -60,7 +60,6 @@ describe('BoardContent', () => { wrapper = shallowMount(BoardContent, { apolloProvider: fakeApollo, propsData: { - disabled: false, boardId: 'gid://gitlab/Board/1', ...props, }, @@ -72,6 +71,7 @@ describe('BoardContent', () => { isIssueBoard, isEpicBoard, isGroupBoard: true, + disabled: false, isApolloBoard, }, store, diff --git a/spec/frontend/boards/components/board_list_header_spec.js b/spec/frontend/boards/components/board_list_header_spec.js index 4633612891c..a16b99728c3 100644 --- a/spec/frontend/boards/components/board_list_header_spec.js +++ b/spec/frontend/boards/components/board_list_header_spec.js @@ -68,7 +68,6 @@ describe('Board List Header Component', () => { apolloProvider: fakeApollo, store, propsData: { - disabled: false, list: listMock, }, provide: { @@ -76,6 +75,7 @@ describe('Board List Header Component', () => { weightFeatureAvailable: false, currentUserId, isEpicBoard: false, + disabled: false, }, }), ); diff --git a/spec/frontend/issues/related_merge_requests/components/related_merge_requests_spec.js b/spec/frontend/issues/related_merge_requests/components/related_merge_requests_spec.js index 368d5017056..896e9356b7d 100644 --- a/spec/frontend/issues/related_merge_requests/components/related_merge_requests_spec.js +++ b/spec/frontend/issues/related_merge_requests/components/related_merge_requests_spec.js @@ -51,7 +51,9 @@ describe('RelatedMergeRequests', () => { }); }); - it('should return an array with single assingee', () => { + // https://gitlab.com/gitlab-org/gitlab/-/issues/387789 + // eslint-disable-next-line jest/no-disabled-tests + it.skip('should return an array with single assingee', () => { const mr = { assignee: assignees[0] }; expect(wrapper.vm.getAssignees(mr)).toEqual([assignees[0]]); diff --git a/spec/migrations/20221222092958_sync_new_amount_used_with_amount_used_spec.rb b/spec/migrations/20221222092958_sync_new_amount_used_with_amount_used_spec.rb new file mode 100644 index 00000000000..158560a2432 --- /dev/null +++ b/spec/migrations/20221222092958_sync_new_amount_used_with_amount_used_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! + +RSpec.describe SyncNewAmountUsedWithAmountUsed, migration: :gitlab_ci, feature_category: :continuous_integration do + let(:project_usages) { table(:ci_project_monthly_usages) } + let(:migration) { described_class.new } + + before do + # Disabling the trigger temporarily to allow records being created with out-of-sync + # `new_amount_used` and `amount_used`. This will simulate existing records before + # we add the trigger. + ActiveRecord::Base.connection + .execute("ALTER TABLE ci_project_monthly_usages DISABLE TRIGGER sync_projects_amount_used_columns") + + this_month = Time.now.utc.beginning_of_month + last_month = 1.month.ago.utc.beginning_of_month + last_year = 1.year.ago.utc.beginning_of_month + + project_usages.create!(project_id: 1, date: last_year) + project_usages.create!(project_id: 1, date: this_month, amount_used: 10, new_amount_used: 0) + project_usages.create!(project_id: 1, date: last_month, amount_used: 20, new_amount_used: 0) + + project_usages.create!(project_id: 2, date: last_year) + project_usages.create!(project_id: 2, date: this_month, amount_used: 30, new_amount_used: 0) + project_usages.create!(project_id: 2, date: last_month, amount_used: 40, new_amount_used: 0) + + ActiveRecord::Base.connection + .execute("ALTER TABLE ci_project_monthly_usages ENABLE TRIGGER sync_projects_amount_used_columns") + end + + describe '#up' do + it "doesnt change new_amount_used values" do + data = project_usages.all + data.each do |item| + expect { migration.up }.to not_change { item.new_amount_used } + end + end + end + + describe '#down' do + it 'updates `new_amount_used` with values from `amount_used`' do + expect(project_usages.where(new_amount_used: 0).count).to eq(6) + + migration.down + + expect(project_usages.where(new_amount_used: 0).count).to eq(2) + expect(project_usages.order(:id).pluck(:new_amount_used)) + .to contain_exactly(0, 0, 10, 20, 30, 40) + end + end +end diff --git a/spec/models/project_import_state_spec.rb b/spec/models/project_import_state_spec.rb index ba1a29a8b27..e5232026c39 100644 --- a/spec/models/project_import_state_spec.rb +++ b/spec/models/project_import_state_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ProjectImportState, type: :model do +RSpec.describe ProjectImportState, type: :model, feature_category: :importers do let_it_be(:correlation_id) { 'cid' } let_it_be(:import_state, refind: true) { create(:import_state, correlation_id_value: correlation_id) } @@ -17,22 +17,19 @@ RSpec.describe ProjectImportState, type: :model do end describe 'Project import job' do - let_it_be(:import_state) { create(:import_state, import_url: generate(:url)) } - let_it_be(:project) { import_state.project } + let_it_be(:project) { create(:project) } - before do - allow_any_instance_of(Gitlab::GitalyClient::RepositoryService).to receive(:import_repository) - .with(project.import_url, http_authorization_header: '', mirror: false, resolved_address: '').and_return(true) + let(:import_state) { create(:import_state, import_url: generate(:url), project: project) } + let(:jid) { '551d3ceac5f67a116719ce41' } + before do # Works around https://github.com/rspec/rspec-mocks/issues/910 allow(Project).to receive(:find).with(project.id).and_return(project) - expect(project).to receive(:after_import).and_call_original + allow(project).to receive(:add_import_job).and_return(jid) end it 'imports a project', :sidekiq_might_not_need_inline do - expect(RepositoryImportWorker).to receive(:perform_async).and_call_original - - expect { import_state.schedule }.to change { import_state.status }.from('none').to('finished') + expect { import_state.schedule }.to change { import_state.status }.from('none').to('scheduled') end it 'records job and correlation IDs', :sidekiq_might_not_need_inline do @@ -40,7 +37,8 @@ RSpec.describe ProjectImportState, type: :model do import_state.schedule - expect(import_state.jid).to be_an_instance_of(String) + expect(project).to have_received(:add_import_job) + expect(import_state.jid).to eq(jid) expect(import_state.correlation_id).to eq(correlation_id) end end diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb index 353af5a594a..344d93fc5ca 100644 --- a/spec/services/merge_requests/update_service_spec.rb +++ b/spec/services/merge_requests/update_service_spec.rb @@ -479,6 +479,16 @@ RSpec.describe MergeRequests::UpdateService, :mailer, feature_category: :code_re end end + shared_examples_for "creates a new pipeline" do + it "creates a new pipeline" do + expect(MergeRequests::CreatePipelineWorker) + .to receive(:perform_async) + .with(project.id, user.id, merge_request.id, { "allow_duplicate" => true }) + + update_merge_request(target_branch: new_target_branch) + end + end + shared_examples_for 'correct merge behavior' do let(:opts) do { @@ -799,6 +809,10 @@ RSpec.describe MergeRequests::UpdateService, :mailer, feature_category: :code_re update_merge_request({ target_branch: "target" }) end + + it_behaves_like "creates a new pipeline" do + let(:new_target_branch) { "target" } + end end context 'when auto merge is enabled and target branch changed' do @@ -813,6 +827,10 @@ RSpec.describe MergeRequests::UpdateService, :mailer, feature_category: :code_re update_merge_request({ target_branch: 'target' }) end + + it_behaves_like "creates a new pipeline" do + let(:new_target_branch) { "target" } + end end end @@ -1237,6 +1255,10 @@ RSpec.describe MergeRequests::UpdateService, :mailer, feature_category: :code_re expect { update_merge_request(target_branch: 'master', target_branch_was_deleted: true) } .to change { merge_request.reload.target_branch }.from('mr-a').to('master') end + + it_behaves_like "creates a new pipeline" do + let(:new_target_branch) { "target" } + end end it_behaves_like 'issuable record that supports quick actions' do diff --git a/spec/workers/repository_import_worker_spec.rb b/spec/workers/repository_import_worker_spec.rb index 1dc77fbf83f..ca7c13fe24e 100644 --- a/spec/workers/repository_import_worker_spec.rb +++ b/spec/workers/repository_import_worker_spec.rb @@ -2,92 +2,88 @@ require 'spec_helper' -RSpec.describe RepositoryImportWorker do +RSpec.describe RepositoryImportWorker, feature_category: :importers do describe '#perform' do - let(:project) { create(:project, :import_scheduled) } - let(:import_state) { project.import_state } - - context 'when worker was reset without cleanup' do - it 'imports the project successfully' do - jid = '12345678' - started_project = create(:project) - started_import_state = create(:import_state, :started, project: started_project, jid: jid) - - allow(subject).to receive(:jid).and_return(jid) + let(:project) { build_stubbed(:project, :import_scheduled, import_state: import_state, import_url: 'url') } + let(:import_state) { create(:import_state, status: :scheduled) } + let(:jid) { '12345678' } + + before do + allow(subject).to receive(:jid).and_return(jid) + allow(Project).to receive(:find_by_id).with(project.id).and_return(project) + allow(project).to receive(:after_import) + allow(import_state).to receive(:start).and_return(true) + end - expect_next_instance_of(Projects::ImportService) do |instance| - expect(instance).to receive(:execute).and_return({ status: :ok }) - end + context 'when project not found (deleted)' do + before do + allow(Project).to receive(:find_by_id).with(project.id).and_return(nil) + end - # Works around https://github.com/rspec/rspec-mocks/issues/910 - expect(Project).to receive(:find).with(started_project.id).and_return(started_project) - expect(started_project.repository).to receive(:expire_emptiness_caches) - expect(started_project.wiki.repository).to receive(:expire_emptiness_caches) - expect(started_import_state).to receive(:finish) + it 'does not raise any exception' do + expect(Projects::ImportService).not_to receive(:new) - subject.perform(started_project.id) + expect { subject.perform(project.id) }.not_to raise_error end end - context 'when the import was successful' do - it 'imports a project' do + context 'when import_state is scheduled' do + it 'imports the project successfully' do expect_next_instance_of(Projects::ImportService) do |instance| expect(instance).to receive(:execute).and_return({ status: :ok }) end - # Works around https://github.com/rspec/rspec-mocks/issues/910 - expect(Project).to receive(:find).with(project.id).and_return(project) - expect(project.repository).to receive(:expire_emptiness_caches) - expect(project.wiki.repository).to receive(:expire_emptiness_caches) - expect(import_state).to receive(:finish) - subject.perform(project.id) + + expect(project).to have_received(:after_import) + expect(import_state).to have_received(:start) end end - context 'when the import has failed' do - it 'updates the error on Import/Export & hides credentials from import URL' do - import_url = 'https://user:pass@test.com/root/repoC.git/' - error = "#{import_url} not found" - - import_state.update!(jid: '123') - project.update!(import_type: 'gitlab_project') + context 'when worker was reset without cleanup (import_state is started)' do + let(:import_state) { create(:import_state, :started, jid: jid) } + it 'imports the project successfully' do expect_next_instance_of(Projects::ImportService) do |instance| - expect(instance).to receive(:track_start_import).and_raise(StandardError, error) + expect(instance).to receive(:execute).and_return({ status: :ok }) end - expect { subject.perform(project.id) }.not_to raise_error + subject.perform(project.id) - import_state.reload - expect(import_state.jid).to eq('123') - expect(import_state.status).to eq('failed') - expect(import_state.last_error).to include("[FILTERED] not found") - expect(import_state.last_error).not_to include(import_url) + expect(project).to have_received(:after_import) + expect(import_state).not_to have_received(:start) end end context 'when using an asynchronous importer' do it 'does not mark the import process as finished' do - service = double(:service) + expect_next_instance_of(Projects::ImportService) do |instance| + expect(instance).to receive(:execute).and_return({ status: :ok }) + expect(instance).to receive(:async?).and_return(true) + end + + subject.perform(project.id) - allow(Projects::ImportService) - .to receive(:new) - .and_return(service) + expect(project).not_to have_received(:after_import) + end + end - allow(service) - .to receive(:execute) - .and_return(true) + context 'when the import has failed' do + let(:error) { "https://user:pass@test.com/root/repoC.git/ not found" } - allow(service) - .to receive(:async?) - .and_return(true) + before do + allow(import_state).to receive(:mark_as_failed) + end - expect_next_instance_of(ProjectImportState) do |instance| - expect(instance).not_to receive(:finish) + it 'marks import_state as failed' do + expect_next_instance_of(Projects::ImportService) do |instance| + expect(instance).to receive(:execute).and_return({ status: :error, message: error }) end subject.perform(project.id) + + expect(import_state).to have_received(:mark_as_failed).with(error) + expect(project).not_to have_received(:after_import) end end end |