diff --git a/lib/decentralised_book_index/metadata/book.ex b/lib/decentralised_book_index/metadata/book.ex index 07bc797..387d97b 100644 --- a/lib/decentralised_book_index/metadata/book.ex +++ b/lib/decentralised_book_index/metadata/book.ex @@ -204,7 +204,7 @@ defmodule DecentralisedBookIndex.Metadata.Book do description "Return a list of Books, optionally filtering by BookId." argument :type, :string, allow_nil?: false - argument :bid, :string, allow_nil?: false + argument :bid, :string, allow_nil?: true filter expr(exists(bids, type == ^arg(:type) and contains(bid, ^arg(:bid)))) diff --git a/test/decentralised_book_index_web/live/book_live/index_test.exs b/test/decentralised_book_index_web/live/book_live/index_test.exs new file mode 100644 index 0000000..deca49c --- /dev/null +++ b/test/decentralised_book_index_web/live/book_live/index_test.exs @@ -0,0 +1,45 @@ +defmodule DecentralisedBookIndexWeb.Live.BookLive.IndexTest do + use DecentralisedBookIndexWeb.LiveCase, async: true + + describe "Search by bid" do + setup do + %{ + modes: [ + "isbn", + "isbn13", + "asin" + ], + books: + for _ <- 1..5 do + generate(book()) + end + } + end + + test "can search by an empty bid", %{conn: conn, modes: modes} do + for mode <- modes do + {:ok, _view, html} = + conn + |> live("/books?search_mode=#{mode}") + + assert html =~ "Listing Books" + assert html =~ "No Books" + end + end + + test "can search by a bid", %{conn: conn, modes: modes, books: books} do + [book | others] = books + + for %{type: type, bid: bid} <- book.bids do + {:ok, view, html} = + conn + |> live("/books?query=#{bid}&search_mode=#{type}") + + html = render(view) + + assert html =~ book.title + refute html =~ "No Books" + end + end + end +end