Add wishlist context tests
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
defmodule MusicLibrary.WishlistTest do
|
||||
use MusicLibrary.DataCase
|
||||
|
||||
alias MusicLibrary.Wishlist
|
||||
import MusicLibrary.RecordsFixtures
|
||||
|
||||
defp fill_wishlist(_) do
|
||||
records = [
|
||||
record_fixture(%{purchased_at: nil, title: "Brave"}),
|
||||
record_fixture(%{purchased_at: nil, title: "Brave"}),
|
||||
record_fixture(%{purchased_at: nil}),
|
||||
record_fixture(%{title: "Brave"})
|
||||
]
|
||||
|
||||
%{wishlist: records}
|
||||
end
|
||||
|
||||
describe "search_records/2" do
|
||||
setup [:fill_wishlist]
|
||||
|
||||
test "returns matching records, excluding purchased records" do
|
||||
assert [%{title: "Brave"}, %{title: "Brave"}] = Wishlist.search_records("brave")
|
||||
end
|
||||
|
||||
test "it respects limit" do
|
||||
assert [%{title: "Brave"}] = Wishlist.search_records("brave", limit: 1)
|
||||
end
|
||||
|
||||
test "it respects offset" do
|
||||
[first_match] = Wishlist.search_records("brave", limit: 1)
|
||||
[second_match] = Wishlist.search_records("brave", limit: 1, offset: 1)
|
||||
assert first_match !== second_match
|
||||
end
|
||||
end
|
||||
|
||||
describe "search_records_count/1" do
|
||||
setup [:fill_wishlist]
|
||||
|
||||
test "returns the count of matching records, excluding purchased records" do
|
||||
assert 2 = Wishlist.search_records_count("brave")
|
||||
end
|
||||
end
|
||||
|
||||
describe "count/0" do
|
||||
setup [:fill_wishlist]
|
||||
|
||||
test "returns the count of records in the wishlist, excluding purchased records" do
|
||||
assert 3 = Wishlist.count()
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user