Improve test coverage

Files Created (8 files, 54 new tests)

  Fixtures

  1. test/support/fixtures/music_library/record_sets.ex — record_set/1
and record_set_with_records/2 helpers
  2. test/support/fixtures/music_library/online_store_templates.ex —
online_store_template/1 helper

  Context Tests

  3. test/music_library/record_sets_test.exs — 20 tests covering search,
count, CRUD, add/remove/move records
  4. test/music_library/online_store_templates_test.exs — 8 tests
covering list, CRUD, URL generation, validation
  5. test/music_library/search_test.exs — 5 tests covering universal
search and search counts
  6. test/music_library/notes_test.exs — 4 tests covering get, create,
update

  LiveView Tests

  7. test/music_library_web/live/record_set_live/index_test.exs — 11
tests covering listing, empty state, search, ordering,
create/edit/delete sets, remove records, reorder records
  8.
test/music_library_web/live/online_store_template_live/index_test.exs —
6 tests covering listing, create/edit/delete, toggle enabled

  Results

  - 297 tests, 0 failures (up from 243 — 54 new tests added)
  - All existing tests continue to pass

There's a remaining gettext warning that needs to be investigated
This commit is contained in:
Claudio Ortolina
2026-02-07 10:39:22 +00:00
parent abb1ab332a
commit 84159a1c0d
8 changed files with 763 additions and 0 deletions
@@ -0,0 +1,95 @@
defmodule MusicLibrary.OnlineStoreTemplatesTest do
use MusicLibrary.DataCase
import MusicLibrary.Fixtures.OnlineStoreTemplates
import MusicLibrary.Fixtures.Records
alias MusicLibrary.OnlineStoreTemplates
describe "list_templates/0 and list_enabled_templates/0" do
test "lists all templates" do
t1 = online_store_template(%{name: "Amazon", enabled: true})
t2 = online_store_template(%{name: "Bandcamp", enabled: false})
all = OnlineStoreTemplates.list_templates()
ids = Enum.map(all, & &1.id)
assert t1.id in ids
assert t2.id in ids
end
test "lists only enabled templates" do
t1 = online_store_template(%{name: "Amazon", enabled: true})
t2 = online_store_template(%{name: "Bandcamp", enabled: false})
enabled = OnlineStoreTemplates.list_enabled_templates()
ids = Enum.map(enabled, & &1.id)
assert t1.id in ids
refute t2.id in ids
end
end
describe "create_template/1" do
test "creates with valid attrs" do
assert {:ok, template} =
OnlineStoreTemplates.create_template(%{
name: "Test Store",
url_template: "https://example.com/search?q={artist}"
})
assert template.name == "Test Store"
assert template.enabled == true
end
test "returns error with invalid attrs" do
assert {:error, changeset} = OnlineStoreTemplates.create_template(%{name: nil})
assert %{name: ["can't be blank"]} = errors_on(changeset)
end
test "returns error with invalid URL template" do
assert {:error, changeset} =
OnlineStoreTemplates.create_template(%{
name: "Bad",
url_template: "not-a-url"
})
assert %{url_template: ["must be a valid HTTP or HTTPS URL"]} = errors_on(changeset)
end
end
describe "update_template/2" do
test "updates with valid attrs" do
template = online_store_template()
assert {:ok, updated} =
OnlineStoreTemplates.update_template(template, %{name: "Updated Name"})
assert updated.name == "Updated Name"
end
end
describe "delete_template/1" do
test "deletes the template" do
template = online_store_template()
assert {:ok, _} = OnlineStoreTemplates.delete_template(template)
assert_raise Ecto.NoResultsError, fn -> OnlineStoreTemplates.get_template!(template.id) end
end
end
describe "generate_url/2" do
test "generates URL from template and record" do
template =
online_store_template(%{
url_template: "https://example.com/search?q={artist}+{title}+{format}"
})
rec = record_with_artist("Pink Floyd", %{title: "The Wall", format: :vinyl})
url = OnlineStoreTemplates.generate_url(template, rec)
assert url =~ "Pink+Floyd"
assert url =~ "The+Wall"
assert url =~ "vinyl"
assert String.starts_with?(url, "https://example.com/search?q=")
end
end
end