2019-02-21 18:11:49 +01:00
|
|
|
defmodule MobilizonWeb.Resolvers.SearchResolverTest do
|
|
|
|
use MobilizonWeb.ConnCase
|
|
|
|
alias MobilizonWeb.AbsintheHelpers
|
|
|
|
import Mobilizon.Factory
|
2019-10-22 10:25:28 +02:00
|
|
|
alias Mobilizon.Service.Search
|
2019-02-21 18:11:49 +01:00
|
|
|
|
|
|
|
setup %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, conn: conn, user: user}
|
|
|
|
end
|
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
test "search_events/3 finds events with basic search", %{
|
2019-02-21 18:11:49 +01:00
|
|
|
conn: conn,
|
|
|
|
user: user
|
|
|
|
} do
|
2019-04-12 15:04:32 +02:00
|
|
|
insert(:actor, user: user, preferred_username: "test_person")
|
|
|
|
insert(:actor, type: :Group, preferred_username: "test_group")
|
|
|
|
event = insert(:event, title: "test_event")
|
2019-10-22 10:25:28 +02:00
|
|
|
Search.insert_search_event(event)
|
2019-02-21 18:11:49 +01:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2019-04-12 15:04:32 +02:00
|
|
|
search_events(search: "test") {
|
|
|
|
total,
|
|
|
|
elements {
|
2019-02-21 18:11:49 +01:00
|
|
|
title,
|
|
|
|
uuid,
|
|
|
|
__typename
|
|
|
|
}
|
2019-04-12 15:04:32 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "search"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
assert json_response(res, 200)["data"]["search_events"]["total"] == 1
|
|
|
|
assert json_response(res, 200)["data"]["search_events"]["elements"] |> length == 1
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["data"]["search_events"]["elements"])["uuid"] ==
|
|
|
|
to_string(event.uuid)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search_persons/3 finds persons with basic search", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
actor = insert(:actor, user: user, preferred_username: "test_person")
|
|
|
|
insert(:actor, type: :Group, preferred_username: "test_group")
|
2019-10-22 10:25:28 +02:00
|
|
|
event = insert(:event, title: "test_event")
|
|
|
|
Search.insert_search_event(event)
|
2019-04-12 15:04:32 +02:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
search_persons(search: "test") {
|
|
|
|
total,
|
|
|
|
elements {
|
|
|
|
preferredUsername,
|
|
|
|
__typename
|
2019-02-21 18:11:49 +01:00
|
|
|
}
|
2019-04-12 15:04:32 +02:00
|
|
|
},
|
2019-02-21 18:11:49 +01:00
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "search"))
|
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
assert json_response(res, 200)["data"]["search_persons"]["total"] == 1
|
|
|
|
assert json_response(res, 200)["data"]["search_persons"]["elements"] |> length == 1
|
2019-02-21 18:11:49 +01:00
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
assert hd(json_response(res, 200)["data"]["search_persons"]["elements"])["preferredUsername"] ==
|
2019-02-21 18:11:49 +01:00
|
|
|
actor.preferred_username
|
|
|
|
end
|
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
test "search_groups/3 finds persons with basic search", %{
|
2019-02-21 18:11:49 +01:00
|
|
|
conn: conn,
|
|
|
|
user: user
|
|
|
|
} do
|
2019-04-12 15:04:32 +02:00
|
|
|
insert(:actor, user: user, preferred_username: "test_person")
|
|
|
|
group = insert(:actor, type: :Group, preferred_username: "test_group")
|
2019-10-22 10:25:28 +02:00
|
|
|
event = insert(:event, title: "test_event")
|
|
|
|
Search.insert_search_event(event)
|
2019-02-21 18:11:49 +01:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
2019-04-12 15:04:32 +02:00
|
|
|
search_groups(search: "test") {
|
|
|
|
total,
|
|
|
|
elements {
|
|
|
|
preferredUsername,
|
|
|
|
__typename
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "search"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
assert json_response(res, 200)["data"]["search_groups"]["total"] == 1
|
|
|
|
assert json_response(res, 200)["data"]["search_groups"]["elements"] |> length == 1
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["data"]["search_groups"]["elements"])["preferredUsername"] ==
|
|
|
|
group.preferred_username
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search_events/3 finds events and actors with word search", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
insert(:actor, user: user, preferred_username: "person", name: "I like pineapples")
|
2019-10-22 10:25:28 +02:00
|
|
|
event1 = insert(:event, title: "Pineapple fashion week")
|
|
|
|
event2 = insert(:event, title: "I love pineAPPLE")
|
|
|
|
event3 = insert(:event, title: "Hello")
|
|
|
|
Search.insert_search_event(event1)
|
|
|
|
Search.insert_search_event(event2)
|
|
|
|
Search.insert_search_event(event3)
|
2019-04-12 15:04:32 +02:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
search_events(search: "pineapple") {
|
|
|
|
total,
|
|
|
|
elements {
|
|
|
|
title,
|
|
|
|
uuid,
|
|
|
|
__typename
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "search"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
assert json_response(res, 200)["data"]["search_events"]["total"] == 2
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["search_events"]["elements"]
|
|
|
|
|> length == 2
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["search_events"]["elements"]
|
|
|
|
|> Enum.map(& &1["title"]) == [
|
2019-10-22 10:25:28 +02:00
|
|
|
"Pineapple fashion week",
|
|
|
|
"I love pineAPPLE"
|
2019-04-12 15:04:32 +02:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search_persons/3 finds persons with word search", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
actor = insert(:actor, user: user, preferred_username: "person", name: "I like pineapples")
|
|
|
|
insert(:actor, preferred_username: "group", type: :Group, name: "pineapple group")
|
2019-10-22 10:25:28 +02:00
|
|
|
event1 = insert(:event, title: "Pineapple fashion week")
|
|
|
|
event2 = insert(:event, title: "I love pineAPPLE")
|
|
|
|
event3 = insert(:event, title: "Hello")
|
|
|
|
Search.insert_search_event(event1)
|
|
|
|
Search.insert_search_event(event2)
|
|
|
|
Search.insert_search_event(event3)
|
2019-04-12 15:04:32 +02:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
search_persons(search: "pineapple") {
|
|
|
|
total,
|
|
|
|
elements {
|
|
|
|
preferredUsername,
|
|
|
|
__typename
|
2019-02-21 18:11:49 +01:00
|
|
|
}
|
2019-04-12 15:04:32 +02:00
|
|
|
}
|
2019-02-21 18:11:49 +01:00
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "search"))
|
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
assert json_response(res, 200)["data"]["search_persons"]["total"] == 1
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["search_persons"]["elements"]
|
|
|
|
|> length == 1
|
2019-02-21 18:11:49 +01:00
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
assert hd(json_response(res, 200)["data"]["search_persons"]["elements"])["preferredUsername"] ==
|
2019-02-21 18:11:49 +01:00
|
|
|
actor.preferred_username
|
|
|
|
end
|
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
test "search_events/3 finds events with accented search", %{
|
2019-02-21 18:11:49 +01:00
|
|
|
conn: conn,
|
|
|
|
user: user
|
|
|
|
} do
|
2019-04-12 15:04:32 +02:00
|
|
|
insert(:actor, user: user, preferred_username: "person", name: "Torréfaction du Kafé")
|
|
|
|
insert(:actor, type: :Group, preferred_username: "group", name: "Kafé group")
|
|
|
|
event = insert(:event, title: "Tour du monde des Kafés")
|
2019-10-22 10:25:28 +02:00
|
|
|
Search.insert_search_event(event)
|
2019-02-21 18:11:49 +01:00
|
|
|
|
|
|
|
# Elaborate query
|
|
|
|
query = """
|
|
|
|
{
|
2019-04-12 15:04:32 +02:00
|
|
|
search_events(search: "Kafé") {
|
|
|
|
total,
|
|
|
|
elements {
|
|
|
|
title,
|
|
|
|
uuid,
|
|
|
|
__typename
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "search"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
assert json_response(res, 200)["data"]["search_events"]["total"] == 1
|
|
|
|
assert hd(json_response(res, 200)["data"]["search_events"]["elements"])["uuid"] == event.uuid
|
|
|
|
end
|
|
|
|
|
|
|
|
test "search_groups/3 finds groups with accented search", %{
|
|
|
|
conn: conn,
|
|
|
|
user: user
|
|
|
|
} do
|
|
|
|
insert(:actor, user: user, preferred_username: "person", name: "Torréfaction du Kafé")
|
|
|
|
group = insert(:actor, type: :Group, preferred_username: "group", name: "Kafé group")
|
2019-10-22 10:25:28 +02:00
|
|
|
event = insert(:event, title: "Tour du monde des Kafés")
|
|
|
|
Search.insert_search_event(event)
|
2019-04-12 15:04:32 +02:00
|
|
|
|
|
|
|
# Elaborate query
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
search_groups(search: "Kafé") {
|
|
|
|
total,
|
|
|
|
elements {
|
|
|
|
preferredUsername,
|
|
|
|
__typename
|
2019-02-21 18:11:49 +01:00
|
|
|
}
|
2019-04-12 15:04:32 +02:00
|
|
|
}
|
2019-02-21 18:11:49 +01:00
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "search"))
|
|
|
|
|
2019-04-12 15:04:32 +02:00
|
|
|
assert json_response(res, 200)["errors"] == nil
|
|
|
|
assert json_response(res, 200)["data"]["search_groups"]["total"] == 1
|
|
|
|
|
|
|
|
assert hd(json_response(res, 200)["data"]["search_groups"]["elements"])["preferredUsername"] ==
|
|
|
|
group.preferred_username
|
2019-02-21 18:11:49 +01:00
|
|
|
end
|
|
|
|
end
|