diff --git a/test/music_library_web/live/record_index_test.exs b/test/music_library_web/live/record_index_test.exs index 60757163..0093d911 100644 --- a/test/music_library_web/live/record_index_test.exs +++ b/test/music_library_web/live/record_index_test.exs @@ -3,6 +3,7 @@ defmodule MusicLibraryWeb.RecordIndexTest do import Phoenix.LiveViewTest import MusicLibrary.RecordsFixtures + import MusicLibrary.ReleaseGroupsFixtures import Mox alias MusicLibrary.Records.Record alias MusicBrainz.APIBehaviourMock @@ -271,23 +272,7 @@ defmodule MusicLibraryWeb.RecordIndexTest do test "it imports a record when selected", %{conn: conn} do {:ok, import_live, _html} = live(conn, ~p"/records/import") - mock_results = - [ - %{ - id: "20790e26-98e4-3ad3-a67f-b674758b942d", - type: :album, - title: "Marbles", - artists: "Marillion", - release: "2004-05-03" - }, - %{ - id: "bf20ac32-a793-3bb4-beff-f7b9bffaca38", - type: :album, - title: "Marbles Live", - artists: "Marillion", - release: "2005-10-24" - } - ] + mock_results = release_group_search_results() expect(APIBehaviourMock, :search_release_group, fn "Marillion Marbles", limit: 10, @@ -310,82 +295,7 @@ defmodule MusicLibraryWeb.RecordIndexTest do first_result = hd(mock_results) first_result_id = first_result.id - release_group = %{ - "artist-credit" => [ - %{ - "artist" => %{ - "disambiguation" => "British progressive rock band", - "genres" => [ - %{ - "count" => 10, - "disambiguation" => "", - "id" => "ae9b8279-3959-48d8-8a88-741a7f6d4a48", - "name" => "progressive rock" - } - ], - "id" => "1932f5b6-0b7b-4050-b1df-833ca89e5f44", - "name" => "Marillion", - "sort-name" => "Marillion", - "type" => "Group", - "type-id" => "e431f5f6-b5d2-343d-8b36-72607fffb74b" - }, - "joinphrase" => "", - "name" => "Marillion" - } - ], - "disambiguation" => "", - "first-release-date" => "2004-05-03", - "genres" => [ - %{ - "count" => 1, - "disambiguation" => "", - "id" => "ceeaa283-5d7b-4202-8d1d-e25d116b2a18", - "name" => "alternative rock" - }, - %{ - "count" => 1, - "disambiguation" => "", - "id" => "b7ef058e-6d83-4ca4-8123-9724bff4648b", - "name" => "art rock" - }, - %{ - "count" => 1, - "disambiguation" => "", - "id" => "150eb95a-7739-4fde-a5fe-b62ca576a928", - "name" => "baroque pop" - }, - %{ - "count" => 1, - "disambiguation" => "", - "id" => "797e2e85-5ffd-495c-a757-8b4079052f0e", - "name" => "pop rock" - }, - %{ - "count" => 2, - "disambiguation" => "", - "id" => "ae9b8279-3959-48d8-8a88-741a7f6d4a48", - "name" => "progressive rock" - }, - %{ - "count" => 1, - "disambiguation" => "", - "id" => "2aeb5340-c474-4677-b9a6-35ddac9b6a58", - "name" => "psychedelic pop" - }, - %{ - "count" => 2, - "disambiguation" => "", - "id" => "0e3fc579-2d24-4f20-9dae-736e1ec78798", - "name" => "rock" - } - ], - "id" => "20790e26-98e4-3ad3-a67f-b674758b942d", - "primary-type" => "Album", - "primary-type-id" => "f529b476-6e62-324f-b0aa-1f3e33d313fc", - "secondary-type-ids" => [], - "secondary-types" => [], - "title" => "Marbles" - } + release_group = release_group() expect(APIBehaviourMock, :get_release_group, fn ^first_result_id -> {:ok, release_group} diff --git a/test/support/fixtures/release_groups_fixtures.ex b/test/support/fixtures/release_groups_fixtures.ex new file mode 100644 index 00000000..24513057 --- /dev/null +++ b/test/support/fixtures/release_groups_fixtures.ex @@ -0,0 +1,103 @@ +defmodule MusicLibrary.ReleaseGroupsFixtures do + def release_group_search_results do + [ + %{ + id: "20790e26-98e4-3ad3-a67f-b674758b942d", + type: :album, + title: "Marbles", + artists: "Marillion", + release: "2004-05-03" + }, + %{ + id: "bf20ac32-a793-3bb4-beff-f7b9bffaca38", + type: :album, + title: "Marbles Live", + artists: "Marillion", + release: "2005-10-24" + } + ] + end + + def release_group_id do + release_group() |> Map.get("id") + end + + def release_group do + %{ + "artist-credit" => [ + %{ + "artist" => %{ + "disambiguation" => "British progressive rock band", + "genres" => [ + %{ + "count" => 10, + "disambiguation" => "", + "id" => "ae9b8279-3959-48d8-8a88-741a7f6d4a48", + "name" => "progressive rock" + } + ], + "id" => "1932f5b6-0b7b-4050-b1df-833ca89e5f44", + "name" => "Marillion", + "sort-name" => "Marillion", + "type" => "Group", + "type-id" => "e431f5f6-b5d2-343d-8b36-72607fffb74b" + }, + "joinphrase" => "", + "name" => "Marillion" + } + ], + "disambiguation" => "", + "first-release-date" => "2004-05-03", + "genres" => [ + %{ + "count" => 1, + "disambiguation" => "", + "id" => "ceeaa283-5d7b-4202-8d1d-e25d116b2a18", + "name" => "alternative rock" + }, + %{ + "count" => 1, + "disambiguation" => "", + "id" => "b7ef058e-6d83-4ca4-8123-9724bff4648b", + "name" => "art rock" + }, + %{ + "count" => 1, + "disambiguation" => "", + "id" => "150eb95a-7739-4fde-a5fe-b62ca576a928", + "name" => "baroque pop" + }, + %{ + "count" => 1, + "disambiguation" => "", + "id" => "797e2e85-5ffd-495c-a757-8b4079052f0e", + "name" => "pop rock" + }, + %{ + "count" => 2, + "disambiguation" => "", + "id" => "ae9b8279-3959-48d8-8a88-741a7f6d4a48", + "name" => "progressive rock" + }, + %{ + "count" => 1, + "disambiguation" => "", + "id" => "2aeb5340-c474-4677-b9a6-35ddac9b6a58", + "name" => "psychedelic pop" + }, + %{ + "count" => 2, + "disambiguation" => "", + "id" => "0e3fc579-2d24-4f20-9dae-736e1ec78798", + "name" => "rock" + } + ], + "id" => "20790e26-98e4-3ad3-a67f-b674758b942d", + "primary-type" => "Album", + "primary-type-id" => "f529b476-6e62-324f-b0aa-1f3e33d313fc", + "secondary-type-ids" => [], + "secondary-types" => [], + "title" => "Marbles" + } + end +end