WIP
This commit is contained in:
parent
617c2ab725
commit
c451662178
17 changed files with 602 additions and 2 deletions
59
test/camp_api/payment_links_test.exs
Normal file
59
test/camp_api/payment_links_test.exs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
defmodule CampApi.PaymentLinksTest do
|
||||
use CampApi.DataCase
|
||||
|
||||
alias CampApi.PaymentLinks
|
||||
|
||||
describe "links" do
|
||||
alias CampApi.PaymentLinks.Link
|
||||
|
||||
import CampApi.PaymentLinksFixtures
|
||||
|
||||
@invalid_attrs %{price: nil}
|
||||
|
||||
test "list_links/0 returns all links" do
|
||||
link = link_fixture()
|
||||
assert PaymentLinks.list_links() == [link]
|
||||
end
|
||||
|
||||
test "get_link!/1 returns the link with given id" do
|
||||
link = link_fixture()
|
||||
assert PaymentLinks.get_link!(link.id) == link
|
||||
end
|
||||
|
||||
test "create_link/1 with valid data creates a link" do
|
||||
valid_attrs = %{price: "some price"}
|
||||
|
||||
assert {:ok, %Link{} = link} = PaymentLinks.create_link(valid_attrs)
|
||||
assert link.price == "some price"
|
||||
end
|
||||
|
||||
test "create_link/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = PaymentLinks.create_link(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_link/2 with valid data updates the link" do
|
||||
link = link_fixture()
|
||||
update_attrs = %{price: "some updated price"}
|
||||
|
||||
assert {:ok, %Link{} = link} = PaymentLinks.update_link(link, update_attrs)
|
||||
assert link.price == "some updated price"
|
||||
end
|
||||
|
||||
test "update_link/2 with invalid data returns error changeset" do
|
||||
link = link_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = PaymentLinks.update_link(link, @invalid_attrs)
|
||||
assert link == PaymentLinks.get_link!(link.id)
|
||||
end
|
||||
|
||||
test "delete_link/1 deletes the link" do
|
||||
link = link_fixture()
|
||||
assert {:ok, %Link{}} = PaymentLinks.delete_link(link)
|
||||
assert_raise Ecto.NoResultsError, fn -> PaymentLinks.get_link!(link.id) end
|
||||
end
|
||||
|
||||
test "change_link/1 returns a link changeset" do
|
||||
link = link_fixture()
|
||||
assert %Ecto.Changeset{} = PaymentLinks.change_link(link)
|
||||
end
|
||||
end
|
||||
end
|
||||
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
|
||||
20
test/support/fixtures/payment_links_fixtures.ex
Normal file
20
test/support/fixtures/payment_links_fixtures.ex
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
defmodule CampApi.PaymentLinksFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `CampApi.PaymentLinks` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a link.
|
||||
"""
|
||||
def link_fixture(attrs \\ %{}) do
|
||||
{:ok, link} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
price: "some price"
|
||||
})
|
||||
|> CampApi.PaymentLinks.create_link()
|
||||
|
||||
link
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue