Goal: have a personal blog, and try out another point in the 'modular app design with elixir' space. Designing OTP systems with elixir had some interesting ideas.
76 lines
2.1 KiB
Elixir
76 lines
2.1 KiB
Elixir
defmodule Blogex.SEOTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
import Blogex.Test.PostBuilder
|
|
alias Blogex.SEO
|
|
|
|
defmodule StubBlog do
|
|
def base_path, do: "/blog/eng"
|
|
end
|
|
|
|
@base_url "https://example.com"
|
|
|
|
describe "meta_tags/3" do
|
|
test "includes post title and description" do
|
|
post = build(title: "My Title", description: "My Description")
|
|
|
|
meta = SEO.meta_tags(post, @base_url, StubBlog)
|
|
|
|
assert meta.title == "My Title"
|
|
assert meta.description == "My Description"
|
|
end
|
|
|
|
test "builds canonical URL from base_url and post id" do
|
|
post = build(id: "hello-world")
|
|
|
|
meta = SEO.meta_tags(post, @base_url, StubBlog)
|
|
|
|
assert meta.og_url == "https://example.com/blog/eng/hello-world"
|
|
end
|
|
|
|
test "includes OpenGraph article metadata" do
|
|
post = build(author: "Alice", date: ~D[2026-06-15], tags: ["a", "b"])
|
|
|
|
meta = SEO.meta_tags(post, @base_url, StubBlog)
|
|
|
|
assert meta.og_type == "article"
|
|
assert meta.article_author == "Alice"
|
|
assert meta.article_published_time == "2026-06-15"
|
|
assert meta.article_tags == ["a", "b"]
|
|
end
|
|
end
|
|
|
|
describe "sitemap/2" do
|
|
defmodule BlogA do
|
|
def base_path, do: "/blog/a"
|
|
def all_posts, do: [Blogex.Test.PostBuilder.build(id: "post-a", date: ~D[2026-01-01])]
|
|
end
|
|
|
|
defmodule BlogB do
|
|
def base_path, do: "/blog/b"
|
|
def all_posts, do: [Blogex.Test.PostBuilder.build(id: "post-b", date: ~D[2026-02-01])]
|
|
end
|
|
|
|
test "includes URLs from all blog modules" do
|
|
xml = SEO.sitemap([BlogA, BlogB], @base_url)
|
|
|
|
assert xml =~ "<loc>https://example.com/blog/a/post-a</loc>"
|
|
assert xml =~ "<loc>https://example.com/blog/b/post-b</loc>"
|
|
end
|
|
|
|
test "produces valid sitemap XML" do
|
|
xml = SEO.sitemap([BlogA], @base_url)
|
|
|
|
assert xml =~ ~s(<?xml version="1.0")
|
|
assert xml =~ ~s(<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">)
|
|
assert xml =~ "</urlset>"
|
|
end
|
|
|
|
test "includes lastmod from post date" do
|
|
xml = SEO.sitemap([BlogA], @base_url)
|
|
|
|
assert xml =~ "<lastmod>2026-01-01</lastmod>"
|
|
end
|
|
end
|
|
end
|