|
| 1 | +defmodule SWAPIWeb.GraphQL.Resolvers.StarshipResolverTest do |
| 2 | + use SWAPI.DataCase |
| 3 | + |
| 4 | + alias SWAPIWeb.GraphQL.Resolvers.StarshipResolver |
| 5 | + import SWAPI.StarshipsFixtures |
| 6 | + |
| 7 | + describe "all/2" do |
| 8 | + test "returns all starships" do |
| 9 | + %{id: starship_id} = starship_fixture() |
| 10 | + assert {:ok, [%{id: ^starship_id}]} = StarshipResolver.all(%{}, %{}) |
| 11 | + end |
| 12 | + |
| 13 | + test "returns empty list when no starships exist" do |
| 14 | + assert {:ok, []} = StarshipResolver.all(%{}, %{}) |
| 15 | + end |
| 16 | + end |
| 17 | + |
| 18 | + describe "one/2" do |
| 19 | + test "returns starship when it exists" do |
| 20 | + %{id: starship_id} = starship_fixture() |
| 21 | + assert {:ok, %{id: ^starship_id}} = StarshipResolver.one(%{id: starship_id}, %{}) |
| 22 | + end |
| 23 | + |
| 24 | + test "returns error when starship doesn't exist" do |
| 25 | + assert {:error, "Starship not found"} = StarshipResolver.one(%{id: 0}, %{}) |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + describe "search/2" do |
| 30 | + test "returns matching starships" do |
| 31 | + %{id: starship_id} = starship_fixture(%{transport: %{name: "X-wing"}}) |
| 32 | + starship_fixture(%{transport: %{name: "TIE Fighter"}}) |
| 33 | + |
| 34 | + assert {:ok, [%{id: ^starship_id}]} = |
| 35 | + StarshipResolver.search(%{search_terms: ["X-wing"]}, %{}) |
| 36 | + end |
| 37 | + |
| 38 | + test "returns empty list when no matches found" do |
| 39 | + starship_fixture(%{transport: %{name: "X-wing"}}) |
| 40 | + |
| 41 | + assert {:ok, []} = StarshipResolver.search(%{search_terms: ["Non-existent"]}, %{}) |
| 42 | + end |
| 43 | + end |
| 44 | +end |
0 commit comments