Skip to content

Commit

Permalink
Extract content/metadata extraction tests into own spec
Browse files Browse the repository at this point in the history
  • Loading branch information
csutter committed Nov 6, 2023
1 parent c9bb25d commit 61ec6f9
Show file tree
Hide file tree
Showing 3 changed files with 497 additions and 489 deletions.
85 changes: 85 additions & 0 deletions spec/models/concerns/publishing_api/content_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
RSpec.describe PublishingApi::Content do
subject(:concern_consumer) { Struct.new(:document_hash).include(described_class) }

describe "#content" do
subject(:extracted_content) { concern_consumer.new(document_hash).content }

describe "with basic top-level fields" do
let(:document_hash) do
{
details: {
description: "a",
introduction: "b",
introductory_paragraph: "c",
title: "d",
summary: "e",
body: "f",
need_to_know: "g",
more_information: "h",
},
}
end

it { is_expected.to eq("a\nb\nc\nd\ne\nf\ng\nh") }
end

describe "with contact groups" do
let(:document_hash) do
{
details: {
contact_groups: [
{ title: "x" },
{ title: "y" },
{ title: "z" },
],
},
}
end

it { is_expected.to eq("x\ny\nz") }
end

describe "with parts" do
let(:document_hash) do
{
details: {
parts: [
{
title: "Foo",
slug: "/foo",
body: [
{
content: "bar",
content_type: "text/html",
},
],
},
{
title: "Bar",
slug: "/bar",
body: [
{
content: "<blink>baz</blink>",
content_type: "text/html",
},
],
},
],
},
}
end

it { is_expected.to eq("<h1>Foo</h1>\nbar\n<h1>Bar</h1>\n<blink>baz</blink>") }
end

describe "without any fields" do
let(:document_hash) do
{
details: {},
}
end

it { is_expected.to be_blank }
end
end
end
Loading

0 comments on commit 61ec6f9

Please sign in to comment.