Skip to content

Commit

Permalink
Add support and test for hiding mapper fields (#1060)
Browse files Browse the repository at this point in the history
  • Loading branch information
nadaismail-stripe authored Apr 4, 2023
1 parent b97b360 commit 4417290
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def update

enabled: @user.enabled,
configuration_hash: @user.configuration_hash,
hidden_mapper_fields: @user.hidden_mapper_fields,
}
end

Expand Down
1 change: 1 addition & 0 deletions lib/stripe-force/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class FeatureFlags < T::Enum
COUPONS = new('coupons')
TERMINATED_ORDER_ITEM_CREDIT = new('terminated_order_item_credit')
AUTO_ADVANCE_PRORATION_INVOICE = new('auto_advance_proration_invoices')
PREBILLING = new('prebilling')
end
end

Expand Down
16 changes: 16 additions & 0 deletions lib/stripe-force/db/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,22 @@ def default_mappings
}
end

# fields to hide from the Data Mapper UI depending
# on the feature flags the user has enabled
def hidden_mapper_fields
hidden_mapper_fields = []

if !feature_enabled?(FeatureFlags::COUPONS)
hidden_mapper_fields << "coupon"
end

if !feature_enabled?(FeatureFlags::PREBILLING)
hidden_mapper_fields << "subscription_schedule.prebilling.iterations"
end

hidden_mapper_fields
end

sig { params(feature: FeatureFlags, update: T::Boolean).void }
def enable_feature(feature, update: false)
if !feature_flags.include?(feature.serialize.to_sym)
Expand Down
23 changes: 23 additions & 0 deletions test/controllers/test_configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,29 @@ class Critic::ConfigurationsControllerTest < ApplicationIntegrationTest
refute_equal(initial_hash, result['configuration_hash'])
assert_equal(40, result['configuration_hash'].size)
end

it 'hidden mapper fields is updated when features are enabled' do
get api_configuration_path, headers: authentication_headers
assert_response :success
result = parsed_json

# initially the hidden mapper fields should contain values
# if no feature flag is enabled for the user
assert(2, result['hidden_mapper_fields'].count)
assert_equal(['coupon', 'subscription_schedule.prebilling.iterations'], result['hidden_mapper_fields'])

# enable features
@user.enable_feature(FeatureFlags::COUPONS)
@user.enable_feature(FeatureFlags::PREBILLING)
@user.save

get api_configuration_path, headers: authentication_headers
assert_response :success
result = parsed_json

# if mappings change, hash should be different
assert_equal([], result['hidden_mapper_fields'])
end
end

describe '#configuration' do
Expand Down

0 comments on commit 4417290

Please sign in to comment.