Commit 5e88a37a authored by Alper Akgun's avatar Alper Akgun

Merge branch '344779-fix-milestone-struct-global-id' into 'master'

Fix scoped board milestone/iteration Timebox global ID

See merge request gitlab-org/gitlab!73875
parents 92b40a04 a3569025
......@@ -11,9 +11,7 @@ module Timebox
include StripAttribute
include FromUnion
TimeboxStruct = Struct.new(:title, :name, :id) do
include GlobalID::Identification
TimeboxStruct = Struct.new(:title, :name, :id, :class_name) do
# Ensure these models match the interface required for exporting
def serializable_hash(_opts = {})
{ title: title, name: name, id: id }
......@@ -22,6 +20,10 @@ module Timebox
def self.declarative_policy_class
"TimeboxPolicy"
end
def to_global_id
::Gitlab::GlobalId.build(self, model_name: class_name, id: id)
end
end
# Represents a "No Timebox" state used for filtering Issues and Merge
......@@ -33,10 +35,10 @@ module Timebox
included do
# Defines the same constants above, but inside the including class.
const_set :None, TimeboxStruct.new("No #{self.name}", "No #{self.name}", 0)
const_set :Any, TimeboxStruct.new("Any #{self.name}", '', -1)
const_set :Upcoming, TimeboxStruct.new('Upcoming', '#upcoming', -2)
const_set :Started, TimeboxStruct.new('Started', '#started', -3)
const_set :None, TimeboxStruct.new("No #{self.name}", "No #{self.name}", 0, self.name)
const_set :Any, TimeboxStruct.new("Any #{self.name}", '', -1, self.name)
const_set :Upcoming, TimeboxStruct.new('Upcoming', '#upcoming', -2, self.name)
const_set :Started, TimeboxStruct.new('Started', '#started', -3, self.name)
alias_method :timebox_id, :id
......
......@@ -12,9 +12,9 @@ module EE
# For Iteration
class Predefined
None = ::Timebox::TimeboxStruct.new('None', 'none', ::Timebox::None.id).freeze
Any = ::Timebox::TimeboxStruct.new('Any', 'any', ::Timebox::Any.id).freeze
Current = ::Timebox::TimeboxStruct.new('Current', 'current', -4).freeze
None = ::Timebox::TimeboxStruct.new('None', 'none', ::Timebox::None.id, ::Iteration.name).freeze
Any = ::Timebox::TimeboxStruct.new('Any', 'any', ::Timebox::Any.id, ::Iteration.name).freeze
Current = ::Timebox::TimeboxStruct.new('Current', 'current', -4, ::Iteration.name).freeze
ALL = [None, Any, Current].freeze
......
......@@ -44,24 +44,28 @@ RSpec.describe Board do
board.milestone_id = Milestone::None.id
expect(board.milestone).to eq Milestone::None
expect(board.milestone.to_global_id.to_s).to eq "gid://gitlab/Milestone/#{Milestone::None.id}"
end
it 'returns Milestone::Any for started milestone id' do
board.milestone_id = Milestone::Any.id
expect(board.milestone).to eq Milestone::Any
expect(board.milestone.to_global_id.to_s).to eq "gid://gitlab/Milestone/#{Milestone::Any.id}"
end
it 'returns Milestone::Upcoming for upcoming milestone id' do
board.milestone_id = Milestone::Upcoming.id
expect(board.milestone).to eq Milestone::Upcoming
expect(board.milestone.to_global_id.to_s).to eq "gid://gitlab/Milestone/#{Milestone::Upcoming.id}"
end
it 'returns Milestone::Started for started milestone id' do
board.milestone_id = Milestone::Started.id
expect(board.milestone).to eq Milestone::Started
expect(board.milestone.to_global_id.to_s).to eq "gid://gitlab/Milestone/#{Milestone::Started.id}"
end
it 'returns milestone for valid milestone id' do
......@@ -101,18 +105,21 @@ RSpec.describe Board do
board.iteration_id = Iteration::Predefined::None.id
expect(board.iteration).to eq Iteration::Predefined::None
expect(board.iteration.to_global_id.to_s).to eq "gid://gitlab/Iteration/#{Iteration::Predefined::None.id}"
end
it 'returns Iteration::Predefined::Any, when iteration_id is Any.id' do
board.iteration_id = Iteration::Predefined::Any.id
expect(board.iteration).to eq Iteration::Predefined::Any
expect(board.iteration.to_global_id.to_s).to eq "gid://gitlab/Iteration/#{Iteration::Predefined::Any.id}"
end
it 'returns ::Iteration::Predefined::Current, when iteration_id is Current.id' do
board.iteration_id = Iteration::Predefined::Current.id
expect(board.iteration).to eq Iteration::Predefined::Current
expect(board.iteration.to_global_id.to_s).to eq "gid://gitlab/Iteration/#{Iteration::Predefined::Current.id}"
end
it 'returns iteration for valid iteration id' do
......
......@@ -42,6 +42,27 @@ RSpec.describe 'get list of boards' do
)
end
def board_milestone_query(board)
graphql_query_for(
board_parent_type,
{ 'fullPath' => board_parent.full_path },
query_graphql_field(
'board', { id: global_id_of(board) },
'milestone { id }'
)
)
end
context 'when board is scoped to a wildcard milestone' do
it 'returns milestone global ID in the correct format' do
board = create(:board, resource_parent: board_parent, milestone_id: -3)
post_graphql(board_milestone_query(board), current_user: current_user)
expect(graphql_data.dig(board_parent_type, "board", "milestone", "id")).to eq("gid://gitlab/Milestone/-3")
end
end
it 'returns open epics referenced by issues in the board' do
board = create(:board, resource_parent: board_parent)
issue_project = board_parent.is_a?(Project) ? board_parent : create(:project, group: board_parent)
......
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