Skip to content

Commit

Permalink
fixup! add service to get html for host document preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Harriethw committed Nov 21, 2024
1 parent 08abc6b commit 47a773d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def frontend_path

def html
# TODO: how to make opening this path secure?
@html ||= URI.open(frontend_path).read
uri = URI(frontend_path)
@html ||= Nokogiri::HTML.parse(Net::HTTP.get(uri))
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class ContentBlockManager::GetPreviewContentTest < ActiveSupport::TestCase
end

it "returns the title and raw frontend HTML for a document" do
URI.expects(:open).with(Plek.website_root + host_base_path).returns(uri_mock)
uri_mock.expects(:read).returns(fake_frontend_response)
Net::HTTP.expects(:get).with(URI(Plek.website_root + host_base_path)).returns(fake_frontend_response)
Nokogiri::HTML4.expects(:parse).with(fake_frontend_response).returns(fake_frontend_response)

expected_content = {
title: host_title,
html: fake_frontend_response,
}

assert_equal ContentBlockManager::GetPreviewContent.new(content_id: host_content_id).preview_content, expected_content
assert_equal expected_content, ContentBlockManager::GetPreviewContent.new(content_id: host_content_id).preview_content
end
end
end

0 comments on commit 47a773d

Please sign in to comment.