Improve tests

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-02-22 18:07:20 +01:00
parent d73f738b1b
commit 8bba35e60b
7 changed files with 131 additions and 26 deletions

View File

@@ -73,5 +73,68 @@ defmodule MobilizonWeb.Resolvers.PersonResolverTest do
assert json_response(res, 200)["data"]["loggedPerson"]["preferredUsername"] ==
actor.preferred_username
end
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 {
avatarUrl,
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
end
end

View File

@@ -0,0 +1,48 @@
defmodule MobilizonWeb.Resolvers.TagResolverTest do
use MobilizonWeb.ConnCase
alias MobilizonWeb.AbsintheHelpers
import Mobilizon.Factory
describe "Tag Resolver" do
test "list_tags/3 returns the list of tags", context do
tag1 = insert(:tag)
tag2 = insert(:tag)
tag3 = insert(:tag)
insert(:tag_relation, tag: tag1, link: tag2)
insert(:tag_relation, tag: tag3, link: tag1)
query = """
{
tags {
id,
slug,
title,
related {
id,
title,
slug
}
}
}
"""
res =
context.conn
|> get("/api", AbsintheHelpers.query_skeleton(query, "tags"))
tags = json_response(res, 200)["data"]["tags"]
assert tags |> length == 3
assert Enum.filter(tags, fn tag -> tag["slug"] == tag1.slug end)
|> hd
|> Map.get("related")
|> Enum.map(fn tag -> tag["slug"] end)
|> MapSet.new() ==
[tag2, tag3]
|> Enum.map(fn
tag -> tag.slug
end)
|> MapSet.new()
end
end
end