Mix format

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-12-03 12:08:18 +01:00
parent 7911d08691
commit 32a06cae87
4 changed files with 15 additions and 10 deletions

View File

@ -174,10 +174,12 @@ defmodule Mobilizon.Actors.Actor do
|> put_change(:local, true) |> put_change(:local, true)
end end
@spec build_urls(Ecto.Changeset.t, atom()) :: Ecto.Changeset.t @spec build_urls(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
defp build_urls(changeset, type \\ :Person) defp build_urls(changeset, type \\ :Person)
defp build_urls(%Ecto.Changeset{changes: %{preferred_username: username}} = changeset, type) do defp build_urls(%Ecto.Changeset{changes: %{preferred_username: username}} = changeset, type) do
symbol = if type == :Group, do: "~", else: "@" symbol = if type == :Group, do: "~", else: "@"
changeset changeset
|> put_change( |> put_change(
:outbox_url, :outbox_url,

View File

@ -21,7 +21,7 @@ defmodule MobilizonWeb.Resolvers.Group do
Lists all groups Lists all groups
""" """
def list_groups(_parent, _args, _resolution) do def list_groups(_parent, _args, _resolution) do
{:ok, Actors.list_groups} {:ok, Actors.list_groups()}
end end
@doc """ @doc """
@ -34,15 +34,15 @@ defmodule MobilizonWeb.Resolvers.Group do
context: %{current_user: user} context: %{current_user: user}
} }
) do ) do
with %Actor{id: actor_id} <- Actors.get_local_actor_by_name(actor_username), with %Actor{id: actor_id} <- Actors.get_local_actor_by_name(actor_username),
{:user_actor, true} <- {:user_actor, true} <-
{:user_actor, actor_id in Enum.map(Actors.get_actors_for_user(user), & &1.id)}, {:user_actor, actor_id in Enum.map(Actors.get_actors_for_user(user), & &1.id)},
{:ok, %Actor{} = group} <- Actors.create_group(%{preferred_username: preferred_username}) do {:ok, %Actor{} = group} <- Actors.create_group(%{preferred_username: preferred_username}) do
{:ok, group} {:ok, group}
else else
{:error, %Ecto.Changeset{errors: [url: {"has already been taken", []}]}} -> {:error, %Ecto.Changeset{errors: [url: {"has already been taken", []}]}} ->
{:error, :group_name_not_available} {:error, :group_name_not_available}
err -> err ->
Logger.error(inspect(err)) Logger.error(inspect(err))
err err

View File

@ -548,6 +548,7 @@ defmodule MobilizonWeb.Schema do
arg(:creator_username, :string, arg(:creator_username, :string,
description: "The actor's username which will be the admin (otherwise user's default one)" description: "The actor's username which will be the admin (otherwise user's default one)"
) )
resolve(&Resolvers.Group.create_group/3) resolve(&Resolvers.Group.create_group/3)
end end

View File

@ -35,11 +35,12 @@ defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|> auth_conn(user) |> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) |> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert json_response(res, 200)["data"]["createGroup"]["preferred_username"] == assert json_response(res, 200)["data"]["createGroup"]["preferred_username"] ==
@new_group_params.groupname @new_group_params.groupname
assert json_response(res, 200)["data"]["createGroup"]["type"] == "GROUP"
mutation = """ assert json_response(res, 200)["data"]["createGroup"]["type"] == "GROUP"
mutation = """
mutation { mutation {
createGroup( createGroup(
preferred_username: "#{@new_group_params.groupname}", preferred_username: "#{@new_group_params.groupname}",
@ -56,11 +57,12 @@ defmodule MobilizonWeb.Resolvers.GroupResolverTest do
|> auth_conn(user) |> auth_conn(user)
|> post("/api", AbsintheHelpers.mutation_skeleton(mutation)) |> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
assert hd(json_response(res, 200)["errors"])["message"] == "group_name_not_available" assert hd(json_response(res, 200)["errors"])["message"] == "group_name_not_available"
end end
test "list_groups/3 returns all groups", context do test "list_groups/3 returns all groups", context do
group = insert(:group) group = insert(:group)
query = """ query = """
{ {
groups { groups {