2018-11-23 14:03:53 +00:00
|
|
|
defmodule MobilizonWeb.Resolvers.PersonResolverTest do
|
2018-11-06 09:30:27 +00:00
|
|
|
use MobilizonWeb.ConnCase
|
|
|
|
alias MobilizonWeb.AbsintheHelpers
|
2019-01-25 12:59:58 +00:00
|
|
|
import Mobilizon.Factory
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
@non_existent_username "nonexistent"
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
describe "Person Resolver" do
|
2018-12-03 10:58:57 +00:00
|
|
|
test "find_person/3 returns a person by it's username", context do
|
2019-01-25 12:59:58 +00:00
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2018-11-23 14:03:53 +00:00
|
|
|
person(preferredUsername: "#{actor.preferred_username}") {
|
2018-11-06 09:30:27 +00:00
|
|
|
preferredUsername,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
2018-11-23 14:03:53 +00:00
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
2018-11-06 09:30:27 +00:00
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
assert json_response(res, 200)["data"]["person"]["preferredUsername"] ==
|
2018-11-06 09:30:27 +00:00
|
|
|
actor.preferred_username
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2018-11-23 14:03:53 +00:00
|
|
|
person(preferredUsername: "#{@non_existent_username}") {
|
2018-11-06 09:30:27 +00:00
|
|
|
preferredUsername,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
2018-11-23 14:03:53 +00:00
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
2018-11-06 09:30:27 +00:00
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
assert json_response(res, 200)["data"]["person"] == nil
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
2018-11-23 14:03:53 +00:00
|
|
|
"Person with name #{@non_existent_username} not found"
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
test "get_current_person/3 returns the current logged-in actor", context do
|
2019-01-25 12:59:58 +00:00
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2018-11-23 14:03:53 +00:00
|
|
|
loggedPerson {
|
2018-11-06 09:30:27 +00:00
|
|
|
avatarUrl,
|
|
|
|
preferredUsername,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
2018-11-23 14:03:53 +00:00
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_person"))
|
2018-11-06 09:30:27 +00:00
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
assert json_response(res, 200)["data"]["loggedPerson"] == nil
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
2018-11-23 14:03:53 +00:00
|
|
|
"You need to be logged-in to view current person"
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
2018-11-29 16:43:22 +00:00
|
|
|
|> auth_conn(user)
|
2018-11-23 14:03:53 +00:00
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_person"))
|
2018-11-06 09:30:27 +00:00
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
assert json_response(res, 200)["data"]["loggedPerson"]["preferredUsername"] ==
|
2018-11-06 09:30:27 +00:00
|
|
|
actor.preferred_username
|
|
|
|
end
|
2019-02-22 17:07:20 +00:00
|
|
|
|
|
|
|
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
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
|
|
|
end
|