Commit ef895556 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo Committed by Mayra Cabrera

Remove the default value stream

With the use_vsa_aggregated_tables feature flag
enabled we should no longer return the in-memory
default value stream.
parent 0214d07d
......@@ -97,7 +97,13 @@ class Groups::Analytics::CycleAnalytics::ValueStreamsController < Groups::Analyt
end
def value_streams
@group.value_streams.preload_associated_models.presence || [in_memory_default_value_stream]
value_streams = @group.value_streams.preload_associated_models
if Feature.enabled?(:use_vsa_aggregated_tables, @group, default_enabled: :yaml)
value_streams
else
value_streams.presence || [in_memory_default_value_stream]
end
end
def in_memory_default_value_stream
......
......@@ -11,7 +11,11 @@ module EE
def execute
return forbidden unless allowed?
success(persisted_stages.presence || build_default_stages)
if parent.is_a?(Group) && ::Feature.enabled?(:use_vsa_aggregated_tables, parent, default_enabled: :yaml)
success(persisted_stages)
else
success(persisted_stages.presence || build_default_stages)
end
end
private
......
......@@ -5,6 +5,15 @@ require 'spec_helper'
RSpec.describe Groups::Analytics::CycleAnalytics::StagesController do
let_it_be(:user) { create(:user) }
let_it_be(:group, refind: true) { create(:group) }
let_it_be(:stages) { [] }
let_it_be(:value_stream) do
create(:cycle_analytics_group_value_stream,
group: group,
name: 'No stage value stream',
stages: stages
)
end
context 'when params have only group_id' do
let(:params) { { group_id: group } }
......@@ -19,6 +28,8 @@ RSpec.describe Groups::Analytics::CycleAnalytics::StagesController do
end
context 'when use_vsa_aggregated_tables FF is disabled' do
let_it_be(:stages) { Gitlab::Analytics::CycleAnalytics::DefaultStages.all }
it_behaves_like 'Value Stream Analytics Stages controller' do
before do
stub_feature_flags(use_vsa_aggregated_tables: false)
......@@ -28,7 +39,19 @@ RSpec.describe Groups::Analytics::CycleAnalytics::StagesController do
end
context 'when params have group_id and value_stream_id' do
let_it_be(:value_stream) { create(:cycle_analytics_group_value_stream, group: group) }
let_it_be(:stages) do
[
create(:cycle_analytics_group_stage, group: group, name: "Issue", relative_position: 1),
create(:cycle_analytics_group_stage, group: group, name: "Code", relative_position: 2)
]
end
let_it_be(:value_stream) do
create(:cycle_analytics_group_value_stream,
group: group,
name: 'First value stream',
stages: stages)
end
let(:params) { { group_id: group, value_stream_id: value_stream.id } }
let(:parent) { group }
......
......@@ -16,14 +16,34 @@ RSpec.describe Groups::Analytics::CycleAnalytics::ValueStreamsController do
end
describe 'GET #index' do
it 'returns an in-memory default value stream' do
get :index, params: params
context 'when the use_vsa_aggregated_tables feature flag is off' do
before do
stub_feature_flags(use_vsa_aggregated_tables: false)
end
it 'returns an in-memory default value stream' do
get :index, params: params
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to eq(1)
expect(json_response.first['id']).to eq(Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME)
expect(json_response.first['name']).to eq(Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME)
end
end
context 'when the use_vsa_aggregated_tables feature flag is on' do
before do
stub_feature_flags(use_vsa_aggregated_tables: true)
end
expect(response).to have_gitlab_http_status(:ok)
it 'returns an empty array' do
get :index, params: params
expect(json_response.size).to eq(1)
expect(json_response.first['id']).to eq(Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME)
expect(json_response.first['name']).to eq(Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to eq(0)
end
end
context 'when persisted value streams present' do
......
......@@ -12,6 +12,16 @@ RSpec.describe 'Value stream analytics charts', :js do
let_it_be(:group_label2) { create(:group_label, group: group) }
let_it_be(:label) { create(:group_label, group: group2) }
let_it_be(:custom_value_stream_name) { "New created value stream" }
let_it_be(:value_stream) do
create(:cycle_analytics_group_value_stream, group: group, name: custom_value_stream_name, stages: [
create(:cycle_analytics_group_stage, group: group, name: "Issue", relative_position: 1, start_event_identifier: :issue_created, end_event_identifier: :issue_closed),
create(:cycle_analytics_group_stage, group: group, name: "Code", relative_position: 2, start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged),
create(:cycle_analytics_group_stage, group: group, name: "Milestone Plan", relative_position: 3, start_event_identifier: :issue_first_associated_with_milestone, end_event_identifier: :issue_first_added_to_board)
])
end
3.times do |i|
let_it_be("issue_#{i}".to_sym) { create(:issue, title: "New Issue #{i}", project: project, created_at: 2.days.ago) }
end
......@@ -33,12 +43,9 @@ RSpec.describe 'Value stream analytics charts', :js do
end
context 'Duration chart' do
let(:custom_value_stream_name) { "New created value stream" }
before do
select_group(group)
create_custom_value_stream(custom_value_stream_name)
select_value_stream(custom_value_stream_name)
end
it 'displays data for all stages on the overview' do
......@@ -81,6 +88,7 @@ RSpec.describe 'Value stream analytics charts', :js do
end
select_group(group)
select_value_stream(custom_value_stream_name)
end
it 'displays the chart' do
......
......@@ -18,7 +18,7 @@ RSpec.describe 'Multiple value streams', :js do
let(:extended_form_fields_selector) { '[data-testid="extended-form-fields"]' }
let(:preset_selector) { '[data-testid="vsa-preset-selector"]' }
let!(:default_value_stream) { create(:cycle_analytics_group_value_stream, group: group, name: 'default') }
let(:empty_state_selector) { '[data-testid="vsa-empty-state"]' }
3.times do |i|
let_it_be("issue_#{i}".to_sym) { create(:issue, title: "New Issue #{i}", project: project, created_at: 2.days.ago) }
......@@ -198,7 +198,7 @@ RSpec.describe 'Multiple value streams', :js do
end
end
describe 'With a group' do
shared_examples 'create group value streams' do
name = 'group value stream'
before do
......@@ -210,7 +210,7 @@ RSpec.describe 'Multiple value streams', :js do
it_behaves_like 'delete a value stream', name
end
describe 'With a sub group' do
shared_examples 'create sub group value streams' do
name = 'sub group value stream'
before do
......@@ -221,4 +221,42 @@ RSpec.describe 'Multiple value streams', :js do
it_behaves_like 'update a value stream', name
it_behaves_like 'delete a value stream', name
end
context 'use_vsa_aggregated_tables feature flag off' do
before do
stub_feature_flags(use_vsa_aggregated_tables: false)
end
it_behaves_like 'create group value streams'
it_behaves_like 'create sub group value streams'
end
context 'use_vsa_aggregated_tables feature flag on' do
context 'without a value stream' do
before do
select_group(group, empty_state_selector)
end
it 'renders the empty state' do
expect(page).to have_text(s_('CycleAnalytics|Custom value streams to measure your DevSecOps lifecycle'))
end
it 'can navigate to the create value stream form' do
page.find('[data-testid="create-value-stream-button"]').click
expect(page).to have_selector('[data-testid="value-stream-form-modal"]')
end
end
context 'with a value stream' do
before do
# ensure we have a value stream already available
create(:cycle_analytics_group_value_stream, group: group, name: 'default')
create(:cycle_analytics_group_value_stream, group: sub_group, name: 'default')
end
it_behaves_like 'create group value streams'
it_behaves_like 'create sub group value streams'
end
end
end
......@@ -19,27 +19,43 @@ RSpec.describe Analytics::CycleAnalytics::Stages::ListService do
stub_licensed_features(cycle_analytics_for_groups: true)
end
it_behaves_like 'permission check for Value Stream Analytics Stage services', :cycle_analytics_for_groups
context 'when the use_vsa_aggregated_tables feature is enabled' do
before do
stub_feature_flags(use_vsa_aggregated_tables: true)
end
it 'returns only the default stages' do
expect(stages.size).to eq(Gitlab::Analytics::CycleAnalytics::DefaultStages.all.size)
end
it_behaves_like 'permission check for Value Stream Analytics Stage services', :cycle_analytics_for_groups
it 'provides the default stages as non-persisted objects' do
expect(stages.map(&:id)).to all(be_nil)
end
it 'returns empty array' do
expect(stages.size).to eq(0)
end
it 'provides the default stages as non-persisted objects' do
expect(stages.map(&:id)).to all(be_nil)
end
it 'does not persist the value stream record' do
expect { subject }.not_to change { Analytics::CycleAnalytics::GroupValueStream.count }
it 'does not persist the value stream record' do
expect { subject }.not_to change { Analytics::CycleAnalytics::GroupValueStream.count }
end
context 'when there are persisted stages' do
let_it_be(:stage1) { create(:cycle_analytics_group_stage, parent: group, relative_position: 2, value_stream: value_stream) }
let_it_be(:stage2) { create(:cycle_analytics_group_stage, parent: group, relative_position: 3, value_stream: value_stream) }
let_it_be(:stage3) { create(:cycle_analytics_group_stage, parent: group, relative_position: 1, value_stream: value_stream) }
it 'returns the persisted stages in order' do
expect(stages).to eq([stage3, stage1, stage2])
end
end
end
context 'when there are persisted stages' do
let_it_be(:stage1) { create(:cycle_analytics_group_stage, parent: group, relative_position: 2, value_stream: value_stream) }
let_it_be(:stage2) { create(:cycle_analytics_group_stage, parent: group, relative_position: 3, value_stream: value_stream) }
let_it_be(:stage3) { create(:cycle_analytics_group_stage, parent: group, relative_position: 1, value_stream: value_stream) }
context 'when the use_vsa_aggregated_tables feature is disabled' do
before do
stub_feature_flags(use_vsa_aggregated_tables: false)
end
it 'returns the persisted stages in order' do
expect(stages).to eq([stage3, stage1, stage2])
it 'returns the default stages' do
expect(stages.size).to eq(Gitlab::Analytics::CycleAnalytics::DefaultStages.all.size)
end
end
end
......@@ -22,7 +22,7 @@ RSpec.shared_examples 'Value Stream Analytics Stages controller' do
subject
response_start_events = json_response['stages'].map { |s| s['start_event_identifier'] }
start_events = Gitlab::Analytics::CycleAnalytics::DefaultStages.all.map { |s| s['start_event_identifier'] }
start_events = stages.map { |s| s['start_event_identifier'] }
expect(response_start_events).to eq(start_events)
end
......
......@@ -86,6 +86,13 @@ module CycleAnalyticsHelpers
wait_for_stages_to_load(ready_selector)
end
def select_value_stream(value_stream_name)
toggle_value_stream_dropdown
page.find('[data-testid="dropdown-value-streams"]').all('li button').find { |item| item.text == value_stream_name.to_s }.click
wait_for_requests
end
def toggle_dropdown(field)
page.within("[data-testid*='#{field}']") do
find('.dropdown-toggle').click
......
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