Skip to content

Commit bc1e1cf

Browse files
committed
adding more of the project tests in - I am sure there's silly errors on purpose as a bonus learning exercise
1 parent 1dda7ad commit bc1e1cf

File tree

1 file changed

+38
-40
lines changed

1 file changed

+38
-40
lines changed

test/tunez/music/album_test.exs

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -165,55 +165,53 @@ defmodule TunezWeb.Music.AlbumTest do
165165
end
166166

167167
describe "validations" do
168-
@tag :skip
169168
test "year_released must be between 1950 and now" do
170-
# admin = generate(user(role: :admin))
171-
# artist = generate(artist())
169+
admin = generate(user(role: :admin))
170+
artist = generate(artist())
172171

173-
# # The assertion isn't really needed here, but we want to signal to
174-
# # our future selves that this is part of the test, not the setup.
175-
# assert %{artist_id: artist.id, name: "test 2024", year_released: 2024}
176-
# |> Music.create_album!(actor: admin)
177-
178-
# # Using `assert_raise`
179-
# assert_raise Ash.Error.Invalid, ~r/must be between 1950 and next year/, fn ->
180-
# %{artist_id: artist.id, name: "test 1925", year_released: 1925}
181-
# |> Music.create_album!(actor: admin)
182-
# end
183-
184-
# # Using `assert_has_error` - note the lack of bang to return the error
185-
# %{artist_id: artist.id, name: "test 1950", year_released: 1950}
186-
# |> Music.create_album(actor: admin)
187-
# |> Ash.Test.assert_has_error(Ash.Error.Invalid, fn error ->
188-
# match?(%{message: "must be between 1950 and next year"}, error)
189-
# end)
172+
# The assertion isn't really needed here, but we want to signal to
173+
# our future selves that this is part of the test, not the setup.
174+
assert %{artist_id: artist.id, name: "test 2024", year_released: 2024}
175+
|> Music.create_album!(actor: admin)
176+
177+
# Using `assert_raise`
178+
assert_raise Ash.Error.Invalid, ~r/must be between 1950 and next year/, fn ->
179+
%{artist_id: artist.id, name: "test 1925", year_released: 1925}
180+
|> Music.create_album!(actor: admin)
181+
end
182+
183+
# Using `assert_has_error` - note the lack of bang to return the error
184+
%{artist_id: artist.id, name: "test 1950", year_released: 1949}
185+
|> Music.create_album(actor: admin)
186+
|> Ash.Test.assert_has_error(Ash.Error.Invalid, fn error ->
187+
match?(%{message: "must be between 1950 and next year"}, error)
188+
end)
190189
end
191190

192-
@tag :skip
193191
test "cover_image_url must be either a remote URL or a local URL from /images" do
194-
# admin = generate(user(role: :admin))
195-
# artist = generate(artist())
192+
admin = generate(user(role: :admin))
193+
artist = generate(artist())
196194

197-
# with_url = fn url ->
198-
# Ash.Generator.action_input(Tunez.Music.Album, :create,
199-
# artist_id: artist.id,
200-
# year_released: 2025,
201-
# cover_image_url: url
202-
# )
203-
# |> Enum.at(0)
204-
# end
195+
with_url = fn url ->
196+
Ash.Generator.action_input(Tunez.Music.Album, :create,
197+
artist_id: artist.id,
198+
year_released: 2025,
199+
cover_image_url: url
200+
)
201+
|> Enum.at(0)
202+
end
205203

206-
# assert Music.create_album!(with_url.("/images/test.jpg"), actor: admin)
204+
assert Music.create_album!(with_url.("/images/test.jpg"), actor: admin)
207205

208-
# assert_raise Ash.Error.Invalid, ~r/must start with/, fn ->
209-
# Music.create_album!(with_url.("notavalidURL"), actor: admin)
210-
# end
206+
assert_raise Ash.Error.Invalid, ~r/must start with/, fn ->
207+
Music.create_album!(with_url.("notavalidURL"), actor: admin)
208+
end
211209

212-
# with_url.("/image/tunez.mp3")
213-
# |> Music.create_album(actor: admin)
214-
# |> assert_has_error(fn error ->
215-
# error.field == :cover_image_url && error.message == "must start with https:// or /images/"
216-
# end)
210+
with_url.("/image/tunez.mp3")
211+
|> Music.create_album(actor: admin)
212+
|> assert_has_error(fn error ->
213+
error.field == :cover_image_url && error.message == "must start with https:// or /images"
214+
end)
217215
end
218216
end
219217
end

0 commit comments

Comments
 (0)