Skip to content

Commit

Permalink
Merge pull request #9898 from alphagov/content-modelling/876-create-p…
Browse files Browse the repository at this point in the history
…ension-block

content modelling/876 create pension block
  • Loading branch information
Harriethw authored Feb 5, 2025
2 parents 7b9d103 + 3b449be commit df6ae0b
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class ContentBlockManager::SchemaTest < ActiveSupport::TestCase
assert_equal ContentBlockManager::ContentBlock::Schema.valid_schemas, %w[
email_address
postal_address
pension
]
end
end
Expand Down Expand Up @@ -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

0 comments on commit df6ae0b

Please sign in to comment.