WIP
This commit is contained in:
parent
617c2ab725
commit
c451662178
17 changed files with 602 additions and 2 deletions
84
test/camp_api_web/controllers/link_controller_test.exs
Normal file
84
test/camp_api_web/controllers/link_controller_test.exs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
defmodule CampApiWeb.LinkControllerTest do
|
||||
use CampApiWeb.ConnCase
|
||||
|
||||
import CampApi.PaymentLinksFixtures
|
||||
alias CampApi.PaymentLinks.Link
|
||||
|
||||
@create_attrs %{
|
||||
price: "some price"
|
||||
}
|
||||
@update_attrs %{
|
||||
price: "some updated price"
|
||||
}
|
||||
@invalid_attrs %{price: nil}
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all links", %{conn: conn} do
|
||||
conn = get(conn, ~p"/api/links")
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create link" do
|
||||
test "renders link when data is valid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/links", link: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/links/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"price" => "some price"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/links", link: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update link" do
|
||||
setup [:create_link]
|
||||
|
||||
test "renders link when data is valid", %{conn: conn, link: %Link{id: id} = link} do
|
||||
conn = put(conn, ~p"/api/links/#{link}", link: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/links/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"price" => "some updated price"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, link: link} do
|
||||
conn = put(conn, ~p"/api/links/#{link}", link: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete link" do
|
||||
setup [:create_link]
|
||||
|
||||
test "deletes chosen link", %{conn: conn, link: link} do
|
||||
conn = delete(conn, ~p"/api/links/#{link}")
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, ~p"/api/links/#{link}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_link(_) do
|
||||
link = link_fixture()
|
||||
|
||||
%{link: link}
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue