0c2931c10b
Signed-off-by: Thomas Citharel <tcit@tcit.fr> Credo fix Signed-off-by: Thomas Citharel <tcit@tcit.fr> Fix rebase Signed-off-by: Thomas Citharel <tcit@tcit.fr>
78 lines
2 KiB
Elixir
78 lines
2 KiB
Elixir
defmodule MobilizonWeb.Resolvers.PersonResolverTest do
|
|
use MobilizonWeb.ConnCase
|
|
alias MobilizonWeb.AbsintheHelpers
|
|
import Mobilizon.Factory
|
|
|
|
@non_existent_username "nonexistent"
|
|
|
|
describe "Person Resolver" do
|
|
test "find_person/3 returns a person by it's username", context do
|
|
user = insert(:user)
|
|
actor = insert(:actor, user: user)
|
|
|
|
query = """
|
|
{
|
|
person(preferredUsername: "#{actor.preferred_username}") {
|
|
preferredUsername,
|
|
}
|
|
}
|
|
"""
|
|
|
|
res =
|
|
context.conn
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
|
|
|
assert json_response(res, 200)["data"]["person"]["preferredUsername"] ==
|
|
actor.preferred_username
|
|
|
|
query = """
|
|
{
|
|
person(preferredUsername: "#{@non_existent_username}") {
|
|
preferredUsername,
|
|
}
|
|
}
|
|
"""
|
|
|
|
res =
|
|
context.conn
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
|
|
|
assert json_response(res, 200)["data"]["person"] == nil
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
"Person with name #{@non_existent_username} not found"
|
|
end
|
|
|
|
test "get_current_person/3 returns the current logged-in actor", context do
|
|
user = insert(:user)
|
|
actor = insert(:actor, user: user)
|
|
|
|
query = """
|
|
{
|
|
loggedPerson {
|
|
avatarUrl,
|
|
preferredUsername,
|
|
}
|
|
}
|
|
"""
|
|
|
|
res =
|
|
context.conn
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_person"))
|
|
|
|
assert json_response(res, 200)["data"]["loggedPerson"] == nil
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
"You need to be logged-in to view current person"
|
|
|
|
res =
|
|
context.conn
|
|
|> auth_conn(user)
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_person"))
|
|
|
|
assert json_response(res, 200)["data"]["loggedPerson"]["preferredUsername"] ==
|
|
actor.preferred_username
|
|
end
|
|
end
|
|
end
|