Update tests
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
dee437e4f3
commit
73ef0dc6af
|
@ -76,7 +76,8 @@ defmodule Eventos.Actors.Actor do
|
||||||
@doc false
|
@doc false
|
||||||
def changeset(%Actor{} = actor, attrs) do
|
def changeset(%Actor{} = actor, attrs) do
|
||||||
actor
|
actor
|
||||||
|> Ecto.Changeset.cast(attrs, [:url, :outbox_url, :inbox_url, :shared_inbox_url, :following_url, :followers_url, :type, :name, :domain, :summary, :preferred_username, :keys, :manually_approves_followers, :suspended, :avatar_url, :banner_url])
|
|> Ecto.Changeset.cast(attrs, [:url, :outbox_url, :inbox_url, :shared_inbox_url, :following_url, :followers_url, :type, :name, :domain, :summary, :preferred_username, :keys, :manually_approves_followers, :suspended, :avatar_url, :banner_url, :user_id])
|
||||||
|
|> put_change(:url, "#{EventosWeb.Endpoint.url()}/@#{attrs["prefered_username"]}")
|
||||||
|> validate_required([:preferred_username, :keys, :suspended, :url])
|
|> validate_required([:preferred_username, :keys, :suspended, :url])
|
||||||
|> unique_constraint(:prefered_username, name: :actors_preferred_username_domain_index)
|
|> unique_constraint(:prefered_username, name: :actors_preferred_username_domain_index)
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ defmodule EventosWeb.ActorController do
|
||||||
use EventosWeb, :controller
|
use EventosWeb, :controller
|
||||||
|
|
||||||
alias Eventos.Actors
|
alias Eventos.Actors
|
||||||
alias Eventos.Actors.Actor
|
alias Eventos.Actors.{Actor, User}
|
||||||
alias Eventos.Service.ActivityPub
|
alias Eventos.Service.ActivityPub
|
||||||
|
|
||||||
action_fallback EventosWeb.FallbackController
|
action_fallback EventosWeb.FallbackController
|
||||||
|
@ -15,6 +15,17 @@ defmodule EventosWeb.ActorController do
|
||||||
render(conn, "index.json", actors: actors)
|
render(conn, "index.json", actors: actors)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create(conn, %{"actor" => actor_params}) do
|
||||||
|
with %User{} = user <- Guardian.Plug.current_resource(conn),
|
||||||
|
actor_params <- Map.put(actor_params, "user_id", user.id),
|
||||||
|
{:ok, %Actor{} = actor} <- Actors.create_actor(actor_params) do
|
||||||
|
conn
|
||||||
|
|> put_status(:created)
|
||||||
|
|> put_resp_header("location", actor_path(conn, :show, actor.preferred_username))
|
||||||
|
|> render("show_basic.json", actor: actor)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def show(conn, %{"name" => name}) do
|
def show(conn, %{"name" => name}) do
|
||||||
actor = Actors.get_actor_by_name_with_everything(name)
|
actor = Actors.get_actor_by_name_with_everything(name)
|
||||||
render(conn, "show.json", actor: actor)
|
render(conn, "show.json", actor: actor)
|
||||||
|
|
|
@ -76,6 +76,7 @@ defmodule EventosWeb.Router do
|
||||||
get "/user", UserController, :show_current_actor
|
get "/user", UserController, :show_current_actor
|
||||||
post "/sign-out", UserSessionController, :sign_out
|
post "/sign-out", UserSessionController, :sign_out
|
||||||
resources "/users", UserController, except: [:new, :edit, :show]
|
resources "/users", UserController, except: [:new, :edit, :show]
|
||||||
|
post "/actors", ActorController, :create
|
||||||
patch "/actors/:name", ActorController, :update
|
patch "/actors/:name", ActorController, :update
|
||||||
post "/events", EventController, :create
|
post "/events", EventController, :create
|
||||||
patch "/events/:uuid", EventController, :update
|
patch "/events/:uuid", EventController, :update
|
||||||
|
|
|
@ -37,7 +37,6 @@ defmodule Eventos.ActorsTest do
|
||||||
assert actor.domain == "some domain"
|
assert actor.domain == "some domain"
|
||||||
assert actor.keys == "some keypair"
|
assert actor.keys == "some keypair"
|
||||||
assert actor.suspended
|
assert actor.suspended
|
||||||
assert actor.url == "some url"
|
|
||||||
assert actor.preferred_username == "some username"
|
assert actor.preferred_username == "some username"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,7 +53,6 @@ defmodule Eventos.ActorsTest do
|
||||||
assert actor.domain == "some updated domain"
|
assert actor.domain == "some updated domain"
|
||||||
assert actor.keys == "some updated keys"
|
assert actor.keys == "some updated keys"
|
||||||
refute actor.suspended
|
refute actor.suspended
|
||||||
assert actor.url == "some updated url"
|
|
||||||
assert actor.preferred_username == "some updated username"
|
assert actor.preferred_username == "some updated username"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,12 @@ defmodule EventosWeb.ActorControllerTest do
|
||||||
{:ok, conn: conn, user: user, actor: actor}
|
{:ok, conn: conn, user: user, actor: actor}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
key = :public_key.generate_key({:rsa, 2048, 65_537})
|
||||||
|
entry = :public_key.pem_entry_encode(:RSAPrivateKey, key)
|
||||||
|
pem = [entry] |> :public_key.pem_encode() |> String.trim_trailing()
|
||||||
|
|
||||||
|
@create_attrs %{preferred_username: "otheridentity", summary: "This is my other identity", domain: nil, keys: pem, user: nil}
|
||||||
|
|
||||||
describe "index" do
|
describe "index" do
|
||||||
test "lists all actors", %{conn: conn, user: user, actor: actor} do
|
test "lists all actors", %{conn: conn, user: user, actor: actor} do
|
||||||
conn = get conn, actor_path(conn, :index)
|
conn = get conn, actor_path(conn, :index)
|
||||||
|
@ -18,6 +24,14 @@ defmodule EventosWeb.ActorControllerTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "create actor" do
|
||||||
|
test "from an existing user", %{conn: conn, user: user} do
|
||||||
|
conn = auth_conn(conn, user)
|
||||||
|
conn = post conn, actor_path(conn, :create), actor: @create_attrs
|
||||||
|
assert json_response(conn, 201)["data"]["username"] == @create_attrs.preferred_username
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
###
|
###
|
||||||
# Not possible atm
|
# Not possible atm
|
||||||
###
|
###
|
||||||
|
|
Loading…
Reference in New Issue