Skip to content

Commit

Permalink
Merge pull request #2835 from alphagov/SFO-finder
Browse files Browse the repository at this point in the history
Add new SFO finder
  • Loading branch information
GDSNewt authored Nov 5, 2024
2 parents cbda85c + f763aa6 commit e4d1ba9
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/models/sfo_case.rb
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
3 changes: 3 additions & 0 deletions app/views/metadata_fields/_sfo_cases.html.erb
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 %>
39 changes: 39 additions & 0 deletions lib/documents/schemas/sfo_cases.json
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"
}
]
}
]
}
122 changes: 122 additions & 0 deletions spec/features/creating_a_sfo_case_spec.rb
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
16 changes: 16 additions & 0 deletions spec/fixtures/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
organisation_content_id { "e338f02d-82a3-4c6c-8a36-df3050869d97" }
end

factory :sfo_case_editor, parent: :user do
organisation_slug { "serious-fraud-office" }
organisation_content_id { "ebae4517-422f-44dd-9f87-13304c9815cb" }
end

factory :statutory_instrument_editor, parent: :user do
permissions { %w[signin statutory_instrument_editor] }
end
Expand Down Expand Up @@ -637,6 +642,17 @@
end
end

factory :sfo_case, parent: :document do
base_path { "/sfo-cases/example-document" }
document_type { "sfo_case" }

transient do
default_metadata do
{ "sfo_case_state" => "open" }
end
end
end

factory :statutory_instrument, parent: :document do
base_path { "/eu-withdrawal-act-2018-statutory-instruments/example-document" }
document_type { "statutory_instrument" }
Expand Down
23 changes: 23 additions & 0 deletions spec/models/sfo_case_spec.rb
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

0 comments on commit e4d1ba9

Please sign in to comment.