Improve GraphQL documentation and cleanup API
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -19,8 +19,8 @@ defmodule Mobilizon.GraphQL.Resolvers.CommentTest do
|
||||
|
||||
describe "Comment Resolver" do
|
||||
@create_comment_mutation """
|
||||
mutation CreateComment($text: String!, $actorId: ID, $eventId: ID, $inReplyToCommentId: ID) {
|
||||
createComment(text: $text, actorId: $actorId, eventId: $eventId, inReplyToCommentId: $inReplyToCommentId) {
|
||||
mutation CreateComment($text: String!, $eventId: ID, $inReplyToCommentId: ID) {
|
||||
createComment(text: $text, eventId: $eventId, inReplyToCommentId: $inReplyToCommentId) {
|
||||
id,
|
||||
text,
|
||||
uuid,
|
||||
@@ -43,27 +43,12 @@ defmodule Mobilizon.GraphQL.Resolvers.CommentTest do
|
||||
|> auth_conn(user)
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @create_comment_mutation,
|
||||
variables: %{text: @comment_text, actorId: actor.id, eventId: event.id}
|
||||
variables: %{text: @comment_text, eventId: event.id}
|
||||
)
|
||||
|
||||
assert res["data"]["createComment"]["text"] == @comment_text
|
||||
end
|
||||
|
||||
test "create_comment/3 checks that user owns actor", %{conn: conn, user: user, event: event} do
|
||||
actor = insert(:actor)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @create_comment_mutation,
|
||||
variables: %{text: @comment_text, actorId: actor.id, eventId: event.id}
|
||||
)
|
||||
|
||||
assert hd(res["errors"])["message"] ==
|
||||
"Profile is not owned by authenticated user"
|
||||
end
|
||||
|
||||
test "create_comment/3 doesn't allow creating events if it's disabled", %{
|
||||
conn: conn,
|
||||
actor: actor,
|
||||
@@ -78,7 +63,7 @@ defmodule Mobilizon.GraphQL.Resolvers.CommentTest do
|
||||
|> auth_conn(user)
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @create_comment_mutation,
|
||||
variables: %{text: @comment_text, actorId: actor.id, eventId: event.id}
|
||||
variables: %{text: @comment_text, eventId: event.id}
|
||||
)
|
||||
|
||||
assert hd(res["errors"])["message"] ==
|
||||
@@ -97,7 +82,7 @@ defmodule Mobilizon.GraphQL.Resolvers.CommentTest do
|
||||
|> auth_conn(user)
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @create_comment_mutation,
|
||||
variables: %{text: @comment_text, actorId: actor.id, eventId: event.id}
|
||||
variables: %{text: @comment_text, eventId: event.id}
|
||||
)
|
||||
|
||||
assert is_nil(res["errors"])
|
||||
@@ -114,7 +99,7 @@ defmodule Mobilizon.GraphQL.Resolvers.CommentTest do
|
||||
conn
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @create_comment_mutation,
|
||||
variables: %{text: @comment_text, actorId: actor.id, eventId: event.id}
|
||||
variables: %{text: @comment_text, eventId: event.id}
|
||||
)
|
||||
|
||||
assert hd(res["errors"])["message"] ==
|
||||
@@ -136,7 +121,6 @@ defmodule Mobilizon.GraphQL.Resolvers.CommentTest do
|
||||
query: @create_comment_mutation,
|
||||
variables: %{
|
||||
text: @comment_text,
|
||||
actorId: actor.id,
|
||||
eventId: event.id,
|
||||
inReplyToCommentId: comment.id
|
||||
}
|
||||
|
||||
@@ -575,8 +575,7 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
|
||||
mutation { uploadPicture(
|
||||
name: "#{picture.name}",
|
||||
alt: "#{picture.alt}",
|
||||
file: "#{picture.file}",
|
||||
actor_id: #{actor.id}
|
||||
file: "#{picture.file}"
|
||||
) {
|
||||
id,
|
||||
url,
|
||||
@@ -1304,7 +1303,6 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
|
||||
mutation = """
|
||||
mutation {
|
||||
deleteEvent(
|
||||
actor_id: #{actor.id},
|
||||
event_id: #{event.id}
|
||||
) {
|
||||
id
|
||||
@@ -1334,7 +1332,6 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
|
||||
mutation = """
|
||||
mutation {
|
||||
deleteEvent(
|
||||
actor_id: #{actor.id},
|
||||
event_id: #{event.id}
|
||||
) {
|
||||
id
|
||||
@@ -1349,32 +1346,6 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
|
||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "logged-in"
|
||||
end
|
||||
|
||||
test "delete_event/3 should check the actor id is owned by the user", %{
|
||||
conn: conn,
|
||||
user: user,
|
||||
actor: actor
|
||||
} do
|
||||
event = insert(:event, organizer_actor: actor)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
deleteEvent(
|
||||
actor_id: 1042,
|
||||
event_id: #{event.id}
|
||||
) {
|
||||
id
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] =~ "not owned"
|
||||
end
|
||||
|
||||
test "delete_event/3 should check the event can be deleted by the user", %{
|
||||
conn: conn,
|
||||
user: user,
|
||||
@@ -1386,7 +1357,6 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
|
||||
mutation = """
|
||||
mutation {
|
||||
deleteEvent(
|
||||
actor_id: #{actor.id},
|
||||
event_id: #{event.id}
|
||||
) {
|
||||
id
|
||||
@@ -1417,7 +1387,6 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
|
||||
mutation = """
|
||||
mutation {
|
||||
deleteEvent(
|
||||
actor_id: #{actor_moderator.id},
|
||||
event_id: #{event.id}
|
||||
) {
|
||||
id
|
||||
|
||||
@@ -17,37 +17,12 @@ defmodule Mobilizon.Web.Resolvers.GroupTest do
|
||||
end
|
||||
|
||||
describe "create a group" do
|
||||
test "create_group/3 should check the user owns the identity", %{conn: conn, user: user} do
|
||||
another_actor = insert(:actor)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
createGroup(
|
||||
preferred_username: "#{@new_group_params.groupname}",
|
||||
creator_actor_id: #{another_actor.id}
|
||||
) {
|
||||
preferred_username,
|
||||
type
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|
||||
assert hd(json_response(res, 200)["errors"])["message"] ==
|
||||
"Creator profile is not owned by the current user"
|
||||
end
|
||||
|
||||
test "create_group/3 creates a group and check a group with this name does not already exist",
|
||||
%{conn: conn, user: user, actor: actor} do
|
||||
%{conn: conn, user: user} do
|
||||
mutation = """
|
||||
mutation {
|
||||
createGroup(
|
||||
preferred_username: "#{@new_group_params.groupname}",
|
||||
creator_actor_id: #{actor.id}
|
||||
preferred_username: "#{@new_group_params.groupname}"
|
||||
) {
|
||||
preferred_username,
|
||||
type
|
||||
@@ -68,8 +43,7 @@ defmodule Mobilizon.Web.Resolvers.GroupTest do
|
||||
mutation = """
|
||||
mutation {
|
||||
createGroup(
|
||||
preferred_username: "#{@new_group_params.groupname}",
|
||||
creator_actor_id: #{actor.id},
|
||||
preferred_username: "#{@new_group_params.groupname}"
|
||||
) {
|
||||
preferred_username,
|
||||
type
|
||||
|
||||
@@ -439,9 +439,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
query = """
|
||||
{
|
||||
event(uuid: "#{event.uuid}") {
|
||||
participants(roles: "participant,moderator,administrator,creator", actor_id: "#{
|
||||
actor.id
|
||||
}") {
|
||||
participants(roles: "participant,moderator,administrator,creator") {
|
||||
elements {
|
||||
role,
|
||||
actor {
|
||||
@@ -478,9 +476,9 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
participant2 = insert(:participant, event: event, actor: actor3, role: :participant)
|
||||
|
||||
query = """
|
||||
query EventParticipants($uuid: UUID!, $actorId: ID, $roles: String, $page: Int, $limit: Int) {
|
||||
query EventParticipants($uuid: UUID!, $roles: String, $page: Int, $limit: Int) {
|
||||
event(uuid: $uuid) {
|
||||
participants(page: $page, limit: $limit, roles: $roles, actorId: $actorId) {
|
||||
participants(page: $page, limit: $limit, roles: $roles) {
|
||||
total,
|
||||
elements {
|
||||
role,
|
||||
@@ -500,7 +498,6 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
query: query,
|
||||
variables: %{
|
||||
uuid: event.uuid,
|
||||
actorId: actor.id,
|
||||
roles: "participant,moderator,administrator,creator",
|
||||
page: 1,
|
||||
limit: 2
|
||||
@@ -696,7 +693,6 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
updateParticipation(
|
||||
id: "#{participation_id}",
|
||||
role: PARTICIPANT,
|
||||
moderator_actor_id: #{actor_creator.id}
|
||||
) {
|
||||
id,
|
||||
role,
|
||||
@@ -739,7 +735,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
|
||||
test "accept_participation/3 with bad parameters", %{conn: conn, actor: actor, user: user} do
|
||||
user_creator = insert(:user)
|
||||
actor_creator = insert(:actor, user: user_creator)
|
||||
_actor_creator = insert(:actor, user: user_creator)
|
||||
event = insert(:event, join_options: :restricted)
|
||||
insert(:participant, event: event, role: :creator)
|
||||
|
||||
@@ -776,8 +772,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
mutation {
|
||||
updateParticipation (
|
||||
id: "#{participation_id}",
|
||||
role: PARTICIPANT,
|
||||
moderator_actor_id: #{actor_creator.id}
|
||||
role: PARTICIPANT
|
||||
) {
|
||||
id,
|
||||
role,
|
||||
@@ -841,8 +836,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
mutation {
|
||||
updateParticipation(
|
||||
id: "#{participation_id}",
|
||||
role: REJECTED,
|
||||
moderator_actor_id: #{actor_creator.id}
|
||||
role: REJECTED
|
||||
) {
|
||||
id,
|
||||
role,
|
||||
@@ -884,7 +878,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
|
||||
test "reject_participation/3 with bad parameters", %{conn: conn, actor: actor, user: user} do
|
||||
user_creator = insert(:user)
|
||||
actor_creator = insert(:actor, user: user_creator)
|
||||
_actor_creator = insert(:actor, user: user_creator)
|
||||
event = insert(:event, join_options: :restricted)
|
||||
insert(:participant, event: event, role: :creator)
|
||||
|
||||
@@ -921,8 +915,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
mutation {
|
||||
updateParticipation (
|
||||
id: "#{participation_id}",
|
||||
role: REJECTED,
|
||||
moderator_actor_id: #{actor_creator.id}
|
||||
role: REJECTED
|
||||
) {
|
||||
id,
|
||||
actor {
|
||||
@@ -1341,8 +1334,8 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
|> hd
|
||||
|
||||
update_participation_mutation = """
|
||||
mutation UpdateParticipation($participantId: ID!, $role: ParticipantRoleEnum!, $moderatorActorId: ID!) {
|
||||
updateParticipation(id: $participantId, role: $role, moderatorActorId: $moderatorActorId) {
|
||||
mutation UpdateParticipation($participantId: ID!, $role: ParticipantRoleEnum!) {
|
||||
updateParticipation(id: $participantId, role: $role) {
|
||||
id,
|
||||
role,
|
||||
actor {
|
||||
@@ -1362,8 +1355,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ParticipantTest do
|
||||
query: update_participation_mutation,
|
||||
variables: %{
|
||||
participantId: participant_id,
|
||||
role: "PARTICIPANT",
|
||||
moderatorActorId: event_creator_actor.id
|
||||
role: "PARTICIPANT"
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -68,15 +68,14 @@ defmodule Mobilizon.GraphQL.Resolvers.PictureTest do
|
||||
end
|
||||
|
||||
describe "Resolver: Upload picture" do
|
||||
test "upload_picture/3 uploads a new picture", %{conn: conn, user: user, actor: actor} do
|
||||
test "upload_picture/3 uploads a new picture", %{conn: conn, user: user} do
|
||||
picture = %{name: "my pic", alt: "represents something", file: "picture.png"}
|
||||
|
||||
mutation = """
|
||||
mutation { uploadPicture(
|
||||
name: "#{picture.name}",
|
||||
alt: "#{picture.alt}",
|
||||
file: "#{picture.file}",
|
||||
actor_id: #{actor.id}
|
||||
file: "#{picture.file}"
|
||||
) {
|
||||
url,
|
||||
name,
|
||||
@@ -109,15 +108,14 @@ defmodule Mobilizon.GraphQL.Resolvers.PictureTest do
|
||||
assert json_response(res, 200)["data"]["uploadPicture"]["url"]
|
||||
end
|
||||
|
||||
test "upload_picture/3 forbids uploading if no auth", %{conn: conn, actor: actor} do
|
||||
test "upload_picture/3 forbids uploading if no auth", %{conn: conn} do
|
||||
picture = %{name: "my pic", alt: "represents something", file: "picture.png"}
|
||||
|
||||
mutation = """
|
||||
mutation { uploadPicture(
|
||||
name: "#{picture.name}",
|
||||
alt: "#{picture.alt}",
|
||||
file: "#{picture.file}",
|
||||
actor_id: #{actor.id}
|
||||
file: "#{picture.file}"
|
||||
) {
|
||||
url,
|
||||
name
|
||||
|
||||
@@ -14,9 +14,8 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
|
||||
|
||||
describe "Resolver: Report a content" do
|
||||
@create_report_mutation """
|
||||
mutation CreateReport($reporterId: ID!, $reportedId: ID!, $eventId: ID, $content: String) {
|
||||
mutation CreateReport($reportedId: ID!, $eventId: ID, $content: String) {
|
||||
createReport(
|
||||
reporterId: $reporterId,
|
||||
reportedId: $reportedId,
|
||||
eventId: $eventId,
|
||||
content: $content
|
||||
@@ -54,7 +53,6 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
|
||||
query: @create_report_mutation,
|
||||
variables: %{
|
||||
reportedId: reported.id,
|
||||
reporterId: reporter.id,
|
||||
eventId: event.id,
|
||||
content: "This is an issue"
|
||||
}
|
||||
@@ -78,7 +76,6 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
|
||||
query: @create_report_mutation,
|
||||
variables: %{
|
||||
reportedId: reported.id,
|
||||
reporterId: 5,
|
||||
content: "This is an issue"
|
||||
}
|
||||
)
|
||||
@@ -100,7 +97,6 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
|
||||
query: @create_report_mutation,
|
||||
variables: %{
|
||||
reportedId: reported.id,
|
||||
reporterId: anonymous_actor_id,
|
||||
content: "This is an issue"
|
||||
}
|
||||
)
|
||||
@@ -112,91 +108,75 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
|
||||
assert res["data"]["createReport"]["reporter"]["id"] ==
|
||||
to_string(anonymous_actor_id)
|
||||
end
|
||||
|
||||
test "create_report/3 anonymously doesn't creates a report if the anonymous actor ID is wrong",
|
||||
%{conn: conn} do
|
||||
%Actor{} = reported = insert(:actor)
|
||||
Config.put([:anonymous, :reports, :allowed], true)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @create_report_mutation,
|
||||
variables: %{
|
||||
reportedId: reported.id,
|
||||
reporterId: 53,
|
||||
content: "This is an issue"
|
||||
}
|
||||
)
|
||||
|
||||
assert res["errors"] |> hd |> Map.get("message") ==
|
||||
"Reporter ID does not match the anonymous profile id"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Resolver: update a report" do
|
||||
@update_report_mutation """
|
||||
mutation UpdateReport($reportId: ID!, $status: ReportStatus!) {
|
||||
updateReportStatus(reportId: $reportId, status: $status) {
|
||||
content,
|
||||
reporter {
|
||||
id
|
||||
},
|
||||
event {
|
||||
id
|
||||
},
|
||||
status
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
test "update_report/3 updates the report's status", %{conn: conn} do
|
||||
%User{} = user_moderator = insert(:user, role: :moderator)
|
||||
%Actor{} = moderator = insert(:actor, user: user_moderator)
|
||||
%Actor{} = _actor_moderator = insert(:actor, user: user_moderator)
|
||||
%Report{} = report = insert(:report)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
updateReportStatus(
|
||||
report_id: #{report.id},
|
||||
moderator_id: #{moderator.id},
|
||||
status: RESOLVED
|
||||
) {
|
||||
content,
|
||||
reporter {
|
||||
id
|
||||
},
|
||||
event {
|
||||
id
|
||||
},
|
||||
status
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user_moderator)
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @update_report_mutation,
|
||||
variables: %{reportId: report.id, status: "RESOLVED"}
|
||||
)
|
||||
|
||||
assert json_response(res, 200)["errors"] == nil
|
||||
assert is_nil(res["errors"])
|
||||
|
||||
assert json_response(res, 200)["data"]["updateReportStatus"]["content"] ==
|
||||
assert res["data"]["updateReportStatus"]["content"] ==
|
||||
"This is problematic"
|
||||
|
||||
assert json_response(res, 200)["data"]["updateReportStatus"]["status"] == "RESOLVED"
|
||||
assert res["data"]["updateReportStatus"]["status"] == "RESOLVED"
|
||||
|
||||
assert json_response(res, 200)["data"]["updateReportStatus"]["reporter"]["id"] ==
|
||||
assert res["data"]["updateReportStatus"]["reporter"]["id"] ==
|
||||
to_string(report.reporter.id)
|
||||
end
|
||||
|
||||
test "create_report/3 without being connected doesn't create any report", %{conn: conn} do
|
||||
%User{} = user_moderator = insert(:user, role: :moderator)
|
||||
%Actor{} = moderator = insert(:actor, user: user_moderator)
|
||||
%Report{} = report = insert(:report)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
updateReportStatus(
|
||||
report_id: #{report.id},
|
||||
moderator_id: #{moderator.id},
|
||||
status: RESOLVED
|
||||
) {
|
||||
content
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
res =
|
||||
conn
|
||||
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @update_report_mutation,
|
||||
variables: %{reportId: report.id, status: "RESOLVED"}
|
||||
)
|
||||
|
||||
assert json_response(res, 200)["errors"] |> hd |> Map.get("message") ==
|
||||
assert res["errors"] |> hd |> Map.get("message") ==
|
||||
"You need to be logged-in and a moderator to update a report"
|
||||
end
|
||||
|
||||
test "update_report/3 without being a moderator doesn't update any report", %{conn: conn} do
|
||||
%User{} = user = insert(:user)
|
||||
%Report{} = report = insert(:report)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> auth_conn(user)
|
||||
|> AbsintheHelpers.graphql_query(
|
||||
query: @update_report_mutation,
|
||||
variables: %{reportId: report.id, status: "RESOLVED"}
|
||||
)
|
||||
|
||||
assert res["errors"] |> hd |> Map.get("message") ==
|
||||
"You need to be logged-in and a moderator to update a report"
|
||||
end
|
||||
end
|
||||
@@ -369,13 +349,12 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
|
||||
|
||||
test "create_report_note/3 creates a report note", %{conn: conn} do
|
||||
%User{} = user_moderator = insert(:user, role: :moderator)
|
||||
%Actor{id: moderator_id} = moderator = insert(:actor, user: user_moderator)
|
||||
%Actor{} = moderator = insert(:actor, user: user_moderator)
|
||||
%Report{id: report_id} = insert(:report)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
createReportNote(
|
||||
moderator_id: #{moderator_id},
|
||||
report_id: #{report_id},
|
||||
content: "#{@report_note_content}"
|
||||
) {
|
||||
@@ -410,13 +389,12 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
|
||||
|
||||
test "delete_report_note deletes a report note", %{conn: conn} do
|
||||
%User{} = user_moderator = insert(:user, role: :moderator)
|
||||
%Actor{id: moderator_id} = moderator = insert(:actor, user: user_moderator)
|
||||
%Actor{} = moderator = insert(:actor, user: user_moderator)
|
||||
%Note{id: report_note_id} = insert(:report_note, moderator: moderator)
|
||||
|
||||
mutation = """
|
||||
mutation {
|
||||
deleteReportNote(
|
||||
moderator_id: #{moderator_id},
|
||||
note_id: #{report_note_id},
|
||||
) {
|
||||
id
|
||||
|
||||
Reference in New Issue
Block a user