Commit 5d0b22da authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '220494-setup-dummy-report-pages' into 'master'

Implement dummy report pages API endpoints

See merge request gitlab-org/gitlab!35432
parents 6fc5c01e 277504c4
# frozen_string_literal: true
module API
module Analytics
class Reports < Grape::API::Instance
DESCRIPTION_DETAIL =
'This feature is experimental and gated by the `:report_pages`'\
' feature flag, introduced in GitLab 13.2.'
helpers do
def api_endpoints_available?
# This will be scoped to a project or a group
Feature.enabled?(:report_pages) && ::License.feature_available?(:group_activity_analytics)
end
end
params do
requires :report_id, type: String, desc: 'The ID of the report'
end
resource :analytics do
resource :reports do
route_param :report_id do
resource :chart do
get do
not_found! unless api_endpoints_available?
# Dummy response
{
id: params[:report_id],
title: 'Recent Issues (90 days)',
chart: {
type: 'bar',
series: [
{
id: 'open_merge_requests',
title: 'Merge requests'
}
]
}
}
end
end
end
end
resource :series do
params do
requires :series_id, type: String, desc: 'The ID of the series'
end
route_param :report_id do
route_param :series_id do
get do
not_found! unless api_endpoints_available?
# Dummy response
{
labels: %w[label1 label2 label3],
datasets: [
{
label: "Series 1",
data: [
1,
2,
3
]
}
]
}
end
end
end
end
end
end
end
end
......@@ -58,6 +58,7 @@ module EE
mount ::API::VisualReviewDiscussions
mount ::API::Analytics::CodeReviewAnalytics
mount ::API::Analytics::GroupActivityAnalytics
mount ::API::Analytics::Reports
mount ::API::ProtectedEnvironments
mount ::API::ResourceWeightEvents
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::Analytics::Reports do
let_it_be(:user) { create(:user) }
let_it_be(:report_id) { 'some_report_id' }
shared_examples 'error response examples' do
context 'when `report_pages` feature flag is off' do
before do
stub_feature_flags(report_pages: false)
end
it 'returns 404, not found' do
api_call
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when `report_pages` license is missing' do
before do
stub_feature_flags(report_pages: true)
stub_licensed_features(group_activity_analytics: false)
end
it 'returns 404, not found' do
api_call
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
describe 'GET /analytics/reports/:id/chart' do
subject(:api_call) do
get api("/analytics/reports/#{report_id}/chart", user)
end
before do
stub_licensed_features(group_activity_analytics: true)
end
it 'is successful' do
api_call
expect(response).to have_gitlab_http_status(:ok)
expect(response.parsed_body["id"]).to eq(report_id)
end
include_examples 'error response examples'
end
describe 'GET /analytics/series/:report_id/:series_id' do
let_it_be(:series_id) { 'some_series_id' }
subject(:api_call) do
get api("/analytics/series/#{report_id}/#{series_id}", user)
end
it 'is successful' do
api_call
expect(response).to have_gitlab_http_status(:ok)
expect(response.parsed_body["datasets"].size).to eq(1)
end
include_examples 'error response examples'
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