mobilizon/test/graphql/resolvers/config_test.exs

158 lines
4.9 KiB
Elixir
Raw Normal View History

2020-01-26 20:34:25 +01:00
defmodule Mobilizon.GraphQL.Resolvers.ConfigTest do
2020-01-26 21:36:50 +01:00
use Mobilizon.Web.ConnCase
alias Mobilizon.Actors
alias Mobilizon.Actors.Actor
2024-04-10 14:36:21 +02:00
alias Mobilizon.Config
2020-01-26 20:34:25 +01:00
alias Mobilizon.GraphQL.AbsintheHelpers
2019-03-22 10:53:38 +01:00
describe "Resolver: Get config" do
test "get_config/3 returns the instance config", context do
Cachex.clear("full_config")
Mobilizon.Config.clear_config_cache()
2024-04-10 14:36:21 +02:00
Config.put([:instance, :name], "Test instance")
Config.put([:instance, :registrations_open], true)
Config.put([:instance, :demo], false)
Config.put([:instance, :duration_of_long_event], 0)
Config.put(
[:instance, :description],
"Change this to a proper description of your instance"
)
Config.put([:instance, :federating], true)
2019-03-22 10:53:38 +01:00
query = """
{
config {
name,
registrationsOpen
anonymous {
participation {
allowed,
validation {
email {
enabled,
confirmationRequired
}
}
},
actor_id
}
2019-03-22 10:53:38 +01:00
}
}
"""
res =
context.conn
|> AbsintheHelpers.graphql_query(query: query)
assert res["data"]["config"]["name"] == "Test instance"
assert res["data"]["config"]["registrationsOpen"] == true
assert res["data"]["config"]["anonymous"]["participation"]["validation"]["email"]["enabled"] ==
true
assert res["data"]["config"]["anonymous"]["participation"]["validation"]["email"][
"confirmationRequired"
] == true
2019-03-22 10:53:38 +01:00
{:ok, %Actor{id: actor_id}} = Actors.get_or_create_internal_actor("anonymous")
assert res["data"]["config"]["anonymous"]["actor_id"] == to_string(actor_id)
2019-03-22 10:53:38 +01:00
end
2024-04-10 14:36:21 +02:00
test "get_config/3 returns the instance config default", context do
Cachex.clear("full_config")
Mobilizon.Config.clear_config_cache()
Config.put([:instance, :name], "Test instance")
Config.put([:instance, :registrations_open], true)
Config.put([:instance, :demo], false)
Config.put([:instance, :duration_of_long_event], 0)
Config.put(
[:instance, :description],
"Change this to a proper description of your instance"
)
Config.put([:instance, :federating], true)
query = """
{
config {
name,
registrationsOpen,
registrations_allowlist,
contact,
demo_mode,
long_events,
description,
long_description,
slogan,
languages,
timezones,
rules,
version,
federating
}
}
"""
res =
context.conn
|> AbsintheHelpers.graphql_query(query: query)
assert res["data"]["config"]["name"] == "Test instance"
assert res["data"]["config"]["registrationsOpen"] == true
assert res["data"]["config"]["registrations_allowlist"] == false
assert res["data"]["config"]["contact"] == nil
assert res["data"]["config"]["demo_mode"] == false
assert res["data"]["config"]["long_events"] == false
assert res["data"]["config"]["description"] ==
"Change this to a proper description of your instance"
assert res["data"]["config"]["long_description"] == nil
assert res["data"]["config"]["slogan"] == nil
assert res["data"]["config"]["languages"] == []
assert length(res["data"]["config"]["timezones"]) == 596
assert res["data"]["config"]["rules"] == nil
assert String.slice(res["data"]["config"]["version"], 0, 5) == "5.0.0"
assert res["data"]["config"]["federating"] == true
end
test "get_config/3 returns the instance config changed", context do
Cachex.clear("full_config")
Mobilizon.Config.clear_config_cache()
Config.put([:instance, :name], "My instance")
Config.put([:instance, :registrations_open], false)
Config.put([:instance, :demo], true)
Config.put([:instance, :duration_of_long_event], 30)
Config.put([:instance, :description], "My description")
Config.put([:instance, :federating], false)
query = """
{
config {
name,
registrationsOpen,
demo_mode,
long_events,
description,
federating
}
}
"""
res =
context.conn
|> AbsintheHelpers.graphql_query(query: query)
assert res["data"]["config"]["name"] == "My instance"
assert res["data"]["config"]["registrationsOpen"] == false
assert res["data"]["config"]["demo_mode"] == true
assert res["data"]["config"]["long_events"] == true
assert res["data"]["config"]["description"] == "My description"
assert res["data"]["config"]["federating"] == false
end
2019-03-22 10:53:38 +01:00
end
end