Skip to content

Commit

Permalink
add lead_organisation filter to Content Block Document Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Harriethw committed Oct 25, 2024
1 parent 4fbbba2 commit aa75d03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def documents
documents = documents.live
documents = documents.with_keyword(@filters[:keyword]) if @filters[:keyword].present?
documents = documents.where(block_type: @filters[:block_type]) if @filters[:block_type].present?
documents = documents.with_lead_organisation(@filters[:lead_organisation]) if @filters[:lead_organisation].present?
documents
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ContentBlockManager::DocumentFilterTest < ActiveSupport::TestCase
ContentBlockManager::ContentBlock::Document.expects(:live).returns(document_scope_mock)
document_scope_mock.expects(:with_keyword).never
document_scope_mock.expects(:where).never
document_scope_mock.expects(:with_lead_organisation).never

ContentBlockManager::ContentBlock::Document::DocumentFilter.new({}).documents
end
Expand All @@ -33,14 +34,24 @@ class ContentBlockManager::DocumentFilterTest < ActiveSupport::TestCase
end
end

describe "when both block types and keyword is given" do
it "returns live documents of the type and keyword given" do
describe "when a lead organisation id is given" do
it "returns live documents with lead org given" do
document_scope_mock = mock
ContentBlockManager::ContentBlock::Document.expects(:live).returns(document_scope_mock)
document_scope_mock.expects(:with_lead_organisation).with("123").returns([])
ContentBlockManager::ContentBlock::Document::DocumentFilter.new({ lead_organisation: "123" }).documents
end
end

describe "when block types, keyword and organisation is given" do
it "returns live documents with the filters given" do
document_scope_mock = mock
ContentBlockManager::ContentBlock::Document.expects(:live).returns(document_scope_mock)
document_scope_mock.expects(:with_keyword).with("ministry of example").returns(document_scope_mock)
document_scope_mock.expects(:where).with(block_type: %w[email_address]).returns([])
document_scope_mock.expects(:where).with(block_type: %w[email_address]).returns(document_scope_mock)
document_scope_mock.expects(:with_lead_organisation).with("123").returns([])
ContentBlockManager::ContentBlock::Document::DocumentFilter.new(
{ block_type: %w[email_address], keyword: "ministry of example" },
{ block_type: %w[email_address], keyword: "ministry of example", lead_organisation: "123" },
).documents
end
end
Expand Down

0 comments on commit aa75d03

Please sign in to comment.