Commit 70e28252 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '322878-refactor-stage-event-response' into 'master'

Nest start and end event identifiers in VSA API

See merge request gitlab-org/gitlab!65395
parents 9d89b120 64fd00e7
...@@ -9,6 +9,21 @@ module Analytics ...@@ -9,6 +9,21 @@ module Analytics
expose :description expose :description
expose :id expose :id
expose :custom expose :custom
# new API
expose :start_event do
expose :start_event_identifier, as: :identifier, if: -> (s) { s.custom? }
expose :start_event_label, as: :label, using: LabelEntity, if: -> (s) { s.start_event_label_based? }
expose :start_event_html_description, as: :html_description
end
expose :end_event do
expose :end_event_identifier, as: :identifier, if: -> (s) { s.custom? }
expose :end_event_label, as: :label, using: LabelEntity, if: -> (s) { s.end_event_label_based? }
expose :end_event_html_description, as: :html_description
end
# old API
expose :start_event_identifier, if: -> (s) { s.custom? } expose :start_event_identifier, if: -> (s) { s.custom? }
expose :end_event_identifier, if: -> (s) { s.custom? } expose :end_event_identifier, if: -> (s) { s.custom? }
expose :start_event_label, using: LabelEntity, if: -> (s) { s.start_event_label_based? } expose :start_event_label, using: LabelEntity, if: -> (s) { s.start_event_label_based? }
......
...@@ -51,15 +51,45 @@ class Groups::Analytics::CycleAnalytics::ValueStreamsController < Groups::Analyt ...@@ -51,15 +51,45 @@ class Groups::Analytics::CycleAnalytics::ValueStreamsController < Groups::Analyt
end end
def create_params def create_params
params.require(:value_stream).permit(:name, stages: stage_create_params) params.require(:value_stream).permit(:name, stages: stage_create_params).tap do |permitted_params|
transform_stage_params(permitted_params)
end
end end
def update_params def update_params
params.require(:value_stream).permit(:name, stages: stage_update_params) params.require(:value_stream).permit(:name, stages: stage_update_params).tap do |permitted_params|
transform_stage_params(permitted_params)
end
end
def transform_stage_params(permitted_params)
Array(permitted_params[:stages]).each do |stage_params|
# supporting the new API
if stage_params[:start_event] && stage_params[:end_event]
start_event = stage_params.delete(:start_event)
end_event = stage_params.delete(:end_event)
stage_params[:start_event_identifier] = start_event[:identifier]
stage_params[:start_event_label_id] = start_event[:label_id]
stage_params[:end_event_identifier] = end_event[:identifier]
stage_params[:end_event_label_id] = end_event[:label_id]
end
end
end end
def stage_create_params def stage_create_params
[:name, :start_event_identifier, :end_event_identifier, :start_event_label_id, :end_event_label_id, :custom] [
:name,
:start_event_identifier,
:start_event_label_id,
:end_event_identifier,
:end_event_label_id,
:custom,
{
start_event: [:identifier, :label_id],
end_event: [:identifier, :label_id]
}
]
end end
def stage_update_params def stage_update_params
......
...@@ -85,6 +85,34 @@ RSpec.describe Groups::Analytics::CycleAnalytics::ValueStreamsController do ...@@ -85,6 +85,34 @@ RSpec.describe Groups::Analytics::CycleAnalytics::ValueStreamsController do
expect(stage_response['title']).to eq('My Stage') expect(stage_response['title']).to eq('My Stage')
end end
context 'when using the new start and end event params format' do
let(:value_stream_params) do
{
name: 'test',
stages: [
{
name: 'My Stage',
start_event: {
identifier: 'issue_created'
},
end_event: {
identifier: 'issue_closed'
},
custom: true
}
]
}
end
it 'succeeds' do
post :create, params: { group_id: group, value_stream: value_stream_params }
expect(response).to have_gitlab_http_status(:created)
stage_response = json_response['stages'].first
expect(stage_response['title']).to eq('My Stage')
end
end
context 'when invalid stage is given' do context 'when invalid stage is given' do
before do before do
value_stream_params[:stages].first[:name] = '' value_stream_params[:stages].first[:name] = ''
...@@ -159,6 +187,39 @@ RSpec.describe Groups::Analytics::CycleAnalytics::ValueStreamsController do ...@@ -159,6 +187,39 @@ RSpec.describe Groups::Analytics::CycleAnalytics::ValueStreamsController do
expect(json_response['stages'].first['title']).to eq('updated stage name') expect(json_response['stages'].first['title']).to eq('updated stage name')
end end
context 'when using the new start and end event params format' do
let(:value_stream_params) do
{
name: 'test',
id: value_stream.id,
stages: [
{
id: stage.id,
name: 'updated stage name',
start_event: {
identifier: 'issue_created'
},
end_event: {
identifier: 'issue_closed'
},
custom: true
}
]
}
end
it 'succeeds' do
put :update, params: { id: value_stream.id, group_id: group, value_stream: value_stream_params }
expect(response).to have_gitlab_http_status(:ok)
start_event_identifier = json_response['stages'].first['start_event']['identifier']
end_event_identifier = json_response['stages'].first['end_event']['identifier']
expect(start_event_identifier).to eq('issue_created')
expect(end_event_identifier).to eq('issue_closed')
end
end
context 'when deleting the stage by excluding it from the stages array' do context 'when deleting the stage by excluding it from the stages array' do
let(:value_stream_params) { { name: 'no stages', stages: [] } } let(:value_stream_params) { { name: 'no stages', stages: [] } }
......
...@@ -5,12 +5,18 @@ Array [ ...@@ -5,12 +5,18 @@ Array [
Object { Object {
"custom": false, "custom": false,
"description": "Time before an issue gets scheduled", "description": "Time before an issue gets scheduled",
"endEvent": Object {
"htmlDescription": "<p data-sourcepos=\\"1:1-1:71\\" dir=\\"auto\\">Issue first associated with a milestone or issue first added to a board</p>",
},
"endEventHtmlDescription": "<p data-sourcepos=\\"1:1-1:71\\" dir=\\"auto\\">Issue first associated with a milestone or issue first added to a board</p>", "endEventHtmlDescription": "<p data-sourcepos=\\"1:1-1:71\\" dir=\\"auto\\">Issue first associated with a milestone or issue first added to a board</p>",
"hidden": false, "hidden": false,
"id": 1, "id": 1,
"legend": "", "legend": "",
"name": "Issue", "name": "Issue",
"slug": 1, "slug": 1,
"startEvent": Object {
"htmlDescription": "<p data-sourcepos=\\"1:1-1:13\\" dir=\\"auto\\">Issue created</p>",
},
"startEventHtmlDescription": "<p data-sourcepos=\\"1:1-1:13\\" dir=\\"auto\\">Issue created</p>", "startEventHtmlDescription": "<p data-sourcepos=\\"1:1-1:13\\" dir=\\"auto\\">Issue created</p>",
"title": "Issue", "title": "Issue",
}, },
......
...@@ -11,4 +11,12 @@ RSpec.describe Analytics::CycleAnalytics::StageEntity do ...@@ -11,4 +11,12 @@ RSpec.describe Analytics::CycleAnalytics::StageEntity do
expect(entity_json).to have_key(:start_event_html_description) expect(entity_json).to have_key(:start_event_html_description)
expect(entity_json).to have_key(:end_event_html_description) expect(entity_json).to have_key(:end_event_html_description)
end end
it 'exposes start_event and end_event objects' do
expect(entity_json[:start_event][:identifier]).to eq(entity_json[:start_event_identifier])
expect(entity_json[:end_event][:identifier]).to eq(entity_json[:end_event_identifier])
expect(entity_json[:start_event][:html_description]).to eq(entity_json[:start_event_html_description])
expect(entity_json[:end_event][:html_description]).to eq(entity_json[:end_event_html_description])
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