Merge branch 'improve-tests' into 'master'
Improve tests See merge request framasoft/mobilizon!78
This commit is contained in:
commit
75554cd3f5
@ -21,8 +21,4 @@ defmodule Mobilizon.Actors.Follower do
|
||||
|> validate_required([:score, :approved, :target_actor_id, :actor_id])
|
||||
|> unique_constraint(:target_actor_id, name: :followers_actor_target_actor_unique_index)
|
||||
end
|
||||
|
||||
def url(%Follower{id: id}) do
|
||||
"#{MobilizonWeb.Endpoint.url()}/follow/#{id}/activity"
|
||||
end
|
||||
end
|
||||
|
@ -6,17 +6,6 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||
alias Mobilizon.Actors.{Actor, User}
|
||||
alias Mobilizon.Service.ActivityPub
|
||||
|
||||
@deprecated "Use find_person/3 or find_group/3 instead"
|
||||
def find_actor(_parent, %{preferred_username: name}, _resolution) do
|
||||
case ActivityPub.find_or_make_actor_from_nickname(name) do
|
||||
{:ok, actor} ->
|
||||
{:ok, actor}
|
||||
|
||||
_ ->
|
||||
{:error, "Actor with name #{name} not found"}
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Find a person
|
||||
"""
|
||||
@ -65,6 +54,13 @@ defmodule MobilizonWeb.Resolvers.Person do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
This function is used to create more identities from an existing user
|
||||
"""
|
||||
def create_person(_parent, _args, _resolution) do
|
||||
{:error, "You need to be logged-in to create a new identity"}
|
||||
end
|
||||
|
||||
@doc """
|
||||
This function is used to register a person afterwards the user has been created (but not activated)
|
||||
"""
|
||||
|
@ -19,15 +19,15 @@ defmodule MobilizonWeb.Resolvers.Tag do
|
||||
{:ok, Mobilizon.Events.list_tags_for_event(id)}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Retrieve the list of related tags for a given tag ID
|
||||
"""
|
||||
def get_related_tags(_parent, %{tag_id: tag_id}, _resolution) do
|
||||
with %Tag{} = tag <- Mobilizon.Events.get_tag!(tag_id),
|
||||
tags <- Mobilizon.Events.tag_neighbors(tag) do
|
||||
{:ok, tags}
|
||||
end
|
||||
end
|
||||
# @doc """
|
||||
# Retrieve the list of related tags for a given tag ID
|
||||
# """
|
||||
# def get_related_tags(_parent, %{tag_id: tag_id}, _resolution) do
|
||||
# with %Tag{} = tag <- Mobilizon.Events.get_tag!(tag_id),
|
||||
# tags <- Mobilizon.Events.tag_neighbors(tag) do
|
||||
# {:ok, tags}
|
||||
# end
|
||||
# end
|
||||
|
||||
@doc """
|
||||
Retrieve the list of related tags for a parent tag
|
||||
|
@ -131,6 +131,7 @@ defmodule MobilizonWeb.Schema do
|
||||
import_fields(:event_queries)
|
||||
import_fields(:participant_queries)
|
||||
import_fields(:category_queries)
|
||||
import_fields(:tag_queries)
|
||||
end
|
||||
|
||||
@desc """
|
||||
|
@ -246,8 +246,9 @@ defmodule Mobilizon.Service.ActivityPub do
|
||||
Make an actor follow another
|
||||
"""
|
||||
def follow(%Actor{} = follower, %Actor{} = followed, activity_id \\ nil, local \\ true) do
|
||||
with {:ok, %Follower{} = follow} <- Actor.follow(followed, follower, true),
|
||||
activity_follow_id <- activity_id || Follower.url(follow),
|
||||
with {:ok, %Follower{id: follow_id}} <- Actor.follow(followed, follower, true),
|
||||
activity_follow_id <-
|
||||
activity_id || "#{MobilizonWeb.Endpoint.url()}/follow/#{follow_id}/activity",
|
||||
data <- make_follow_data(followed, follower, activity_follow_id),
|
||||
{:ok, activity} <- insert(data, local),
|
||||
:ok <- maybe_federate(activity) do
|
||||
|
@ -73,5 +73,68 @@ defmodule MobilizonWeb.Resolvers.PersonResolverTest do
|
||||
assert json_response(res, 200)["data"]["loggedPerson"]["preferredUsername"] ==
|
||||
actor.preferred_username
|
||||
end
|
||||
|
||||
test "create_person/3 creates a new identity", context do
|
||||
user = insert(:user)
|
||||
actor = insert(:actor, user: user)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
createPerson(
|
||||
preferredUsername: "new_identity",
|
||||
name: "secret person",
|
||||
summary: "no-one will know who I am"
|
||||
) {
|
||||
id,
|
||||
preferredUsername
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert json_response(res, 200)["data"]["createPerson"] == nil
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] ==
|
||||
"You need to be logged-in to create a new identity"
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert json_response(res, 200)["data"]["createPerson"]["preferredUsername"] ==
|
||||
"new_identity"
|
||||
|
||||
query = """
|
||||
{
|
||||
identities {
|
||||
avatarUrl,
|
||||
preferredUsername,
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "identities"))
|
||||
|
||||
assert json_response(res, 200)["data"]["identities"] == nil
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] ==
|
||||
"You need to be logged-in to view your list of identities"
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> auth_conn(user)
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "identities"))
|
||||
|
||||
assert json_response(res, 200)["data"]["identities"]
|
||||
|> Enum.map(fn identity -> Map.get(identity, "preferredUsername") end)
|
||||
|> MapSet.new() ==
|
||||
MapSet.new([actor.preferred_username, "new_identity"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
48
test/mobilizon_web/resolvers/tag_resolver_test.exs
Normal file
48
test/mobilizon_web/resolvers/tag_resolver_test.exs
Normal file
@ -0,0 +1,48 @@
|
||||
defmodule MobilizonWeb.Resolvers.TagResolverTest do
|
||||
use MobilizonWeb.ConnCase
|
||||
alias MobilizonWeb.AbsintheHelpers
|
||||
import Mobilizon.Factory
|
||||
|
||||
describe "Tag Resolver" do
|
||||
test "list_tags/3 returns the list of tags", context do
|
||||
tag1 = insert(:tag)
|
||||
tag2 = insert(:tag)
|
||||
tag3 = insert(:tag)
|
||||
insert(:tag_relation, tag: tag1, link: tag2)
|
||||
insert(:tag_relation, tag: tag3, link: tag1)
|
||||
|
||||
query = """
|
||||
{
|
||||
tags {
|
||||
id,
|
||||
slug,
|
||||
title,
|
||||
related {
|
||||
id,
|
||||
title,
|
||||
slug
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "tags"))
|
||||
|
||||
tags = json_response(res, 200)["data"]["tags"]
|
||||
assert tags |> length == 3
|
||||
|
||||
assert Enum.filter(tags, fn tag -> tag["slug"] == tag1.slug end)
|
||||
|> hd
|
||||
|> Map.get("related")
|
||||
|> Enum.map(fn tag -> tag["slug"] end)
|
||||
|> MapSet.new() ==
|
||||
[tag2, tag3]
|
||||
|> Enum.map(fn
|
||||
tag -> tag.slug
|
||||
end)
|
||||
|> MapSet.new()
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user