2018-11-23 15:03:53 +01:00
|
|
|
defmodule MobilizonWeb.Resolvers.PersonResolverTest do
|
2018-11-06 10:30:27 +01:00
|
|
|
use MobilizonWeb.ConnCase
|
2018-11-12 18:17:53 +01:00
|
|
|
alias Mobilizon.Actors
|
2018-11-06 10:30:27 +01:00
|
|
|
alias MobilizonWeb.AbsintheHelpers
|
|
|
|
|
|
|
|
@valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"}
|
|
|
|
@non_existent_username "nonexistent"
|
|
|
|
|
2018-11-23 15:03:53 +01:00
|
|
|
describe "Person Resolver" do
|
|
|
|
test "find_actor/3 returns a person by it's username", context do
|
2018-11-06 10:30:27 +01:00
|
|
|
{:ok, actor} = Actors.register(@valid_actor_params)
|
|
|
|
|
|
|
|
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
|
2018-11-06 10:30:27 +01:00
|
|
|
{:ok, actor} = Actors.register(@valid_actor_params)
|
|
|
|
|
|
|
|
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
|
|
|
|
|> auth_conn(actor.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
|