chore: apply mix format to blogex test files and router

This commit is contained in:
Firehose Bot 2026-05-07 11:57:17 +01:00
parent ab7a520e9e
commit 2b7cf0a3b9
6 changed files with 70 additions and 40 deletions

View File

@ -75,11 +75,14 @@ defmodule Blogex.Router do
else else
conn conn
|> put_resp_content_type("application/json") |> put_resp_content_type("application/json")
|> send_resp(200, Jason.encode!(%{ |> send_resp(
blog: blog.blog_id(), 200,
tag: tag, Jason.encode!(%{
posts: Enum.map(posts, &post_json/1) blog: blog.blog_id(),
})) tag: tag,
posts: Enum.map(posts, &post_json/1)
})
)
end end
end end
@ -121,14 +124,17 @@ defmodule Blogex.Router do
else else
conn conn
|> put_resp_content_type("application/json") |> put_resp_content_type("application/json")
|> send_resp(200, Jason.encode!(%{ |> send_resp(
blog: blog.blog_id(), 200,
title: blog.title(), Jason.encode!(%{
posts: Enum.map(result.entries, &post_json/1), blog: blog.blog_id(),
page: result.page, title: blog.title(),
total_pages: result.total_pages, posts: Enum.map(result.entries, &post_json/1),
total_entries: result.total_entries page: result.page,
})) total_pages: result.total_pages,
total_entries: result.total_entries
})
)
end end
end end

View File

@ -22,10 +22,11 @@ defmodule Blogex.BlogTest do
end end
test "includes today-dated published posts" do test "includes today-dated published posts" do
{:ok, _} = FakeBlog.start([ {:ok, _} =
build(id: "today", date: Date.utc_today(), published: true), FakeBlog.start([
build(id: "tomorrow", date: Date.add(Date.utc_today(), 1), published: true) build(id: "today", date: Date.utc_today(), published: true),
]) build(id: "tomorrow", date: Date.add(Date.utc_today(), 1), published: true)
])
ids = FakeBlog.all_posts() |> Enum.map(& &1.id) ids = FakeBlog.all_posts() |> Enum.map(& &1.id)
@ -77,10 +78,11 @@ defmodule Blogex.BlogTest do
end end
test "excludes drafts even if tag matches" do test "excludes drafts even if tag matches" do
{:ok, _} = FakeBlog.start([ {:ok, _} =
build(id: "pub", tags: ["elixir"], published: true), FakeBlog.start([
build(id: "draft", tags: ["elixir"], published: false) build(id: "pub", tags: ["elixir"], published: true),
]) build(id: "draft", tags: ["elixir"], published: false)
])
ids = FakeBlog.posts_by_tag("elixir") |> Enum.map(& &1.id) ids = FakeBlog.posts_by_tag("elixir") |> Enum.map(& &1.id)
@ -103,10 +105,11 @@ defmodule Blogex.BlogTest do
end end
test "excludes tags only appearing on drafts" do test "excludes tags only appearing on drafts" do
{:ok, _} = FakeBlog.start([ {:ok, _} =
build(tags: ["visible"], published: true), FakeBlog.start([
build(id: "d", tags: ["hidden"], published: false) build(tags: ["visible"], published: true),
]) build(id: "d", tags: ["hidden"], published: false)
])
refute "hidden" in FakeBlog.all_tags() refute "hidden" in FakeBlog.all_tags()
end end

View File

@ -109,10 +109,11 @@ defmodule Blogex.FeedTest do
describe "XML escaping" do describe "XML escaping" do
test "escapes special characters in titles" do test "escapes special characters in titles" do
{:ok, _} = FakeBlog.start( {:ok, _} =
[build(title: "Foo & Bar <Baz>")], FakeBlog.start(
title: "A & B" [build(title: "Foo & Bar <Baz>")],
) title: "A & B"
)
xml = Feed.rss(FakeBlog, @base_url) xml = Feed.rss(FakeBlog, @base_url)

View File

@ -6,19 +6,30 @@ defmodule Blogex.RegistryTest do
defmodule AlphaBlog do defmodule AlphaBlog do
def blog_id, do: :alpha def blog_id, do: :alpha
def all_posts, do: [Blogex.Test.PostBuilder.build(id: "a1", date: ~D[2026-03-01], blog: :alpha)]
def all_posts,
do: [Blogex.Test.PostBuilder.build(id: "a1", date: ~D[2026-03-01], blog: :alpha)]
def all_tags, do: ["elixir"] def all_tags, do: ["elixir"]
def unfiltered_posts, def unfiltered_posts,
do: [ do: [
Blogex.Test.PostBuilder.build(id: "a1", date: ~D[2026-03-01], blog: :alpha), Blogex.Test.PostBuilder.build(id: "a1", date: ~D[2026-03-01], blog: :alpha),
Blogex.Test.PostBuilder.build(id: "a-draft", date: ~D[2026-03-05], blog: :alpha, published: false) Blogex.Test.PostBuilder.build(
id: "a-draft",
date: ~D[2026-03-05],
blog: :alpha,
published: false
)
] ]
end end
defmodule BetaBlog do defmodule BetaBlog do
def blog_id, do: :beta def blog_id, do: :beta
def all_posts, do: [Blogex.Test.PostBuilder.build(id: "b1", date: ~D[2026-03-15], blog: :beta)]
def all_posts,
do: [Blogex.Test.PostBuilder.build(id: "b1", date: ~D[2026-03-15], blog: :beta)]
def all_tags, do: ["devops"] def all_tags, do: ["devops"]
def unfiltered_posts, def unfiltered_posts,

View File

@ -10,15 +10,22 @@ defmodule Blogex.RouterTest do
build(id: "first-post", title: "First", tags: ["elixir"], date: ~D[2026-03-10]), build(id: "first-post", title: "First", tags: ["elixir"], date: ~D[2026-03-10]),
build(id: "second-post", title: "Second", tags: ["otp"], date: ~D[2026-02-01]), build(id: "second-post", title: "Second", tags: ["otp"], date: ~D[2026-02-01]),
build(id: "draft", published: false, date: ~D[2026-03-12]), build(id: "draft", published: false, date: ~D[2026-03-12]),
build(id: "future-post", title: "Future", tags: ["elixir"], date: ~D[2099-01-01], published: true) build(
id: "future-post",
title: "Future",
tags: ["elixir"],
date: ~D[2099-01-01],
published: true
)
] ]
{:ok, _} = FakeBlog.start(posts, {:ok, _} =
blog_id: :test, FakeBlog.start(posts,
title: "Test Blog", blog_id: :test,
description: "Test", title: "Test Blog",
base_path: "/blog/test" description: "Test",
) base_path: "/blog/test"
)
:ok :ok
end end

View File

@ -35,7 +35,9 @@ defmodule Blogex.Test.FakeBlog do
} }
case Agent.start(fn -> state end, name: __MODULE__) do case Agent.start(fn -> state end, name: __MODULE__) do
{:ok, pid} -> {:ok, pid} {:ok, pid} ->
{:ok, pid}
{:error, {:already_started, pid}} -> {:error, {:already_started, pid}} ->
Agent.update(__MODULE__, fn _ -> state end) Agent.update(__MODULE__, fn _ -> state end)
{:ok, pid} {:ok, pid}