diff --git a/test/outlook/public_test.exs b/test/outlook/public_test.exs new file mode 100644 index 0000000..909dbbf --- /dev/null +++ b/test/outlook/public_test.exs @@ -0,0 +1,131 @@ +defmodule Outlook.PublicTest do + use Outlook.DataCase + + # TODO: make this work + + alias Outlook.Public + + describe "artikel" do + alias Outlook.Public.Artikel + + import Outlook.PublicFixtures + + @invalid_attrs %{date: nil, public_content: nil, teaser: nil, title: nil, translator: nil, unauthorized: nil} + + test "list_artikel/0 returns all artikel" do + artikel = artikel_fixture() + assert Artikel.list_artikel() == [artikel] + end + + test "get_artikel!/1 returns the artikel with given id" do + artikel = artikel_fixture() + assert Artikel.get_artikel!(artikel.id) == artikel + end + + test "create_artikel/1 with valid data creates a artikel" do + valid_attrs = %{date: "some date", public_content: "some public_content", teaser: "some teaser", title: "some title", translator: "some translator", unauthorized: true} + + assert {:ok, %Artikel{} = artikel} = Artikel.create_artikel(valid_attrs) + assert artikel.date == "some date" + assert artikel.public_content == "some public_content" + assert artikel.teaser == "some teaser" + assert artikel.title == "some title" + assert artikel.translator == "some translator" + assert artikel.unauthorized == true + end + + test "create_artikel/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = Artikel.create_artikel(@invalid_attrs) + end + + test "update_artikel/2 with valid data updates the artikel" do + artikel = artikel_fixture() + update_attrs = %{date: "some updated date", public_content: "some updated public_content", teaser: "some updated teaser", title: "some updated title", translator: "some updated translator", unauthorized: false} + + assert {:ok, %Artikel{} = artikel} = Artikel.update_artikel(artikel, update_attrs) + assert artikel.date == "some updated date" + assert artikel.public_content == "some updated public_content" + assert artikel.teaser == "some updated teaser" + assert artikel.title == "some updated title" + assert artikel.translator == "some updated translator" + assert artikel.unauthorized == false + end + + test "update_artikel/2 with invalid data returns error changeset" do + artikel = artikel_fixture() + assert {:error, %Ecto.Changeset{}} = Artikel.update_artikel(artikel, @invalid_attrs) + assert artikel == Artikel.get_artikel!(artikel.id) + end + + test "delete_artikel/1 deletes the artikel" do + artikel = artikel_fixture() + assert {:ok, %Artikel{}} = Artikel.delete_artikel(artikel) + assert_raise Ecto.NoResultsError, fn -> Artikel.get_artikel!(artikel.id) end + end + + test "change_artikel/1 returns a artikel changeset" do + artikel = artikel_fixture() + assert %Ecto.Changeset{} = Artikel.change_artikel(artikel) + end + end + + describe "autoren" do + alias Outlook.Public.Autor + + import Outlook.PublicFixtures + + @invalid_attrs %{description: nil, homepage_name: nil, homepage_url: nil, name: nil} + + test "list_autoren/0 returns all autoren" do + autor = autor_fixture() + assert Autoren.list_autoren() == [autor] + end + + test "get_autor!/1 returns the autor with given id" do + autor = autor_fixture() + assert Autoren.get_autor!(autor.id) == autor + end + + test "create_autor/1 with valid data creates a autor" do + valid_attrs = %{description: "some description", homepage_name: "some homepage_name", homepage_url: "some homepage_url", name: "some name"} + + assert {:ok, %Autor{} = autor} = Autoren.create_autor(valid_attrs) + assert autor.description == "some description" + assert autor.homepage_name == "some homepage_name" + assert autor.homepage_url == "some homepage_url" + assert autor.name == "some name" + end + + test "create_autor/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = Autoren.create_autor(@invalid_attrs) + end + + test "update_autor/2 with valid data updates the autor" do + autor = autor_fixture() + update_attrs = %{description: "some updated description", homepage_name: "some updated homepage_name", homepage_url: "some updated homepage_url", name: "some updated name"} + + assert {:ok, %Autor{} = autor} = Autoren.update_autor(autor, update_attrs) + assert autor.description == "some updated description" + assert autor.homepage_name == "some updated homepage_name" + assert autor.homepage_url == "some updated homepage_url" + assert autor.name == "some updated name" + end + + test "update_autor/2 with invalid data returns error changeset" do + autor = autor_fixture() + assert {:error, %Ecto.Changeset{}} = Autoren.update_autor(autor, @invalid_attrs) + assert autor == Autoren.get_autor!(autor.id) + end + + test "delete_autor/1 deletes the autor" do + autor = autor_fixture() + assert {:ok, %Autor{}} = Autoren.delete_autor(autor) + assert_raise Ecto.NoResultsError, fn -> Autoren.get_autor!(autor.id) end + end + + test "change_autor/1 returns a autor changeset" do + autor = autor_fixture() + assert %Ecto.Changeset{} = Autoren.change_autor(autor) + end + end +end diff --git a/test/outlook_web/controllers/artikel_controller_test.exs b/test/outlook_web/controllers/artikel_controller_test.exs new file mode 100644 index 0000000..569df2b --- /dev/null +++ b/test/outlook_web/controllers/artikel_controller_test.exs @@ -0,0 +1,86 @@ +defmodule OutlookWeb.ArtikelControllerTest do + use OutlookWeb.ConnCase + + # TODO: make this work + + import Outlook.PublicFixtures + + @create_attrs %{date: "some date", public_content: "some public_content", teaser: "some teaser", title: "some title", translator: "some translator", unauthorized: true} + @update_attrs %{date: "some updated date", public_content: "some updated public_content", teaser: "some updated teaser", title: "some updated title", translator: "some updated translator", unauthorized: false} + @invalid_attrs %{date: nil, public_content: nil, teaser: nil, title: nil, translator: nil, unauthorized: nil} + + describe "index" do + test "lists all artikel", %{conn: conn} do + conn = get(conn, ~p"/artikel") + assert html_response(conn, 200) =~ "Listing Artikel" + end + end + + describe "new artikel" do + test "renders form", %{conn: conn} do + conn = get(conn, ~p"/artikel/new") + assert html_response(conn, 200) =~ "New Artikel" + end + end + + describe "create artikel" do + test "redirects to show when data is valid", %{conn: conn} do + conn = post(conn, ~p"/artikel", artikel: @create_attrs) + + assert %{id: id} = redirected_params(conn) + assert redirected_to(conn) == ~p"/artikel/#{id}" + + conn = get(conn, ~p"/artikel/#{id}") + assert html_response(conn, 200) =~ "Artikel #{id}" + end + + test "renders errors when data is invalid", %{conn: conn} do + conn = post(conn, ~p"/artikel", artikel: @invalid_attrs) + assert html_response(conn, 200) =~ "New Artikel" + end + end + + describe "edit artikel" do + setup [:create_artikel] + + test "renders form for editing chosen artikel", %{conn: conn, artikel: artikel} do + conn = get(conn, ~p"/artikel/#{artikel}/edit") + assert html_response(conn, 200) =~ "Edit Artikel" + end + end + + describe "update artikel" do + setup [:create_artikel] + + test "redirects when data is valid", %{conn: conn, artikel: artikel} do + conn = put(conn, ~p"/artikel/#{artikel}", artikel: @update_attrs) + assert redirected_to(conn) == ~p"/artikel/#{artikel}" + + conn = get(conn, ~p"/artikel/#{artikel}") + assert html_response(conn, 200) =~ "some updated date" + end + + test "renders errors when data is invalid", %{conn: conn, artikel: artikel} do + conn = put(conn, ~p"/artikel/#{artikel}", artikel: @invalid_attrs) + assert html_response(conn, 200) =~ "Edit Artikel" + end + end + + describe "delete artikel" do + setup [:create_artikel] + + test "deletes chosen artikel", %{conn: conn, artikel: artikel} do + conn = delete(conn, ~p"/artikel/#{artikel}") + assert redirected_to(conn) == ~p"/artikel" + + assert_error_sent 404, fn -> + get(conn, ~p"/artikel/#{artikel}") + end + end + end + + defp create_artikel(_) do + artikel = artikel_fixture() + %{artikel: artikel} + end +end diff --git a/test/outlook_web/controllers/autor_controller_test.exs b/test/outlook_web/controllers/autor_controller_test.exs new file mode 100644 index 0000000..cd35ac0 --- /dev/null +++ b/test/outlook_web/controllers/autor_controller_test.exs @@ -0,0 +1,86 @@ +defmodule OutlookWeb.AutorControllerTest do + use OutlookWeb.ConnCase + + # TODO: make this work + + import Outlook.PublicFixtures + + @create_attrs %{description: "some description", homepage_name: "some homepage_name", homepage_url: "some homepage_url", name: "some name"} + @update_attrs %{description: "some updated description", homepage_name: "some updated homepage_name", homepage_url: "some updated homepage_url", name: "some updated name"} + @invalid_attrs %{description: nil, homepage_name: nil, homepage_url: nil, name: nil} + + describe "index" do + test "lists all autoren", %{conn: conn} do + conn = get(conn, ~p"/autoren") + assert html_response(conn, 200) =~ "Listing Autoren" + end + end + + describe "new autor" do + test "renders form", %{conn: conn} do + conn = get(conn, ~p"/autoren/new") + assert html_response(conn, 200) =~ "New Autor" + end + end + + describe "create autor" do + test "redirects to show when data is valid", %{conn: conn} do + conn = post(conn, ~p"/autoren", autor: @create_attrs) + + assert %{id: id} = redirected_params(conn) + assert redirected_to(conn) == ~p"/autoren/#{id}" + + conn = get(conn, ~p"/autoren/#{id}") + assert html_response(conn, 200) =~ "Autor #{id}" + end + + test "renders errors when data is invalid", %{conn: conn} do + conn = post(conn, ~p"/autoren", autor: @invalid_attrs) + assert html_response(conn, 200) =~ "New Autor" + end + end + + describe "edit autor" do + setup [:create_autor] + + test "renders form for editing chosen autor", %{conn: conn, autor: autor} do + conn = get(conn, ~p"/autoren/#{autor}/edit") + assert html_response(conn, 200) =~ "Edit Autor" + end + end + + describe "update autor" do + setup [:create_autor] + + test "redirects when data is valid", %{conn: conn, autor: autor} do + conn = put(conn, ~p"/autoren/#{autor}", autor: @update_attrs) + assert redirected_to(conn) == ~p"/autoren/#{autor}" + + conn = get(conn, ~p"/autoren/#{autor}") + assert html_response(conn, 200) =~ "some updated description" + end + + test "renders errors when data is invalid", %{conn: conn, autor: autor} do + conn = put(conn, ~p"/autoren/#{autor}", autor: @invalid_attrs) + assert html_response(conn, 200) =~ "Edit Autor" + end + end + + describe "delete autor" do + setup [:create_autor] + + test "deletes chosen autor", %{conn: conn, autor: autor} do + conn = delete(conn, ~p"/autoren/#{autor}") + assert redirected_to(conn) == ~p"/autoren" + + assert_error_sent 404, fn -> + get(conn, ~p"/autoren/#{autor}") + end + end + end + + defp create_autor(_) do + autor = autor_fixture() + %{autor: autor} + end +end diff --git a/test/support/fixtures/articles_fixtures.ex b/test/support/fixtures/articles_fixtures.ex index bab4783..5d45a54 100644 --- a/test/support/fixtures/articles_fixtures.ex +++ b/test/support/fixtures/articles_fixtures.ex @@ -4,6 +4,8 @@ defmodule Outlook.ArticlesFixtures do entities via the `Outlook.Articles` context. """ + # TODO: make this work + @doc """ Generate a article. """ @@ -11,11 +13,17 @@ defmodule Outlook.ArticlesFixtures do {:ok, article} = attrs |> Enum.into(%{ - content: "some content", + content: [%Outlook.InternalTree.InternalNode{name: "p", attributes: %{}, type: :element, nid: "54e8cedb-6459-4605-8301-367758675bb8", content: [ + %Outlook.InternalTree.TranslationUnit{status: :untranslated, nid: "c0fcdf61-ae2d-482e-81b4-9b6e3baacd8b", + content: "A sentence with many letters and many, many words. "}, + %Outlook.InternalTree.TranslationUnit{status: :untranslated, nid: "eac12d97-623d-4237-9f33-666298c7f494", + content: "A sentence with many letters and many, many words. "}], + eph: %{sibling_with: :block}}], date: ~U[2022-12-25 16:16:00Z], - language: "some language", + language: "EN", title: "some title", - url: "some url" + url: "some url", + author_id: 1 }) |> Outlook.Articles.create_article() diff --git a/test/support/fixtures/public_fixtures.ex b/test/support/fixtures/public_fixtures.ex new file mode 100644 index 0000000..452e964 --- /dev/null +++ b/test/support/fixtures/public_fixtures.ex @@ -0,0 +1,45 @@ +defmodule Outlook.PublicFixtures do + @moduledoc """ + This module defines test helpers for creating + entities via the `Outlook.Public` context. + """ + + # TODO: make this work + + @doc """ + Generate an artikel. + """ + def artikel_fixture(attrs \\ %{}) do + {:ok, artikel} = + attrs + |> Enum.into(%{ + date: "some date", + public_content: "some public_content", + teaser: "some teaser", + title: "some title", + translator: "some translator", + unauthorized: true + }) + |> Outlook.Public.create_artikel() + + artikel + end + + @doc """ + Generate an autor. + """ + def autor_fixture(attrs \\ %{}) do + {:ok, autor} = + attrs + |> Enum.into(%{ + description: "some description", + homepage_name: "some homepage_name", + homepage_url: "some homepage_url", + name: "some name" + }) + |> Outlook.Public.create_autor() + + autor + end + +end diff --git a/test/support/fixtures/translations_fixtures.ex b/test/support/fixtures/translations_fixtures.ex index 16f4d8d..5745d6a 100644 --- a/test/support/fixtures/translations_fixtures.ex +++ b/test/support/fixtures/translations_fixtures.ex @@ -4,6 +4,8 @@ defmodule Outlook.TranslationsFixtures do entities via the `Outlook.Translations` context. """ + # TODO: make this work + @doc """ Generate a translation. """ @@ -17,7 +19,8 @@ defmodule Outlook.TranslationsFixtures do public: true, teaser: "some teaser", title: "some title", - unauthorized: true + unauthorized: true, + article_id: 1 }) |> Outlook.Translations.create_translation()