2019-02-22 18:07:20 +01:00
|
|
|
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
|
|
|
|
|
2019-09-22 13:41:24 +02:00
|
|
|
assert tags
|
|
|
|
|> Enum.filter(fn tag -> tag["slug"] == tag1.slug end)
|
2019-02-22 18:07:20 +01:00
|
|
|
|> hd
|
|
|
|
|> Map.get("related")
|
|
|
|
|> Enum.map(fn tag -> tag["slug"] end)
|
|
|
|
|> MapSet.new() ==
|
|
|
|
[tag2, tag3]
|
2019-09-16 02:07:44 +02:00
|
|
|
|> Enum.map(fn tag -> tag.slug end)
|
2019-02-22 18:07:20 +01:00
|
|
|
|> MapSet.new()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|