@@ -585,23 +585,23 @@ defmodule Mobilizon.ActorsTest do
|
||||
actor = Actors.get_actor_with_everything!(actor.id)
|
||||
target_actor = Actors.get_actor_with_everything!(target_actor.id)
|
||||
|
||||
{:ok, follower} = Actor.follow(actor, target_actor)
|
||||
{:ok, follower} = Actor.follow(target_actor, actor)
|
||||
assert follower.actor.id == actor.id
|
||||
|
||||
# Referesh followers/followings
|
||||
actor = Actors.get_actor_with_everything!(actor.id)
|
||||
target_actor = Actors.get_actor_with_everything!(target_actor.id)
|
||||
|
||||
assert target_actor.followers |> Enum.map(&(&1.actor_id)) == [actor.id]
|
||||
assert actor.followings |> Enum.map(&(&1.target_actor_id)) == [target_actor.id]
|
||||
assert target_actor.followers |> Enum.map(& &1.actor_id) == [actor.id]
|
||||
assert actor.followings |> Enum.map(& &1.target_actor_id) == [target_actor.id]
|
||||
|
||||
# Test if actor is already following target actor
|
||||
{:error, msg} = Actor.follow(actor, target_actor)
|
||||
{:error, msg} = Actor.follow(target_actor, actor)
|
||||
assert msg =~ "already following"
|
||||
|
||||
# Test if target actor is suspended
|
||||
target_actor = %{target_actor | suspended: true}
|
||||
{:error, msg} = Actor.follow(actor, target_actor)
|
||||
{:error, msg} = Actor.follow(target_actor, actor)
|
||||
assert msg =~ "suspended"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||
import Mobilizon.Factory
|
||||
alias MobilizonWeb.ActivityPub.{ActorView, ObjectView}
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
alias Mobilizon.Service.ActivityPub.Utils
|
||||
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
|
||||
@@ -47,6 +48,32 @@ defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "/comments/:uuid" do
|
||||
test "it returns a json representation of the comment", %{conn: conn} do
|
||||
comment = insert(:comment)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/comments/#{comment.uuid}")
|
||||
|
||||
assert json_response(conn, 200) ==
|
||||
ObjectView.render("comment.json", %{comment: comment |> Utils.make_comment_data()})
|
||||
end
|
||||
|
||||
# TODO !
|
||||
# test "it returns 404 for non-public comments", %{conn: conn} do
|
||||
# event = insert(:event, public: false)
|
||||
|
||||
# conn =
|
||||
# conn
|
||||
# |> put_req_header("accept", "application/activity+json")
|
||||
# |> get("/events/#{event.uuid}")
|
||||
|
||||
# assert json_response(conn, 404)
|
||||
# end
|
||||
end
|
||||
|
||||
describe "/@:preferred_username/inbox" do
|
||||
test "it inserts an incoming event into the database", %{conn: conn} do
|
||||
use_cassette "activity_pub_controller/mastodon-post-activity_actor_call" do
|
||||
@@ -91,46 +118,88 @@ defmodule MobilizonWeb.ActivityPubControllerTest do
|
||||
end
|
||||
end
|
||||
|
||||
# describe "/actors/: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 "/@actor/followers" do
|
||||
test "it returns the followers in a collection", %{conn: conn} do
|
||||
actor = insert(:actor)
|
||||
actor2 = insert(:actor)
|
||||
Actor.follow(actor, actor2)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/@#{actor.preferred_username}/followers")
|
||||
|> json_response(200)
|
||||
|
||||
assert result["first"]["orderedItems"] == [actor2.url]
|
||||
end
|
||||
|
||||
test "it works for more than 10 actors", %{conn: conn} do
|
||||
actor = insert(:actor)
|
||||
|
||||
Enum.each(1..15, fn _ ->
|
||||
other_actor = insert(:actor)
|
||||
Actor.follow(actor, other_actor)
|
||||
end)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/@#{actor.preferred_username}/followers")
|
||||
|> json_response(200)
|
||||
|
||||
assert length(result["first"]["orderedItems"]) == 10
|
||||
# assert result["first"]["totalItems"] == 15
|
||||
# assert result["totalItems"] == 15
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/@#{actor.preferred_username}/followers?page=2")
|
||||
|> json_response(200)
|
||||
|
||||
assert length(result["orderedItems"]) == 5
|
||||
# assert result["totalItems"] == 15
|
||||
end
|
||||
end
|
||||
|
||||
describe "/@actor/following" do
|
||||
test "it returns the followings in a collection", %{conn: conn} do
|
||||
actor = insert(:actor)
|
||||
actor2 = insert(:actor)
|
||||
Actor.follow(actor, actor2)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/@#{actor2.preferred_username}/following")
|
||||
|> json_response(200)
|
||||
|
||||
assert result["first"]["orderedItems"] == [actor.url]
|
||||
end
|
||||
|
||||
test "it works for more than 10 actors", %{conn: conn} do
|
||||
actor = insert(:actor)
|
||||
|
||||
Enum.each(1..15, fn _ ->
|
||||
other_actor = insert(:actor)
|
||||
Actor.follow(other_actor, actor)
|
||||
end)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/@#{actor.preferred_username}/following")
|
||||
|> json_response(200)
|
||||
|
||||
assert length(result["first"]["orderedItems"]) == 10
|
||||
# assert result["first"]["totalItems"] == 15
|
||||
# assert result["totalItems"] == 15
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/@#{actor.preferred_username}/following?page=2")
|
||||
|> json_response(200)
|
||||
|
||||
assert length(result["orderedItems"]) == 5
|
||||
# assert result["totalItems"] == 15
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# describe "/@:preferred_username/following" do
|
||||
# test "it returns the following in a collection", %{conn: conn} do
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
defmodule MobilizonWeb.PageControllerTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
import Mobilizon.Factory
|
||||
|
||||
test "GET /", %{conn: conn} do
|
||||
conn = get(conn, "/")
|
||||
assert html_response(conn, 200)
|
||||
end
|
||||
|
||||
test "GET /@actor", %{conn: conn} do
|
||||
actor = insert(:actor)
|
||||
conn = get(conn, "/@#{actor.preferred_username}")
|
||||
assert html_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.Actors.{User, Actor}
|
||||
alias MobilizonWeb.AbsintheHelpers
|
||||
import Mobilizon.Factory
|
||||
use Bamboo.Test
|
||||
@@ -234,4 +235,114 @@ defmodule MobilizonWeb.Resolvers.UserResolverTest do
|
||||
assert hd(json_response(res, 200)["errors"])["message"] ==
|
||||
"No user to validate with this email was found"
|
||||
end
|
||||
|
||||
test "test send_reset_password/3 with valid email", context do
|
||||
user = insert(:user)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
sendResetPassword(
|
||||
email: "#{user.email}"
|
||||
)
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert json_response(res, 200)["data"]["sendResetPassword"] == user.email
|
||||
end
|
||||
|
||||
test "test send_reset_password/3 with invalid email", context do
|
||||
mutation = """
|
||||
mutation {
|
||||
sendResetPassword(
|
||||
email: "oh no"
|
||||
)
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] == "No user with this email was found"
|
||||
end
|
||||
|
||||
test "test reset_password/3 with valid email", context do
|
||||
%User{} = user = insert(:user)
|
||||
%Actor{} = insert(:actor, user: user)
|
||||
{:ok, _email_sent} = Mobilizon.Actors.Service.ResetPassword.send_password_reset_email(user)
|
||||
%User{reset_password_token: reset_password_token} = Mobilizon.Actors.get_user!(user.id)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
resetPassword(
|
||||
token: "#{reset_password_token}",
|
||||
password: "new password"
|
||||
) {
|
||||
user {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert json_response(res, 200)["data"]["resetPassword"]["user"]["id"] == to_string(user.id)
|
||||
end
|
||||
|
||||
test "test reset_password/3 with a password too short", context do
|
||||
%User{} = user = insert(:user)
|
||||
{:ok, _email_sent} = Mobilizon.Actors.Service.ResetPassword.send_password_reset_email(user)
|
||||
%User{reset_password_token: reset_password_token} = Mobilizon.Actors.get_user!(user.id)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
resetPassword(
|
||||
token: "#{reset_password_token}",
|
||||
password: "new"
|
||||
) {
|
||||
user {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] == "password_too_short"
|
||||
end
|
||||
|
||||
test "test reset_password/3 with an invalid token", context do
|
||||
%User{} = user = insert(:user)
|
||||
{:ok, _email_sent} = Mobilizon.Actors.Service.ResetPassword.send_password_reset_email(user)
|
||||
%User{} = Mobilizon.Actors.get_user!(user.id)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
resetPassword(
|
||||
token: "not good",
|
||||
password: "new"
|
||||
) {
|
||||
user {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] == "invalid_token"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,9 +23,13 @@ defmodule Mobilizon.Factory do
|
||||
%Mobilizon.Actors.Actor{
|
||||
preferred_username: preferred_username,
|
||||
domain: nil,
|
||||
followers: [],
|
||||
followings: [],
|
||||
keys: pem,
|
||||
type: :Person,
|
||||
url: MobilizonWeb.Endpoint.url() <> "/@#{preferred_username}",
|
||||
followers_url: MobilizonWeb.Endpoint.url() <> "/@#{preferred_username}/followers",
|
||||
following_url: MobilizonWeb.Endpoint.url() <> "/@#{preferred_username}/following",
|
||||
user: nil
|
||||
}
|
||||
end
|
||||
@@ -81,6 +85,7 @@ defmodule Mobilizon.Factory do
|
||||
actor: build(:actor),
|
||||
event: build(:event),
|
||||
uuid: uuid,
|
||||
in_reply_to_comment: nil,
|
||||
url: "#{MobilizonWeb.Endpoint.url()}/comments/#{uuid}"
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user