Use Enum for scrobble rule type

This commit is contained in:
Claudio Ortolina
2025-07-04 14:23:19 +01:00
parent 81f0ec8830
commit aee08cc2bb
7 changed files with 36 additions and 39 deletions
@@ -6,7 +6,7 @@ defmodule MusicLibrary.ScrobbleRules.ScrobbleRuleTest do
describe "changeset/2" do
test "valid changeset with all required fields" do
attrs = %{
type: "album",
type: :album,
match_value: "Dark Side of the Moon",
target_musicbrainz_id: "12345678-1234-1234-1234-123456789012",
enabled: true,
@@ -19,7 +19,7 @@ defmodule MusicLibrary.ScrobbleRules.ScrobbleRuleTest do
test "valid changeset with minimal required fields" do
attrs = %{
type: "artist",
type: :artist,
match_value: "Pink Floyd",
target_musicbrainz_id: "12345678-1234-1234-1234-123456789012"
}
@@ -42,7 +42,7 @@ defmodule MusicLibrary.ScrobbleRules.ScrobbleRuleTest do
test "invalid changeset when match_value is missing" do
attrs = %{
type: "artist",
type: :artist,
target_musicbrainz_id: "12345678-1234-1234-1234-123456789012"
}
@@ -53,7 +53,7 @@ defmodule MusicLibrary.ScrobbleRules.ScrobbleRuleTest do
test "invalid changeset when target_musicbrainz_id is missing" do
attrs = %{
type: "artist",
type: :artist,
match_value: "Pink Floyd"
}
@@ -64,7 +64,7 @@ defmodule MusicLibrary.ScrobbleRules.ScrobbleRuleTest do
test "invalid changeset when type is not album or artist" do
attrs = %{
type: "invalid_type",
type: :invalid_type,
match_value: "Pink Floyd",
target_musicbrainz_id: "12345678-1234-1234-1234-123456789012"
}
@@ -76,7 +76,7 @@ defmodule MusicLibrary.ScrobbleRules.ScrobbleRuleTest do
test "invalid changeset when match_value is empty" do
attrs = %{
type: "artist",
type: :artist,
match_value: "",
target_musicbrainz_id: "12345678-1234-1234-1234-123456789012"
}
@@ -88,7 +88,7 @@ defmodule MusicLibrary.ScrobbleRules.ScrobbleRuleTest do
test "invalid changeset when target_musicbrainz_id is empty" do
attrs = %{
type: "artist",
type: :artist,
match_value: "Pink Floyd",
target_musicbrainz_id: ""
}
@@ -100,7 +100,7 @@ defmodule MusicLibrary.ScrobbleRules.ScrobbleRuleTest do
test "invalid changeset when target_musicbrainz_id is not a valid UUID" do
attrs = %{
type: "artist",
type: :artist,
match_value: "Pink Floyd",
target_musicbrainz_id: "invalid-uuid"
}
@@ -113,7 +113,7 @@ defmodule MusicLibrary.ScrobbleRules.ScrobbleRuleTest do
test "valid changeset with uppercase UUID" do
attrs = %{
type: "artist",
type: :artist,
match_value: "Pink Floyd",
target_musicbrainz_id: "12345678-1234-1234-1234-123456789012"
}
@@ -124,7 +124,7 @@ defmodule MusicLibrary.ScrobbleRules.ScrobbleRuleTest do
test "valid changeset with lowercase UUID" do
attrs = %{
type: "artist",
type: :artist,
match_value: "Pink Floyd",
target_musicbrainz_id: "abcdefab-abcd-abcd-abcd-abcdefabcdef"
}
+1 -1
View File
@@ -88,7 +88,7 @@ defmodule MusicLibrary.ScrobbleRulesTest do
assert {:ok, %ScrobbleRule{} = scrobble_rule} =
ScrobbleRules.create_scrobble_rule(valid_attrs)
assert scrobble_rule.type == "album"
assert scrobble_rule.type == :album
assert scrobble_rule.match_value == "Dark Side of the Moon"
assert scrobble_rule.target_musicbrainz_id == "12345678-1234-1234-1234-123456789012"
assert scrobble_rule.enabled == true
@@ -9,14 +9,14 @@ defmodule MusicLibraryWeb.ScrobbleRulesLiveTest do
# Test data
@invalid_attrs %{type: "", match_value: "", target_musicbrainz_id: ""}
@valid_attrs %{
type: "album",
type: :album,
match_value: "some match_value",
target_musicbrainz_id: "12345678-1234-1234-1234-123456789012",
description: "some description",
enabled: "true"
}
@update_attrs %{
type: "artist",
type: :artist,
match_value: "some updated match_value",
target_musicbrainz_id: "87654321-4321-4321-4321-210987654321",
description: "some updated description"
@@ -157,7 +157,7 @@ defmodule MusicLibraryWeb.ScrobbleRulesLiveTest do
assert index_live
|> form("#scrobble_rule-form",
scrobble_rule: %{
type: "album",
type: :album,
match_value: "Test Album",
target_musicbrainz_id: "invalid-uuid"
}
@@ -173,7 +173,7 @@ defmodule MusicLibraryWeb.ScrobbleRulesLiveTest do
# Select album type
html =
index_live
|> form("#scrobble_rule-form", scrobble_rule: %{type: "album"})
|> form("#scrobble_rule-form", scrobble_rule: %{type: :album})
|> render_change()
assert html =~ "Album Title"
@@ -181,7 +181,7 @@ defmodule MusicLibraryWeb.ScrobbleRulesLiveTest do
# Select artist type
html =
index_live
|> form("#scrobble_rule-form", scrobble_rule: %{type: "artist"})
|> form("#scrobble_rule-form", scrobble_rule: %{type: :artist})
|> render_change()
assert html =~ "Artist Name"
@@ -11,7 +11,7 @@ defmodule MusicLibrary.ScrobbleRulesFixtures do
"""
def scrobble_rule_fixture(attrs \\ %{}) do
default_attrs = %{
type: "album",
type: :album,
match_value: "Dark Side of the Moon",
target_musicbrainz_id: "12345678-1234-1234-1234-123456789012",
enabled: true,