2022-10-25 04:04:45 +13:00
|
|
|
defmodule AshBlogTest do
|
|
|
|
use ExUnit.Case
|
|
|
|
|
2022-10-29 04:21:13 +13:00
|
|
|
alias AshBlog.Test.Post
|
|
|
|
|
|
|
|
setup do
|
|
|
|
on_exit(fn ->
|
|
|
|
File.rm_rf!("priv/blog")
|
|
|
|
end)
|
|
|
|
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "creating a blog post" do
|
|
|
|
test "a blog post can be created" do
|
|
|
|
assert %{title: "first\"", body: "the body"} = Post.create!("first\"", "the body")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "reading blog posts" do
|
|
|
|
test "blog posts can be listed" do
|
|
|
|
Post.create!("first\"", "the body")
|
|
|
|
assert [%{title: "first\"", body: "the body"}] = Post.read!()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-01 20:11:06 +13:00
|
|
|
describe "slug" do
|
|
|
|
test "a slug is auto generated" do
|
2023-02-01 18:49:57 +13:00
|
|
|
Post.create!("first", "the body")
|
2022-11-01 20:11:06 +13:00
|
|
|
Post.read!()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-29 04:21:13 +13:00
|
|
|
describe "updating blog posts" do
|
|
|
|
test "blog posts can be published" do
|
|
|
|
post = Post.create!("first\"", "the body")
|
|
|
|
assert %{state: :published} = Post.publish!(post)
|
|
|
|
assert [%{state: :published, title: "first\"", body: "the body"}] = Post.read!()
|
2022-10-29 06:57:02 +13:00
|
|
|
assert [_] = Path.wildcard("priv/blog/**/*.md")
|
2022-10-29 04:21:13 +13:00
|
|
|
end
|
|
|
|
|
|
|
|
test "blog posts can be archived" do
|
|
|
|
post = Post.create!("first\"", "the body")
|
|
|
|
assert %{state: :published} = Post.publish!(post)
|
|
|
|
assert [%{state: :published, title: "first\"", body: "the body"} = post] = Post.read!()
|
2022-10-29 06:57:02 +13:00
|
|
|
assert [_] = Path.wildcard("priv/blog/**/*.md")
|
2022-10-29 04:21:13 +13:00
|
|
|
assert %{state: :archived} = Post.archive!(post)
|
2022-10-29 06:57:02 +13:00
|
|
|
assert [_] = Path.wildcard("priv/blog/archived/**/*.md")
|
2022-10-29 04:21:13 +13:00
|
|
|
end
|
2022-10-25 04:04:45 +13:00
|
|
|
end
|
|
|
|
end
|