diff --git a/lib/engines/content_block_manager/app/models/content_block_manager/content_block/schema.rb b/lib/engines/content_block_manager/app/models/content_block_manager/content_block/schema.rb index 43b13555045..470783dd70c 100644 --- a/lib/engines/content_block_manager/app/models/content_block_manager/content_block/schema.rb +++ b/lib/engines/content_block_manager/app/models/content_block_manager/content_block/schema.rb @@ -3,7 +3,7 @@ module ContentBlock class Schema SCHEMA_PREFIX = "content_block".freeze - VALID_SCHEMAS = %w[email_address postal_address].freeze + VALID_SCHEMAS = %w[email_address postal_address pension].freeze private_constant :VALID_SCHEMAS def self.valid_schemas @@ -26,7 +26,11 @@ def parameter end def fields - @body["properties"].keys + (@body["properties"].to_a - embedded_objects.to_a).to_h.keys + end + + def embedded_objects + @body["properties"].select { |_k, v| v["type"] == "object" } end def permitted_params diff --git a/lib/engines/content_block_manager/features/create_object.feature b/lib/engines/content_block_manager/features/create_email_object.feature similarity index 100% rename from lib/engines/content_block_manager/features/create_object.feature rename to lib/engines/content_block_manager/features/create_email_object.feature diff --git a/lib/engines/content_block_manager/features/create_pension_object.feature b/lib/engines/content_block_manager/features/create_pension_object.feature new file mode 100644 index 00000000000..83c8e7ca95c --- /dev/null +++ b/lib/engines/content_block_manager/features/create_pension_object.feature @@ -0,0 +1,22 @@ +Feature: Create a content object + + Background: + Given I am a GDS admin + And the organisation "Ministry of Example" exists + And a schema "pension" exists with the following fields: + | field | type | format | required | + | description | string | string | true | + + Scenario: GDS editor creates a Pension + When I visit the Content Block Manager home page + And I click to create an object + Then I should see all the schemas listed + When I click on the "pension" schema + Then I should see a form for the schema + When I complete the form with the following fields: + | title | description | organisation | instructions_to_publishers | + | my basic pension | this is basic | Ministry of Example | this is important | + Then I am asked to review my answers for a "pension" + And I review and confirm my answers are correct + Then the edition should have been created successfully + And I should be taken to the confirmation page for a new "pension" diff --git a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb index e73bb3ad4eb..ded87c9d5ef 100644 --- a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb +++ b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb @@ -119,6 +119,22 @@ has_support_button end +And("I should be taken to the confirmation page for a new {string}") do |block_type| + content_block = ContentBlockManager::ContentBlock::Edition.last + + assert_text I18n.t("content_block_edition.confirmation_page.created.banner", block_type: block_type.titlecase) + assert_text I18n.t("content_block_edition.confirmation_page.created.detail") + + expect(page).to have_link( + "View content block", + href: content_block_manager.content_block_manager_content_block_document_path( + content_block.document, + ), + ) + + has_support_button +end + When("I click to view the content block") do click_link href: content_block_manager.content_block_manager_content_block_document_path( ContentBlockManager::ContentBlock::Edition.last.document, @@ -314,6 +330,10 @@ assert_text "Review email address" end +Then("I am asked to review my answers for a {string}") do |block_type| + assert_text "Review #{block_type}" +end + Then("I confirm my answers are correct") do check "is_confirmed" end diff --git a/lib/engines/content_block_manager/features/step_definitions/schema_steps.rb b/lib/engines/content_block_manager/features/step_definitions/schema_steps.rb index fc21b98e902..fd8d61fb347 100644 --- a/lib/engines/content_block_manager/features/step_definitions/schema_steps.rb +++ b/lib/engines/content_block_manager/features/step_definitions/schema_steps.rb @@ -21,7 +21,7 @@ end Then("I should see a form for the schema") do - expect(page).to have_content(@schema.name) + expect(page).to have_text("Create #{@schema.name.downcase}") end Then("I should see all the schemas listed") do diff --git a/lib/engines/content_block_manager/test/unit/app/models/content_block_schema_test.rb b/lib/engines/content_block_manager/test/unit/app/models/content_block_schema_test.rb index fecd63a169b..44824e0b4bc 100644 --- a/lib/engines/content_block_manager/test/unit/app/models/content_block_schema_test.rb +++ b/lib/engines/content_block_manager/test/unit/app/models/content_block_schema_test.rb @@ -33,6 +33,7 @@ class ContentBlockManager::SchemaTest < ActiveSupport::TestCase assert_equal ContentBlockManager::ContentBlock::Schema.valid_schemas, %w[ email_address postal_address + pension ] end end @@ -148,4 +149,38 @@ class ContentBlockManager::SchemaTest < ActiveSupport::TestCase assert_equal ContentBlockManager::ContentBlock::Schema.is_valid_schema?(schema_name), false end end + + describe "when a schema has embedded objects" do + let(:body) do + { + "properties" => { + "foo" => { + "type" => "string", + }, + "bar" => { + "type" => "object", + "patternProperties" => { + "*" => { + "type" => "object", + "properties" => { + "my_string" => { + "type" => "string", + }, + "something_else" => { + "type" => "string", + }, + }, + }, + }, + }, + }, + } + end + + describe "#fields" do + it "removes object fields" do + assert_equal schema.fields, %w[foo] + end + end + end end