Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/atlas/events/event_category.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ defmodule Atlas.Events.EventCategory do
def changeset(event_category, attrs) do
event_category
|> cast(attrs, @required_fields ++ @optional_fields)
|> validate_format(:color, ~r/^#[0-9a-fA-F]{6}$/,
message: "Invalid color format!(e.g., #RRGGBB)"
)
|> validate_required(@required_fields)
end
end
8 changes: 4 additions & 4 deletions test/atlas/events_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ defmodule Atlas.EventsTest do
end

test "create_event_category/1 with valid data creates a event_category" do
valid_attrs = %{name: "some name", color: "some color", type: "optional"}
valid_attrs = %{name: "some name", color: "#abcdef", type: "optional"}

assert {:ok, %EventCategory{} = event_category} = Events.create_event_category(valid_attrs)
assert event_category.name == "some name"
assert event_category.color == "some color"
assert event_category.color == "#abcdef"
end

test "create_event_category/1 with invalid data returns error changeset" do
Expand All @@ -34,13 +34,13 @@ defmodule Atlas.EventsTest do

test "update_event_category/2 with valid data updates the event_category" do
event_category = event_category_fixture()
update_attrs = %{name: "some updated name", color: "some updated color"}
update_attrs = %{name: "some updated name", color: "#123456"}

assert {:ok, %EventCategory{} = event_category} =
Events.update_event_category(event_category, update_attrs)

assert event_category.name == "some updated name"
assert event_category.color == "some updated color"
assert event_category.color == "#123456"
end

test "update_event_category/2 with invalid data returns error changeset" do
Expand Down
12 changes: 6 additions & 6 deletions test/atlas_web/controllers/event_category_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ defmodule AtlasWeb.EventCategoryControllerTest do

@create_attrs %{
name: "some name",
color: "some color"
color: "#abcdef",
type: "optional"
}
@update_attrs %{
name: "some updated name",
color: "some updated color"
color: "#123456",
type: "mandatory"
}
@create_attrs Map.put(@create_attrs, :type, "optional")
@update_attrs Map.put(@update_attrs, :type, "optional")
@invalid_attrs %{name: nil, color: nil, type: nil}

setup %{conn: _conn} do
Expand All @@ -38,7 +38,7 @@ defmodule AtlasWeb.EventCategoryControllerTest do

assert %{
"id" => ^id,
"color" => "some color",
"color" => "#abcdef",
"name" => "some name"
} = json_response(conn, 200)["event_category"]
end
Expand All @@ -63,7 +63,7 @@ defmodule AtlasWeb.EventCategoryControllerTest do

assert %{
"id" => ^id,
"color" => "some updated color",
"color" => "#123456",
"name" => "some updated name"
} = json_response(conn, 200)["event_category"]
end
Expand Down
20 changes: 9 additions & 11 deletions test/support/fixtures/events_fixtures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ defmodule Atlas.EventsFixtures do
{:ok, event_category} =
attrs
|> Enum.into(%{
color: "some color",
name: "some name",
color: "#abcdef",
type: "optional"
})
|> Atlas.Events.create_event_category()
Expand All @@ -26,18 +26,16 @@ defmodule Atlas.EventsFixtures do
def event_fixture(attrs \\ %{}) do
category = event_category_fixture()

defaults = %{
end: ~N[2025-01-01 14:00:00],
link: "some link",
place: "some place",
start: ~N[2025-01-01 14:00:00],
title: "some title",
category_id: category.id
}

{:ok, event} =
attrs
|> Enum.into(defaults)
|> Enum.into(%{
title: "some title",
start: ~U[2025-01-01T14:00:00Z],
end: ~U[2025-01-01T15:00:00Z],
place: "some place",
link: "some link",
category_id: category.id
})
|> Atlas.Events.create_event()

event
Expand Down