-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2835 from alphagov/SFO-finder
Add new SFO finder
- Loading branch information
Showing
6 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class SfoCase < Document | ||
validates :sfo_case_state, presence: true | ||
|
||
FORMAT_SPECIFIC_FIELDS = %i[ | ||
sfo_case_state | ||
].freeze | ||
|
||
attr_accessor(*FORMAT_SPECIFIC_FIELDS) | ||
|
||
def initialize(params = {}) | ||
super(params, FORMAT_SPECIFIC_FIELDS) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= render layout: "shared/form_group", locals: { f: f, field: :sfo_case_state, label: "Case state" } do %> | ||
<%= f.select :sfo_case_state, facet_options(f, :sfo_case_state), {}, { class: 'form-control' } %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"target_stack": "draft", | ||
"content_id": "b8b8fb77-c5e9-41d6-b133-44ecd1958e28", | ||
"base_path": "/sfo-cases", | ||
"format_name": "Find an SFO case", | ||
"name": "Find an SFO case", | ||
"description": "Find fraud, bribery and corruption cases investigated by the SFO.", | ||
"summary": "<p>This case finder includes all ongoing Serious Fraud Office (SFO) prosecutions and investigations that are in the public domain. This does not include intelligence referrals, covert investigations or proceeds of crime cases.</p><p>For updates on the SFO’s proceeds of crime recovery, see <a href=#>this page</a>.</p>", | ||
"filter": { | ||
"format": "sfo_case" | ||
}, | ||
"related": [], | ||
"show_summaries": true, | ||
"organisations": [ | ||
"ebae4517-422f-44dd-9f87-13304c9815cb" | ||
], | ||
"document_noun": "case", | ||
"document_title": "SFO Case", | ||
"facets": [ | ||
{ | ||
"key": "sfo_case_state", | ||
"name": "Case state", | ||
"type": "text", | ||
"preposition": "with case state", | ||
"display_as_result_metadata": false, | ||
"filterable": true, | ||
"allowed_values": [ | ||
{ | ||
"label": "Open", | ||
"value": "open" | ||
}, | ||
{ | ||
"label": "Closed", | ||
"value": "closed" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
require "spec_helper" | ||
|
||
RSpec.feature "Creating an sfo Case", type: :feature do | ||
let(:sfo_case) { FactoryBot.create(:sfo_case) } | ||
let(:content_id) { sfo_case["content_id"] } | ||
let(:save_button_disable_with_message) { page.find_button("Save as draft")["data-disable-with"] } | ||
|
||
before do | ||
log_in_as_editor(:sfo_case_editor) | ||
allow(SecureRandom).to receive(:uuid).and_return(content_id) | ||
|
||
stub_publishing_api_has_content([sfo_case], hash_including(document_type: SfoCase.document_type)) | ||
stub_publishing_api_has_item(sfo_case) | ||
stub_any_publishing_api_put_content | ||
stub_any_publishing_api_patch_links | ||
end | ||
|
||
scenario "visiting the new document page" do | ||
visit "/sfo-cases" | ||
click_link "Add another SFO Case" | ||
|
||
expect(page.status_code).to eq(200) | ||
expect(page.current_path).to eq("/sfo-cases/new") | ||
end | ||
|
||
scenario "with valid data" do | ||
visit "/sfo-cases/new" | ||
|
||
fill_in "Title", with: "Example sfo Case" | ||
fill_in "Summary", with: "This is the summary of an example sfo case" | ||
fill_in "Body", with: "## Header#{"\n\nThis is the long body of an example life saving maritime appliance service station" * 2}" | ||
select "Closed", from: "Case state" | ||
|
||
expect(page).to have_css("div.govspeak-help") | ||
expect(page).to have_content("To add an attachment, please save the draft first.") | ||
expect(save_button_disable_with_message).to eq("Saving...") | ||
|
||
click_button "Save as draft" | ||
|
||
expected_sent_payload = { | ||
"base_path" => "/sfo-cases/example-sfo-case", | ||
"title" => "Example sfo Case", | ||
"description" => "This is the summary of an example sfo case", | ||
"document_type" => "sfo_case", | ||
"schema_name" => "specialist_document", | ||
"publishing_app" => "specialist-publisher", | ||
"rendering_app" => "government-frontend", | ||
"locale" => "en", | ||
"phase": "live", | ||
"details" => { | ||
"body" => | ||
[ | ||
{ | ||
"content_type" => "text/govspeak", | ||
"content" => "## Header\r\n\r\nThis is the long body of an example life saving maritime appliance service station\r\n\r\nThis is the long body of an example life saving maritime appliance service station", | ||
}, | ||
], | ||
"metadata" => { | ||
"sfo_case_state" => "closed", | ||
}, | ||
"max_cache_time" => 10, | ||
"headers" => [ | ||
{ "text" => "Header", "level" => 2, "id" => "header" }, | ||
], | ||
"temporary_update_type" => false, | ||
}, | ||
"routes" => [ | ||
{ | ||
"path" => "/sfo-cases/example-sfo-case", | ||
"type" => "exact", | ||
}, | ||
], | ||
"redirects" => [], | ||
"update_type" => "major", | ||
"links" => | ||
{ | ||
"finder" => %w[b8b8fb77-c5e9-41d6-b133-44ecd1958e28], | ||
}, | ||
} | ||
|
||
assert_publishing_api_put_content(content_id, expected_sent_payload) | ||
|
||
expect(page.status_code).to eq(200) | ||
expect(page).to have_content("Created Example sfo Case") | ||
expect(page).to have_content("Bulk published false") | ||
end | ||
|
||
scenario "with no data" do | ||
visit "/sfo-cases/new" | ||
|
||
click_button "Save as draft" | ||
|
||
expect(page.status_code).to eq(422) | ||
|
||
expect(page).to have_css(".elements-error-summary") | ||
expect(page).to have_css(".form-group.elements-error") | ||
expect(page).to have_css(".elements-error-message") | ||
|
||
expect(page).to have_content("There is a problem") | ||
expect(page).to have_content("Title can't be blank") | ||
expect(page).to have_content("Summary can't be blank") | ||
expect(page).to have_content("Body can't be blank") | ||
end | ||
|
||
scenario "with invalid data" do | ||
visit "/sfo-cases/new" | ||
|
||
fill_in "Title", with: "Example sfo Case" | ||
fill_in "Summary", with: "This is the summary of an example sfo case" | ||
fill_in "Body", with: "<script>alert('hello')</script>" | ||
|
||
click_button "Save as draft" | ||
|
||
expect(page.status_code).to eq(422) | ||
|
||
expect(page).to have_css(".elements-error-summary") | ||
expect(page).to have_css(".elements-error-message") | ||
|
||
expect(page).to have_content("There is a problem") | ||
expect(page).to have_content("Body cannot include invalid Govspeak") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "spec_helper" | ||
require "models/valid_against_schema" | ||
|
||
RSpec.describe SfoCase do | ||
let(:payload) { FactoryBot.create(:sfo_case) } | ||
include_examples "it saves payloads that are valid against the 'specialist_document' schema" | ||
subject(:sfo_case) { described_class.from_publishing_api(payload) } | ||
|
||
it "is not exportable" do | ||
expect(described_class).not_to be_exportable | ||
end | ||
|
||
describe "validations" do | ||
it "is valid from the payload" do | ||
expect(sfo_case).to be_valid | ||
end | ||
|
||
it "is invalid if the case state is missing" do | ||
sfo_case.sfo_case_state = nil | ||
expect(sfo_case).not_to be_valid | ||
end | ||
end | ||
end |