Fix report resolver test
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
f699efe109
commit
96511ea4bc
@ -182,34 +182,38 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "Resolver: Get list of reports" do
|
describe "Resolver: Get list of reports" do
|
||||||
|
@reports_query """
|
||||||
|
query ListReports($page: Int, $limit: Int) {
|
||||||
|
reports(page: $page, limit: $limit) {
|
||||||
|
elements {
|
||||||
|
id
|
||||||
|
reported {
|
||||||
|
id
|
||||||
|
preferredUsername
|
||||||
|
}
|
||||||
|
content,
|
||||||
|
updatedAt
|
||||||
|
}
|
||||||
|
total
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
test "get an empty list of reports", %{conn: conn} do
|
test "get an empty list of reports", %{conn: conn} do
|
||||||
%User{} = user_moderator = insert(:user, role: :moderator)
|
%User{} = user_moderator = insert(:user, role: :moderator)
|
||||||
|
|
||||||
query = """
|
res = AbsintheHelpers.graphql_query(conn, query: @reports_query)
|
||||||
{
|
|
||||||
reports {
|
|
||||||
id,
|
|
||||||
reported {
|
|
||||||
preferredUsername
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
res =
|
assert hd(res["errors"])["message"] ==
|
||||||
conn
|
|
||||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "report"))
|
|
||||||
|
|
||||||
assert json_response(res, 200)["errors"] |> hd |> Map.get("message") ==
|
|
||||||
"You need to be logged-in and a moderator to list reports"
|
"You need to be logged-in and a moderator to list reports"
|
||||||
|
|
||||||
res =
|
res =
|
||||||
conn
|
conn
|
||||||
|> auth_conn(user_moderator)
|
|> auth_conn(user_moderator)
|
||||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "report"))
|
|> AbsintheHelpers.graphql_query(query: @reports_query)
|
||||||
|
|
||||||
assert json_response(res, 200)["errors"] == nil
|
assert res["errors"] == nil
|
||||||
assert json_response(res, 200)["data"]["reports"] == []
|
assert res["data"]["reports"]["elements"] == []
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get a list of reports", %{conn: conn} do
|
test "get a list of reports", %{conn: conn} do
|
||||||
@ -224,67 +228,34 @@ defmodule Mobilizon.GraphQL.Resolvers.ReportTest do
|
|||||||
%Report{id: report_3_id} = insert(:report, content: "My content 3")
|
%Report{id: report_3_id} = insert(:report, content: "My content 3")
|
||||||
%Report{} = insert(:report, status: :closed)
|
%Report{} = insert(:report, status: :closed)
|
||||||
|
|
||||||
query = """
|
|
||||||
{
|
|
||||||
reports {
|
|
||||||
id,
|
|
||||||
reported {
|
|
||||||
preferredUsername
|
|
||||||
},
|
|
||||||
content,
|
|
||||||
updatedAt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
res =
|
res =
|
||||||
conn
|
conn
|
||||||
|> auth_conn(user_moderator)
|
|> auth_conn(user_moderator)
|
||||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "report"))
|
|> AbsintheHelpers.graphql_query(query: @reports_query)
|
||||||
|
|
||||||
assert json_response(res, 200)["errors"] == nil
|
assert res["errors"] == nil
|
||||||
|
assert res["data"]["reports"]["total"] == 3
|
||||||
|
|
||||||
assert json_response(res, 200)["data"]["reports"]
|
assert res["data"]["reports"]["elements"]
|
||||||
|> Enum.map(fn report -> Map.get(report, "id") end) ==
|
|> Enum.map(fn report -> Map.get(report, "id") end) ==
|
||||||
Enum.map([report_3_id, report_2_id, report_1_id], &to_string/1)
|
Enum.map([report_3_id, report_2_id, report_1_id], &to_string/1)
|
||||||
|
|
||||||
query = """
|
res =
|
||||||
{
|
conn
|
||||||
reports(page: 2, limit: 2) {
|
|> auth_conn(user_moderator)
|
||||||
id,
|
|> AbsintheHelpers.graphql_query(query: @reports_query, variables: %{page: 2, limit: 2})
|
||||||
reported {
|
|
||||||
preferredUsername
|
assert res["errors"] == nil
|
||||||
}
|
assert res["data"]["reports"]["total"] == 3
|
||||||
}
|
assert res["data"]["reports"]["elements"] |> length == 1
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
res =
|
res =
|
||||||
conn
|
conn
|
||||||
|> auth_conn(user_moderator)
|
|> auth_conn(user_moderator)
|
||||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "report"))
|
|> AbsintheHelpers.graphql_query(query: @reports_query, variables: %{page: 3, limit: 2})
|
||||||
|
|
||||||
assert json_response(res, 200)["errors"] == nil
|
assert res["errors"] == nil
|
||||||
assert json_response(res, 200)["data"]["reports"] |> length == 1
|
assert res["data"]["reports"]["elements"] |> length == 0
|
||||||
|
|
||||||
query = """
|
|
||||||
{
|
|
||||||
reports(page: 3, limit: 2) {
|
|
||||||
id,
|
|
||||||
reported {
|
|
||||||
preferredUsername
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
res =
|
|
||||||
conn
|
|
||||||
|> auth_conn(user_moderator)
|
|
||||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "report"))
|
|
||||||
|
|
||||||
assert json_response(res, 200)["errors"] == nil
|
|
||||||
assert json_response(res, 200)["data"]["reports"] |> length == 0
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user