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