Add categories properly

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-01-15 12:04:09 +01:00
parent 9df9a795c7
commit 8b4d1ab4e4
6 changed files with 23 additions and 13 deletions

View File

@@ -17,6 +17,10 @@ defmodule Eventos.EventsTest do
insert(:event, organizer: account_fixture())
end
def category_fixture do
insert(:category)
end
describe "events" do
alias Eventos.Events.Event
@@ -37,7 +41,9 @@ defmodule Eventos.EventsTest do
test "create_event/1 with valid data creates a event" do
{:ok, account} = Accounts.create_account(@account_valid_attrs)
category = category_fixture()
valid_attrs_with_account_id = Map.put(@event_valid_attrs, :organizer_id, account.id)
valid_attrs_with_account_id = Map.put(valid_attrs_with_account_id, :category_id, category.id)
assert {:ok, %Event{} = event} = Events.create_event(valid_attrs_with_account_id)
assert event.begins_on == DateTime.from_naive!(~N[2010-04-17 14:00:00.000000Z], "Etc/UTC")
assert event.description == "some description"
@@ -146,15 +152,6 @@ defmodule Eventos.EventsTest do
@update_attrs %{description: "some updated description", picture: "some updated picture", title: "some updated title"}
@invalid_attrs %{description: nil, picture: nil, title: nil}
def category_fixture(attrs \\ %{}) do
{:ok, category} =
attrs
|> Enum.into(@valid_attrs)
|> Events.create_category()
category
end
test "list_categories/0 returns all categories" do
category = category_fixture()
assert Events.list_categories() == [category]

View File

@@ -30,6 +30,9 @@ defmodule EventosWeb.EventControllerTest do
describe "create event" do
test "renders event when data is valid", %{conn: conn, user: user} do
attrs = Map.put(@create_attrs, :organizer_id, user.account.id)
category = insert(:category)
attrs = Map.put(attrs, :category_id, category.id)
conn = auth_conn(conn, user)
conn = post conn, event_path(conn, :create), event: attrs
assert %{"id" => id} = json_response(conn, 201)["data"]

View File

@@ -25,6 +25,13 @@ defmodule Eventos.Factory do
}
end
def category_factory do
%Eventos.Events.Category{
title: sequence("MyCategory"),
description: "My category desc"
}
end
def event_factory do
%Eventos.Events.Event{
title: sequence("MyEvent"),
@@ -32,7 +39,8 @@ defmodule Eventos.Factory do
description: "My desc",
begins_on: nil,
ends_on: nil,
organizer: build(:account)
organizer: build(:account),
category: build(:category)
}
end