From 6fcca38e27cc267fe7e39cfd1172c648419ac731 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Wed, 1 Apr 2026 07:11:47 +0100 Subject: [PATCH] Make sure to pull artists info when record is updated Catches the scenario when a new artist is added --- lib/music_library/records.ex | 7 +++++++ test/music_library/records_test.exs | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/music_library/records.ex b/lib/music_library/records.ex index d3e5b493..d62b4f79 100644 --- a/lib/music_library/records.ex +++ b/lib/music_library/records.ex @@ -430,6 +430,13 @@ defmodule MusicLibrary.Records do @spec update_record(Record.t(), map()) :: {:ok, Record.t()} | {:error, Ecto.Changeset.t()} def update_record(%Record{} = record, attrs) do + with {:ok, updated_record} <- do_update_record(record, attrs), + :ok <- refresh_artist_info_async(updated_record) do + {:ok, updated_record} + end + end + + defp do_update_record(record, attrs) do record |> Record.changeset(attrs) |> Repo.update() diff --git a/test/music_library/records_test.exs b/test/music_library/records_test.exs index ac45413f..d16b963d 100644 --- a/test/music_library/records_test.exs +++ b/test/music_library/records_test.exs @@ -69,6 +69,22 @@ defmodule MusicLibrary.RecordsTest do end end + describe "update_record/2" do + test "queues a task to retrieve artist info data" do + record = + record(musicbrainz_data: release_group(:lockdown_trilogy)) + + [artist] = record.artists + + Oban.drain_queue(queue: :default) + + Records.update_record(record, %{title: "Updated Title"}) + + assert_enqueued worker: MusicLibrary.Worker.FetchArtistInfo, + args: %{id: artist.musicbrainz_id} + end + end + describe "delete_record/1" do test "queues a task to delete artist info data" do record =