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