Update
This commit is contained in:
parent
f90a7133bc
commit
00ecbadeca
29 changed files with 871 additions and 12 deletions
100
test/nulla_web/controllers/api/announce_controller_test.exs
Normal file
100
test/nulla_web/controllers/api/announce_controller_test.exs
Normal 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
|
97
test/nulla_web/controllers/api/like_controller_test.exs
Normal file
97
test/nulla_web/controllers/api/like_controller_test.exs
Normal 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
|
|
@ -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"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue