Skip to content

Commit

Permalink
Merge pull request #1429 from alphagov/check-for-related-link-overrides
Browse files Browse the repository at this point in the history
Ensure suggested related links respect overrides
  • Loading branch information
Karl Baker authored Jul 30, 2019
2 parents cf8391b + 92b3321 commit eef77dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/feature_toggler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def use_recommended_related_links?(content_item_links, request_headers)
return false if content_item_links.nil?

content_item_links.fetch('ordered_related_items', []).empty? &&
content_item_links.fetch('ordered_related_items_overrides', []).empty? &&
@feature_flags.feature_enabled?(FeatureFlagNames.recommended_related_links, request_headers)
end
end
16 changes: 15 additions & 1 deletion test/controllers/content_items_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ class ContentItemsControllerTest < ActionController::TestCase
assert_equal content_item['links']['ordered_related_items'], assigns[:content_item].content_item['links']['ordered_related_items']
end

test "gets item from content store and does not change ordered_related_items when feature flag header is specified but link overrides exist" do
HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, 'true')
request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = 'true'

content_item = content_store_has_schema_example('guide', 'guide-with-related-link-overrides')

get :show, params: { path: path_for(content_item) }
assert_response :success
assert_nil content_item['links']['ordered_related_items'], 'Content item should not have existing related links'
refute_empty content_item['links']['ordered_related_items_overrides'], 'Content item should have existing related link overrides'
refute_empty content_item['links']['suggested_ordered_related_items'], 'Content item should have existing suggested related links'
assert_nil content_item['links']['ordered_related_items']
end

test "gets item from content store and keeps ordered_related_items when feature flag header is specified but recommended links turned off" do
HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, 'false')
request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = 'true'
Expand All @@ -165,7 +179,7 @@ class ContentItemsControllerTest < ActionController::TestCase
assert_equal [], assigns[:content_item].content_item['links']['ordered_related_items']
end

test "gets item from content store and replaces ordered_related_items when feature flag header is specified and there are no existing links" do
test "gets item from content store and replaces ordered_related_items when feature flag header is specified and there are no existing links or overrides" do
HttpFeatureFlags.instance.add_http_feature_flag(FeatureFlagNames.recommended_related_links, 'true')
request.headers["HTTP_GOVUK_USE_RECOMMENDED_RELATED_LINKS"] = 'true'

Expand Down

0 comments on commit eef77dc

Please sign in to comment.