Commit 9eb7439d authored by Ezekiel Kigbo's avatar Ezekiel Kigbo Committed by Peter Leitzen

Remove unneeded freeze_time

Applies some minor cleanup suggestions
to the spec files
parent 4f2c23a7
...@@ -20,8 +20,8 @@ const fixtureEndpoints = { ...@@ -20,8 +20,8 @@ const fixtureEndpoints = {
customizableCycleAnalyticsStagesAndEvents: 'analytics/value_stream_analytics/stages.json', // customizable stages and events endpoint customizableCycleAnalyticsStagesAndEvents: 'analytics/value_stream_analytics/stages.json', // customizable stages and events endpoint
stageEvents: stage => `analytics/value_stream_analytics/stages/${stage}/records.json`, stageEvents: stage => `analytics/value_stream_analytics/stages/${stage}/records.json`,
stageMedian: stage => `analytics/value_stream_analytics/stages/${stage}/median.json`, stageMedian: stage => `analytics/value_stream_analytics/stages/${stage}/median.json`,
recentActivityData: 'analytics/value_stream_analytics/summary.json', recentActivityData: 'analytics/metrics/value_stream_analytics/summary.json',
timeMetricsData: 'analytics/value_stream_analytics/time_summary.json', timeMetricsData: 'analytics/metrics/value_stream_analytics/time_summary.json',
groupLabels: 'api/group_labels.json', groupLabels: 'api/group_labels.json',
}; };
...@@ -161,17 +161,17 @@ export const customStageFormErrors = convertObjectPropsToCamelCase(rawCustomStag ...@@ -161,17 +161,17 @@ export const customStageFormErrors = convertObjectPropsToCamelCase(rawCustomStag
const dateRange = getDatesInRange(startDate, endDate, toYmd); const dateRange = getDatesInRange(startDate, endDate, toYmd);
export const apiTasksByTypeData = getJSONFixture('analytics/type_of_work/tasks_by_type.json').map( export const apiTasksByTypeData = getJSONFixture(
labelData => { 'analytics/charts/type_of_work/tasks_by_type.json',
// add data points for our mock date range ).map(labelData => {
const maxValue = 10; // add data points for our mock date range
const series = dateRange.map(date => [date, Math.floor(Math.random() * Math.floor(maxValue))]); const maxValue = 10;
return { const series = dateRange.map(date => [date, Math.floor(Math.random() * Math.floor(maxValue))]);
...labelData, return {
series, ...labelData,
}; series,
}, };
); });
export const rawTasksByTypeData = transformRawTasksByTypeData(apiTasksByTypeData); export const rawTasksByTypeData = transformRawTasksByTypeData(apiTasksByTypeData);
export const transformedTasksByTypeData = getTasksByTypeData(apiTasksByTypeData); export const transformedTasksByTypeData = getTasksByTypeData(apiTasksByTypeData);
...@@ -264,5 +264,5 @@ export const selectedProjects = [ ...@@ -264,5 +264,5 @@ export const selectedProjects = [
}, },
]; ];
// Value returned from JSON fixture is 345600 for issue stage which equals 4d // Value returned from JSON fixture is 172800 for issue stage which equals 2d
export const pathNavIssueMetric = '4d'; export const pathNavIssueMetric = '2d';
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do
include JavaScriptFixturesHelpers
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, namespace: group) }
let_it_be(:user) { create(:user, :admin) }
around do |example|
freeze_time { example.run }
end
before(:all) do
clean_frontend_fixtures('analytics/charts/')
end
describe Groups::Analytics::TasksByTypeController, type: :controller do
render_views
let_it_be(:labels) { create_list(:group_label, 3, group: group) }
before do
2.times do |i|
create(:labeled_issue, created_at: i.days.ago, project: create(:project, group: group), labels: [labels[0]])
create(:labeled_issue, created_at: i.days.ago, project: create(:project, group: group), labels: [labels[1]])
create(:labeled_issue, created_at: i.days.ago, project: create(:project, group: group), labels: [labels[2]])
end
stub_licensed_features(type_of_work_analytics: true)
group.add_maintainer(user)
sign_in(user)
end
it 'analytics/charts/type_of_work/tasks_by_type.json' do
params = { group_id: group.full_path, label_ids: labels.map(&:id), created_after: 10.days.ago, subject: 'Issue' }
get(:show, params: params, format: :json)
expect(response).to have_gitlab_http_status(:success)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do
include JavaScriptFixturesHelpers
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, namespace: group) }
let_it_be(:user) { create(:user, :admin) }
let(:issue) { create(:issue, project: project, created_at: 4.days.ago) }
let(:issue_1) { create(:issue, project: project, created_at: 5.days.ago) }
let(:issue_2) { create(:issue, project: project, created_at: 4.days.ago) }
let(:issue_3) { create(:issue, project: project, created_at: 3.days.ago) }
def prepare_cycle_analytics_data
group.add_maintainer(user)
project.add_maintainer(user)
create_commit_referencing_issue(issue_1)
create_commit_referencing_issue(issue_2)
create_merge_request_closing_issue(user, project, issue_1)
create_merge_request_closing_issue(user, project, issue_2)
merge_merge_requests_closing_issue(user, project, issue_3)
end
around do |example|
freeze_time { example.run }
end
before(:all) do
clean_frontend_fixtures('analytics/metrics')
end
describe Groups::Analytics::CycleAnalytics::SummaryController, type: :controller do
render_views
let(:params) { { created_after: 3.months.ago, created_before: Time.now, group_id: group.full_path } }
def prepare_cycle_time_data
issue.update!(created_at: 5.days.ago)
issue.metrics.update!(first_mentioned_in_commit_at: 4.days.ago)
issue.update!(closed_at: 3.days.ago)
issue_1.update!(created_at: 8.days.ago)
issue_1.metrics.update!(first_mentioned_in_commit_at: 6.days.ago)
issue_1.update!(closed_at: 1.day.ago)
end
before do
stub_licensed_features(cycle_analytics_for_groups: true)
prepare_cycle_analytics_data
prepare_cycle_time_data
sign_in(user)
end
it 'analytics/metrics/value_stream_analytics/summary.json' do
get(:show, params: params, format: :json)
expect(response).to be_successful
end
it 'analytics/metrics/value_stream_analytics/time_summary.json' do
get(:time_summary, params: params, format: :json)
expect(response).to be_successful
end
end
end
...@@ -4,11 +4,11 @@ require 'spec_helper' ...@@ -4,11 +4,11 @@ require 'spec_helper'
RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do
include JavaScriptFixturesHelpers include JavaScriptFixturesHelpers
let(:group) { create(:group) } let_it_be(:group) { create(:group) }
let(:value_stream) { create(:cycle_analytics_group_value_stream, group: group) } let_it_be(:value_stream) { create(:cycle_analytics_group_value_stream, group: group) }
let(:project) { create(:project, :repository, namespace: group) } let_it_be(:project) { create(:project, :repository, namespace: group) }
let(:user) { create(:user, :admin) } let_it_be(:user) { create(:user, :admin) }
let(:milestone) { create(:milestone, project: project) } let_it_be(:milestone) { create(:milestone, project: project) }
let(:issue) { create(:issue, project: project, created_at: 4.days.ago) } let(:issue) { create(:issue, project: project, created_at: 4.days.ago) }
let(:issue_1) { create(:issue, project: project, created_at: 5.days.ago) } let(:issue_1) { create(:issue, project: project, created_at: 5.days.ago) }
...@@ -17,18 +17,14 @@ RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do ...@@ -17,18 +17,14 @@ RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do
let(:label) { create(:group_label, name: 'in-code-review', group: group) } let(:label) { create(:group_label, name: 'in-code-review', group: group) }
let(:mr) { create_merge_request_closing_issue(user, project, issue, commit_message: "References #{issue.to_reference}") }
let(:mr_1) { create(:merge_request, source_project: project, allow_broken: true, created_at: 20.days.ago) } let(:mr_1) { create(:merge_request, source_project: project, allow_broken: true, created_at: 20.days.ago) }
let(:mr_2) { create(:merge_request, source_project: project, allow_broken: true, created_at: 19.days.ago) } let(:mr_2) { create(:merge_request, source_project: project, allow_broken: true, created_at: 19.days.ago) }
let(:mr_3) { create(:merge_request, source_project: project, allow_broken: true, created_at: 18.days.ago) }
let(:pipeline_1) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr_1.source_branch, sha: mr_1.source_branch_sha, head_pipeline_of: mr_1) } let(:pipeline_1) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr_1.source_branch, sha: mr_1.source_branch_sha, head_pipeline_of: mr_1) }
let(:pipeline_2) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr_2.source_branch, sha: mr_2.source_branch_sha, head_pipeline_of: mr_2) } let(:pipeline_2) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr_2.source_branch, sha: mr_2.source_branch_sha, head_pipeline_of: mr_2) }
let(:pipeline_3) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr_3.source_branch, sha: mr_3.source_branch_sha, head_pipeline_of: mr_3) }
let(:build_1) { create(:ci_build, :success, pipeline: pipeline_1, author: user) } let(:build_1) { create(:ci_build, :success, pipeline: pipeline_1, author: user) }
let(:build_2) { create(:ci_build, :success, pipeline: pipeline_2, author: user) } let(:build_2) { create(:ci_build, :success, pipeline: pipeline_2, author: user) }
let(:build_3) { create(:ci_build, :success, pipeline: pipeline_3, author: user) }
let(:label_based_stage) do let(:label_based_stage) do
create(:cycle_analytics_group_stage, { create(:cycle_analytics_group_stage, {
...@@ -45,9 +41,6 @@ RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do ...@@ -45,9 +41,6 @@ RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do
group.add_maintainer(user) group.add_maintainer(user)
project.add_maintainer(user) project.add_maintainer(user)
create_cycle(user, project, issue_1, mr_1, milestone, pipeline_1)
create_cycle(user, project, issue_2, mr_2, milestone, pipeline_2)
create_commit_referencing_issue(issue_1) create_commit_referencing_issue(issue_1)
create_commit_referencing_issue(issue_2) create_commit_referencing_issue(issue_2)
...@@ -62,8 +55,8 @@ RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do ...@@ -62,8 +55,8 @@ RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do
end end
def update_metrics def update_metrics
issue_1.metrics.update(first_added_to_board_at: 3.days.ago, first_mentioned_in_commit_at: 2.days.ago) issue_1.metrics.update!(first_added_to_board_at: 3.days.ago, first_mentioned_in_commit_at: 2.days.ago)
issue_2.metrics.update(first_added_to_board_at: 2.days.ago, first_mentioned_in_commit_at: 1.day.ago) issue_2.metrics.update!(first_added_to_board_at: 2.days.ago, first_mentioned_in_commit_at: 1.day.ago)
mr_1.metrics.update!({ mr_1.metrics.update!({
merged_at: 5.days.ago, merged_at: 5.days.ago,
...@@ -87,9 +80,6 @@ RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do ...@@ -87,9 +80,6 @@ RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do
update_metrics update_metrics
create_cycle(user, project, issue_1, mr_1, milestone, pipeline_1)
create_cycle(user, project, issue_2, mr_2, milestone, pipeline_2)
create_cycle(user, project, issue_3, mr_3, milestone, pipeline_3)
deploy_master(user, project, environment: 'staging') deploy_master(user, project, environment: 'staging')
end end
...@@ -115,13 +105,8 @@ RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do ...@@ -115,13 +105,8 @@ RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do
end end
end end
around do |example|
Timecop.freeze { example.run }
end
before(:all) do before(:all) do
clean_frontend_fixtures('analytics/') clean_frontend_fixtures('analytics/value_stream_analytics/')
clean_frontend_fixtures('cycle_analytics/')
end end
describe Groups::Analytics::CycleAnalytics::StagesController, type: :controller do describe Groups::Analytics::CycleAnalytics::StagesController, type: :controller do
...@@ -181,71 +166,4 @@ RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do ...@@ -181,71 +166,4 @@ RSpec.describe 'Analytics (JavaScript fixtures)', :sidekiq_inline do
expect(response).to be_successful expect(response).to be_successful
end end
end end
describe Groups::Analytics::CycleAnalytics::SummaryController, type: :controller do
render_views
let(:params) { { created_after: 3.months.ago, created_before: Time.now, group_id: group.full_path } }
def prepare_cycle_time_data
issue.update!(created_at: 5.days.ago)
issue.metrics.update!(first_mentioned_in_commit_at: 4.days.ago)
issue.update!(closed_at: 3.days.ago)
issue_1.update!(created_at: 8.days.ago)
issue_1.metrics.update!(first_mentioned_in_commit_at: 6.days.ago)
issue_1.update!(closed_at: 1.day.ago)
end
before do
stub_licensed_features(cycle_analytics_for_groups: true)
prepare_cycle_analytics_data
prepare_cycle_time_data
sign_in(user)
end
it 'analytics/value_stream_analytics/summary.json' do
get(:show, params: params, format: :json)
expect(response).to be_successful
end
it 'analytics/value_stream_analytics/time_summary.json' do
get(:time_summary, params: params, format: :json)
expect(response).to be_successful
end
end
describe Groups::Analytics::TasksByTypeController, type: :controller do
render_views
let(:label) { create(:group_label, group: group) }
let(:label2) { create(:group_label, group: group) }
let(:label3) { create(:group_label, group: group) }
before do
5.times do |i|
create(:labeled_issue, created_at: i.days.ago, project: create(:project, group: group), labels: [label])
create(:labeled_issue, created_at: i.days.ago, project: create(:project, group: group), labels: [label2])
create(:labeled_issue, created_at: i.days.ago, project: create(:project, group: group), labels: [label3])
end
stub_licensed_features(type_of_work_analytics: true)
group.add_maintainer(user)
sign_in(user)
end
it 'analytics/type_of_work/tasks_by_type.json' do
params = { group_id: group.full_path, label_ids: [label.id, label2.id, label3.id], created_after: 10.days.ago, subject: 'Issue' }
get(:show, params: params, format: :json)
expect(response).to be_successful
end
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