debianize-mobilizon/test/mobilizon_web/resolvers/person_resolver_test.exs
Thomas Citharel 0c2931c10b
Make register/1 only create an user
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>
2019-01-30 10:53:40 +01:00

78 lines
2.0 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