Make Categories a predefined list

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Allow null values for categories for now

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2019-02-22 16:54:01 +01:00
parent 75554cd3f5
commit 7086fe8389
27 changed files with 89 additions and 655 deletions

View File

@@ -11,7 +11,8 @@ defmodule Mobilizon.EventsTest do
ends_on: "2010-04-17 14:00:00Z",
title: "some title",
url: "some url",
uuid: "b5126423-f1af-43e4-a923-002a03003ba4"
uuid: "b5126423-f1af-43e4-a923-002a03003ba4",
category: "meeting"
}
describe "events" do
@@ -79,14 +80,12 @@ defmodule Mobilizon.EventsTest do
test "create_event/1 with valid data creates a event" do
actor = insert(:actor)
category = insert(:category)
address = insert(:address)
valid_attrs =
@event_valid_attrs
|> Map.put(:organizer_actor, actor)
|> Map.put(:organizer_actor_id, actor.id)
|> Map.put(:category_id, category.id)
|> Map.put(:address_id, address.id)
with {:ok, %Event{} = event} <- Events.create_event(valid_attrs) do
@@ -175,77 +174,6 @@ defmodule Mobilizon.EventsTest do
end
end
describe "categories" do
alias Mobilizon.Events.Category
setup do
category = insert(:category)
{:ok, category: category}
end
@valid_attrs %{
description: "some description",
picture: %Plug.Upload{
path: "test/fixtures/category_picture.png",
filename: "category_picture.png"
},
title: "some title"
}
@update_attrs %{
description: "some updated description",
picture: %Plug.Upload{
path: "test/fixtures/category_picture_updated.png",
filename: "category_picture_updated.png"
},
title: "some updated title"
}
@invalid_attrs %{description: nil, picture: nil, title: nil}
test "list_categories/0 returns all categories", %{category: category} do
assert [category.id] == Events.list_categories() |> Enum.map(& &1.id)
end
test "get_category!/1 returns the category with given id", %{category: category} do
assert Events.get_category!(category.id).id == category.id
end
test "get_category_by_title/1 return the category with given title", %{category: category} do
assert Events.get_category_by_title(category.title).id == category.id
end
test "create_category/1 with valid data creates a category" do
assert {:ok, %Category{} = category} = Events.create_category(@valid_attrs)
assert category.description == "some description"
assert category.picture.file_name == @valid_attrs.picture.filename
assert category.title == "some title"
end
test "create_category/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Events.create_category(@invalid_attrs)
end
test "update_category/2 with valid data updates the category", %{category: category} do
assert {:ok, %Category{} = category} = Events.update_category(category, @update_attrs)
assert category.description == "some updated description"
assert category.picture.file_name == @update_attrs.picture.filename
assert category.title == "some updated title"
end
test "update_category/2 with invalid data returns error changeset", %{category: category} do
assert {:error, %Ecto.Changeset{}} = Events.update_category(category, @invalid_attrs)
assert category.description == Events.get_category!(category.id).description
end
test "delete_category/1 deletes the category", %{category: category} do
assert {:ok, %Category{}} = Events.delete_category(category)
assert_raise Ecto.NoResultsError, fn -> Events.get_category!(category.id) end
end
test "change_category/1 returns a category changeset", %{category: category} do
assert %Ecto.Changeset{} = Events.change_category(category)
end
end
describe "tags" do
alias Mobilizon.Events.Tag

View File

@@ -1,77 +0,0 @@
defmodule MobilizonWeb.Resolvers.CategoryResolverTest do
use MobilizonWeb.ConnCase
alias MobilizonWeb.AbsintheHelpers
import Mobilizon.Factory
setup %{conn: conn} do
user = insert(:user)
actor = insert(:actor, user: user)
{:ok, conn: conn, actor: actor, user: user}
end
describe "Category Resolver" do
test "list_categories/3 returns the list of categories", context do
insert(:category)
insert(:category)
query = """
{
categories {
id,
title,
description,
picture {
url,
},
}
}
"""
res =
context.conn
|> get("/api", AbsintheHelpers.query_skeleton(query, "categories"))
assert json_response(res, 200)["data"]["categories"] |> length == 2
end
# We can't test an upload…yet?
# test "create_category/3 creates a category", %{conn: conn, actor: actor, user: user} do
# mutation = """
# mutation {
# createCategory(title: "my category", description: "my desc") {
# id,
# title,
# description,
# },
# }
# """
# res =
# conn
# |> auth_conn(user)
# |> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
# assert json_response(res, 200)["data"]["createCategory"]["title"] == "my category"
# end
# test "create_category/3 doesn't create a category if the user isn't logged in", %{conn: conn, actor: actor} do
# mutation = """
# mutation {
# createCategory(title: "my category", description: "my desc") {
# id,
# title,
# description,
# },
# }
# """
# res =
# conn
# |> post("/api", AbsintheHelpers.mutation_skeleton(mutation))
# assert hd(json_response(res, 200)["errors"])["message"] ==
# "You are not allowed to create a category if not connected"
# end
end
end

View File

@@ -9,7 +9,8 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
title: "some title",
begins_on: DateTime.utc_now() |> DateTime.truncate(:second),
uuid: "b5126423-f1af-43e4-a923-002a03003ba4",
url: "some url"
url: "some url",
category: "meeting"
}
setup %{conn: conn} do
@@ -21,12 +22,9 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
describe "Event Resolver" do
test "find_event/3 returns an event", context do
category = insert(:category)
event =
@event
|> Map.put(:organizer_actor_id, context.actor.id)
|> Map.put(:category_id, category.id)
{:ok, event} = Events.create_event(event)
@@ -61,8 +59,6 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
end
test "create_event/3 creates an event", %{conn: conn, actor: actor, user: user} do
category = insert(:category)
mutation = """
mutation {
createEvent(
@@ -72,7 +68,7 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
DateTime.utc_now() |> DateTime.truncate(:second) |> DateTime.to_iso8601()
}",
organizer_actor_id: "#{actor.id}",
category: "#{category.title}"
category: "birthday"
) {
title,
uuid

View File

@@ -9,7 +9,8 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
title: "some title",
begins_on: DateTime.utc_now() |> DateTime.truncate(:second),
uuid: "b5126423-f1af-43e4-a923-002a03003ba4",
url: "some url"
url: "some url",
category: "meeting"
}
setup %{conn: conn} do
@@ -313,13 +314,9 @@ defmodule MobilizonWeb.Resolvers.ParticipantResolverTest do
end
test "list_participants_for_event/3 returns participants for an event", context do
# Plain event
category = insert(:category)
event =
@event
|> Map.put(:organizer_actor_id, context.actor.id)
|> Map.put(:category_id, category.id)
{:ok, event} = Events.create_event(event)

View File

@@ -53,13 +53,6 @@ defmodule Mobilizon.Factory do
}
end
def category_factory do
%Mobilizon.Events.Category{
title: sequence("MyCategory"),
description: "My category desc"
}
end
def tag_factory do
%Mobilizon.Events.Tag{
title: "MyTag",
@@ -112,7 +105,7 @@ defmodule Mobilizon.Factory do
begins_on: start,
ends_on: Timex.shift(start, hours: 2),
organizer_actor: actor,
category: build(:category),
category: sequence("something"),
physical_address: build(:address),
visibility: :public,
url: "#{actor.url}/#{uuid}",