Skip to content

Commit

Permalink
Check GraphQL feature flag in ministers index
Browse files Browse the repository at this point in the history
When the `GRAPHQL_FEATURE_FLAG` environment variable or the `graphql`
query param is set, use Publishing API's GraphQL endpoint as the source
of the data for serving the Ministers Index page. Otherwise use the
standard Content Store data source.
  • Loading branch information
mike3985 committed Nov 28, 2024
1 parent d2c6b63 commit a25eba3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
11 changes: 9 additions & 2 deletions app/controllers/ministers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ class MinistersController < ApplicationController
around_action :switch_locale

def index
ministers_index = MinistersIndex.find!(request.path)
@presented_ministers = MinistersIndexPresenter.new(ministers_index.content_item.content_item_data)
if Features.graphql_feature_enabled? || params.include?(:graphql)
ministers_index = Graphql::MinistersIndex.find!(request.path)
content_item_data = ministers_index.content_item
else
ministers_index = MinistersIndex.find!(request.path)
content_item_data = ministers_index.content_item.content_item_data
end

@presented_ministers = MinistersIndexPresenter.new(content_item_data)
setup_content_item_and_navigation_helpers(ministers_index)
end
end
53 changes: 41 additions & 12 deletions spec/features/ministers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,53 @@
end
end

let(:document) { GovukSchemas::Example.find("ministers_index", example_name: "ministers_index-reshuffle-mode-off") }
context "without the graphql feature flag" do
let(:document) { GovukSchemas::Example.find("ministers_index", example_name: "ministers_index-reshuffle-mode-off") }

before do
stub_content_store_has_item("/government/ministers", document)
visit "/government/ministers"
end
before do
stub_content_store_has_item("/government/ministers", document)
visit "/government/ministers"
end

it_behaves_like "ministers index page"
it_behaves_like "ministers index page"

context "during a reshuffle" do
let(:document) { GovukSchemas::Example.find("ministers_index", example_name: "ministers_index-reshuffle-mode-on") }
context "during a reshuffle" do
let(:document) { GovukSchemas::Example.find("ministers_index", example_name: "ministers_index-reshuffle-mode-on") }

it_behaves_like "ministers index page during a reshuffle"
end

it_behaves_like "ministers index page during a reshuffle"
context "during a reshuffle preview" do
let(:document) { GovukSchemas::Example.find("ministers_index", example_name: "ministers_index-reshuffle-mode-on-preview") }

it_behaves_like "ministers index page during a reshuffle preview"
end
end

context "during a reshuffle preview" do
let(:document) { GovukSchemas::Example.find("ministers_index", example_name: "ministers_index-reshuffle-mode-on-preview") }
context "with the GraphQL feature flag" do
let(:document) { fetch_graphql_fixture("ministers_index-reshuffle-mode-off") }

before do
enable_graphql_feature_flag
stub_publishing_api_graphql_query(
Graphql::MinistersIndexQuery.new("/government/ministers").query,
document,
)
visit "/government/ministers"
end

it_behaves_like "ministers index page"

it_behaves_like "ministers index page during a reshuffle preview"
context "during a reshuffle" do
let(:document) { fetch_graphql_fixture("ministers_index-reshuffle-mode-on") }

it_behaves_like "ministers index page during a reshuffle"
end

context "during a reshuffle preview" do
let(:document) { fetch_graphql_fixture("ministers_index-reshuffle-mode-on-preview") }

it_behaves_like "ministers index page during a reshuffle preview"
end
end
end

0 comments on commit a25eba3

Please sign in to comment.