ash_blog/test/ash_blog_test.exs

52 lines
1.4 KiB
Elixir
Raw Permalink Normal View History

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
describe "slug" do
test "a slug is auto generated" do
Post.create!("first", "the body")
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