Commit ada68ecc authored by Ash McKenzie's avatar Ash McKenzie

Merge branch '64320-add-process-assignees' into 'master'

Added ProcessAssignees class

See merge request gitlab-org/gitlab!49814
parents 374e16e2 c79ec40a
# frozen_string_literal: true
# This follows the rules specified in the specs.
# See spec/requests/api/graphql/mutations/merge_requests/set_assignees_spec.rb
module Issuable
class ProcessAssignees
def initialize(assignee_ids:, add_assignee_ids:, remove_assignee_ids:, existing_assignee_ids: nil, extra_assignee_ids: nil)
@assignee_ids = assignee_ids
@add_assignee_ids = add_assignee_ids
@remove_assignee_ids = remove_assignee_ids
@existing_assignee_ids = existing_assignee_ids || []
@extra_assignee_ids = extra_assignee_ids || []
end
def execute
if assignee_ids.blank?
updated_new_assignees = new_assignee_ids
updated_new_assignees |= add_assignee_ids if add_assignee_ids
updated_new_assignees -= remove_assignee_ids if remove_assignee_ids
else
updated_new_assignees = assignee_ids
end
updated_new_assignees.uniq
end
private
attr_accessor :assignee_ids, :add_assignee_ids, :remove_assignee_ids, :existing_assignee_ids, :extra_assignee_ids
def new_assignee_ids
existing_assignee_ids | extra_assignee_ids
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Issuable::ProcessAssignees do
describe '#execute' do
it 'returns assignee_ids when assignee_ids are specified' do
process = Issuable::ProcessAssignees.new(assignee_ids: %w(5 7 9),
add_assignee_ids: %w(2 4 6),
remove_assignee_ids: %w(4 7 11),
existing_assignee_ids: %w(1 3 9),
extra_assignee_ids: %w(2 5 12))
result = process.execute
expect(result.sort).to eq(%w(5 7 9).sort)
end
it 'combines other ids when assignee_ids is empty' do
process = Issuable::ProcessAssignees.new(assignee_ids: [],
add_assignee_ids: %w(2 4 6),
remove_assignee_ids: %w(4 7 11),
existing_assignee_ids: %w(1 3 11),
extra_assignee_ids: %w(2 5 12))
result = process.execute
expect(result.sort).to eq(%w(1 2 3 5 6 12).sort)
end
it 'combines other ids when assignee_ids is nil' do
process = Issuable::ProcessAssignees.new(assignee_ids: nil,
add_assignee_ids: %w(2 4 6),
remove_assignee_ids: %w(4 7 11),
existing_assignee_ids: %w(1 3 11),
extra_assignee_ids: %w(2 5 12))
result = process.execute
expect(result.sort).to eq(%w(1 2 3 5 6 12).sort)
end
it 'combines other ids when assignee_ids and add_assignee_ids are nil' do
process = Issuable::ProcessAssignees.new(assignee_ids: nil,
add_assignee_ids: nil,
remove_assignee_ids: %w(4 7 11),
existing_assignee_ids: %w(1 3 11),
extra_assignee_ids: %w(2 5 12))
result = process.execute
expect(result.sort).to eq(%w(1 2 3 5 12).sort)
end
it 'combines other ids when assignee_ids and remove_assignee_ids are nil' do
process = Issuable::ProcessAssignees.new(assignee_ids: nil,
add_assignee_ids: %w(2 4 6),
remove_assignee_ids: nil,
existing_assignee_ids: %w(1 3 11),
extra_assignee_ids: %w(2 5 12))
result = process.execute
expect(result.sort).to eq(%w(1 2 4 3 5 6 11 12).sort)
end
it 'combines ids when only add_assignee_ids and remove_assignee_ids are passed' do
process = Issuable::ProcessAssignees.new(assignee_ids: nil,
add_assignee_ids: %w(2 4 6),
remove_assignee_ids: %w(4 7 11))
result = process.execute
expect(result.sort).to eq(%w(2 6).sort)
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