debian-mirror-gitlab/spec/controllers/projects/cycle_analytics/events_controller_spec.rb

67 lines
1.7 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Projects::CycleAnalytics::EventsController do
2019-10-12 21:52:04 +05:30
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
before do
sign_in(user)
project.add_maintainer(user)
end
describe 'cycle analytics not set up flag' do
context 'with no data' do
it 'is empty' do
get_issue
2019-12-04 20:38:33 +05:30
expect(response).to be_successful
2020-05-24 23:13:21 +05:30
expect(Gitlab::Json.parse(response.body)['events']).to be_empty
2019-10-12 21:52:04 +05:30
end
end
context 'with data' do
let(:milestone) { create(:milestone, project: project, created_at: 10.days.ago) }
let(:issue) { create(:issue, project: project, created_at: 9.days.ago) }
before do
issue.update(milestone: milestone)
end
it 'is not empty' do
get_issue
2019-12-04 20:38:33 +05:30
expect(response).to be_successful
2019-10-12 21:52:04 +05:30
end
it 'contains event detais' do
get_issue
2020-05-24 23:13:21 +05:30
events = Gitlab::Json.parse(response.body)['events']
2019-10-12 21:52:04 +05:30
expect(events).not_to be_empty
expect(events.first).to include('title', 'author', 'iid', 'total_time', 'created_at', 'url')
expect(events.first['title']).to eq(issue.title)
end
context 'with data older than start date' do
it 'is empty' do
get_issue(additional_params: { cycle_analytics: { start_date: 7 } })
2019-12-04 20:38:33 +05:30
expect(response).to be_successful
2019-10-12 21:52:04 +05:30
2020-05-24 23:13:21 +05:30
expect(Gitlab::Json.parse(response.body)['events']).to be_empty
2019-10-12 21:52:04 +05:30
end
end
end
end
2020-10-24 23:57:45 +05:30
include_examples GracefulTimeoutHandling
2019-10-12 21:52:04 +05:30
def get_issue(additional_params: {})
params = additional_params.merge(namespace_id: project.namespace, project_id: project)
get(:issue, params: params, format: :json)
end
end