Commit dd03f39e authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'add-feature-flag-summary-serializer' into 'master'

Add summary entity to `FeatureFlagController#index` endpoint

See merge request gitlab-org/gitlab-ee!9048
parents 107eb6fb 2be223b6
......@@ -21,10 +21,7 @@ class Projects::FeatureFlagsController < Projects::ApplicationController
format.json do
Gitlab::PollingInterval.set_header(response, interval: 10_000)
render json: FeatureFlagSerializer
.new(project: @project, current_user: @current_user)
.with_pagination(request, response)
.represent(@feature_flags)
render json: { feature_flags: feature_flags_json }.merge(summary_json)
end
end
end
......@@ -77,4 +74,17 @@ class Projects::FeatureFlagsController < Projects::ApplicationController
params.require(:operations_feature_flag)
.permit(:name, :description, :active)
end
def feature_flags_json
FeatureFlagSerializer
.new(project: @project, current_user: @current_user)
.with_pagination(request, response)
.represent(@feature_flags)
end
def summary_json
FeatureFlagSummarySerializer
.new(project: @project, current_user: @current_user)
.represent(@project)
end
end
# frozen_string_literal: true
class FeatureFlagSummaryEntity < Grape::Entity
include RequestAwareEntity
expose :count do
expose :all do |project|
project.operations_feature_flags.count
end
expose :enabled do |project|
project.operations_feature_flags.enabled.count
end
expose :disabled do |project|
project.operations_feature_flags.disabled.count
end
end
end
# frozen_string_literal: true
class FeatureFlagSummarySerializer < BaseSerializer
entity FeatureFlagSummaryEntity
end
......@@ -74,16 +74,24 @@ describe Projects::FeatureFlagsController do
it 'returns all feature flags as json response' do
subject
expect(json_response.count).to eq(2)
expect(json_response.first['name']).to eq(feature_flag_active.name)
expect(json_response.second['name']).to eq(feature_flag_inactive.name)
expect(json_response['feature_flags'].count).to eq(2)
expect(json_response['feature_flags'].first['name']).to eq(feature_flag_active.name)
expect(json_response['feature_flags'].second['name']).to eq(feature_flag_inactive.name)
end
it 'returns edit path and destroy path' do
subject
expect(json_response.first['edit_path']).not_to be_nil
expect(json_response.first['destroy_path']).not_to be_nil
expect(json_response['feature_flags'].first['edit_path']).not_to be_nil
expect(json_response['feature_flags'].first['destroy_path']).not_to be_nil
end
it 'returns the summary of feature flags' do
subject
expect(json_response['count']['all']).to eq(2)
expect(json_response['count']['enabled']).to eq(1)
expect(json_response['count']['disabled']).to eq(1)
end
it 'matches json schema' do
......@@ -103,7 +111,7 @@ describe Projects::FeatureFlagsController do
it 'returns all feature flags' do
subject
expect(json_response.count).to eq(2)
expect(json_response['feature_flags'].count).to eq(2)
end
end
......@@ -113,8 +121,8 @@ describe Projects::FeatureFlagsController do
it 'returns enabled feature flags' do
subject
expect(json_response.count).to eq(1)
expect(json_response.first['active']).to be_truthy
expect(json_response['feature_flags'].count).to eq(1)
expect(json_response['feature_flags'].first['active']).to be_truthy
end
end
......@@ -124,8 +132,8 @@ describe Projects::FeatureFlagsController do
it 'returns disabled feature flags' do
subject
expect(json_response.count).to eq(1)
expect(json_response.first['active']).to be_falsy
expect(json_response['feature_flags'].count).to eq(1)
expect(json_response['feature_flags'].first['active']).to be_falsy
end
end
end
......
{
"type": "array",
"items": { "$ref": "feature_flag.json" }
"required": ["feature_flags", "count"],
"feature_flags": { "type": "array", "items": { "$ref": "feature_flag.json" } },
"count": {
"type": "object",
"properties" : {
"all": { "type": "integer" },
"enabled": { "type": "integer" },
"disabled": { "type": "integer" }
},
"additionalProperties": false
}
}
# frozen_string_literal: true
require 'spec_helper'
describe FeatureFlagSummaryEntity do
let!(:feature_flag) { create(:operations_feature_flag, project: project) }
let(:project) { create(:project) }
let(:request) { double('request', current_user: user) }
let(:user) { create(:user) }
let(:entity) { described_class.new(project, request: request) }
before do
project.add_developer(user)
stub_licensed_features(feature_flags: true)
end
subject { entity.as_json }
it 'has summary information' do
expect(subject).to include(:count)
end
end
# frozen_string_literal: true
require 'spec_helper'
describe FeatureFlagSummarySerializer do
let(:serializer) { described_class.new(project: project, current_user: user) }
let(:user) { create(:user) }
let(:project) { create(:project) }
let!(:feature_flags) { create(:operations_feature_flag, project: project) }
before do
stub_licensed_features(feature_flags: true)
project.add_developer(user)
end
describe '#represent' do
subject { serializer.represent(project) }
it 'has summary information' do
expect(subject).to include(:count)
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