@@ -540,4 +540,66 @@ defmodule Eventos.EventsTest do
|
||||
assert %Ecto.Changeset{} = Events.change_track(track)
|
||||
end
|
||||
end
|
||||
|
||||
describe "comments" do
|
||||
alias Eventos.Events.Comment
|
||||
|
||||
@valid_attrs %{text: "some text", url: "some url"}
|
||||
@update_attrs %{text: "some updated text", url: "some updated url"}
|
||||
@invalid_attrs %{text: nil, url: nil}
|
||||
|
||||
def comment_fixture(attrs \\ %{}) do
|
||||
{:ok, comment} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> Events.create_comment()
|
||||
|
||||
comment
|
||||
end
|
||||
|
||||
test "list_comments/0 returns all comments" do
|
||||
comment = comment_fixture()
|
||||
assert Events.list_comments() == [comment]
|
||||
end
|
||||
|
||||
test "get_comment!/1 returns the comment with given id" do
|
||||
comment = comment_fixture()
|
||||
assert Events.get_comment!(comment.id) == comment
|
||||
end
|
||||
|
||||
test "create_comment/1 with valid data creates a comment" do
|
||||
assert {:ok, %Comment{} = comment} = Events.create_comment(@valid_attrs)
|
||||
assert comment.text == "some text"
|
||||
assert comment.url == "some url"
|
||||
end
|
||||
|
||||
test "create_comment/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Events.create_comment(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_comment/2 with valid data updates the comment" do
|
||||
comment = comment_fixture()
|
||||
assert {:ok, comment} = Events.update_comment(comment, @update_attrs)
|
||||
assert %Comment{} = comment
|
||||
assert comment.text == "some updated text"
|
||||
assert comment.url == "some updated url"
|
||||
end
|
||||
|
||||
test "update_comment/2 with invalid data returns error changeset" do
|
||||
comment = comment_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Events.update_comment(comment, @invalid_attrs)
|
||||
assert comment == Events.get_comment!(comment.id)
|
||||
end
|
||||
|
||||
test "delete_comment/1 deletes the comment" do
|
||||
comment = comment_fixture()
|
||||
assert {:ok, %Comment{}} = Events.delete_comment(comment)
|
||||
assert_raise Ecto.NoResultsError, fn -> Events.get_comment!(comment.id) end
|
||||
end
|
||||
|
||||
test "change_comment/1 returns a comment changeset" do
|
||||
comment = comment_fixture()
|
||||
assert %Ecto.Changeset{} = Events.change_comment(comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
81
test/eventos/service/activitypub/activitypub_test.exs
Normal file
81
test/eventos/service/activitypub/activitypub_test.exs
Normal file
@@ -0,0 +1,81 @@
|
||||
defmodule Eventos.Service.Activitypub.ActivitypubTest do
|
||||
|
||||
use Eventos.DataCase
|
||||
|
||||
import Eventos.Factory
|
||||
|
||||
alias Eventos.Events
|
||||
alias Eventos.Accounts.Account
|
||||
alias Eventos.Service.ActivityPub
|
||||
alias Eventos.Activity
|
||||
|
||||
describe "fetching account from it's url" do
|
||||
test "returns an account" do
|
||||
assert {:ok, %Account{username: "tcit@framapiaf.org"} = account} = ActivityPub.make_account_from_nickname("tcit@framapiaf.org")
|
||||
end
|
||||
end
|
||||
|
||||
describe "create activities" do
|
||||
test "removes doubled 'to' recipients" do
|
||||
account = insert(:account)
|
||||
|
||||
{:ok, activity} =
|
||||
ActivityPub.create(%{
|
||||
to: ["user1", "user1", "user2"],
|
||||
actor: account,
|
||||
context: "",
|
||||
object: %{}
|
||||
})
|
||||
|
||||
assert activity.data["to"] == ["user1", "user2"]
|
||||
assert activity.actor == account.url
|
||||
assert activity.recipients == ["user1", "user2"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetching an object" do
|
||||
test "it fetches an object" do
|
||||
{:ok, object} =
|
||||
ActivityPub.fetch_event_from_url("https://social.tcit.fr/@tcit/99908779444618462")
|
||||
|
||||
{:ok, object_again} =
|
||||
ActivityPub.fetch_event_from_url("https://social.tcit.fr/@tcit/99908779444618462")
|
||||
|
||||
assert object == object_again
|
||||
end
|
||||
end
|
||||
|
||||
describe "deletion" do
|
||||
test "it creates a delete activity and deletes the original event" do
|
||||
event = insert(:event)
|
||||
event = Events.get_event_full_by_url!(event.url)
|
||||
{:ok, delete} = ActivityPub.delete(event)
|
||||
|
||||
assert delete.data["type"] == "Delete"
|
||||
assert delete.data["actor"] == event.organizer_account.url
|
||||
assert delete.data["object"] == event.url
|
||||
|
||||
assert Events.get_event_by_url!(event.url) == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "update" do
|
||||
test "it creates an update activity with the new user data" do
|
||||
account = insert(:account)
|
||||
account_data = EventosWeb.ActivityPub.UserView.render("account.json", %{account: account})
|
||||
|
||||
{:ok, update} =
|
||||
ActivityPub.update(%{
|
||||
actor: account_data["url"],
|
||||
to: [account.url <> "/followers"],
|
||||
cc: [],
|
||||
object: account_data
|
||||
})
|
||||
|
||||
assert update.data["actor"] == account.url
|
||||
assert update.data["to"] == [account.url <> "/followers"]
|
||||
assert update.data["object"]["id"] == account_data["id"]
|
||||
assert update.data["object"]["type"] == account_data["type"]
|
||||
end
|
||||
end
|
||||
end
|
||||
59
test/eventos/service/web_finger/web_finger_test.exs
Normal file
59
test/eventos/service/web_finger/web_finger_test.exs
Normal file
@@ -0,0 +1,59 @@
|
||||
defmodule Eventos.Service.WebFingerTest do
|
||||
use Eventos.DataCase
|
||||
alias Eventos.Service.WebFinger
|
||||
import Eventos.Factory
|
||||
|
||||
describe "host meta" do
|
||||
test "returns a link to the xml lrdd" do
|
||||
host_info = WebFinger.host_meta()
|
||||
|
||||
assert String.contains?(host_info, EventosWeb.Endpoint.url())
|
||||
end
|
||||
end
|
||||
|
||||
describe "incoming webfinger request" do
|
||||
test "works for fqns" do
|
||||
account = insert(:account)
|
||||
|
||||
{:ok, result} =
|
||||
WebFinger.webfinger("#{account.username}@#{EventosWeb.Endpoint.host()}", "JSON")
|
||||
assert is_map(result)
|
||||
end
|
||||
|
||||
test "works for urls" do
|
||||
account = insert(:account)
|
||||
|
||||
{:ok, result} = WebFinger.webfinger(account.url, "JSON")
|
||||
assert is_map(result)
|
||||
end
|
||||
end
|
||||
|
||||
describe "fingering" do
|
||||
|
||||
test "a mastodon account" do
|
||||
account = "tcit@social.tcit.fr"
|
||||
|
||||
assert {:ok, %{"subject" => "acct:" <> account, "url" => "https://social.tcit.fr/users/tcit"}} = WebFinger.finger(account)
|
||||
end
|
||||
|
||||
test "a pleroma account" do
|
||||
account = "@lain@pleroma.soykaf.com"
|
||||
|
||||
assert {:ok, %{"subject" => "acct:" <> account, "url" => "https://pleroma.soykaf.com/users/lain"}} = WebFinger.finger(account)
|
||||
end
|
||||
|
||||
test "a peertube account" do
|
||||
account = "framasoft@framatube.org"
|
||||
|
||||
assert {:ok, %{"subject" => "acct:" <> account, "url" => "https://framatube.org/accounts/framasoft"}} = WebFinger.finger(account)
|
||||
end
|
||||
|
||||
test "a friendica account" do
|
||||
# Hasn't any ActivityPub
|
||||
account = "lain@squeet.me"
|
||||
|
||||
assert {:ok, %{"subject" => "acct:" <> account} = data} = WebFinger.finger(account)
|
||||
refute Map.has_key?(data, "url")
|
||||
end
|
||||
end
|
||||
end
|
||||
139
test/eventos_web/controllers/activity_pub_controller_test.exs
Normal file
139
test/eventos_web/controllers/activity_pub_controller_test.exs
Normal file
@@ -0,0 +1,139 @@
|
||||
defmodule EventosWeb.ActivityPubControllerTest do
|
||||
use EventosWeb.ConnCase
|
||||
import Eventos.Factory
|
||||
alias EventosWeb.ActivityPub.{AccountView, ObjectView}
|
||||
alias Eventos.{Repo, Accounts, Accounts.Account}
|
||||
alias Eventos.Activity
|
||||
import Logger
|
||||
|
||||
describe "/@:username" do
|
||||
test "it returns a json representation of the account", %{conn: conn} do
|
||||
account = insert(:account)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/@#{account.username}")
|
||||
|
||||
account = Accounts.get_account!(account.id)
|
||||
|
||||
assert json_response(conn, 200) == AccountView.render("account.json", %{account: account})
|
||||
Logger.error(inspect AccountView.render("account.json", %{account: account}))
|
||||
end
|
||||
end
|
||||
|
||||
describe "/@username/slug" do
|
||||
test "it returns a json representation of the object", %{conn: conn} do
|
||||
event = insert(:event)
|
||||
{slug, parts} = List.pop_at(String.split(event.url, "/"), -1)
|
||||
"@" <> username = List.last(parts)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/@#{username}/#{slug}")
|
||||
|
||||
assert json_response(conn, 200) == ObjectView.render("event.json", %{event: event})
|
||||
Logger.error(inspect ObjectView.render("event.json", %{event: event}))
|
||||
end
|
||||
end
|
||||
|
||||
# describe "/accounts/:username/inbox" do
|
||||
# test "it inserts an incoming activity into the database", %{conn: conn} do
|
||||
# data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
#
|
||||
# conn =
|
||||
# conn
|
||||
# |> assign(:valid_signature, true)
|
||||
# |> put_req_header("content-type", "application/activity+json")
|
||||
# |> post("/inbox", data)
|
||||
#
|
||||
# assert "ok" == json_response(conn, 200)
|
||||
# :timer.sleep(500)
|
||||
# assert Activity.get_by_ap_id(data["id"])
|
||||
# end
|
||||
# end
|
||||
|
||||
# describe "/accounts/:nickname/followers" do
|
||||
# test "it returns the followers in a collection", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
# user_two = insert(:user)
|
||||
# User.follow(user, user_two)
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user_two.nickname}/followers")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert result["first"]["orderedItems"] == [user.ap_id]
|
||||
# end
|
||||
#
|
||||
# test "it works for more than 10 users", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
#
|
||||
# Enum.each(1..15, fn _ ->
|
||||
# other_user = insert(:user)
|
||||
# User.follow(other_user, user)
|
||||
# end)
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/followers")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert length(result["first"]["orderedItems"]) == 10
|
||||
# assert result["first"]["totalItems"] == 15
|
||||
# assert result["totalItems"] == 15
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/followers?page=2")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert length(result["orderedItems"]) == 5
|
||||
# assert result["totalItems"] == 15
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# describe "/users/:nickname/following" do
|
||||
# test "it returns the following in a collection", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
# user_two = insert(:user)
|
||||
# User.follow(user, user_two)
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/following")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert result["first"]["orderedItems"] == [user_two.ap_id]
|
||||
# end
|
||||
#
|
||||
# test "it works for more than 10 users", %{conn: conn} do
|
||||
# user = insert(:user)
|
||||
#
|
||||
# Enum.each(1..15, fn _ ->
|
||||
# user = Repo.get(User, user.id)
|
||||
# other_user = insert(:user)
|
||||
# User.follow(user, other_user)
|
||||
# end)
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/following")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert length(result["first"]["orderedItems"]) == 10
|
||||
# assert result["first"]["totalItems"] == 15
|
||||
# assert result["totalItems"] == 15
|
||||
#
|
||||
# result =
|
||||
# conn
|
||||
# |> get("/users/#{user.nickname}/following?page=2")
|
||||
# |> json_response(200)
|
||||
#
|
||||
# assert length(result["orderedItems"]) == 5
|
||||
# assert result["totalItems"] == 15
|
||||
# end
|
||||
# end
|
||||
end
|
||||
81
test/eventos_web/controllers/comment_controller_test.exs
Normal file
81
test/eventos_web/controllers/comment_controller_test.exs
Normal file
@@ -0,0 +1,81 @@
|
||||
defmodule EventosWeb.CommentControllerTest do
|
||||
use EventosWeb.ConnCase
|
||||
|
||||
alias Eventos.Events
|
||||
alias Eventos.Events.Comment
|
||||
|
||||
@create_attrs %{text: "some text", url: "some url"}
|
||||
@update_attrs %{text: "some updated text", url: "some updated url"}
|
||||
@invalid_attrs %{text: nil, url: nil}
|
||||
|
||||
def fixture(:comment) do
|
||||
{:ok, comment} = Events.create_comment(@create_attrs)
|
||||
comment
|
||||
end
|
||||
|
||||
setup %{conn: conn} do
|
||||
{:ok, conn: put_req_header(conn, "accept", "application/json")}
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all comments", %{conn: conn} do
|
||||
conn = get conn, comment_path(conn, :index)
|
||||
assert json_response(conn, 200)["data"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "create comment" do
|
||||
test "renders comment when data is valid", %{conn: conn} do
|
||||
conn = post conn, comment_path(conn, :create), comment: @create_attrs
|
||||
assert %{"id" => id} = json_response(conn, 201)["data"]
|
||||
|
||||
conn = get conn, comment_path(conn, :show, id)
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"text" => "some text",
|
||||
"url" => "some url"}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post conn, comment_path(conn, :create), comment: @invalid_attrs
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "update comment" do
|
||||
setup [:create_comment]
|
||||
|
||||
test "renders comment when data is valid", %{conn: conn, comment: %Comment{id: id} = comment} do
|
||||
conn = put conn, comment_path(conn, :update, comment), comment: @update_attrs
|
||||
assert %{"id" => ^id} = json_response(conn, 200)["data"]
|
||||
|
||||
conn = get conn, comment_path(conn, :show, id)
|
||||
assert json_response(conn, 200)["data"] == %{
|
||||
"id" => id,
|
||||
"text" => "some updated text",
|
||||
"url" => "some updated url"}
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, comment: comment} do
|
||||
conn = put conn, comment_path(conn, :update, comment), comment: @invalid_attrs
|
||||
assert json_response(conn, 422)["errors"] != %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete comment" do
|
||||
setup [:create_comment]
|
||||
|
||||
test "deletes chosen comment", %{conn: conn, comment: comment} do
|
||||
conn = delete conn, comment_path(conn, :delete, comment)
|
||||
assert response(conn, 204)
|
||||
assert_error_sent 404, fn ->
|
||||
get conn, comment_path(conn, :show, comment)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_comment(_) do
|
||||
comment = fixture(:comment)
|
||||
{:ok, comment: comment}
|
||||
end
|
||||
end
|
||||
@@ -16,12 +16,12 @@ defmodule Eventos.Factory do
|
||||
|
||||
def account_factory do
|
||||
{:ok, {_, pubkey}} = RsaEx.generate_keypair("4096")
|
||||
username = sequence("thomas")
|
||||
%Eventos.Accounts.Account{
|
||||
username: sequence("Thomas"),
|
||||
username: username,
|
||||
domain: nil,
|
||||
public_key: pubkey,
|
||||
uri: "https://",
|
||||
url: "https://"
|
||||
url: EventosWeb.Endpoint.url() <> "/@#{username}"
|
||||
}
|
||||
end
|
||||
|
||||
@@ -46,15 +46,19 @@ defmodule Eventos.Factory do
|
||||
end
|
||||
|
||||
def event_factory do
|
||||
account = build(:account)
|
||||
slug = sequence("my-event")
|
||||
|
||||
%Eventos.Events.Event{
|
||||
title: sequence("MyEvent"),
|
||||
slug: sequence("my-event"),
|
||||
slug: slug,
|
||||
description: "My desc",
|
||||
begins_on: nil,
|
||||
ends_on: nil,
|
||||
organizer_account: build(:account),
|
||||
organizer_account: account,
|
||||
category: build(:category),
|
||||
address: build(:address)
|
||||
address: build(:address),
|
||||
url: EventosWeb.Endpoint.url() <> "/@" <> account.username <> "/" <> slug
|
||||
}
|
||||
end
|
||||
|
||||
@@ -79,7 +83,6 @@ defmodule Eventos.Factory do
|
||||
description: "My group",
|
||||
suspended: false,
|
||||
url: "https://",
|
||||
uri: "https://",
|
||||
address: build(:address)
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user