Use randomized data in test fixtures
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -4,19 +4,46 @@ defmodule MusicLibrary.RecordsFixtures do
|
|||||||
entities via the `MusicLibrary.Records` context.
|
entities via the `MusicLibrary.Records` context.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@doc """
|
@genres [
|
||||||
Generate a record.
|
"progressive rock",
|
||||||
"""
|
"art rock",
|
||||||
|
"symphonic rock",
|
||||||
|
"jazz fusion",
|
||||||
|
"psychedelic rock",
|
||||||
|
"space rock",
|
||||||
|
"krautrock",
|
||||||
|
"canterbury scene",
|
||||||
|
"zeuhl",
|
||||||
|
"avant-prog"
|
||||||
|
]
|
||||||
|
@titles [
|
||||||
|
"In the Court of the Crimson King",
|
||||||
|
"Close to the Edge",
|
||||||
|
"The Dark Side of the Moon",
|
||||||
|
"Wish You Were Here",
|
||||||
|
"Selling England by the Pound",
|
||||||
|
"Larks' Tongues in Aspic",
|
||||||
|
"Red",
|
||||||
|
"Foxtrot",
|
||||||
|
"The Lamb Lies Down on Broadway",
|
||||||
|
"Thick as a Brick"
|
||||||
|
]
|
||||||
|
# While it would be great to have this random, it's ok to use one single image
|
||||||
|
@image_data_path "#{__DIR__}/marillion-marbles.jpg"
|
||||||
|
|
||||||
def record_fixture(attrs \\ %{}) do
|
def record_fixture(attrs \\ %{}) do
|
||||||
|
musicbrainz_id = Ecto.UUID.generate()
|
||||||
|
|
||||||
{:ok, record} =
|
{:ok, record} =
|
||||||
attrs
|
attrs
|
||||||
|> Enum.into(%{
|
|> Enum.into(%{
|
||||||
genres: ["option1", "option2"],
|
genres: Enum.take_random(@genres, :rand.uniform(3)),
|
||||||
image_url: "some image url",
|
image_url: "https://coverartarchive.org/release-group/#{musicbrainz_id}/front",
|
||||||
musicbrainz_id: "7488a646-e31f-11e4-aace-600308960662",
|
image_data: File.read!(@image_data_path),
|
||||||
title: "some title",
|
musicbrainz_id: musicbrainz_id,
|
||||||
|
title: Enum.random(@titles),
|
||||||
type: :album,
|
type: :album,
|
||||||
year: 42
|
year: Enum.random(1969..2024)
|
||||||
})
|
})
|
||||||
|> MusicLibrary.Records.create_record()
|
|> MusicLibrary.Records.create_record()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user