Update
This commit is contained in:
parent
188bc08494
commit
4af88f3e1d
44 changed files with 1041 additions and 34 deletions
211
test/nulla_web/controllers/api/actor_controller_test.exs
Normal file
211
test/nulla_web/controllers/api/actor_controller_test.exs
Normal file
|
@ -0,0 +1,211 @@
|
|||
defmodule NullaWeb.Api.ActorControllerTest do
|
||||
use NullaWeb.ConnCase
|
||||
|
||||
import Nulla.ActorsFixtures
|
||||
|
||||
alias Nulla.Actors.Actor
|
||||
|
||||
@create_attrs %{
|
||||
name: "some name",
|
||||
tag: [],
|
||||
type: "some type",
|
||||
image: %{},
|
||||
url: "some url",
|
||||
acct: "some acct",
|
||||
ap_id: "some ap_id",
|
||||
following: "some following",
|
||||
followers: "some followers",
|
||||
inbox: "some inbox",
|
||||
outbox: "some outbox",
|
||||
featured: "some featured",
|
||||
featuredTags: "some featuredTags",
|
||||
preferredUsername: "some preferredUsername",
|
||||
summary: "some summary",
|
||||
manuallyApprovesFollowers: true,
|
||||
discoverable: true,
|
||||
indexable: true,
|
||||
published: ~U[2025-06-30 13:31:00Z],
|
||||
memorial: true,
|
||||
publicKey: %{},
|
||||
attachment: [],
|
||||
endpoints: %{},
|
||||
icon: %{},
|
||||
vcard_bday: ~D[2025-06-30],
|
||||
vcard_Address: "some vcard_Address"
|
||||
}
|
||||
@update_attrs %{
|
||||
name: "some updated name",
|
||||
tag: [],
|
||||
type: "some updated type",
|
||||
image: %{},
|
||||
url: "some updated url",
|
||||
acct: "some updated acct",
|
||||
ap_id: "some updated ap_id",
|
||||
following: "some updated following",
|
||||
followers: "some updated followers",
|
||||
inbox: "some updated inbox",
|
||||
outbox: "some updated outbox",
|
||||
featured: "some updated featured",
|
||||
featuredTags: "some updated featuredTags",
|
||||
preferredUsername: "some updated preferredUsername",
|
||||
summary: "some updated summary",
|
||||
manuallyApprovesFollowers: false,
|
||||
discoverable: false,
|
||||
indexable: false,
|
||||
published: ~U[2025-07-01 13:31:00Z],
|
||||
memorial: false,
|
||||
publicKey: %{},
|
||||
attachment: [],
|
||||
endpoints: %{},
|
||||
icon: %{},
|
||||
vcard_bday: ~D[2025-07-01],
|
||||
vcard_Address: "some updated vcard_Address"
|
||||
}
|
||||
@invalid_attrs %{
|
||||
name: nil,
|
||||
tag: nil,
|
||||
type: nil,
|
||||
image: nil,
|
||||
url: nil,
|
||||
acct: nil,
|
||||
ap_id: nil,
|
||||
following: nil,
|
||||
followers: nil,
|
||||
inbox: nil,
|
||||
outbox: nil,
|
||||
featured: nil,
|
||||
featuredTags: nil,
|
||||
preferredUsername: nil,
|
||||
summary: nil,
|
||||
manuallyApprovesFollowers: nil,
|
||||
discoverable: nil,
|
||||
indexable: nil,
|
||||
published: nil,
|
||||
memorial: nil,
|
||||
publicKey: nil,
|
||||
attachment: nil,
|
||||
endpoints: nil,
|
||||
icon: nil,
|
||||
vcard_bday: nil,
|
||||
vcard_Address: nil
|
||||
}
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all actors", %{conn: conn} do
|
||||
conn = get(conn, ~p"/api/actors")
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create actor" do
|
||||
test "renders actor when data is valid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/actors", actor: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/actors/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"acct" => "some acct",
|
||||
"ap_id" => "some ap_id",
|
||||
"attachment" => [],
|
||||
"discoverable" => true,
|
||||
"endpoints" => %{},
|
||||
"featured" => "some featured",
|
||||
"featuredTags" => "some featuredTags",
|
||||
"followers" => "some followers",
|
||||
"following" => "some following",
|
||||
"icon" => %{},
|
||||
"image" => %{},
|
||||
"inbox" => "some inbox",
|
||||
"indexable" => true,
|
||||
"manuallyApprovesFollowers" => true,
|
||||
"memorial" => true,
|
||||
"name" => "some name",
|
||||
"outbox" => "some outbox",
|
||||
"preferredUsername" => "some preferredUsername",
|
||||
"publicKey" => %{},
|
||||
"published" => "2025-06-30T13:31:00Z",
|
||||
"summary" => "some summary",
|
||||
"tag" => [],
|
||||
"type" => "some type",
|
||||
"url" => "some url",
|
||||
"vcard_Address" => "some vcard_Address",
|
||||
"vcard_bday" => "2025-06-30"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/actors", actor: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update actor" do
|
||||
setup [:create_actor]
|
||||
|
||||
test "renders actor when data is valid", %{conn: conn, actor: %Actor{id: id} = actor} do
|
||||
conn = put(conn, ~p"/api/actors/#{actor}", actor: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/actors/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"acct" => "some updated acct",
|
||||
"ap_id" => "some updated ap_id",
|
||||
"attachment" => [],
|
||||
"discoverable" => false,
|
||||
"endpoints" => %{},
|
||||
"featured" => "some updated featured",
|
||||
"featuredTags" => "some updated featuredTags",
|
||||
"followers" => "some updated followers",
|
||||
"following" => "some updated following",
|
||||
"icon" => %{},
|
||||
"image" => %{},
|
||||
"inbox" => "some updated inbox",
|
||||
"indexable" => false,
|
||||
"manuallyApprovesFollowers" => false,
|
||||
"memorial" => false,
|
||||
"name" => "some updated name",
|
||||
"outbox" => "some updated outbox",
|
||||
"preferredUsername" => "some updated preferredUsername",
|
||||
"publicKey" => %{},
|
||||
"published" => "2025-07-01T13:31:00Z",
|
||||
"summary" => "some updated summary",
|
||||
"tag" => [],
|
||||
"type" => "some updated type",
|
||||
"url" => "some updated url",
|
||||
"vcard_Address" => "some updated vcard_Address",
|
||||
"vcard_bday" => "2025-07-01"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, actor: actor} do
|
||||
conn = put(conn, ~p"/api/actors/#{actor}", actor: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete actor" do
|
||||
setup [:create_actor]
|
||||
|
||||
test "deletes chosen actor", %{conn: conn, actor: actor} do
|
||||
conn = delete(conn, ~p"/api/actors/#{actor}")
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, ~p"/api/actors/#{actor}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_actor(_) do
|
||||
actor = actor_fixture()
|
||||
%{actor: actor}
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue