-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In some circumstances (such as guides), instances can be over multiple pages, so we can’t reliably get the number of instances from the preview, so we need to get the metadata directly from the Publishing API
- Loading branch information
Showing
2 changed files
with
20 additions
and
6 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
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 |
---|---|---|
|
@@ -32,6 +32,19 @@ class ContentBlockManager::GetPreviewContentTest < ActiveSupport::TestCase | |
let(:block_to_preview) do | ||
build(:content_block_edition, :email_address, document:, details: { "email_address" => "[email protected]" }, id: 1) | ||
end | ||
let(:metadata_response) do | ||
stub(:response, parsed_content: { | ||
"results" => [ | ||
{ "instances" => 2 }, | ||
], | ||
}) | ||
end | ||
|
||
before do | ||
Services.publishing_api.expects(:get_content_by_embedded_document) | ||
.with(block_to_preview.document.content_id, { host_content_id: }) | ||
.returns(metadata_response) | ||
end | ||
|
||
describe "#for_content_id" do | ||
setup do | ||
|
@@ -57,16 +70,12 @@ class ContentBlockManager::GetPreviewContentTest < ActiveSupport::TestCase | |
it "returns the count of instances" do | ||
Net::HTTP.expects(:get).with(URI(Plek.website_root + host_base_path)).returns(fake_frontend_response) | ||
|
||
expected_content = { | ||
instances_count: 1, | ||
} | ||
|
||
actual_content = ContentBlockManager::GetPreviewContent.for_content_id( | ||
content_id: host_content_id, | ||
content_block_edition: block_to_preview, | ||
) | ||
|
||
assert_equal expected_content[:instances_count], actual_content.instances_count | ||
assert_equal 2, actual_content.instances_count | ||
end | ||
|
||
it "returns the preview html" do | ||
|