Add all
This commit is contained in:
parent
b35e18cd20
commit
82f55f7afe
80 changed files with 6687 additions and 5 deletions
|
@ -35,4 +35,30 @@ defmodule NullaWeb.ConnCase do
|
|||
Nulla.DataCase.setup_sandbox(tags)
|
||||
{:ok, conn: Phoenix.ConnTest.build_conn()}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Setup helper that registers and logs in users.
|
||||
|
||||
setup :register_and_log_in_user
|
||||
|
||||
It stores an updated connection and a registered user in the
|
||||
test context.
|
||||
"""
|
||||
def register_and_log_in_user(%{conn: conn}) do
|
||||
user = Nulla.AccountsFixtures.user_fixture()
|
||||
%{conn: log_in_user(conn, user), user: user}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Logs the given `user` into the `conn`.
|
||||
|
||||
It returns an updated `conn`.
|
||||
"""
|
||||
def log_in_user(conn, user) do
|
||||
token = Nulla.Accounts.generate_user_session_token(user)
|
||||
|
||||
conn
|
||||
|> Phoenix.ConnTest.init_test_session(%{})
|
||||
|> Plug.Conn.put_session(:user_token, token)
|
||||
end
|
||||
end
|
||||
|
|
31
test/support/fixtures/accounts_fixtures.ex
Normal file
31
test/support/fixtures/accounts_fixtures.ex
Normal file
|
@ -0,0 +1,31 @@
|
|||
defmodule Nulla.AccountsFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Nulla.Accounts` context.
|
||||
"""
|
||||
|
||||
def unique_user_email, do: "user#{System.unique_integer()}@example.com"
|
||||
def valid_user_password, do: "hello world!"
|
||||
|
||||
def valid_user_attributes(attrs \\ %{}) do
|
||||
Enum.into(attrs, %{
|
||||
email: unique_user_email(),
|
||||
password: valid_user_password()
|
||||
})
|
||||
end
|
||||
|
||||
def user_fixture(attrs \\ %{}) do
|
||||
{:ok, user} =
|
||||
attrs
|
||||
|> valid_user_attributes()
|
||||
|> Nulla.Accounts.register_user()
|
||||
|
||||
user
|
||||
end
|
||||
|
||||
def extract_user_token(fun) do
|
||||
{:ok, captured_email} = fun.(&"[TOKEN]#{&1}[TOKEN]")
|
||||
[_, token | _] = String.split(captured_email.text_body, "[TOKEN]")
|
||||
token
|
||||
end
|
||||
end
|
25
test/support/fixtures/activities_fixtures.ex
Normal file
25
test/support/fixtures/activities_fixtures.ex
Normal file
|
@ -0,0 +1,25 @@
|
|||
defmodule Nulla.ActivitiesFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Nulla.Activities` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a activity.
|
||||
"""
|
||||
def activity_fixture(attrs \\ %{}) do
|
||||
{:ok, activity} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
actor: "some actor",
|
||||
ap_id: "some ap_id",
|
||||
cc: ["option1", "option2"],
|
||||
object: "some object",
|
||||
to: ["option1", "option2"],
|
||||
type: "some type"
|
||||
})
|
||||
|> Nulla.Activities.create_activity()
|
||||
|
||||
activity
|
||||
end
|
||||
end
|
60
test/support/fixtures/actors_fixtures.ex
Normal file
60
test/support/fixtures/actors_fixtures.ex
Normal file
|
@ -0,0 +1,60 @@
|
|||
defmodule Nulla.ActorsFixtures do
|
||||
alias Nulla.KeyGen
|
||||
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Nulla.Actors` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a actor.
|
||||
"""
|
||||
def actor_fixture(attrs \\ %{}) do
|
||||
username = "test#{System.unique_integer()}"
|
||||
{publicKeyPem, privateKeyPem} = KeyGen.gen()
|
||||
|
||||
attrs =
|
||||
Enum.into(attrs, %{
|
||||
acct: "#{username}@localhost",
|
||||
ap_id: "http://localhost/users/#{username}",
|
||||
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: username,
|
||||
publicKey: %{
|
||||
"id" => "http://localhost/users/#{username}#main-key",
|
||||
"owner" => "http://localhost/users/#{username}",
|
||||
"publicKeyPem" => publicKeyPem
|
||||
},
|
||||
privateKeyPem: privateKeyPem,
|
||||
published: ~U[2025-06-30 13:31:00Z],
|
||||
summary: "some summary",
|
||||
tag: [],
|
||||
type: "some type",
|
||||
url: "some url",
|
||||
vcard_Address: "some vcard_Address",
|
||||
vcard_bday: ~D[2025-06-30]
|
||||
})
|
||||
|
||||
case Nulla.Actors.create_actor(attrs) do
|
||||
{:ok, actor} ->
|
||||
actor
|
||||
|
||||
{:error, changeset} ->
|
||||
IO.inspect(changeset, label: "Actor creation failed")
|
||||
raise "Failed to create actor fixture"
|
||||
end
|
||||
end
|
||||
end
|
30
test/support/fixtures/media_attachments_fixtures.ex
Normal file
30
test/support/fixtures/media_attachments_fixtures.ex
Normal file
|
@ -0,0 +1,30 @@
|
|||
defmodule Nulla.MediaAttachmentsFixtures do
|
||||
import Nulla.NotesFixtures
|
||||
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Nulla.MediaAttachments` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a media_attachment.
|
||||
"""
|
||||
def media_attachment_fixture(attrs \\ %{}) do
|
||||
note = note_fixture()
|
||||
|
||||
{:ok, media_attachment} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
height: 42,
|
||||
mediaType: "some mediaType",
|
||||
name: "some name",
|
||||
type: "some type",
|
||||
url: "some url",
|
||||
width: 42,
|
||||
note_id: note.id
|
||||
})
|
||||
|> Nulla.MediaAttachments.create_media_attachment()
|
||||
|
||||
media_attachment
|
||||
end
|
||||
end
|
33
test/support/fixtures/notes_fixtures.ex
Normal file
33
test/support/fixtures/notes_fixtures.ex
Normal file
|
@ -0,0 +1,33 @@
|
|||
defmodule Nulla.NotesFixtures do
|
||||
import Nulla.ActorsFixtures
|
||||
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Nulla.Notes` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a note.
|
||||
"""
|
||||
def note_fixture(attrs \\ %{}) do
|
||||
actor = actor_fixture()
|
||||
|
||||
{:ok, note} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
cc: ["option1", "option2"],
|
||||
content: "some content",
|
||||
inReplyTo: "some inReplyTo",
|
||||
language: "some language",
|
||||
published: ~U[2025-07-01 09:17:00Z],
|
||||
sensitive: true,
|
||||
to: ["option1", "option2"],
|
||||
url: "some url",
|
||||
visibility: "some visibility",
|
||||
actor_id: actor.id
|
||||
})
|
||||
|> Nulla.Notes.create_note()
|
||||
|
||||
note
|
||||
end
|
||||
end
|
38
test/support/fixtures/relations_fixtures.ex
Normal file
38
test/support/fixtures/relations_fixtures.ex
Normal file
|
@ -0,0 +1,38 @@
|
|||
defmodule Nulla.RelationsFixtures do
|
||||
import Nulla.ActorsFixtures
|
||||
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Nulla.Relations` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a relation.
|
||||
"""
|
||||
def relation_fixture(attrs \\ %{}) do
|
||||
local_actor = actor_fixture()
|
||||
remote_actor = actor_fixture()
|
||||
|
||||
{:ok, relation} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
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,
|
||||
local_actor_id: local_actor.id,
|
||||
remote_actor_id: remote_actor.id
|
||||
})
|
||||
|> Nulla.Relations.create_relation()
|
||||
|
||||
relation
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue