From 62b4578a444b2e57e050eab82315cf2e0073b132 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sun, 10 Nov 2024 19:11:57 +0000 Subject: [PATCH] Add wishlist context tests --- test/music_library/wishlist_test.exs | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/music_library/wishlist_test.exs diff --git a/test/music_library/wishlist_test.exs b/test/music_library/wishlist_test.exs new file mode 100644 index 00000000..acdafd3d --- /dev/null +++ b/test/music_library/wishlist_test.exs @@ -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