Skip to content

Commit

Permalink
test: api error case
Browse files Browse the repository at this point in the history
  • Loading branch information
sorax committed Nov 27, 2023
1 parent 3938883 commit 6f4dd11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/radiator_web/controllers/api/outline_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ defmodule RadiatorWeb.Api.OutlineController do
def create(conn, _params) do
conn
|> put_resp_content_type("application/json")
|> send_resp(500, Jason.encode!(%{error: "params"}))
|> send_resp(400, Jason.encode!(%{error: "params"}))
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ defmodule RadiatorWeb.Api.OutlineControllerTest do
alias Radiator.Outline

describe "POST /api/v1/outline" do
test "creates a node", %{conn: conn} do
test "creates a node if content is present", %{conn: conn} do
body = %{"content" => "new node content"}
conn = post(conn, ~p"/api/v1/outline", body)

%{"uuid" => uuid} = json_response(conn, 200)

assert %{content: "new node content"} = Outline.get_node!(uuid)
end

test "can't create node when content is missing", %{conn: conn} do
conn = post(conn, ~p"/api/v1/outline", nil)

assert %{"error" => "params"} = json_response(conn, 400)
end
end
end

0 comments on commit 6f4dd11

Please sign in to comment.