Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update data format for platform API feature management #5718

11 changes: 6 additions & 5 deletions app/controllers/platform/api/v1/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ def set_resource
end

def account_params
if permitted_params[:enabled_features]
return permitted_params.except(:enabled_features).merge(selected_feature_flags: permitted_params[:enabled_features].map(&:to_sym))
if permitted_params[:features].present?
feature_flags = permitted_params[:features].select { |_key, value| value }.keys.map { |name| "feature_#{name}".to_sym }
permitted_params.except(:features).merge(selected_feature_flags: feature_flags)
else
permitted_params
end

permitted_params
end

def permitted_params
params.permit(:name, :locale, enabled_features: [], limits: {})
params.permit(:name, :locale, :domain, :support_email, :status, features: {}, limits: {}, custom_attributes: {})
end
end
35 changes: 19 additions & 16 deletions spec/controllers/platform/api/v1/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,27 @@
json_response = JSON.parse(response.body)
expect(json_response['name']).to eq('Test Account')
expect(json_response['locale']).to eq('es')
expect(json_response['enabled_features']).to eq(
sojan-official marked this conversation as resolved.
Show resolved Hide resolved
{
'agent_management' => true
}
)
expect(json_response['enabled_features']['agent_management']).to be(true)
sojan-official marked this conversation as resolved.
Show resolved Hide resolved
end

it 'creates an account with feature flags' do
InstallationConfig.where(name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS').first_or_create!(value: [{ 'name' => 'inbox_management',
smartdev58 marked this conversation as resolved.
Show resolved Hide resolved
'enabled' => true }])
'enabled' => true },
{ 'name' => 'disable_branding',
'enabled' => false }])

post '/platform/api/v1/accounts', params: { name: 'Test Account', enabled_features: %w[feature_ip_lookup feature_help_center] },
headers: { api_access_token: platform_app.access_token.token }, as: :json
post '/platform/api/v1/accounts', params: { name: 'Test Account', features: {
ip_lookup: true,
help_center: true,
disable_branding: false
} }, headers: { api_access_token: platform_app.access_token.token }, as: :json

json_response = JSON.parse(response.body)
expect(json_response['name']).to include('Test Account')
expect(json_response['enabled_features']).to eq(
{
'inbox_management' => true,
'ip_lookup' => true,
'help_center' => true
}
)
expect(json_response['enabled_features']['inbox_management']).to be(true)
expect(json_response['enabled_features']['ip_lookup']).to be(true)
expect(json_response['enabled_features']['help_center']).to be(true)
expect(json_response['enabled_features']['disable_branding']).to be_nil
end

it 'creates an account with limits settings' do
Expand Down Expand Up @@ -144,14 +142,19 @@

patch "/platform/api/v1/accounts/#{account.id}", params: {
name: 'Test Account',
enabled_features: %w[feature_ip_lookup feature_help_center],
features: {
smartdev58 marked this conversation as resolved.
Show resolved Hide resolved
ip_lookup: true,
help_center: true,
channel_facebook: false
smartdev58 marked this conversation as resolved.
Show resolved Hide resolved
},
limits: { agents: 5, inboxes: 10 }
}, headers: { api_access_token: platform_app.access_token.token }, as: :json

expect(response).to have_http_status(:success)
expect(account.reload.name).to eq('Test Account')
expect(account.reload.enabled_features['ip_lookup']).to be(true)
expect(account.reload.enabled_features['help_center']).to be(true)
expect(account.reload.enabled_features['channel_facebook']).to be_nil
expect(account.reload.limits['agents']).to eq(5)
expect(account.reload.limits['inboxes']).to eq(10)
end
Expand Down