2018-11-23 14:03:53 +00:00
|
|
|
defmodule MobilizonWeb.Resolvers.PersonResolverTest do
|
2018-11-06 09:30:27 +00:00
|
|
|
use MobilizonWeb.ConnCase
|
|
|
|
alias MobilizonWeb.AbsintheHelpers
|
2019-10-04 16:28:25 +00:00
|
|
|
alias Mobilizon.Actors.Actor
|
2019-01-25 12:59:58 +00:00
|
|
|
import Mobilizon.Factory
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
@non_existent_username "nonexistent"
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
describe "Person Resolver" do
|
2019-10-15 19:18:03 +00:00
|
|
|
test "get_person/3 returns a person by its username", context do
|
2019-01-25 12:59:58 +00:00
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2019-10-04 16:28:25 +00:00
|
|
|
person(id: "#{actor.id}") {
|
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 = """
|
|
|
|
{
|
2019-10-04 16:28:25 +00:00
|
|
|
person(id: "6895567") {
|
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"] ==
|
2019-10-04 16:28:25 +00:00
|
|
|
"Person with ID 6895567 not found"
|
|
|
|
end
|
|
|
|
|
2019-10-15 19:18:03 +00:00
|
|
|
test "find_person/3 returns a person by its username", context do
|
2019-10-04 16:28:25 +00:00
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
fetchPerson(preferredUsername: "#{actor.preferred_username}") {
|
|
|
|
preferredUsername,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["fetchPerson"]["preferredUsername"] ==
|
|
|
|
actor.preferred_username
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
fetchPerson(preferredUsername: "#{@non_existent_username}") {
|
|
|
|
preferredUsername,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["fetchPerson"] == nil
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"Person with username #{@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
|
2019-01-25 12:59:58 +00:00
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
2018-11-06 09:30:27 +00:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2018-11-23 14:03:53 +00:00
|
|
|
loggedPerson {
|
2019-05-22 12:12:11 +00:00
|
|
|
avatar {
|
|
|
|
url
|
|
|
|
},
|
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, "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
|
2019-05-22 12:12:11 +00:00
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["loggedPerson"]["avatar"]["url"] =~
|
|
|
|
MobilizonWeb.Endpoint.url()
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|
2019-02-22 17:07:20 +00:00
|
|
|
|
|
|
|
test "create_person/3 creates a new identity", context do
|
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
createPerson(
|
|
|
|
preferredUsername: "new_identity",
|
|
|
|
name: "secret person",
|
|
|
|
summary: "no-one will know who I am"
|
|
|
|
) {
|
|
|
|
id,
|
|
|
|
preferredUsername
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createPerson"] == nil
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"You need to be logged-in to create a new identity"
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createPerson"]["preferredUsername"] ==
|
|
|
|
"new_identity"
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
identities {
|
2019-05-22 12:12:11 +00:00
|
|
|
avatar {
|
|
|
|
url
|
|
|
|
},
|
2019-02-22 17:07:20 +00:00
|
|
|
preferredUsername,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "identities"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["identities"] == nil
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"You need to be logged-in to view your list of identities"
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "identities"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["identities"]
|
|
|
|
|> Enum.map(fn identity -> Map.get(identity, "preferredUsername") end)
|
|
|
|
|> MapSet.new() ==
|
|
|
|
MapSet.new([actor.preferred_username, "new_identity"])
|
|
|
|
end
|
2019-03-21 19:23:42 +00:00
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
test "create_person/3 with an avatar and an banner creates a new identity", context do
|
|
|
|
user = insert(:user)
|
|
|
|
insert(:actor, user: user)
|
2019-03-21 19:23:42 +00:00
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
createPerson(
|
|
|
|
preferredUsername: "new_identity",
|
|
|
|
name: "secret person",
|
|
|
|
summary: "no-one will know who I am",
|
|
|
|
banner: {
|
|
|
|
picture: {
|
|
|
|
file: "landscape.jpg",
|
|
|
|
name: "irish landscape",
|
|
|
|
alt: "The beautiful atlantic way"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
id,
|
|
|
|
preferredUsername
|
|
|
|
avatar {
|
|
|
|
id,
|
|
|
|
url
|
|
|
|
},
|
|
|
|
banner {
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
2019-03-21 19:23:42 +00:00
|
|
|
}
|
2019-05-22 12:12:11 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
map = %{
|
|
|
|
"query" => mutation,
|
|
|
|
"landscape.jpg" => %Plug.Upload{
|
|
|
|
path: "test/fixtures/picture.png",
|
|
|
|
filename: "landscape.jpg"
|
2019-03-21 19:23:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> put_req_header("content-type", "multipart/form-data")
|
|
|
|
|> post("/api", map)
|
2019-03-21 19:23:42 +00:00
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
assert json_response(res, 200)["data"]["createPerson"] == nil
|
2019-03-21 19:23:42 +00:00
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"You need to be logged-in to create a new identity"
|
2019-03-21 19:23:42 +00:00
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> put_req_header("content-type", "multipart/form-data")
|
|
|
|
|> post("/api", map)
|
2019-03-21 19:23:42 +00:00
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
assert json_response(res, 200)["data"]["createPerson"]["preferredUsername"] ==
|
|
|
|
"new_identity"
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createPerson"]["banner"]["id"]
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createPerson"]["banner"]["name"] ==
|
|
|
|
"The beautiful atlantic way"
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["createPerson"]["banner"]["url"] =~
|
|
|
|
MobilizonWeb.Endpoint.url() <> "/media/"
|
|
|
|
end
|
|
|
|
|
2019-06-17 15:15:27 +00:00
|
|
|
test "update_person/3 updates an existing identity", context do
|
|
|
|
user = insert(:user)
|
2019-10-04 16:28:25 +00:00
|
|
|
%Actor{id: person_id} = insert(:actor, user: user, preferred_username: "riri")
|
2019-06-17 15:15:27 +00:00
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
updatePerson(
|
2019-10-04 16:28:25 +00:00
|
|
|
id: "#{person_id}",
|
2019-06-17 15:15:27 +00:00
|
|
|
name: "riri updated",
|
|
|
|
summary: "summary updated",
|
|
|
|
banner: {
|
|
|
|
picture: {
|
|
|
|
file: "landscape.jpg",
|
|
|
|
name: "irish landscape",
|
|
|
|
alt: "The beautiful atlantic way"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
id,
|
|
|
|
preferredUsername,
|
|
|
|
name,
|
|
|
|
summary,
|
|
|
|
avatar {
|
|
|
|
id,
|
|
|
|
url
|
|
|
|
},
|
|
|
|
banner {
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
map = %{
|
|
|
|
"query" => mutation,
|
|
|
|
"landscape.jpg" => %Plug.Upload{
|
|
|
|
path: "test/fixtures/picture.png",
|
|
|
|
filename: "landscape.jpg"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> put_req_header("content-type", "multipart/form-data")
|
|
|
|
|> post("/api", map)
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["updatePerson"] == nil
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"You need to be logged-in to update an identity"
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> put_req_header("content-type", "multipart/form-data")
|
|
|
|
|> post("/api", map)
|
|
|
|
|
|
|
|
res_person = json_response(res, 200)["data"]["updatePerson"]
|
|
|
|
|
|
|
|
assert res_person["preferredUsername"] == "riri"
|
|
|
|
assert res_person["name"] == "riri updated"
|
|
|
|
assert res_person["summary"] == "summary updated"
|
|
|
|
|
|
|
|
assert res_person["banner"]["id"]
|
|
|
|
assert res_person["banner"]["name"] == "The beautiful atlantic way"
|
|
|
|
assert res_person["banner"]["url"] =~ MobilizonWeb.Endpoint.url() <> "/media/"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_person/3 should fail to update a not owned identity", context do
|
|
|
|
user1 = insert(:user)
|
|
|
|
user2 = insert(:user)
|
2019-10-04 16:28:25 +00:00
|
|
|
%Actor{id: person_id} = insert(:actor, user: user2, preferred_username: "riri")
|
2019-06-17 15:15:27 +00:00
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
updatePerson(
|
2019-10-04 16:28:25 +00:00
|
|
|
id: "#{person_id}",
|
2019-06-17 15:15:27 +00:00
|
|
|
name: "riri updated",
|
|
|
|
) {
|
|
|
|
id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user1)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["updatePerson"] == nil
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"Actor is not owned by authenticated user"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "update_person/3 should fail to update a not existing identity", context do
|
|
|
|
user = insert(:user)
|
|
|
|
insert(:actor, user: user, preferred_username: "riri")
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
|
|
|
updatePerson(
|
2019-10-04 16:28:25 +00:00
|
|
|
id: "48918",
|
2019-06-17 15:15:27 +00:00
|
|
|
name: "riri updated",
|
|
|
|
) {
|
|
|
|
id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["updatePerson"] == nil
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"Actor not found"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "delete_person/3 should fail to update a not owned identity", context do
|
|
|
|
user1 = insert(:user)
|
|
|
|
user2 = insert(:user)
|
2019-10-04 16:28:25 +00:00
|
|
|
%Actor{id: person_id} = insert(:actor, user: user2, preferred_username: "riri")
|
2019-06-17 15:15:27 +00:00
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
2019-10-04 16:28:25 +00:00
|
|
|
deletePerson(id: "#{person_id}") {
|
2019-06-17 15:15:27 +00:00
|
|
|
id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user1)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
2019-08-26 13:44:02 +00:00
|
|
|
assert json_response(res, 200)["data"]["deletePerson"] == nil
|
2019-06-17 15:15:27 +00:00
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"Actor is not owned by authenticated user"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "delete_person/3 should fail to delete a not existing identity", context do
|
|
|
|
user = insert(:user)
|
|
|
|
insert(:actor, user: user, preferred_username: "riri")
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
2019-10-04 16:28:25 +00:00
|
|
|
deletePerson(id: "9798665") {
|
2019-06-17 15:15:27 +00:00
|
|
|
id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
2019-08-26 13:44:02 +00:00
|
|
|
assert json_response(res, 200)["data"]["deletePerson"] == nil
|
2019-06-17 15:15:27 +00:00
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"Actor not found"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "delete_person/3 should fail to delete the last user identity", context do
|
|
|
|
user = insert(:user)
|
2019-10-04 16:28:25 +00:00
|
|
|
%Actor{id: person_id} = insert(:actor, user: user, preferred_username: "riri")
|
2019-06-17 15:15:27 +00:00
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
2019-10-04 16:28:25 +00:00
|
|
|
deletePerson(id: "#{person_id}") {
|
2019-06-17 15:15:27 +00:00
|
|
|
id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
2019-08-26 13:44:02 +00:00
|
|
|
assert json_response(res, 200)["data"]["deletePerson"] == nil
|
2019-06-17 15:15:27 +00:00
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"Cannot remove the last identity of a user"
|
|
|
|
end
|
|
|
|
|
2019-08-26 13:44:02 +00:00
|
|
|
test "delete_person/3 should fail to delete an identity that is the last admin of a group",
|
|
|
|
context do
|
|
|
|
group = insert(:group)
|
|
|
|
classic_user = insert(:user)
|
|
|
|
classic_actor = insert(:actor, user: classic_user, preferred_username: "classic_user")
|
|
|
|
|
|
|
|
admin_user = insert(:user)
|
|
|
|
admin_actor = insert(:actor, user: admin_user, preferred_username: "last_admin")
|
|
|
|
insert(:actor, user: admin_user)
|
|
|
|
|
|
|
|
insert(:member, %{actor: admin_actor, role: :creator, parent: group})
|
|
|
|
insert(:member, %{actor: classic_actor, role: :member, parent: group})
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
2019-10-04 16:28:25 +00:00
|
|
|
deletePerson(id: "#{admin_actor.id}") {
|
2019-08-26 13:44:02 +00:00
|
|
|
id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(admin_user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["deletePerson"] == nil
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"Cannot remove the last administrator of a group"
|
|
|
|
end
|
|
|
|
|
2019-06-17 15:15:27 +00:00
|
|
|
test "delete_person/3 should delete a user identity", context do
|
|
|
|
user = insert(:user)
|
2019-10-04 16:28:25 +00:00
|
|
|
%Actor{id: person_id} = insert(:actor, user: user, preferred_username: "riri")
|
2019-06-17 15:15:27 +00:00
|
|
|
insert(:actor, user: user, preferred_username: "fifi")
|
|
|
|
|
|
|
|
mutation = """
|
|
|
|
mutation {
|
2019-10-04 16:28:25 +00:00
|
|
|
deletePerson(id: "#{person_id}") {
|
2019-06-17 15:15:27 +00:00
|
|
|
id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2019-10-04 16:28:25 +00:00
|
|
|
person(id: "#{person_id}") {
|
2019-06-17 15:15:27 +00:00
|
|
|
id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
|
|
|
|
2019-10-04 16:28:25 +00:00
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"Person with ID #{person_id} not found"
|
2019-06-17 15:15:27 +00:00
|
|
|
end
|
2019-09-26 14:38:58 +00:00
|
|
|
end
|
2019-06-17 15:15:27 +00:00
|
|
|
|
2019-09-26 14:38:58 +00:00
|
|
|
describe "get_current_person/3" do
|
2019-05-22 12:12:11 +00:00
|
|
|
test "get_current_person/3 can return the events the person is going to", context do
|
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
2019-03-21 19:23:42 +00:00
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
query = """
|
|
|
|
{
|
|
|
|
loggedPerson {
|
2019-09-26 14:38:58 +00:00
|
|
|
participations {
|
|
|
|
event {
|
|
|
|
uuid,
|
|
|
|
title
|
|
|
|
}
|
2019-05-22 12:12:11 +00:00
|
|
|
}
|
2019-03-21 19:23:42 +00:00
|
|
|
}
|
2019-05-22 12:12:11 +00:00
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_person"))
|
|
|
|
|
2019-09-26 14:38:58 +00:00
|
|
|
assert json_response(res, 200)["data"]["loggedPerson"]["participations"] == []
|
2019-05-22 12:12:11 +00:00
|
|
|
|
|
|
|
event = insert(:event, %{organizer_actor: actor})
|
|
|
|
insert(:participant, %{actor: actor, event: event})
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "logged_person"))
|
|
|
|
|
2019-09-26 14:38:58 +00:00
|
|
|
assert json_response(res, 200)["data"]["loggedPerson"]["participations"] == [
|
|
|
|
%{"event" => %{"title" => event.title, "uuid" => event.uuid}}
|
2019-05-22 12:12:11 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "find_person/3 can return the events an identity is going to if it's the same actor",
|
|
|
|
context do
|
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
|
|
|
insert(:actor, user: user)
|
|
|
|
actor_from_other_user = insert(:actor)
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2019-10-04 16:28:25 +00:00
|
|
|
person(id: "#{actor.id}") {
|
2019-09-26 14:38:58 +00:00
|
|
|
participations {
|
|
|
|
event {
|
|
|
|
uuid,
|
|
|
|
title
|
|
|
|
}
|
2019-05-22 12:12:11 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-21 19:23:42 +00:00
|
|
|
}
|
2019-05-22 12:12:11 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
|
|
|
|
2019-09-26 14:38:58 +00:00
|
|
|
assert json_response(res, 200)["data"]["person"]["participations"] == []
|
2019-05-22 12:12:11 +00:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2019-10-04 16:28:25 +00:00
|
|
|
person(id: "#{actor_from_other_user.id}") {
|
2019-09-26 14:38:58 +00:00
|
|
|
participations {
|
|
|
|
event {
|
|
|
|
uuid,
|
|
|
|
title
|
|
|
|
}
|
2019-05-22 12:12:11 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-21 19:23:42 +00:00
|
|
|
}
|
2019-05-22 12:12:11 +00:00
|
|
|
"""
|
2019-03-21 19:23:42 +00:00
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
2019-03-21 19:23:42 +00:00
|
|
|
|
2019-09-26 14:38:58 +00:00
|
|
|
assert json_response(res, 200)["data"]["person"]["participations"] == nil
|
2019-03-21 19:23:42 +00:00
|
|
|
|
2019-05-22 12:12:11 +00:00
|
|
|
assert hd(json_response(res, 200)["errors"])["message"] ==
|
|
|
|
"Actor id is not owned by authenticated user"
|
|
|
|
end
|
2019-09-26 14:38:58 +00:00
|
|
|
|
|
|
|
test "find_person/3 can return the participation for an identity on a specific event",
|
|
|
|
context do
|
|
|
|
user = insert(:user)
|
|
|
|
actor = insert(:actor, user: user)
|
|
|
|
event = insert(:event, organizer_actor: actor)
|
|
|
|
insert(:participant, event: event, actor: actor)
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2019-10-04 16:28:25 +00:00
|
|
|
person(id: "#{actor.id}") {
|
2019-09-26 14:38:58 +00:00
|
|
|
participations(eventId: "#{event.id}") {
|
|
|
|
event {
|
|
|
|
uuid,
|
|
|
|
title
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
context.conn
|
|
|
|
|> auth_conn(user)
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "person"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["person"]["participations"] == [
|
|
|
|
%{
|
|
|
|
"event" => %{
|
|
|
|
"uuid" => event.uuid,
|
|
|
|
"title" => event.title
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
2019-03-21 19:23:42 +00:00
|
|
|
end
|
2018-11-06 09:30:27 +00:00
|
|
|
end
|