mobilizon.chapril.org-mobil.../test/mobilizon_web/resolvers/person_resolver_test.exs

78 lines
2.0 KiB
Elixir
Raw Normal View History

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