-
Notifications
You must be signed in to change notification settings - Fork 20
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
Move fatality notices from government frontend #4640
base: main
Are you sure you want to change the base?
Changes from 1 commit
e50adca
d72f582
c301da7
3b2fa6b
ba5c664
98eeac6
9f8bfd3
db94142
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class FatalityNotice < ContentItem | ||
include Updatable | ||
|
||
def field_of_operation | ||
content_item_links = content_store_hash["links"]["field_of_operation"] | ||
if content_item_links | ||
attributes = content_item_links.first | ||
OpenStruct.new(title: attributes["title"], path: attributes["base_path"]) | ||
end | ||
end | ||
|
||
def contributors | ||
organisations_ordered_by_emphasis + links_group(%w[worldwide_organisations people speaker]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do fatality notices have a "speaker"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder how many content items need to access "people" in contributors. Perhaps Do we need to start thinking about modelling Links? Not a linkable concern, but something that does the job of getting the |
||
end | ||
|
||
private | ||
|
||
def links_group(types) | ||
types.flat_map { |type| links(type) }.uniq | ||
end | ||
|
||
def links(type) | ||
expanded_links_from_content_item(type) | ||
.select { |link| link["base_path"] } | ||
.map { |link| { "title" => link["title"], "base_path" => link["base_path"] } } | ||
end | ||
|
||
def expanded_links_from_content_item(type) | ||
return [] unless content_store_hash["links"][type] | ||
|
||
content_store_hash["links"][type] | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
RSpec.describe FatalityNotice do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This tests should also include the shared examples |
||
let(:content_item) { GovukSchemas::Example.find("fatality_notice", example_name: "fatality_notice") } | ||
|
||
describe "#field_of_operation" do | ||
it "returns the field of operation link structure" do | ||
model_instance = described_class.new(content_item) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick. I'd probably have called this |
||
|
||
expect(model_instance.field_of_operation.title).to eq("Zululand") | ||
expect(model_instance.field_of_operation.path).to eq("/government/fields-of-operation/zululand") | ||
end | ||
|
||
context "when no field of operation is present" do | ||
it "returns nil" do | ||
content_item["links"].delete("field_of_operation") | ||
model_instance = described_class.new(content_item) | ||
|
||
expect(model_instance.field_of_operation).to be_nil | ||
end | ||
end | ||
end | ||
|
||
describe "#contributors" do | ||
it "returns the publishing organisation" do | ||
model_instance = described_class.new(content_item) | ||
|
||
expect(model_instance.contributors.count).to eq(1) | ||
expect(model_instance.contributors[0]["title"]).to eq("Ministry of Defence") | ||
expect(model_instance.contributors[0]["base_path"]).to eq("/government/organisations/ministry-of-defence") | ||
end | ||
|
||
context "when a minister is listed" do | ||
let(:content_item) { GovukSchemas::Example.find("fatality_notice", example_name: "fatality_notice_with_minister") } | ||
|
||
it "includes the minister" do | ||
model_instance = described_class.new(content_item) | ||
|
||
expect(model_instance.contributors.count).to eq(2) | ||
expect(model_instance.contributors[1]["title"]).to eq("The Rt Hon Sir Eric Pickles MP") | ||
expect(model_instance.contributors[1]["base_path"]).to eq("/government/people/eric-pickles") | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice! I think we should use this pattern in other places too.