Skip to content
代码片段 群组 项目
提交 b4b9bcc7 编辑于 作者: Eulyeon Ko's avatar Eulyeon Ko 提交者: Sean Arnold
浏览文件

Support GraphQL subscription for weight update

A GraphQL subscription for issuable weight update is added.

Changelog: added
EE: true
上级 31d09ac0
No related branches found
No related tags found
无相关合并请求
...@@ -21,3 +21,5 @@ def self.issuable_dates_updated(issuable) ...@@ -21,3 +21,5 @@ def self.issuable_dates_updated(issuable)
GitlabSchema.subscriptions.trigger('issuableDatesUpdated', { issuable_id: issuable.to_gid }, issuable) GitlabSchema.subscriptions.trigger('issuableDatesUpdated', { issuable_id: issuable.to_gid }, issuable)
end end
end end
GraphqlTriggers.prepend_mod
...@@ -25,3 +25,5 @@ class SubscriptionType < ::Types::BaseObject ...@@ -25,3 +25,5 @@ class SubscriptionType < ::Types::BaseObject
description: 'Triggered when the reviewers of a merge request are updated.' description: 'Triggered when the reviewers of a merge request are updated.'
end end
end end
Types::SubscriptionType.prepend_mod
# frozen_string_literal: true
module EE
module GraphqlTriggers
extend ActiveSupport::Concern
prepended do
def self.issuable_weight_updated(issuable)
::GitlabSchema.subscriptions.trigger('issuableWeightUpdated', { issuable_id: issuable.to_gid }, issuable)
end
end
end
end
# frozen_string_literal: true
module EE
module Types
module SubscriptionType
extend ActiveSupport::Concern
prepended do
field :issuable_weight_updated, subscription: Subscriptions::IssuableUpdated, null: true,
description: 'Triggered when the weight of an issuable is updated.'
end
end
end
end
...@@ -36,6 +36,7 @@ def handle_changes(issue, _options) ...@@ -36,6 +36,7 @@ def handle_changes(issue, _options)
super super
handle_iteration_change(issue) handle_iteration_change(issue)
handle_weight_change(issue)
end end
override :before_update override :before_update
...@@ -60,6 +61,12 @@ def handle_iteration_change(issue) ...@@ -60,6 +61,12 @@ def handle_iteration_change(issue)
send_iteration_change_notification(issue) send_iteration_change_notification(issue)
end end
def handle_weight_change(issue)
return unless issue.previous_changes.key?(:weight)
::GraphqlTriggers.issuable_weight_updated(issue)
end
def send_iteration_change_notification(issue) def send_iteration_change_notification(issue)
if issue.iteration.nil? if issue.iteration.nil?
notification_service.async.removed_iteration_issue(issue, current_user) notification_service.async.removed_iteration_issue(issue, current_user)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GraphqlTriggers do
describe '.issuable_weight_updated' do
let(:work_item) { create(:work_item) }
it 'triggers the issuableWeightUpdated subscription' do
expect(GitlabSchema.subscriptions).to receive(:trigger).with(
'issuableWeightUpdated',
{ issuable_id: work_item.to_gid },
work_item
).and_call_original
::GraphqlTriggers.issuable_weight_updated(work_item)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['Subscription'] do
it 'has the expected fields' do
expected_fields = %i[
issuable_weight_updated
]
expect(described_class).to include_graphql_fields(*expected_fields)
end
end
...@@ -20,6 +20,40 @@ def update_issue(opts) ...@@ -20,6 +20,40 @@ def update_issue(opts)
described_class.new(project: project, current_user: user, params: opts).execute(issue) described_class.new(project: project, current_user: user, params: opts).execute(issue)
end end
context 'updating weight' do
before do
stub_licensed_features(issue_weights: true)
project.add_developer(user)
issue.update!(weight: 1)
end
context 'when weight is changed' do
it "triggers 'issuableWeightUpdated' for issuable weight update subscription" do
expect(GraphqlTriggers).to receive(:issuable_weight_updated).with(issue).and_call_original
update_issue(weight: nil)
end
end
context 'when weight remains unchanged' do
it "does not trigger 'issuableWeightUpdated' for issuable weight update subscription" do
expect(GraphqlTriggers).not_to receive(:issuable_weight_updated)
update_issue(weight: 1)
end
end
context 'when weight param is not provided' do
it "does not trigger 'issuableWeightUpdated' for issuable weight update subscription" do
expect(GraphqlTriggers).not_to receive(:issuable_weight_updated)
update_issue(title: "foobar")
end
end
end
context 'refresh epic dates' do context 'refresh epic dates' do
before do before do
issue.update!(epic: epic) issue.update!(epic: epic)
......
...@@ -11,6 +11,18 @@ ...@@ -11,6 +11,18 @@
let(:current_user) { developer } let(:current_user) { developer }
describe '#execute' do describe '#execute' do
let(:service) do
described_class.new(
project: project,
current_user: current_user,
params: {},
spam_params: spam_params,
widget_params: widget_params
)
end
subject { service.execute(work_item) }
before do before do
stub_spam_services stub_spam_services
end end
...@@ -22,17 +34,7 @@ ...@@ -22,17 +34,7 @@
} }
end end
let(:service) do let(:service_execute) { subject }
described_class.new(
project: project,
current_user: current_user,
params: {},
spam_params: spam_params,
widget_params: widget_params
)
end
let(:service_execute) { service.execute(work_item) }
let(:supported_widgets) do let(:supported_widgets) do
[ [
...@@ -43,5 +45,47 @@ ...@@ -43,5 +45,47 @@
] ]
end end
end end
context 'when updating widgets' do
context 'for the weight widget' do
let(:widget_params) { { weight_widget: { weight: new_weight } } }
before do
stub_licensed_features(issue_weights: true)
work_item.update!(weight: 1)
end
context 'when weight is changed' do
let(:new_weight) { nil }
it "triggers 'issuableWeightUpdated' for issuable weight update subscription" do
expect(GraphqlTriggers).to receive(:issuable_weight_updated).with(work_item).and_call_original
subject
end
end
context 'when weight remains unchanged' do
let(:new_weight) { 1 }
it "does not trigger 'issuableWeightUpdated' for issuable weight update subscription" do
expect(GraphqlTriggers).not_to receive(:issuable_weight_updated)
subject
end
end
context 'when weight widget param is not provided' do
let(:widget_params) {}
it "does not trigger 'issuableWeightUpdated' for issuable weight update subscription" do
expect(GraphqlTriggers).not_to receive(:issuable_weight_updated)
subject
end
end
end
end
end end
end end
...@@ -13,6 +13,6 @@ ...@@ -13,6 +13,6 @@
merge_request_reviewers_updated merge_request_reviewers_updated
] ]
expect(described_class).to have_graphql_fields(*expected_fields).only expect(described_class).to include_graphql_fields(*expected_fields)
end end
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册