154 lines
4.2 KiB
Elixir
154 lines
4.2 KiB
Elixir
defmodule NullaWeb.RelationControllerTest do
|
|
use NullaWeb.ConnCase
|
|
|
|
import Nulla.ActorsFixtures
|
|
import Nulla.RelationsFixtures
|
|
|
|
alias Nulla.Relations.Relation
|
|
|
|
@create_attrs %{
|
|
following: true,
|
|
followed_by: true,
|
|
showing_replies: true,
|
|
showings_reblogs: true,
|
|
notifying: true,
|
|
muting: true,
|
|
muting_notifications: true,
|
|
blocking: true,
|
|
blocked_by: true,
|
|
domain_blocking: true,
|
|
requested: true,
|
|
note: "some note"
|
|
}
|
|
@update_attrs %{
|
|
following: false,
|
|
followed_by: false,
|
|
showing_replies: false,
|
|
showings_reblogs: false,
|
|
notifying: false,
|
|
muting: false,
|
|
muting_notifications: false,
|
|
blocking: false,
|
|
blocked_by: false,
|
|
domain_blocking: false,
|
|
requested: false,
|
|
note: "some updated note"
|
|
}
|
|
@invalid_attrs %{
|
|
following: nil,
|
|
followed_by: nil,
|
|
showing_replies: nil,
|
|
showings_reblogs: nil,
|
|
notifying: nil,
|
|
muting: nil,
|
|
muting_notifications: nil,
|
|
blocking: nil,
|
|
blocked_by: nil,
|
|
domain_blocking: nil,
|
|
requested: nil,
|
|
note: nil
|
|
}
|
|
|
|
setup %{conn: conn} do
|
|
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
|
end
|
|
|
|
describe "index" do
|
|
test "lists all relations", %{conn: conn} do
|
|
conn = get(conn, ~p"/api/relations")
|
|
assert json_response(conn, 200)["data"] == []
|
|
end
|
|
end
|
|
|
|
describe "create relation" do
|
|
test "renders relation when data is valid", %{conn: conn} do
|
|
local_actor = actor_fixture()
|
|
remote_actor = actor_fixture()
|
|
|
|
create_attrs =
|
|
Map.merge(@create_attrs, %{
|
|
local_actor_id: local_actor.id,
|
|
remote_actor_id: remote_actor.id
|
|
})
|
|
|
|
conn = post(conn, ~p"/api/relations", relation: create_attrs)
|
|
assert %{"id" => id} = json_response(conn, 201)["data"]
|
|
|
|
conn = get(conn, ~p"/api/relations/#{id}")
|
|
|
|
assert %{
|
|
"id" => ^id,
|
|
"blocked_by" => true,
|
|
"blocking" => true,
|
|
"domain_blocking" => true,
|
|
"followed_by" => true,
|
|
"following" => true,
|
|
"muting" => true,
|
|
"muting_notifications" => true,
|
|
"note" => "some note",
|
|
"notifying" => true,
|
|
"requested" => true,
|
|
"showing_replies" => true,
|
|
"showings_reblogs" => true
|
|
} = json_response(conn, 200)["data"]
|
|
end
|
|
|
|
test "renders errors when data is invalid", %{conn: conn} do
|
|
conn = post(conn, ~p"/api/relations", relation: @invalid_attrs)
|
|
assert json_response(conn, 422)["errors"] != %{}
|
|
end
|
|
end
|
|
|
|
describe "update relation" do
|
|
setup [:create_relation]
|
|
|
|
test "renders relation when data is valid", %{
|
|
conn: conn,
|
|
relation: %Relation{id: id} = relation
|
|
} do
|
|
conn = put(conn, ~p"/api/relations/#{relation}", relation: @update_attrs)
|
|
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
|
|
|
conn = get(conn, ~p"/api/relations/#{id}")
|
|
|
|
assert %{
|
|
"id" => ^id,
|
|
"blocked_by" => false,
|
|
"blocking" => false,
|
|
"domain_blocking" => false,
|
|
"followed_by" => false,
|
|
"following" => false,
|
|
"muting" => false,
|
|
"muting_notifications" => false,
|
|
"note" => "some updated note",
|
|
"notifying" => false,
|
|
"requested" => false,
|
|
"showing_replies" => false,
|
|
"showings_reblogs" => false
|
|
} = json_response(conn, 200)["data"]
|
|
end
|
|
|
|
test "renders errors when data is invalid", %{conn: conn, relation: relation} do
|
|
conn = put(conn, ~p"/api/relations/#{relation}", relation: @invalid_attrs)
|
|
assert json_response(conn, 422)["errors"] != %{}
|
|
end
|
|
end
|
|
|
|
describe "delete relation" do
|
|
setup [:create_relation]
|
|
|
|
test "deletes chosen relation", %{conn: conn, relation: relation} do
|
|
conn = delete(conn, ~p"/api/relations/#{relation}")
|
|
assert response(conn, 204)
|
|
|
|
assert_error_sent 404, fn ->
|
|
get(conn, ~p"/api/relations/#{relation}")
|
|
end
|
|
end
|
|
end
|
|
|
|
defp create_relation(_) do
|
|
relation = relation_fixture()
|
|
%{relation: relation}
|
|
end
|
|
end
|