Skip to content

Commit

Permalink
Create controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
erickmp07 committed Oct 22, 2021
1 parent cf85037 commit c122232
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/inmana_web/controllers/restaurants_controller_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
defmodule InmanaWeb.RestaurantsControllerTest do
use InmanaWeb.ConnCase

describe "create/2" do
test "when all params are valid, creates the restaurant", %{conn: connection} do
params = %{name: "Restaurant name", email: "[email protected]"}

response =
connection
|> post(Routes.restaurants_path(connection, :create, params))
|> json_response(:created)

assert %{
"message" => "Restaurant created!",
"restaurant" => %{
"email" => "[email protected]",
"id" => _id,
"name" => "Restaurant name"
}
} = response
end

test "when there are invalid params, returns an error", %{conn: connection} do
params = %{email: "[email protected]"}
expected_response = %{"message" => %{"name" => ["can't be blank"]}}

response =
connection
|> post(Routes.restaurants_path(connection, :create, params))
|> json_response(:bad_request)

assert response == expected_response
end
end
end

0 comments on commit c122232

Please sign in to comment.