2018-11-23 14:03:53 +00:00
|
|
|
defmodule MobilizonWeb.Resolvers.PersonResolverTest do
|
2018-11-06 09:30:27 +00:00
|
|
|
use MobilizonWeb.ConnCase
|
2018-11-12 17:17:53 +00:00
|
|
|
alias Mobilizon.Actors
|
2018-11-29 16:43:22 +00:00
|
|
|
alias Mobilizon.Actors.{User, Actor}
|
2018-11-06 09:30:27 +00:00
|
|
|
alias MobilizonWeb.AbsintheHelpers
|
|
|
|
|
|
|
|
@valid_actor_params %{email: "test@test.tld", password: "testest", username: "test"}
|
|
|
|
@non_existent_username "nonexistent"
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
describe "Person Resolver" do
|
2018-12-03 10:58:57 +00:00
|
|
|
test "find_person/3 returns a person by it's username", context do
|
2018-11-29 16:43:22 +00:00
|
|
|
{:ok, %User{default_actor: %Actor{} = actor} = _user} = Actors.register(@valid_actor_params)
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2018-11-23 14:03:53 +00:00
|
|
|
person(preferredUsername: "#{actor.preferred_username}") {
|
2018-11-06 09:30:27 +00:00
|
|
|
preferredUsername,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
2018-11-23 14:03:53 +00:00
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
2018-11-06 09:30:27 +00:00
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
assert json_response(res, 200)["data"]["person"]["preferredUsername"] ==
|
2018-11-06 09:30:27 +00:00
|
|
|
actor.preferred_username
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2018-11-23 14:03:53 +00:00
|
|
|
person(preferredUsername: "#{@non_existent_username}") {
|
2018-11-06 09:30:27 +00:00
|
|
|
preferredUsername,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
2018-11-23 14:03:53 +00:00
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
2018-11-06 09:30:27 +00:00
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
assert json_response(res, 200)["data"]["person"] == nil
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
2018-11-23 14:03:53 +00:00
|
|
|
"Person with name #{@non_existent_username} not found"
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
test "get_current_person/3 returns the current logged-in actor", context do
|
2018-11-29 16:43:22 +00:00
|
|
|
{:ok, %User{default_actor: %Actor{} = actor} = user} = Actors.register(@valid_actor_params)
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2018-11-23 14:03:53 +00:00
|
|
|
loggedPerson {
|
2018-11-06 09:30:27 +00:00
|
|
|
avatarUrl,
|
|
|
|
preferredUsername,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
2018-11-23 14:03:53 +00:00
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_person"))
|
2018-11-06 09:30:27 +00:00
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
assert json_response(res, 200)["data"]["loggedPerson"] == nil
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
2018-11-23 14:03:53 +00:00
|
|
|
"You need to be logged-in to view current person"
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
2018-11-29 16:43:22 +00:00
|
|
|
|> auth_conn(user)
|
2018-11-23 14:03:53 +00:00
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_person"))
|
2018-11-06 09:30:27 +00:00
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
assert json_response(res, 200)["data"]["loggedPerson"]["preferredUsername"] ==
|
2018-11-06 09:30:27 +00:00
|
|
|
actor.preferred_username
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|