update
This commit is contained in:
parent
e2967f68b2
commit
ef2a6c41b4
39 changed files with 2349 additions and 30 deletions
26
test/support/fixtures/api_keys_fixtures.ex
Normal file
26
test/support/fixtures/api_keys_fixtures.ex
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
defmodule Zoeyscomputer.ApiKeysFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Zoeyscomputer.ApiKeys` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a unique api_key token.
|
||||
"""
|
||||
def unique_api_key_token, do: "some token#{System.unique_integer([:positive])}"
|
||||
|
||||
@doc """
|
||||
Generate a api_key.
|
||||
"""
|
||||
def api_key_fixture(attrs \\ %{}) do
|
||||
{:ok, api_key} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
name: "some name",
|
||||
token: unique_api_key_token()
|
||||
})
|
||||
|> Zoeyscomputer.ApiKeys.create_api_key()
|
||||
|
||||
api_key
|
||||
end
|
||||
end
|
||||
20
test/support/fixtures/images_fixtures.ex
Normal file
20
test/support/fixtures/images_fixtures.ex
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
defmodule Zoeyscomputer.ImagesFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Zoeyscomputer.Images` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a image.
|
||||
"""
|
||||
def image_fixture(attrs \\ %{}) do
|
||||
{:ok, image} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
file: "some file"
|
||||
})
|
||||
|> Zoeyscomputer.Images.create_image()
|
||||
|
||||
image
|
||||
end
|
||||
end
|
||||
61
test/zoeyscomputer/api_keys_test.exs
Normal file
61
test/zoeyscomputer/api_keys_test.exs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
defmodule Zoeyscomputer.ApiKeysTest do
|
||||
use Zoeyscomputer.DataCase
|
||||
|
||||
alias Zoeyscomputer.ApiKeys
|
||||
|
||||
describe "api_keys" do
|
||||
alias Zoeyscomputer.ApiKeys.ApiKey
|
||||
|
||||
import Zoeyscomputer.ApiKeysFixtures
|
||||
|
||||
@invalid_attrs %{name: nil, token: nil}
|
||||
|
||||
test "list_api_keys/0 returns all api_keys" do
|
||||
api_key = api_key_fixture()
|
||||
assert ApiKeys.list_api_keys() == [api_key]
|
||||
end
|
||||
|
||||
test "get_api_key!/1 returns the api_key with given id" do
|
||||
api_key = api_key_fixture()
|
||||
assert ApiKeys.get_api_key!(api_key.id) == api_key
|
||||
end
|
||||
|
||||
test "create_api_key/1 with valid data creates a api_key" do
|
||||
valid_attrs = %{name: "some name", token: "some token"}
|
||||
|
||||
assert {:ok, %ApiKey{} = api_key} = ApiKeys.create_api_key(valid_attrs)
|
||||
assert api_key.name == "some name"
|
||||
assert api_key.token == "some token"
|
||||
end
|
||||
|
||||
test "create_api_key/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = ApiKeys.create_api_key(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_api_key/2 with valid data updates the api_key" do
|
||||
api_key = api_key_fixture()
|
||||
update_attrs = %{name: "some updated name", token: "some updated token"}
|
||||
|
||||
assert {:ok, %ApiKey{} = api_key} = ApiKeys.update_api_key(api_key, update_attrs)
|
||||
assert api_key.name == "some updated name"
|
||||
assert api_key.token == "some updated token"
|
||||
end
|
||||
|
||||
test "update_api_key/2 with invalid data returns error changeset" do
|
||||
api_key = api_key_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = ApiKeys.update_api_key(api_key, @invalid_attrs)
|
||||
assert api_key == ApiKeys.get_api_key!(api_key.id)
|
||||
end
|
||||
|
||||
test "delete_api_key/1 deletes the api_key" do
|
||||
api_key = api_key_fixture()
|
||||
assert {:ok, %ApiKey{}} = ApiKeys.delete_api_key(api_key)
|
||||
assert_raise Ecto.NoResultsError, fn -> ApiKeys.get_api_key!(api_key.id) end
|
||||
end
|
||||
|
||||
test "change_api_key/1 returns a api_key changeset" do
|
||||
api_key = api_key_fixture()
|
||||
assert %Ecto.Changeset{} = ApiKeys.change_api_key(api_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
59
test/zoeyscomputer/images_test.exs
Normal file
59
test/zoeyscomputer/images_test.exs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
defmodule Zoeyscomputer.ImagesTest do
|
||||
use Zoeyscomputer.DataCase
|
||||
|
||||
alias Zoeyscomputer.Images
|
||||
|
||||
describe "images" do
|
||||
alias Zoeyscomputer.Images.Image
|
||||
|
||||
import Zoeyscomputer.ImagesFixtures
|
||||
|
||||
@invalid_attrs %{file: nil}
|
||||
|
||||
test "list_images/0 returns all images" do
|
||||
image = image_fixture()
|
||||
assert Images.list_images() == [image]
|
||||
end
|
||||
|
||||
test "get_image!/1 returns the image with given id" do
|
||||
image = image_fixture()
|
||||
assert Images.get_image!(image.id) == image
|
||||
end
|
||||
|
||||
test "create_image/1 with valid data creates a image" do
|
||||
valid_attrs = %{file: "some file"}
|
||||
|
||||
assert {:ok, %Image{} = image} = Images.create_image(valid_attrs)
|
||||
assert image.file == "some file"
|
||||
end
|
||||
|
||||
test "create_image/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Images.create_image(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_image/2 with valid data updates the image" do
|
||||
image = image_fixture()
|
||||
update_attrs = %{file: "some updated file"}
|
||||
|
||||
assert {:ok, %Image{} = image} = Images.update_image(image, update_attrs)
|
||||
assert image.file == "some updated file"
|
||||
end
|
||||
|
||||
test "update_image/2 with invalid data returns error changeset" do
|
||||
image = image_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Images.update_image(image, @invalid_attrs)
|
||||
assert image == Images.get_image!(image.id)
|
||||
end
|
||||
|
||||
test "delete_image/1 deletes the image" do
|
||||
image = image_fixture()
|
||||
assert {:ok, %Image{}} = Images.delete_image(image)
|
||||
assert_raise Ecto.NoResultsError, fn -> Images.get_image!(image.id) end
|
||||
end
|
||||
|
||||
test "change_image/1 returns a image changeset" do
|
||||
image = image_fixture()
|
||||
assert %Ecto.Changeset{} = Images.change_image(image)
|
||||
end
|
||||
end
|
||||
end
|
||||
84
test/zoeyscomputer_web/controllers/image_controller_test.exs
Normal file
84
test/zoeyscomputer_web/controllers/image_controller_test.exs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
defmodule ZoeyscomputerWeb.ImageControllerTest do
|
||||
use ZoeyscomputerWeb.ConnCase
|
||||
|
||||
import Zoeyscomputer.ImagesFixtures
|
||||
|
||||
alias Zoeyscomputer.Images.Image
|
||||
|
||||
@create_attrs %{
|
||||
file: "some file"
|
||||
}
|
||||
@update_attrs %{
|
||||
file: "some updated file"
|
||||
}
|
||||
@invalid_attrs %{file: nil}
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all images", %{conn: conn} do
|
||||
conn = get(conn, ~p"/api/images")
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create image" do
|
||||
test "renders image when data is valid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/images", image: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/images/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"file" => "some file"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/images", image: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update image" do
|
||||
setup [:create_image]
|
||||
|
||||
test "renders image when data is valid", %{conn: conn, image: %Image{id: id} = image} do
|
||||
conn = put(conn, ~p"/api/images/#{image}", image: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/images/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"file" => "some updated file"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, image: image} do
|
||||
conn = put(conn, ~p"/api/images/#{image}", image: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete image" do
|
||||
setup [:create_image]
|
||||
|
||||
test "deletes chosen image", %{conn: conn, image: image} do
|
||||
conn = delete(conn, ~p"/api/images/#{image}")
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, ~p"/api/images/#{image}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_image(_) do
|
||||
image = image_fixture()
|
||||
%{image: image}
|
||||
end
|
||||
end
|
||||
113
test/zoeyscomputer_web/live/api_key_live_test.exs
Normal file
113
test/zoeyscomputer_web/live/api_key_live_test.exs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
defmodule ZoeyscomputerWeb.ApiKeyLiveTest do
|
||||
use ZoeyscomputerWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import Zoeyscomputer.ApiKeysFixtures
|
||||
|
||||
@create_attrs %{name: "some name", token: "some token"}
|
||||
@update_attrs %{name: "some updated name", token: "some updated token"}
|
||||
@invalid_attrs %{name: nil, token: nil}
|
||||
|
||||
defp create_api_key(_) do
|
||||
api_key = api_key_fixture()
|
||||
%{api_key: api_key}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_api_key]
|
||||
|
||||
test "lists all api_keys", %{conn: conn, api_key: api_key} do
|
||||
{:ok, _index_live, html} = live(conn, ~p"/api_keys")
|
||||
|
||||
assert html =~ "Listing Api keys"
|
||||
assert html =~ api_key.name
|
||||
end
|
||||
|
||||
test "saves new api_key", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/api_keys")
|
||||
|
||||
assert index_live |> element("a", "New Api key") |> render_click() =~
|
||||
"New Api key"
|
||||
|
||||
assert_patch(index_live, ~p"/api_keys/new")
|
||||
|
||||
assert index_live
|
||||
|> form("#api_key-form", api_key: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#api_key-form", api_key: @create_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/api_keys")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Api key created successfully"
|
||||
assert html =~ "some name"
|
||||
end
|
||||
|
||||
test "updates api_key in listing", %{conn: conn, api_key: api_key} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/api_keys")
|
||||
|
||||
assert index_live |> element("#api_keys-#{api_key.id} a", "Edit") |> render_click() =~
|
||||
"Edit Api key"
|
||||
|
||||
assert_patch(index_live, ~p"/api_keys/#{api_key}/edit")
|
||||
|
||||
assert index_live
|
||||
|> form("#api_key-form", api_key: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#api_key-form", api_key: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/api_keys")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Api key updated successfully"
|
||||
assert html =~ "some updated name"
|
||||
end
|
||||
|
||||
test "deletes api_key in listing", %{conn: conn, api_key: api_key} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/api_keys")
|
||||
|
||||
assert index_live |> element("#api_keys-#{api_key.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#api_keys-#{api_key.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_api_key]
|
||||
|
||||
test "displays api_key", %{conn: conn, api_key: api_key} do
|
||||
{:ok, _show_live, html} = live(conn, ~p"/api_keys/#{api_key}")
|
||||
|
||||
assert html =~ "Show Api key"
|
||||
assert html =~ api_key.name
|
||||
end
|
||||
|
||||
test "updates api_key within modal", %{conn: conn, api_key: api_key} do
|
||||
{:ok, show_live, _html} = live(conn, ~p"/api_keys/#{api_key}")
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Api key"
|
||||
|
||||
assert_patch(show_live, ~p"/api_keys/#{api_key}/show/edit")
|
||||
|
||||
assert show_live
|
||||
|> form("#api_key-form", api_key: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert show_live
|
||||
|> form("#api_key-form", api_key: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(show_live, ~p"/api_keys/#{api_key}")
|
||||
|
||||
html = render(show_live)
|
||||
assert html =~ "Api key updated successfully"
|
||||
assert html =~ "some updated name"
|
||||
end
|
||||
end
|
||||
end
|
||||
113
test/zoeyscomputer_web/live/image_live_test.exs
Normal file
113
test/zoeyscomputer_web/live/image_live_test.exs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
defmodule ZoeyscomputerWeb.ImageLiveTest do
|
||||
use ZoeyscomputerWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import Zoeyscomputer.ImagesFixtures
|
||||
|
||||
@create_attrs %{file: "some file"}
|
||||
@update_attrs %{file: "some updated file"}
|
||||
@invalid_attrs %{file: nil}
|
||||
|
||||
defp create_image(_) do
|
||||
image = image_fixture()
|
||||
%{image: image}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_image]
|
||||
|
||||
test "lists all images", %{conn: conn, image: image} do
|
||||
{:ok, _index_live, html} = live(conn, ~p"/images")
|
||||
|
||||
assert html =~ "Listing Images"
|
||||
assert html =~ image.file
|
||||
end
|
||||
|
||||
test "saves new image", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/images")
|
||||
|
||||
assert index_live |> element("a", "New Image") |> render_click() =~
|
||||
"New Image"
|
||||
|
||||
assert_patch(index_live, ~p"/images/new")
|
||||
|
||||
assert index_live
|
||||
|> form("#image-form", image: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#image-form", image: @create_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/images")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Image created successfully"
|
||||
assert html =~ "some file"
|
||||
end
|
||||
|
||||
test "updates image in listing", %{conn: conn, image: image} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/images")
|
||||
|
||||
assert index_live |> element("#images-#{image.id} a", "Edit") |> render_click() =~
|
||||
"Edit Image"
|
||||
|
||||
assert_patch(index_live, ~p"/images/#{image}/edit")
|
||||
|
||||
assert index_live
|
||||
|> form("#image-form", image: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#image-form", image: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/images")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Image updated successfully"
|
||||
assert html =~ "some updated file"
|
||||
end
|
||||
|
||||
test "deletes image in listing", %{conn: conn, image: image} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/images")
|
||||
|
||||
assert index_live |> element("#images-#{image.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#images-#{image.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_image]
|
||||
|
||||
test "displays image", %{conn: conn, image: image} do
|
||||
{:ok, _show_live, html} = live(conn, ~p"/images/#{image}")
|
||||
|
||||
assert html =~ "Show Image"
|
||||
assert html =~ image.file
|
||||
end
|
||||
|
||||
test "updates image within modal", %{conn: conn, image: image} do
|
||||
{:ok, show_live, _html} = live(conn, ~p"/images/#{image}")
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Image"
|
||||
|
||||
assert_patch(show_live, ~p"/images/#{image}/show/edit")
|
||||
|
||||
assert show_live
|
||||
|> form("#image-form", image: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert show_live
|
||||
|> form("#image-form", image: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(show_live, ~p"/images/#{image}")
|
||||
|
||||
html = render(show_live)
|
||||
assert html =~ "Image updated successfully"
|
||||
assert html =~ "some updated file"
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue