-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
test/inmana_web/controllers/restaurants_controller_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |