This commit is contained in:
Mirai Kumiko 2025-07-06 14:46:08 +02:00
parent f90a7133bc
commit 00ecbadeca
Signed by: miraikumiko
GPG key ID: 3F178B1B5E0CB278
29 changed files with 871 additions and 12 deletions

View file

@ -0,0 +1,78 @@
defmodule Nulla.AnnouncesTest do
use Nulla.DataCase
alias Nulla.Announces
describe "announces" do
alias Nulla.Announces.Announce
import Nulla.ActorsFixtures
import Nulla.NotesFixtures
import Nulla.AnnouncesFixtures
@invalid_attrs %{
actor_id: nil,
note_id: nil
}
test "list_announces/0 returns all announces" do
announce = announce_fixture()
assert Announces.list_announces() == [announce]
end
test "get_announce!/1 returns the announce with given id" do
announce = announce_fixture()
assert Announces.get_announce!(announce.id) == announce
end
test "create_announce/1 with valid data creates a announce" do
actor = actor_fixture()
note = note_fixture()
valid_attrs = %{
actor_id: actor.id,
note_id: note.id
}
assert {:ok, %Announce{} = announce} = Announces.create_announce(valid_attrs)
assert is_integer(announce.actor_id)
assert is_integer(announce.note_id)
end
test "create_announce/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Announces.create_announce(@invalid_attrs)
end
test "update_announce/2 with valid data updates the announce" do
actor = actor_fixture()
note = note_fixture()
announce = announce_fixture()
update_attrs = %{
actor_id: actor.id,
note_id: note.id
}
assert {:ok, %Announce{} = announce} = Announces.update_announce(announce, update_attrs)
assert is_integer(announce.actor_id)
assert is_integer(announce.note_id)
end
test "update_announce/2 with invalid data returns error changeset" do
announce = announce_fixture()
assert {:error, %Ecto.Changeset{}} = Announces.update_announce(announce, @invalid_attrs)
assert announce == Announces.get_announce!(announce.id)
end
test "delete_announce/1 deletes the announce" do
announce = announce_fixture()
assert {:ok, %Announce{}} = Announces.delete_announce(announce)
assert_raise Ecto.NoResultsError, fn -> Announces.get_announce!(announce.id) end
end
test "change_announce/1 returns a announce changeset" do
announce = announce_fixture()
assert %Ecto.Changeset{} = Announces.change_announce(announce)
end
end
end

78
test/nulla/likes_test.exs Normal file
View file

@ -0,0 +1,78 @@
defmodule Nulla.LikesTest do
use Nulla.DataCase
alias Nulla.Likes
describe "likes" do
alias Nulla.Likes.Like
import Nulla.ActorsFixtures
import Nulla.NotesFixtures
import Nulla.LikesFixtures
@invalid_attrs %{
actor_id: nil,
note_id: nil
}
test "list_likes/0 returns all likes" do
like = like_fixture()
assert Likes.list_likes() == [like]
end
test "get_like!/1 returns the like with given id" do
like = like_fixture()
assert Likes.get_like!(like.id) == like
end
test "create_like/1 with valid data creates a like" do
actor = actor_fixture()
note = note_fixture()
valid_attrs = %{
actor_id: actor.id,
note_id: note.id
}
assert {:ok, %Like{} = like} = Likes.create_like(valid_attrs)
assert is_integer(like.actor_id)
assert is_integer(like.note_id)
end
test "create_like/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Likes.create_like(@invalid_attrs)
end
test "update_like/2 with valid data updates the like" do
actor = actor_fixture()
note = note_fixture()
like = like_fixture()
update_attrs = %{
actor_id: actor.id,
note_id: note.id
}
assert {:ok, %Like{} = like} = Likes.update_like(like, update_attrs)
assert is_integer(like.actor_id)
assert is_integer(like.note_id)
end
test "update_like/2 with invalid data returns error changeset" do
like = like_fixture()
assert {:error, %Ecto.Changeset{}} = Likes.update_like(like, @invalid_attrs)
assert like == Likes.get_like!(like.id)
end
test "delete_like/1 deletes the like" do
like = like_fixture()
assert {:ok, %Like{}} = Likes.delete_like(like)
assert_raise Ecto.NoResultsError, fn -> Likes.get_like!(like.id) end
end
test "change_like/1 returns a like changeset" do
like = like_fixture()
assert %Ecto.Changeset{} = Likes.change_like(like)
end
end
end

View file

@ -13,6 +13,7 @@ defmodule Nulla.NotesTest do
sensitive: nil,
cc: nil,
to: nil,
tag: nil,
url: nil,
language: nil,
inReplyTo: nil,
@ -39,6 +40,7 @@ defmodule Nulla.NotesTest do
sensitive: true,
cc: ["option1", "option2"],
to: ["option1", "option2"],
tag: [%{"key1" => "value1"}, %{"key2" => "value2"}],
url: "some url",
language: "some language",
inReplyTo: "some inReplyTo",
@ -52,6 +54,7 @@ defmodule Nulla.NotesTest do
assert note.sensitive == true
assert note.cc == ["option1", "option2"]
assert note.to == ["option1", "option2"]
assert note.tag == [%{"key1" => "value1"}, %{"key2" => "value2"}]
assert note.url == "some url"
assert note.language == "some language"
assert note.inReplyTo == "some inReplyTo"
@ -73,6 +76,7 @@ defmodule Nulla.NotesTest do
sensitive: false,
cc: ["option1"],
to: ["option1"],
tag: [%{"key1" => "value1"}],
url: "some updated url",
language: "some updated language",
inReplyTo: "some updated inReplyTo",
@ -86,6 +90,7 @@ defmodule Nulla.NotesTest do
assert note.sensitive == false
assert note.cc == ["option1"]
assert note.to == ["option1"]
assert note.tag == [%{"key1" => "value1"}]
assert note.url == "some updated url"
assert note.language == "some updated language"
assert note.inReplyTo == "some updated inReplyTo"

View file

@ -0,0 +1,100 @@
defmodule NullaWeb.Api.AnnounceControllerTest do
use NullaWeb.ConnCase
import Nulla.ActorsFixtures
import Nulla.NotesFixtures
import Nulla.AnnouncesFixtures
alias Nulla.Announces.Announce
@invalid_attrs %{
actor_id: nil,
note_id: nil
}
setup %{conn: conn} do
{:ok, conn: put_req_header(conn, "accept", "application/json")}
end
describe "index" do
test "lists all announces", %{conn: conn} do
conn = get(conn, ~p"/api/announces")
assert json_response(conn, 200)["data"] == []
end
end
describe "create announce" do
test "renders announce when data is valid", %{conn: conn} do
actor = actor_fixture()
note = note_fixture()
create_attrs = %{
actor_id: actor.id,
note_id: note.id
}
conn = post(conn, ~p"/api/announces", announce: create_attrs)
assert %{"id" => id} = json_response(conn, 201)["data"]
conn = get(conn, ~p"/api/announces/#{id}")
assert %{
"id" => ^id
} = json_response(conn, 200)["data"]
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post(conn, ~p"/api/announces", announce: @invalid_attrs)
assert json_response(conn, 422)["errors"] != %{}
end
end
describe "update announce" do
setup [:create_announce]
test "renders announce when data is valid", %{
conn: conn,
announce: %Announce{id: id} = announce
} do
actor = actor_fixture()
note = note_fixture()
update_attrs = %{
actor_id: actor.id,
note_id: note.id
}
conn = put(conn, ~p"/api/announces/#{announce}", announce: update_attrs)
assert %{"id" => ^id} = json_response(conn, 200)["data"]
conn = get(conn, ~p"/api/announces/#{id}")
assert %{
"id" => ^id
} = json_response(conn, 200)["data"]
end
test "renders errors when data is invalid", %{conn: conn, announce: announce} do
conn = put(conn, ~p"/api/announces/#{announce}", announce: @invalid_attrs)
assert json_response(conn, 422)["errors"] != %{}
end
end
describe "delete announce" do
setup [:create_announce]
test "deletes chosen announce", %{conn: conn, announce: announce} do
conn = delete(conn, ~p"/api/announces/#{announce}")
assert response(conn, 204)
assert_error_sent 404, fn ->
get(conn, ~p"/api/announces/#{announce}")
end
end
end
defp create_announce(_) do
announce = announce_fixture()
%{announce: announce}
end
end

View file

@ -0,0 +1,97 @@
defmodule NullaWeb.Api.LikeControllerTest do
use NullaWeb.ConnCase
import Nulla.ActorsFixtures
import Nulla.NotesFixtures
import Nulla.LikesFixtures
alias Nulla.Likes.Like
@invalid_attrs %{
actor_id: nil,
note_id: nil
}
setup %{conn: conn} do
{:ok, conn: put_req_header(conn, "accept", "application/json")}
end
describe "index" do
test "lists all likes", %{conn: conn} do
conn = get(conn, ~p"/api/likes")
assert json_response(conn, 200)["data"] == []
end
end
describe "create like" do
test "renders like when data is valid", %{conn: conn} do
actor = actor_fixture()
note = note_fixture()
create_attrs = %{
actor_id: actor.id,
note_id: note.id
}
conn = post(conn, ~p"/api/likes", like: create_attrs)
assert %{"id" => id} = json_response(conn, 201)["data"]
conn = get(conn, ~p"/api/likes/#{id}")
assert %{
"id" => ^id
} = json_response(conn, 200)["data"]
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post(conn, ~p"/api/likes", like: @invalid_attrs)
assert json_response(conn, 422)["errors"] != %{}
end
end
describe "update like" do
setup [:create_like]
test "renders like when data is valid", %{conn: conn, like: %Like{id: id} = like} do
actor = actor_fixture()
note = note_fixture()
update_attrs = %{
actor_id: actor.id,
note_id: note.id
}
conn = put(conn, ~p"/api/likes/#{like}", like: update_attrs)
assert %{"id" => ^id} = json_response(conn, 200)["data"]
conn = get(conn, ~p"/api/likes/#{id}")
assert %{
"id" => ^id
} = json_response(conn, 200)["data"]
end
test "renders errors when data is invalid", %{conn: conn, like: like} do
conn = put(conn, ~p"/api/likes/#{like}", like: @invalid_attrs)
assert json_response(conn, 422)["errors"] != %{}
end
end
describe "delete like" do
setup [:create_like]
test "deletes chosen like", %{conn: conn, like: like} do
conn = delete(conn, ~p"/api/likes/#{like}")
assert response(conn, 204)
assert_error_sent 404, fn ->
get(conn, ~p"/api/likes/#{like}")
end
end
end
defp create_like(_) do
like = like_fixture()
%{like: like}
end
end

View file

@ -10,6 +10,7 @@ defmodule NullaWeb.Api.NoteControllerTest do
sensitive: true,
cc: ["option1", "option2"],
to: ["option1", "option2"],
tag: [%{"key1" => "value1"}, %{"key2" => "value2"}],
url: "some url",
language: "some language",
inReplyTo: "some inReplyTo",
@ -21,6 +22,7 @@ defmodule NullaWeb.Api.NoteControllerTest do
sensitive: false,
cc: ["option1"],
to: ["option1"],
tag: [%{"key1" => "value1"}],
url: "some updated url",
language: "some updated language",
inReplyTo: "some updated inReplyTo",
@ -32,6 +34,7 @@ defmodule NullaWeb.Api.NoteControllerTest do
sensitive: nil,
cc: nil,
to: nil,
tag: nil,
url: nil,
language: nil,
inReplyTo: nil,
@ -71,6 +74,7 @@ defmodule NullaWeb.Api.NoteControllerTest do
"published" => "2025-07-01T09:17:00Z",
"sensitive" => true,
"to" => ["option1", "option2"],
"tag" => [%{"key1" => "value1"}, %{"key2" => "value2"}],
"url" => "some url",
"visibility" => "some visibility"
} = json_response(conn, 200)["data"]
@ -100,6 +104,7 @@ defmodule NullaWeb.Api.NoteControllerTest do
"published" => "2025-07-02T09:17:00Z",
"sensitive" => false,
"to" => ["option1"],
"tag" => [%{"key1" => "value1"}],
"url" => "some updated url",
"visibility" => "some updated visibility"
} = json_response(conn, 200)["data"]

View file

@ -0,0 +1,24 @@
defmodule Nulla.AnnouncesFixtures do
import Nulla.ActorsFixtures
import Nulla.NotesFixtures
@moduledoc """
This module defines test helpers for creating
entities via the `Nulla.Announces` context.
"""
@doc """
Generate a announce.
"""
def announce_fixture(attrs \\ %{}) do
actor = actor_fixture()
note = note_fixture()
{:ok, announce} =
attrs
|> Enum.into(%{actor_id: actor.id, note_id: note.id})
|> Nulla.Announces.create_announce()
announce
end
end

View file

@ -0,0 +1,24 @@
defmodule Nulla.LikesFixtures do
import Nulla.ActorsFixtures
import Nulla.NotesFixtures
@moduledoc """
This module defines test helpers for creating
entities via the `Nulla.Likes` context.
"""
@doc """
Generate a like.
"""
def like_fixture(attrs \\ %{}) do
actor = actor_fixture()
note = note_fixture()
{:ok, like} =
attrs
|> Enum.into(%{actor_id: actor.id, note_id: note.id})
|> Nulla.Likes.create_like()
like
end
end

View file

@ -22,6 +22,7 @@ defmodule Nulla.NotesFixtures do
published: ~U[2025-07-01 09:17:00Z],
sensitive: true,
to: ["option1", "option2"],
tag: [%{"key1" => "value1"}, %{"key2" => "value2"}],
url: "some url",
visibility: "some visibility",
actor_id: actor.id