Add Translators/deepl_accounts

mix phx.gen.live Translators DeeplAccount deepl_accounts\
  name:string description:text auth_key:string character_limit:integer\
  character_count:integer our_character_count:integer user_id:references:users
This commit is contained in:
Thelonius Kort
2022-12-26 18:51:30 +01:00
parent f66521dba8
commit 9e9c7b5519
12 changed files with 585 additions and 0 deletions

View File

@ -0,0 +1,69 @@
defmodule Outlook.TranslatorsTest do
use Outlook.DataCase
alias Outlook.Translators
describe "deepl_accounts" do
alias Outlook.Translators.DeeplAccount
import Outlook.TranslatorsFixtures
@invalid_attrs %{auth_key: nil, character_count: nil, character_limit: nil, description: nil, name: nil, our_character_count: nil}
test "list_deepl_accounts/0 returns all deepl_accounts" do
deepl_account = deepl_account_fixture()
assert Translators.list_deepl_accounts() == [deepl_account]
end
test "get_deepl_account!/1 returns the deepl_account with given id" do
deepl_account = deepl_account_fixture()
assert Translators.get_deepl_account!(deepl_account.id) == deepl_account
end
test "create_deepl_account/1 with valid data creates a deepl_account" do
valid_attrs = %{auth_key: "some auth_key", character_count: 42, character_limit: 42, description: "some description", name: "some name", our_character_count: 42}
assert {:ok, %DeeplAccount{} = deepl_account} = Translators.create_deepl_account(valid_attrs)
assert deepl_account.auth_key == "some auth_key"
assert deepl_account.character_count == 42
assert deepl_account.character_limit == 42
assert deepl_account.description == "some description"
assert deepl_account.name == "some name"
assert deepl_account.our_character_count == 42
end
test "create_deepl_account/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Translators.create_deepl_account(@invalid_attrs)
end
test "update_deepl_account/2 with valid data updates the deepl_account" do
deepl_account = deepl_account_fixture()
update_attrs = %{auth_key: "some updated auth_key", character_count: 43, character_limit: 43, description: "some updated description", name: "some updated name", our_character_count: 43}
assert {:ok, %DeeplAccount{} = deepl_account} = Translators.update_deepl_account(deepl_account, update_attrs)
assert deepl_account.auth_key == "some updated auth_key"
assert deepl_account.character_count == 43
assert deepl_account.character_limit == 43
assert deepl_account.description == "some updated description"
assert deepl_account.name == "some updated name"
assert deepl_account.our_character_count == 43
end
test "update_deepl_account/2 with invalid data returns error changeset" do
deepl_account = deepl_account_fixture()
assert {:error, %Ecto.Changeset{}} = Translators.update_deepl_account(deepl_account, @invalid_attrs)
assert deepl_account == Translators.get_deepl_account!(deepl_account.id)
end
test "delete_deepl_account/1 deletes the deepl_account" do
deepl_account = deepl_account_fixture()
assert {:ok, %DeeplAccount{}} = Translators.delete_deepl_account(deepl_account)
assert_raise Ecto.NoResultsError, fn -> Translators.get_deepl_account!(deepl_account.id) end
end
test "change_deepl_account/1 returns a deepl_account changeset" do
deepl_account = deepl_account_fixture()
assert %Ecto.Changeset{} = Translators.change_deepl_account(deepl_account)
end
end
end

View File

@ -0,0 +1,110 @@
defmodule OutlookWeb.DeeplAccountLiveTest do
use OutlookWeb.ConnCase
import Phoenix.LiveViewTest
import Outlook.TranslatorsFixtures
@create_attrs %{auth_key: "some auth_key", character_count: 42, character_limit: 42, description: "some description", name: "some name", our_character_count: 42}
@update_attrs %{auth_key: "some updated auth_key", character_count: 43, character_limit: 43, description: "some updated description", name: "some updated name", our_character_count: 43}
@invalid_attrs %{auth_key: nil, character_count: nil, character_limit: nil, description: nil, name: nil, our_character_count: nil}
defp create_deepl_account(_) do
deepl_account = deepl_account_fixture()
%{deepl_account: deepl_account}
end
describe "Index" do
setup [:create_deepl_account]
test "lists all deepl_accounts", %{conn: conn, deepl_account: deepl_account} do
{:ok, _index_live, html} = live(conn, ~p"/deepl_accounts")
assert html =~ "Listing Deepl accounts"
assert html =~ deepl_account.auth_key
end
test "saves new deepl_account", %{conn: conn} do
{:ok, index_live, _html} = live(conn, ~p"/deepl_accounts")
assert index_live |> element("a", "New Deepl account") |> render_click() =~
"New Deepl account"
assert_patch(index_live, ~p"/deepl_accounts/new")
assert index_live
|> form("#deepl_account-form", deepl_account: @invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _, html} =
index_live
|> form("#deepl_account-form", deepl_account: @create_attrs)
|> render_submit()
|> follow_redirect(conn, ~p"/deepl_accounts")
assert html =~ "Deepl account created successfully"
assert html =~ "some auth_key"
end
test "updates deepl_account in listing", %{conn: conn, deepl_account: deepl_account} do
{:ok, index_live, _html} = live(conn, ~p"/deepl_accounts")
assert index_live |> element("#deepl_accounts-#{deepl_account.id} a", "Edit") |> render_click() =~
"Edit Deepl account"
assert_patch(index_live, ~p"/deepl_accounts/#{deepl_account}/edit")
assert index_live
|> form("#deepl_account-form", deepl_account: @invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _, html} =
index_live
|> form("#deepl_account-form", deepl_account: @update_attrs)
|> render_submit()
|> follow_redirect(conn, ~p"/deepl_accounts")
assert html =~ "Deepl account updated successfully"
assert html =~ "some updated auth_key"
end
test "deletes deepl_account in listing", %{conn: conn, deepl_account: deepl_account} do
{:ok, index_live, _html} = live(conn, ~p"/deepl_accounts")
assert index_live |> element("#deepl_accounts-#{deepl_account.id} a", "Delete") |> render_click()
refute has_element?(index_live, "#deepl_account-#{deepl_account.id}")
end
end
describe "Show" do
setup [:create_deepl_account]
test "displays deepl_account", %{conn: conn, deepl_account: deepl_account} do
{:ok, _show_live, html} = live(conn, ~p"/deepl_accounts/#{deepl_account}")
assert html =~ "Show Deepl account"
assert html =~ deepl_account.auth_key
end
test "updates deepl_account within modal", %{conn: conn, deepl_account: deepl_account} do
{:ok, show_live, _html} = live(conn, ~p"/deepl_accounts/#{deepl_account}")
assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Deepl account"
assert_patch(show_live, ~p"/deepl_accounts/#{deepl_account}/show/edit")
assert show_live
|> form("#deepl_account-form", deepl_account: @invalid_attrs)
|> render_change() =~ "can't be blank"
{:ok, _, html} =
show_live
|> form("#deepl_account-form", deepl_account: @update_attrs)
|> render_submit()
|> follow_redirect(conn, ~p"/deepl_accounts/#{deepl_account}")
assert html =~ "Deepl account updated successfully"
assert html =~ "some updated auth_key"
end
end
end

View File

@ -0,0 +1,25 @@
defmodule Outlook.TranslatorsFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `Outlook.Translators` context.
"""
@doc """
Generate a deepl_account.
"""
def deepl_account_fixture(attrs \\ %{}) do
{:ok, deepl_account} =
attrs
|> Enum.into(%{
auth_key: "some auth_key",
character_count: 42,
character_limit: 42,
description: "some description",
name: "some name",
our_character_count: 42
})
|> Outlook.Translators.create_deepl_account()
deepl_account
end
end