Commit 605de202 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '290116-enable-webhook-test-reorder-feature' into 'master'

Enable selecting newest record for webhook tests [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!54030
parents 79abd01a c3661ac0
...@@ -8,10 +8,6 @@ module Integrations ...@@ -8,10 +8,6 @@ module Integrations
Gitlab::DataBuilder::Push.build_sample(project, current_user) Gitlab::DataBuilder::Push.build_sample(project, current_user)
end end
def use_newest_record?
Feature.enabled?(:integrations_test_webhook_reorder, project)
end
def note_events_data def note_events_data
note = NotesFinder.new(current_user, project: project, target: project).execute.reorder(nil).last # rubocop: disable CodeReuse/ActiveRecord note = NotesFinder.new(current_user, project: project, target: project).execute.reorder(nil).last # rubocop: disable CodeReuse/ActiveRecord
...@@ -37,11 +33,7 @@ module Integrations ...@@ -37,11 +33,7 @@ module Integrations
end end
def job_events_data def job_events_data
build = if use_newest_record? build = Ci::JobsFinder.new(current_user: current_user, project: project).execute.first
Ci::JobsFinder.new(current_user: current_user, project: project).execute.first
else
project.builds.first
end
return { error: s_('TestHooks|Ensure the project has CI jobs.') } unless build.present? return { error: s_('TestHooks|Ensure the project has CI jobs.') } unless build.present?
...@@ -49,11 +41,7 @@ module Integrations ...@@ -49,11 +41,7 @@ module Integrations
end end
def pipeline_events_data def pipeline_events_data
pipeline = if use_newest_record? pipeline = Ci::PipelinesFinder.new(project, current_user, order_by: 'id', sort: 'desc').execute.first
Ci::PipelinesFinder.new(project, current_user, order_by: 'id', sort: 'desc').execute.first
else
project.ci_pipelines.newest_first.first
end
return { error: s_('TestHooks|Ensure the project has CI pipelines.') } unless pipeline.present? return { error: s_('TestHooks|Ensure the project has CI pipelines.') } unless pipeline.present?
...@@ -71,11 +59,7 @@ module Integrations ...@@ -71,11 +59,7 @@ module Integrations
end end
def deployment_events_data def deployment_events_data
deployment = if use_newest_record? deployment = DeploymentsFinder.new(project: project, order_by: 'created_at', sort: 'desc').execute.first
DeploymentsFinder.new(project: project, order_by: 'created_at', sort: 'desc').execute.first
else
project.deployments.first
end
return { error: s_('TestHooks|Ensure the project has deployments.') } unless deployment.present? return { error: s_('TestHooks|Ensure the project has deployments.') } unless deployment.present?
...@@ -83,11 +67,7 @@ module Integrations ...@@ -83,11 +67,7 @@ module Integrations
end end
def releases_events_data def releases_events_data
release = if use_newest_record? release = ReleasesFinder.new(project, current_user, order_by: :created_at, sort: :desc).execute.first
ReleasesFinder.new(project, current_user, order_by: :created_at, sort: :desc).execute.first
else
project.releases.first
end
return { error: s_('TestHooks|Ensure the project has releases.') } unless release.present? return { error: s_('TestHooks|Ensure the project has releases.') } unless release.present?
......
...@@ -6,10 +6,6 @@ module TestHooks ...@@ -6,10 +6,6 @@ module TestHooks
private private
def use_newest_record?
Feature.enabled?(:integrations_test_webhook_reorder)
end
def data def data
strong_memoize(:data) do strong_memoize(:data) do
case trigger case trigger
...@@ -24,11 +20,7 @@ module TestHooks ...@@ -24,11 +20,7 @@ module TestHooks
end end
def merge_requests_events_data def merge_requests_events_data
merge_request = if use_newest_record? merge_request = MergeRequest.of_projects(current_user.projects.select(:id)).last
MergeRequest.of_projects(current_user.projects.select(:id)).last
else
MergeRequest.of_projects(current_user.projects.select(:id)).first
end
return { error: s_('TestHooks|Ensure one of your projects has merge requests.') } unless merge_request.present? return { error: s_('TestHooks|Ensure one of your projects has merge requests.') } unless merge_request.present?
......
---
title: Select the newest records for webhook test payloads
merge_request: 54030
author:
type: changed
---
name: integrations_test_webhook_reorder
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/53433
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/320861
milestone: '13.9'
type: development
group: group::ecosystem
default_enabled: false
...@@ -146,21 +146,6 @@ RSpec.describe Integrations::Test::ProjectService do ...@@ -146,21 +146,6 @@ RSpec.describe Integrations::Test::ProjectService do
expect(integration).to receive(:test).with(sample_data).and_return(success_result) expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result) expect(subject).to eq(success_result)
end end
context 'when the reorder feature flag is disabled' do
before do
stub_feature_flags(integrations_test_webhook_reorder: false)
end
it 'executes the old query' do
allow(Gitlab::DataBuilder::Deployment).to receive(:build).and_return(sample_data)
expect(DeploymentsFinder).not_to receive(:new)
expect(project).to receive(:deployments).and_return([deployment])
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
end end
context 'pipeline' do context 'pipeline' do
...@@ -179,21 +164,6 @@ RSpec.describe Integrations::Test::ProjectService do ...@@ -179,21 +164,6 @@ RSpec.describe Integrations::Test::ProjectService do
expect(integration).to receive(:test).with(sample_data).and_return(success_result) expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result) expect(subject).to eq(success_result)
end end
context 'when the reorder feature flag is disabled' do
before do
stub_feature_flags(integrations_test_webhook_reorder: false)
end
it 'executes the old query' do
create(:ci_empty_pipeline, project: project)
allow(Gitlab::DataBuilder::Pipeline).to receive(:build).and_return(sample_data)
expect(Ci::PipelinesFinder).not_to receive(:new)
expect(integration).to receive(:test).with(sample_data).and_return(success_result)
expect(subject).to eq(success_result)
end
end
end end
context 'wiki_page' do context 'wiki_page' do
......
...@@ -140,21 +140,6 @@ RSpec.describe TestHooks::ProjectService do ...@@ -140,21 +140,6 @@ RSpec.describe TestHooks::ProjectService do
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result) expect(service.execute).to include(success_result)
end end
context 'when the reorder feature flag is disabled' do
before do
stub_feature_flags(integrations_test_webhook_reorder: false)
end
it 'executes the old query' do
allow(Gitlab::DataBuilder::Build).to receive(:build).and_return(sample_data)
expect(Ci::JobsFinder).not_to receive(:new)
expect(project).to receive(:builds).and_return([ci_job])
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result)
end
end
end end
context 'pipeline_events' do context 'pipeline_events' do
...@@ -174,21 +159,6 @@ RSpec.describe TestHooks::ProjectService do ...@@ -174,21 +159,6 @@ RSpec.describe TestHooks::ProjectService do
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result) expect(service.execute).to include(success_result)
end end
context 'when the reorder feature flag is disabled' do
before do
stub_feature_flags(integrations_test_webhook_reorder: false)
end
it 'executes the old query' do
create(:ci_empty_pipeline, project: project)
allow(Gitlab::DataBuilder::Pipeline).to receive(:build).and_return(sample_data)
expect(Ci::PipelinesFinder).not_to receive(:new)
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result)
end
end
end end
context 'wiki_page_events' do context 'wiki_page_events' do
...@@ -234,21 +204,6 @@ RSpec.describe TestHooks::ProjectService do ...@@ -234,21 +204,6 @@ RSpec.describe TestHooks::ProjectService do
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result) expect(service.execute).to include(success_result)
end end
context 'when the reorder feature flag is disabled' do
before do
stub_feature_flags(integrations_test_webhook_reorder: false)
end
it 'executes the old query' do
allow(release).to receive(:to_hook_data).and_return(sample_data)
expect(ReleasesFinder).not_to receive(:new)
expect(project).to receive(:releases).and_return([release])
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result)
end
end
end end
end end
end end
...@@ -64,7 +64,7 @@ RSpec.describe TestHooks::SystemService do ...@@ -64,7 +64,7 @@ RSpec.describe TestHooks::SystemService do
context 'merge_requests_events' do context 'merge_requests_events' do
let(:trigger) { 'merge_requests_events' } let(:trigger) { 'merge_requests_events' }
let(:trigger_key) { :merge_request_hooks } let(:trigger_key) { :merge_request_hooks }
let(:merge_requests) { build_list(:merge_request, 2) } let(:merge_request) { build(:merge_request) }
let(:sample_data) { { data: 'sample' } } let(:sample_data) { { data: 'sample' } }
it 'returns error message if the user does not have any repository with a merge request' do it 'returns error message if the user does not have any repository with a merge request' do
...@@ -73,24 +73,11 @@ RSpec.describe TestHooks::SystemService do ...@@ -73,24 +73,11 @@ RSpec.describe TestHooks::SystemService do
end end
it 'executes hook' do it 'executes hook' do
expect(MergeRequest).to receive(:of_projects).and_return(merge_requests) expect(MergeRequest).to receive(:of_projects).and_return([merge_request])
expect(merge_requests.last).to receive(:to_hook_data).and_return(sample_data) expect(merge_request).to receive(:to_hook_data).and_return(sample_data)
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result) expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result) expect(service.execute).to include(success_result)
end end
context 'when the reorder feature flag is disabled' do
before do
stub_feature_flags(integrations_test_webhook_reorder: false)
end
it 'executes the old query' do
expect(MergeRequest).to receive(:of_projects).and_return(merge_requests)
expect(merge_requests.first).to receive(:to_hook_data).and_return(sample_data)
expect(hook).to receive(:execute).with(sample_data, trigger_key).and_return(success_result)
expect(service.execute).to include(success_result)
end
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment