2021-08-14 23:36:10 +02:00
|
|
|
require "../spec_helper"
|
|
|
|
|
|
|
|
include Nodes
|
|
|
|
|
|
|
|
describe PageConverter do
|
2021-10-04 00:14:46 +02:00
|
|
|
it "sets the page title" do
|
|
|
|
title = "Hello, world!"
|
2021-09-04 23:15:30 +02:00
|
|
|
paragraph_json = <<-JSON
|
2021-08-14 23:36:10 +02:00
|
|
|
[
|
|
|
|
{
|
2021-10-04 00:14:46 +02:00
|
|
|
"text": "#{title}",
|
2021-08-14 23:36:10 +02:00
|
|
|
"type": "H3",
|
|
|
|
"markups": [],
|
|
|
|
"iframe": null,
|
|
|
|
"layout": null,
|
|
|
|
"metadata": null
|
|
|
|
}
|
|
|
|
]
|
|
|
|
JSON
|
2022-06-17 19:26:35 +02:00
|
|
|
data_json = default_post_json(title, paragraph_json)
|
|
|
|
data = PostResponse::Post.from_json(data_json)
|
2021-08-14 23:36:10 +02:00
|
|
|
|
2021-09-04 23:15:30 +02:00
|
|
|
page = PageConverter.new.convert(data)
|
2021-08-14 23:36:10 +02:00
|
|
|
|
2021-10-04 00:14:46 +02:00
|
|
|
page.title.should eq title
|
2021-08-14 23:36:10 +02:00
|
|
|
end
|
|
|
|
|
2021-09-04 23:15:30 +02:00
|
|
|
it "sets the author" do
|
2022-06-17 19:26:35 +02:00
|
|
|
post_json = <<-JSON
|
2021-09-04 23:15:30 +02:00
|
|
|
{
|
2022-06-17 19:26:35 +02:00
|
|
|
"title": "This is a story",
|
|
|
|
"createdAt": 0,
|
|
|
|
"creator": {
|
|
|
|
"id": "abc123",
|
|
|
|
"name": "Author"
|
|
|
|
},
|
|
|
|
"content": {
|
|
|
|
"bodyModel": {
|
|
|
|
"paragraphs": []
|
2021-09-04 23:15:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSON
|
2022-06-17 19:26:35 +02:00
|
|
|
post = PostResponse::Post.from_json(post_json)
|
2021-09-04 23:15:30 +02:00
|
|
|
|
2022-06-17 19:26:35 +02:00
|
|
|
page = PageConverter.new.convert(post)
|
2021-09-04 23:15:30 +02:00
|
|
|
|
2021-09-15 21:44:28 +02:00
|
|
|
page.author.name.should eq "Author"
|
|
|
|
page.author.id.should eq "abc123"
|
2021-09-04 23:15:30 +02:00
|
|
|
end
|
|
|
|
|
2021-09-04 23:32:27 +02:00
|
|
|
it "sets the publish date/time" do
|
2022-06-17 19:26:35 +02:00
|
|
|
post_json = <<-JSON
|
2021-09-04 23:32:27 +02:00
|
|
|
{
|
2022-06-17 19:26:35 +02:00
|
|
|
"title": "This is a story",
|
|
|
|
"createdAt": 1000,
|
|
|
|
"creator": {
|
|
|
|
"id": "abc123",
|
|
|
|
"name": "Author"
|
|
|
|
},
|
|
|
|
"content": {
|
|
|
|
"bodyModel": {
|
|
|
|
"paragraphs": []
|
2021-09-04 23:32:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSON
|
2022-06-17 19:26:35 +02:00
|
|
|
post = PostResponse::Post.from_json(post_json)
|
2021-09-04 23:32:27 +02:00
|
|
|
|
2022-06-17 19:26:35 +02:00
|
|
|
page = PageConverter.new.convert(post)
|
2021-09-04 23:32:27 +02:00
|
|
|
|
|
|
|
page.created_at.should eq Time.utc(1970, 1, 1, 0, 0, 1)
|
|
|
|
end
|
|
|
|
|
2021-10-04 00:14:46 +02:00
|
|
|
it "calls converts the remaining paragraph content" do
|
|
|
|
title = "Title"
|
2021-09-04 23:15:30 +02:00
|
|
|
paragraph_json = <<-JSON
|
2021-08-14 23:36:10 +02:00
|
|
|
[
|
|
|
|
{
|
2021-10-04 00:14:46 +02:00
|
|
|
"text": "#{title}",
|
2021-08-14 23:36:10 +02:00
|
|
|
"type": "H3",
|
|
|
|
"markups": [],
|
|
|
|
"iframe": null,
|
|
|
|
"layout": null,
|
|
|
|
"metadata": null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"text": "Content",
|
|
|
|
"type": "P",
|
|
|
|
"markups": [],
|
|
|
|
"iframe": null,
|
|
|
|
"layout": null,
|
|
|
|
"metadata": null
|
|
|
|
}
|
|
|
|
]
|
|
|
|
JSON
|
2022-06-17 19:26:35 +02:00
|
|
|
post_json = default_post_json(title, paragraph_json)
|
|
|
|
data = PostResponse::Post.from_json(post_json)
|
2021-08-14 23:36:10 +02:00
|
|
|
|
2021-09-04 23:15:30 +02:00
|
|
|
page = PageConverter.new.convert(data)
|
2021-08-14 23:36:10 +02:00
|
|
|
|
|
|
|
page.nodes.should eq [
|
|
|
|
Paragraph.new([
|
|
|
|
Text.new("Content"),
|
|
|
|
] of Child),
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
2021-09-04 23:15:30 +02:00
|
|
|
|
2021-10-04 00:14:46 +02:00
|
|
|
def default_paragraph_json
|
|
|
|
"[]"
|
|
|
|
end
|
|
|
|
|
2022-06-17 19:26:35 +02:00
|
|
|
def default_post_json(
|
2021-10-04 00:14:46 +02:00
|
|
|
title : String = "This is a story",
|
|
|
|
paragraph_json : String = default_paragraph_json
|
|
|
|
)
|
2021-09-04 23:15:30 +02:00
|
|
|
<<-JSON
|
|
|
|
{
|
2022-06-17 19:26:35 +02:00
|
|
|
"title": "#{title}",
|
|
|
|
"createdAt": 1628974309758,
|
|
|
|
"creator": {
|
|
|
|
"id": "abc123",
|
|
|
|
"name": "Author"
|
|
|
|
},
|
|
|
|
"content": {
|
|
|
|
"bodyModel": {
|
|
|
|
"paragraphs": #{paragraph_json}
|
2021-09-04 23:15:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSON
|
|
|
|
end
|