Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content modelling/876 create pension block #9898

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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