defmodule FirehoseWeb.BlogControllerTest do use FirehoseWeb.ConnCase, async: false # Content churns; the behavior under test does not. Pick deterministically # from the compiled posts instead of pinning slugs - the pinned "hello-world" # post was deleted in 1709cb7 and ten tests silently rotted with it. defp a_draft_post do Enum.find(Firehose.EngineeringBlog.all_posts(), &(&1.published == false)) || raise "no draft (published: false) engineering post to exercise status banners" end defp a_live_post do Enum.find(Firehose.EngineeringBlog.all_posts(), &(Blogex.Post.visibility(&1) == :live)) || raise "no live engineering post to exercise og meta tags" end describe "GET /blog/:blog_id (index) - date filtering" do test "does not show future-dated posts", %{conn: conn} do html = conn |> get(~p"/blog/engineering") |> html_response(200) refute html =~ "Future Test Post" end end describe "GET /blog/:blog_id/:slug (show) - date filtering" do test "still shows a future-dated post by slug", %{conn: conn} do assert conn |> get(~p"/blog/engineering/future-test-post") |> html_response(200) =~ "Future Test Post" end end describe "GET /blog/:blog_id/tag/:tag - date filtering" do test "excludes future-dated posts from tag page", %{conn: conn} do html = conn |> get(~p"/blog/engineering/tag/test") |> html_response(200) refute html =~ "Future Test Post" end end describe "GET /blog/:blog_id/:slug - status banners" do setup :register_and_log_in_user test "authenticated user sees draft banner on draft post", %{conn: conn} do post = a_draft_post() response = conn |> get(~p"/blog/engineering/#{post.id}") assert html_response(response, 200) =~ "Draft" assert response.resp_body =~ "not published" end test "authenticated user sees scheduled banner on future post", %{conn: conn} do response = conn |> get(~p"/blog/engineering/future-test-post") |> html_response(200) assert response =~ "scheduled for" assert response =~ "January 01, 2099" end test "authenticated user sees no banner on live post", %{conn: conn} do response = conn |> get(~p"/blog/engineering/why-firehose") |> html_response(200) refute response =~ "Draft" refute response =~ "scheduled for" end end describe "GET /blog/:blog_id/:slug - no banners for unauthenticated" do test "unauthenticated user sees no banner on draft post", %{conn: conn} do post = a_draft_post() response = conn |> get(~p"/blog/engineering/#{post.id}") |> html_response(200) refute response =~ "post-status-banner" end test "unauthenticated user sees no banner on future post", %{conn: conn} do response = conn |> get(~p"/blog/engineering/future-test-post") |> html_response(200) refute response =~ "post-status-banner" end end describe "GET /blog/:blog_id/:slug - Open Graph meta tags" do test "meta tags include og_title", %{conn: conn} do post = a_live_post() response = conn |> get(~p"/blog/engineering/#{post.id}") |> html_response(200) assert response =~ ~s( get(~p"/blog/engineering/#{post.id}") |> html_response(200) assert response =~ ~s( get(~p"/blog/engineering/#{post.id}") |> html_response(200) assert response =~ ~s( get(~p"/blog/engineering/#{post.id}") |> html_response(200) assert response =~ ~s( get(~p"/blog/engineering/why-firehose") |> html_response(200) assert response =~ ~s( get(~p"/blog/engineering/#{post.id}") |> html_response(200) assert response =~ ~s( get(~p"/blog/engineering") |> html_response(200) assert response =~ ~s( get(~p"/blog/engineering") |> html_response(200) assert response =~ ~s( get(~p"/blog/engineering") |> html_response(200) assert response =~ ~s(