Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring #26

Merged
merged 8 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
checkpoint
  • Loading branch information
dogweather committed Dec 11, 2023
commit a47abad0774ff2135e789b81e5f49835127f9f89
171 changes: 8 additions & 163 deletions test/news/date_modified_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,175 +2,20 @@ alias News.Test
alias News.DateModified



defmodule News.DateModifiedTest do
@moduledoc false
use ExUnit.Case
doctest News.DateModified


@yoast_schema_org """
{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": "https://probatestars.com/#organization",
"name": "Probate Stars",
"url": "https://probatestars.com/",
"sameAs": [
"https://www.facebook.com/Probate-Stars-104203374358153/"
],
"logo": {
"@type": "ImageObject",
"@id": "https://probatestars.com/#logo",
"inLanguage": "en-US",
"url": "https://probatestars.com/wp-content/uploads/2020/03/profil-facebook.jpg",
"width": 180,
"height": 180,
"caption": "Probate Stars"
},
"image": {
"@id": "https://probatestars.com/#logo"
}
},
{
"@type": "WebSite",
"@id": "https://probatestars.com/#website",
"url": "https://probatestars.com/",
"name": "Probate Stars",
"description": "Find a Probate Lawyer in all 50 States",
"publisher": {
"@id": "https://probatestars.com/#organization"
},
"potentialAction": [
{
"@type": "SearchAction",
"target": "https://probatestars.com/?s={search_term_string}",
"query-input": "required name=search_term_string"
}
],
"inLanguage": "en-US"
},
{
"@type": "ImageObject",
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#primaryimage",
"inLanguage": "en-US",
"url": "https://probatestars.com/wp-content/uploads/2019/12/texas-15.jpg",
"width": 1999,
"height": 1333,
"caption": "Texas trust protector fiduciary"
},
{
"@type": "WebPage",
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#webpage",
"url": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/",
"name": "Texas Trust Protector Has No Fiduciary Duty to Settlor | Probate Stars",
"isPartOf": {
"@id": "https://probatestars.com/#website"
},
"primaryImageOfPage": {
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#primaryimage"
},
"datePublished": "2020-05-19T16:20:34+00:00",
"dateModified": "2020-05-19T16:20:34+00:00",
"description": "Under Texas law a trust protector has no fiduciary duty to the settlor of the trust, but may have one to the trustee or beneficiaires.",
"inLanguage": "en-US",
"potentialAction": [
{
"@type": "ReadAction",
"target": [
"https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/"
]
}
]
},
{
"@type": "Article",
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#article",
"isPartOf": {
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#webpage"
},
"author": {
"@id": "https://probatestars.com/#/schema/person/0d4a38ec0c5ba42eb7b63278e6501199"
},
"headline": "Texas Trust Protector Has No Fiduciary Duty to Settlor",
"datePublished": "2020-05-19T16:20:34+00:00",
"dateModified": "2020-05-19T16:20:34+00:00",
"mainEntityOfPage": {
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#webpage"
},
"publisher": {
"@id": "https://probatestars.com/#organization"
},
"image": {
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#primaryimage"
},
"keywords": "Trust Litigation",
"articleSection": "Texas",
"inLanguage": "en-US"
},
{
"@type": "Person",
"@id": "https://probatestars.com/#/schema/person/0d4a38ec0c5ba42eb7b63278e6501199",
"name": "Jeffrey Skatoff",
"image": {
"@type": "ImageObject",
"@id": "https://probatestars.com/#personlogo",
"inLanguage": "en-US",
"url": "https://secure.gravatar.com/avatar/a12f92f4f11563eb702b172299c7aa93?s=96&d=mm&r=g",
"caption": "Jeffrey Skatoff"
},
"description": "Jeffrey Skatoff has been an attorney for over 30 years, practicing in the areas of estate planning, probate, estate litigation, and guardianship litigation.",
"sameAs": [
"https://www.facebook.com/jeffrey.skatoff"
]
}
]
}
"""

test "parse/1 returns the date from a Yoast-style schema.org" do
document = "<html><script type='application/ld+json'>#{@yoast_schema_org}</script></html>"

assert DateModified.parse(document) == ~D[2020-05-19]
end



@test_cases [
%{
html: "<html></html>",
date: nil,
},
%{
html: "<html><script type='application/ld+json'>{\"dateBorn\": \"2020-01-01\"}</script></html>",
date: nil,
},
%{
html: "<html><script type='application/ld+json'>{\"datePublished\": \"2020-01-01\"}</script></html>",
date: "2020-01-01",
},
%{
html: "<html><script type='application/ld+json'>{\"datePublished\": \"2020-01-01\", \"dateModified\": \"2020-01-02\"}</script></html>",
date: "2020-01-02",
},
%{
html: "<html><script type='application/ld+json'>{\"dateModified\": \"2020-01-01\"}</script></html>",
date: "2020-01-01",
},
%{
html: "<html><script type='application/ld+json'>{\"dateModified\": \"Fri, 2023-08-25 21:16:28\"}</script></html>",
date: "2023-08-25"
},
%{
html: "<html><script type='application/ld+json'>{\"dateModified\": \"2023-09-20T16:20:21-05:00\"}</script></html>",
date: "2023-09-20"
},
%{
html: "<html><head><meta property=\"article:published_time\" content=\"2020-05-19T16:20:34+00:00\"></head></html>",
date: "2020-05-19"
},
%{date: nil, html: "<html></html>"},
%{date: nil, html: "<html><script type='application/ld+json'>{\"dateBorn\": \"2020-01-01\"}</script></html>"},
%{date: "2020-01-01", html: "<html><script type='application/ld+json'>{\"datePublished\": \"2020-01-01\"}</script></html>"},
%{date: "2020-01-02", html: "<html><script type='application/ld+json'>{\"datePublished\": \"2020-01-01\", \"dateModified\": \"2020-01-02\"}</script></html>"},
%{date: "2020-01-01", html: "<html><script type='application/ld+json'>{\"dateModified\": \"2020-01-01\"}</script></html>"},
%{date: "2023-08-25", html: "<html><script type='application/ld+json'>{\"dateModified\": \"Fri, 2023-08-25 21:16:28\"}</script></html>"},
%{date: "2023-09-20", html: "<html><script type='application/ld+json'>{\"dateModified\": \"2023-09-20T16:20:21-05:00\"}</script></html>"},
%{date: "2020-05-19", html: "<html><head><meta property=\"article:published_time\" content=\"2020-05-19T16:20:34+00:00\"></head></html>"}
]

# Create and run a test for each of the @test_cases
Expand Down
134 changes: 134 additions & 0 deletions test/news/date_modified_yoast_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
alias News.DateModified


defmodule News.YoastTest do
@moduledoc false
use ExUnit.Case

@yoast_schema_org """
{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Organization",
"@id": "https://probatestars.com/#organization",
"name": "Probate Stars",
"url": "https://probatestars.com/",
"sameAs": [
"https://www.facebook.com/Probate-Stars-104203374358153/"
],
"logo": {
"@type": "ImageObject",
"@id": "https://probatestars.com/#logo",
"inLanguage": "en-US",
"url": "https://probatestars.com/wp-content/uploads/2020/03/profil-facebook.jpg",
"width": 180,
"height": 180,
"caption": "Probate Stars"
},
"image": {
"@id": "https://probatestars.com/#logo"
}
},
{
"@type": "WebSite",
"@id": "https://probatestars.com/#website",
"url": "https://probatestars.com/",
"name": "Probate Stars",
"description": "Find a Probate Lawyer in all 50 States",
"publisher": {
"@id": "https://probatestars.com/#organization"
},
"potentialAction": [
{
"@type": "SearchAction",
"target": "https://probatestars.com/?s={search_term_string}",
"query-input": "required name=search_term_string"
}
],
"inLanguage": "en-US"
},
{
"@type": "ImageObject",
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#primaryimage",
"inLanguage": "en-US",
"url": "https://probatestars.com/wp-content/uploads/2019/12/texas-15.jpg",
"width": 1999,
"height": 1333,
"caption": "Texas trust protector fiduciary"
},
{
"@type": "WebPage",
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#webpage",
"url": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/",
"name": "Texas Trust Protector Has No Fiduciary Duty to Settlor | Probate Stars",
"isPartOf": {
"@id": "https://probatestars.com/#website"
},
"primaryImageOfPage": {
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#primaryimage"
},
"datePublished": "2020-05-19T16:20:34+00:00",
"dateModified": "2020-05-19T16:20:34+00:00",
"description": "Under Texas law a trust protector has no fiduciary duty to the settlor of the trust, but may have one to the trustee or beneficiaires.",
"inLanguage": "en-US",
"potentialAction": [
{
"@type": "ReadAction",
"target": [
"https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/"
]
}
]
},
{
"@type": "Article",
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#article",
"isPartOf": {
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#webpage"
},
"author": {
"@id": "https://probatestars.com/#/schema/person/0d4a38ec0c5ba42eb7b63278e6501199"
},
"headline": "Texas Trust Protector Has No Fiduciary Duty to Settlor",
"datePublished": "2020-05-19T16:20:34+00:00",
"dateModified": "2020-05-19T16:20:34+00:00",
"mainEntityOfPage": {
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#webpage"
},
"publisher": {
"@id": "https://probatestars.com/#organization"
},
"image": {
"@id": "https://probatestars.com/texas-trust-protector-has-no-fiduciary-duty-to-settlor/#primaryimage"
},
"keywords": "Trust Litigation",
"articleSection": "Texas",
"inLanguage": "en-US"
},
{
"@type": "Person",
"@id": "https://probatestars.com/#/schema/person/0d4a38ec0c5ba42eb7b63278e6501199",
"name": "Jeffrey Skatoff",
"image": {
"@type": "ImageObject",
"@id": "https://probatestars.com/#personlogo",
"inLanguage": "en-US",
"url": "https://secure.gravatar.com/avatar/a12f92f4f11563eb702b172299c7aa93?s=96&d=mm&r=g",
"caption": "Jeffrey Skatoff"
},
"description": "Jeffrey Skatoff has been an attorney for over 30 years, practicing in the areas of estate planning, probate, estate litigation, and guardianship litigation.",
"sameAs": [
"https://www.facebook.com/jeffrey.skatoff"
]
}
]
}
"""

test "parse/1 returns the date from a Yoast-style schema.org" do
document = "<html><script type='application/ld+json'>#{@yoast_schema_org}</script></html>"

assert DateModified.parse(document) == ~D[2020-05-19]
end
end