Add all
This commit is contained in:
parent
b35e18cd20
commit
82f55f7afe
80 changed files with 6687 additions and 5 deletions
107
test/nulla_web/controllers/activity_controller_test.exs
Normal file
107
test/nulla_web/controllers/activity_controller_test.exs
Normal file
|
@ -0,0 +1,107 @@
|
|||
defmodule NullaWeb.ActivityControllerTest do
|
||||
use NullaWeb.ConnCase
|
||||
|
||||
import Nulla.ActivitiesFixtures
|
||||
|
||||
alias Nulla.Activities.Activity
|
||||
|
||||
@create_attrs %{
|
||||
type: "some type",
|
||||
cc: ["option1", "option2"],
|
||||
to: ["option1", "option2"],
|
||||
ap_id: "some ap_id",
|
||||
actor: "some actor",
|
||||
object: "some object"
|
||||
}
|
||||
@update_attrs %{
|
||||
type: "some updated type",
|
||||
cc: ["option1"],
|
||||
to: ["option1"],
|
||||
ap_id: "some updated ap_id",
|
||||
actor: "some updated actor",
|
||||
object: "some updated object"
|
||||
}
|
||||
@invalid_attrs %{type: nil, cc: nil, to: nil, ap_id: nil, actor: nil, object: nil}
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all activities", %{conn: conn} do
|
||||
conn = get(conn, ~p"/api/activities")
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create activity" do
|
||||
test "renders activity when data is valid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/activities", activity: @create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/activities/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"actor" => "some actor",
|
||||
"ap_id" => "some ap_id",
|
||||
"cc" => ["option1", "option2"],
|
||||
"object" => "some object",
|
||||
"to" => ["option1", "option2"],
|
||||
"type" => "some type"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/activities", activity: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update activity" do
|
||||
setup [:create_activity]
|
||||
|
||||
test "renders activity when data is valid", %{
|
||||
conn: conn,
|
||||
activity: %Activity{id: id} = activity
|
||||
} do
|
||||
conn = put(conn, ~p"/api/activities/#{activity}", activity: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/activities/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"actor" => "some updated actor",
|
||||
"ap_id" => "some updated ap_id",
|
||||
"cc" => ["option1"],
|
||||
"object" => "some updated object",
|
||||
"to" => ["option1"],
|
||||
"type" => "some updated type"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, activity: activity} do
|
||||
conn = put(conn, ~p"/api/activities/#{activity}", activity: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete activity" do
|
||||
setup [:create_activity]
|
||||
|
||||
test "deletes chosen activity", %{conn: conn, activity: activity} do
|
||||
conn = delete(conn, ~p"/api/activities/#{activity}")
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, ~p"/api/activities/#{activity}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_activity(_) do
|
||||
activity = activity_fixture()
|
||||
%{activity: activity}
|
||||
end
|
||||
end
|
211
test/nulla_web/controllers/actor_controller_test.exs
Normal file
211
test/nulla_web/controllers/actor_controller_test.exs
Normal file
|
@ -0,0 +1,211 @@
|
|||
defmodule NullaWeb.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
|
118
test/nulla_web/controllers/media_attachment_controller_test.exs
Normal file
118
test/nulla_web/controllers/media_attachment_controller_test.exs
Normal file
|
@ -0,0 +1,118 @@
|
|||
defmodule NullaWeb.MediaAttachmentControllerTest do
|
||||
use NullaWeb.ConnCase
|
||||
|
||||
import Nulla.NotesFixtures
|
||||
import Nulla.MediaAttachmentsFixtures
|
||||
|
||||
alias Nulla.MediaAttachments.MediaAttachment
|
||||
|
||||
@create_attrs %{
|
||||
name: "some name",
|
||||
type: "some type",
|
||||
width: 42,
|
||||
url: "some url",
|
||||
mediaType: "some mediaType",
|
||||
height: 42
|
||||
}
|
||||
@update_attrs %{
|
||||
name: "some updated name",
|
||||
type: "some updated type",
|
||||
width: 43,
|
||||
url: "some updated url",
|
||||
mediaType: "some updated mediaType",
|
||||
height: 43
|
||||
}
|
||||
@invalid_attrs %{name: nil, type: nil, width: nil, url: nil, mediaType: nil, height: nil}
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all media_attachments", %{conn: conn} do
|
||||
conn = get(conn, ~p"/api/media_attachments")
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create media_attachment" do
|
||||
test "renders media_attachment when data is valid", %{conn: conn} do
|
||||
note = note_fixture()
|
||||
|
||||
create_attrs = Map.merge(@create_attrs, %{note_id: note.id})
|
||||
|
||||
conn = post(conn, ~p"/api/media_attachments", media_attachment: create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/media_attachments/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"height" => 42,
|
||||
"mediaType" => "some mediaType",
|
||||
"name" => "some name",
|
||||
"type" => "some type",
|
||||
"url" => "some url",
|
||||
"width" => 42
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/media_attachments", media_attachment: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update media_attachment" do
|
||||
setup [:create_media_attachment]
|
||||
|
||||
test "renders media_attachment when data is valid", %{
|
||||
conn: conn,
|
||||
media_attachment: %MediaAttachment{id: id} = media_attachment
|
||||
} do
|
||||
conn =
|
||||
put(conn, ~p"/api/media_attachments/#{media_attachment}", media_attachment: @update_attrs)
|
||||
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/media_attachments/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"height" => 43,
|
||||
"mediaType" => "some updated mediaType",
|
||||
"name" => "some updated name",
|
||||
"type" => "some updated type",
|
||||
"url" => "some updated url",
|
||||
"width" => 43
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, media_attachment: media_attachment} do
|
||||
conn =
|
||||
put(conn, ~p"/api/media_attachments/#{media_attachment}",
|
||||
media_attachment: @invalid_attrs
|
||||
)
|
||||
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete media_attachment" do
|
||||
setup [:create_media_attachment]
|
||||
|
||||
test "deletes chosen media_attachment", %{conn: conn, media_attachment: media_attachment} do
|
||||
conn = delete(conn, ~p"/api/media_attachments/#{media_attachment}")
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, ~p"/api/media_attachments/#{media_attachment}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_media_attachment(_) do
|
||||
media_attachment = media_attachment_fixture()
|
||||
%{media_attachment: media_attachment}
|
||||
end
|
||||
end
|
131
test/nulla_web/controllers/note_controller_test.exs
Normal file
131
test/nulla_web/controllers/note_controller_test.exs
Normal file
|
@ -0,0 +1,131 @@
|
|||
defmodule NullaWeb.NoteControllerTest do
|
||||
use NullaWeb.ConnCase
|
||||
|
||||
import Nulla.ActorsFixtures
|
||||
import Nulla.NotesFixtures
|
||||
|
||||
alias Nulla.Notes.Note
|
||||
|
||||
@create_attrs %{
|
||||
sensitive: true,
|
||||
cc: ["option1", "option2"],
|
||||
to: ["option1", "option2"],
|
||||
url: "some url",
|
||||
language: "some language",
|
||||
inReplyTo: "some inReplyTo",
|
||||
published: ~U[2025-07-01 09:17:00Z],
|
||||
visibility: "some visibility",
|
||||
content: "some content"
|
||||
}
|
||||
@update_attrs %{
|
||||
sensitive: false,
|
||||
cc: ["option1"],
|
||||
to: ["option1"],
|
||||
url: "some updated url",
|
||||
language: "some updated language",
|
||||
inReplyTo: "some updated inReplyTo",
|
||||
published: ~U[2025-07-02 09:17:00Z],
|
||||
visibility: "some updated visibility",
|
||||
content: "some updated content"
|
||||
}
|
||||
@invalid_attrs %{
|
||||
sensitive: nil,
|
||||
cc: nil,
|
||||
to: nil,
|
||||
url: nil,
|
||||
language: nil,
|
||||
inReplyTo: nil,
|
||||
published: nil,
|
||||
visibility: nil,
|
||||
content: nil
|
||||
}
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all notes", %{conn: conn} do
|
||||
conn = get(conn, ~p"/api/notes")
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create note" do
|
||||
test "renders note when data is valid", %{conn: conn} do
|
||||
actor = actor_fixture()
|
||||
|
||||
create_attrs = Map.merge(@create_attrs, %{actor_id: actor.id})
|
||||
|
||||
conn = post(conn, ~p"/api/notes", note: create_attrs)
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/notes/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"cc" => ["option1", "option2"],
|
||||
"content" => "some content",
|
||||
"inReplyTo" => "some inReplyTo",
|
||||
"language" => "some language",
|
||||
"published" => "2025-07-01T09:17:00Z",
|
||||
"sensitive" => true,
|
||||
"to" => ["option1", "option2"],
|
||||
"url" => "some url",
|
||||
"visibility" => "some visibility"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/api/notes", note: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update note" do
|
||||
setup [:create_note]
|
||||
|
||||
test "renders note when data is valid", %{conn: conn, note: %Note{id: id} = note} do
|
||||
conn = put(conn, ~p"/api/notes/#{note}", note: @update_attrs)
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get(conn, ~p"/api/notes/#{id}")
|
||||
|
||||
assert %{
|
||||
"id" => ^id,
|
||||
"cc" => ["option1"],
|
||||
"content" => "some updated content",
|
||||
"inReplyTo" => "some updated inReplyTo",
|
||||
"language" => "some updated language",
|
||||
"published" => "2025-07-02T09:17:00Z",
|
||||
"sensitive" => false,
|
||||
"to" => ["option1"],
|
||||
"url" => "some updated url",
|
||||
"visibility" => "some updated visibility"
|
||||
} = json_response(conn, 200)["data"]
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, note: note} do
|
||||
conn = put(conn, ~p"/api/notes/#{note}", note: @invalid_attrs)
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete note" do
|
||||
setup [:create_note]
|
||||
|
||||
test "deletes chosen note", %{conn: conn, note: note} do
|
||||
conn = delete(conn, ~p"/api/notes/#{note}")
|
||||
assert response(conn, 204)
|
||||
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, ~p"/api/notes/#{note}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_note(_) do
|
||||
note = note_fixture()
|
||||
%{note: note}
|
||||
end
|
||||
end
|
154
test/nulla_web/controllers/relation_controller_test.exs
Normal file
154
test/nulla_web/controllers/relation_controller_test.exs
Normal file
|
@ -0,0 +1,154 @@
|
|||
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
|
113
test/nulla_web/controllers/user_session_controller_test.exs
Normal file
113
test/nulla_web/controllers/user_session_controller_test.exs
Normal file
|
@ -0,0 +1,113 @@
|
|||
defmodule NullaWeb.UserSessionControllerTest do
|
||||
use NullaWeb.ConnCase, async: true
|
||||
|
||||
import Nulla.AccountsFixtures
|
||||
|
||||
setup do
|
||||
%{user: user_fixture()}
|
||||
end
|
||||
|
||||
describe "POST /users/log_in" do
|
||||
test "logs the user in", %{conn: conn, user: user} do
|
||||
conn =
|
||||
post(conn, ~p"/users/log_in", %{
|
||||
"user" => %{"email" => user.email, "password" => valid_user_password()}
|
||||
})
|
||||
|
||||
assert get_session(conn, :user_token)
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
|
||||
# Now do a logged in request and assert on the menu
|
||||
conn = get(conn, ~p"/")
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ user.email
|
||||
assert response =~ ~p"/users/settings"
|
||||
assert response =~ ~p"/users/log_out"
|
||||
end
|
||||
|
||||
test "logs the user in with remember me", %{conn: conn, user: user} do
|
||||
conn =
|
||||
post(conn, ~p"/users/log_in", %{
|
||||
"user" => %{
|
||||
"email" => user.email,
|
||||
"password" => valid_user_password(),
|
||||
"remember_me" => "true"
|
||||
}
|
||||
})
|
||||
|
||||
assert conn.resp_cookies["_nulla_web_user_remember_me"]
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
end
|
||||
|
||||
test "logs the user in with return to", %{conn: conn, user: user} do
|
||||
conn =
|
||||
conn
|
||||
|> init_test_session(user_return_to: "/foo/bar")
|
||||
|> post(~p"/users/log_in", %{
|
||||
"user" => %{
|
||||
"email" => user.email,
|
||||
"password" => valid_user_password()
|
||||
}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/foo/bar"
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Welcome back!"
|
||||
end
|
||||
|
||||
test "login following registration", %{conn: conn, user: user} do
|
||||
conn =
|
||||
conn
|
||||
|> post(~p"/users/log_in", %{
|
||||
"_action" => "registered",
|
||||
"user" => %{
|
||||
"email" => user.email,
|
||||
"password" => valid_user_password()
|
||||
}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Account created successfully"
|
||||
end
|
||||
|
||||
test "login following password update", %{conn: conn, user: user} do
|
||||
conn =
|
||||
conn
|
||||
|> post(~p"/users/log_in", %{
|
||||
"_action" => "password_updated",
|
||||
"user" => %{
|
||||
"email" => user.email,
|
||||
"password" => valid_user_password()
|
||||
}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == ~p"/users/settings"
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Password updated successfully"
|
||||
end
|
||||
|
||||
test "redirects to login page with invalid credentials", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, ~p"/users/log_in", %{
|
||||
"user" => %{"email" => "invalid@email.com", "password" => "invalid_password"}
|
||||
})
|
||||
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :error) == "Invalid email or password"
|
||||
assert redirected_to(conn) == ~p"/users/log_in"
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /users/log_out" do
|
||||
test "logs the user out", %{conn: conn, user: user} do
|
||||
conn = conn |> log_in_user(user) |> delete(~p"/users/log_out")
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
refute get_session(conn, :user_token)
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Logged out successfully"
|
||||
end
|
||||
|
||||
test "succeeds even if the user is not logged in", %{conn: conn} do
|
||||
conn = delete(conn, ~p"/users/log_out")
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
refute get_session(conn, :user_token)
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Logged out successfully"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue