diff --git a/test/swapi/films_test.exs b/test/swapi/films_test.exs new file mode 100644 index 0000000..ce5d6e3 --- /dev/null +++ b/test/swapi/films_test.exs @@ -0,0 +1,69 @@ +defmodule SWAPI.FilmsTest do + use SWAPI.DataCase + + alias SWAPI.Films + + describe "films" do + alias SWAPI.Schemas.Film + + import SWAPI.FilmsFixtures + + @invalid_attrs %{title: nil, episode_id: nil, opening_crawl: nil, director: nil, producer: nil, release_date: nil} + + test "list_films/0 returns all films" do + film = film_fixture() + assert Films.list_films() == [film] + end + + test "get_film!/1 returns the film with given id" do + film = film_fixture() + assert Films.get_film!(film.id) == film + end + + test "create_film/1 with valid data creates a film" do + valid_attrs = %{title: "some title", episode_id: 42, opening_crawl: "some opening_crawl", director: "some director", producer: "some producer", release_date: ~D[2023-11-28]} + + assert {:ok, %Film{} = film} = Films.create_film(valid_attrs) + assert film.title == "some title" + assert film.episode_id == 42 + assert film.opening_crawl == "some opening_crawl" + assert film.director == "some director" + assert film.producer == "some producer" + assert film.release_date == ~D[2023-11-28] + end + + test "create_film/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = Films.create_film(@invalid_attrs) + end + + test "update_film/2 with valid data updates the film" do + film = film_fixture() + update_attrs = %{title: "some updated title", episode_id: 43, opening_crawl: "some updated opening_crawl", director: "some updated director", producer: "some updated producer", release_date: ~D[2023-11-29]} + + assert {:ok, %Film{} = film} = Films.update_film(film, update_attrs) + assert film.title == "some updated title" + assert film.episode_id == 43 + assert film.opening_crawl == "some updated opening_crawl" + assert film.director == "some updated director" + assert film.producer == "some updated producer" + assert film.release_date == ~D[2023-11-29] + end + + test "update_film/2 with invalid data returns error changeset" do + film = film_fixture() + assert {:error, %Ecto.Changeset{}} = Films.update_film(film, @invalid_attrs) + assert film == Films.get_film!(film.id) + end + + test "delete_film/1 deletes the film" do + film = film_fixture() + assert {:ok, %Film{}} = Films.delete_film(film) + assert_raise Ecto.NoResultsError, fn -> Films.get_film!(film.id) end + end + + test "change_film/1 returns a film changeset" do + film = film_fixture() + assert %Ecto.Changeset{} = Films.change_film(film) + end + end +end diff --git a/test/swapi/people_test.exs b/test/swapi/people_test.exs new file mode 100644 index 0000000..a118459 --- /dev/null +++ b/test/swapi/people_test.exs @@ -0,0 +1,73 @@ +defmodule SWAPI.PeopleTest do + use SWAPI.DataCase + + alias SWAPI.People + + describe "people" do + alias SWAPI.Schemas.Person + + import SWAPI.PeopleFixtures + + @invalid_attrs %{name: nil, birth_year: nil, eye_color: nil, gender: nil, hair_color: nil, height: nil, mass: nil, skin_color: nil} + + test "list_people/0 returns all people" do + person = person_fixture() + assert People.list_people() == [person] + end + + test "get_person!/1 returns the person with given id" do + person = person_fixture() + assert People.get_person!(person.id) == person + end + + test "create_person/1 with valid data creates a person" do + valid_attrs = %{name: "some name", birth_year: "some birth_year", eye_color: "some eye_color", gender: "some gender", hair_color: "some hair_color", height: "some height", mass: "some mass",skin_color: "some skin_color"} + + assert {:ok, %Person{} = person} = People.create_person(valid_attrs) + assert person.name == "some name" + assert person.birth_year == "some birth_year" + assert person.eye_color == "some eye_color" + assert person.gender == "some gender" + assert person.hair_color == "some hair_color" + assert person.height == "some height" + assert person.mass == "some mass" + assert person.skin_color == "some skin_color" + end + + test "create_person/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = People.create_person(@invalid_attrs) + end + + test "update_person/2 with valid data updates the person" do + person = person_fixture() + update_attrs = %{name: "some updated name", birth_year: "some updated birth_year", eye_color: "some updated eye_color", gender: "some updated gender", hair_color: "some updated hair_color", height: "some updated height", mass: "some updated mass", skin_color: "some updated skin_color"} + + assert {:ok, %Person{} = person} = People.update_person(person, update_attrs) + assert person.name == "some updated name" + assert person.birth_year == "some updated birth_year" + assert person.eye_color == "some updated eye_color" + assert person.gender == "some updated gender" + assert person.hair_color == "some updated hair_color" + assert person.height == "some updated height" + assert person.mass == "some updated mass" + assert person.skin_color == "some updated skin_color" + end + + test "update_person/2 with invalid data returns error changeset" do + person = person_fixture() + assert {:error, %Ecto.Changeset{}} = People.update_person(person, @invalid_attrs) + assert person == People.get_person!(person.id) + end + + test "delete_person/1 deletes the person" do + person = person_fixture() + assert {:ok, %Person{}} = People.delete_person(person) + assert_raise Ecto.NoResultsError, fn -> People.get_person!(person.id) end + end + + test "change_person/1 returns a person changeset" do + person = person_fixture() + assert %Ecto.Changeset{} = People.change_person(person) + end + end +end diff --git a/test/swapi/planets_test.exs b/test/swapi/planets_test.exs new file mode 100644 index 0000000..c9e0266 --- /dev/null +++ b/test/swapi/planets_test.exs @@ -0,0 +1,75 @@ +defmodule SWAPI.PlanetsTest do + use SWAPI.DataCase + + alias SWAPI.Planets + + describe "planets" do + alias SWAPI.Schemas.Planet + + import SWAPI.PlanetsFixtures + + @invalid_attrs %{name: nil, diameter: nil, rotation_period: nil, orbital_period: nil, gravity: nil, population: nil, climate: nil, terrain: nil, surface_water: nil} + + test "list_planets/0 returns all planets" do + planet = planet_fixture() + assert Planets.list_planets() == [planet] + end + + test "get_planet!/1 returns the planet with given id" do + planet = planet_fixture() + assert Planets.get_planet!(planet.id) == planet + end + + test "create_planet/1 with valid data creates a planet" do + valid_attrs = %{name: "some name", diameter: "some diameter", rotation_period: "some rotation_period", orbital_period: "some orbital_period", gravity: "some gravity", population: "some population", climate: "some climate", terrain: "some terrain", surface_water: "some surface_water"} + + assert {:ok, %Planet{} = planet} = Planets.create_planet(valid_attrs) + assert planet.name == "some name" + assert planet.diameter == "some diameter" + assert planet.rotation_period == "some rotation_period" + assert planet.orbital_period == "some orbital_period" + assert planet.gravity == "some gravity" + assert planet.population == "some population" + assert planet.climate == "some climate" + assert planet.terrain == "some terrain" + assert planet.surface_water == "some surface_water" + end + + test "create_planet/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = Planets.create_planet(@invalid_attrs) + end + + test "update_planet/2 with valid data updates the planet" do + planet = planet_fixture() + update_attrs = %{name: "some updated name", diameter: "some updated diameter", rotation_period: "some updated rotation_period", orbital_period: "some updated orbital_period", gravity: "some updated gravity", population: "some updated population", climate: "some updated climate", terrain: "some updated terrain", surface_water: "some updated surface_water"} + + assert {:ok, %Planet{} = planet} = Planets.update_planet(planet, update_attrs) + assert planet.name == "some updated name" + assert planet.diameter == "some updated diameter" + assert planet.rotation_period == "some updated rotation_period" + assert planet.orbital_period == "some updated orbital_period" + assert planet.gravity == "some updated gravity" + assert planet.population == "some updated population" + assert planet.climate == "some updated climate" + assert planet.terrain == "some updated terrain" + assert planet.surface_water == "some updated surface_water" + end + + test "update_planet/2 with invalid data returns error changeset" do + planet = planet_fixture() + assert {:error, %Ecto.Changeset{}} = Planets.update_planet(planet, @invalid_attrs) + assert planet == Planets.get_planet!(planet.id) + end + + test "delete_planet/1 deletes the planet" do + planet = planet_fixture() + assert {:ok, %Planet{}} = Planets.delete_planet(planet) + assert_raise Ecto.NoResultsError, fn -> Planets.get_planet!(planet.id) end + end + + test "change_planet/1 returns a planet changeset" do + planet = planet_fixture() + assert %Ecto.Changeset{} = Planets.change_planet(planet) + end + end +end diff --git a/test/swapi/species_test.exs b/test/swapi/species_test.exs new file mode 100644 index 0000000..13621f8 --- /dev/null +++ b/test/swapi/species_test.exs @@ -0,0 +1,75 @@ +defmodule SWAPI.SpeciesTest do + use SWAPI.DataCase + + alias SWAPI.Species + + describe "species" do + alias SWAPI.Schemas.Species, as: SpeciesSchema + + import SWAPI.SpeciesFixtures + + @invalid_attrs %{name: nil, classification: nil, designation: nil, average_height: nil, average_lifespan: nil, eye_colors: nil, hair_colors: nil, skin_colors: nil, language: nil} + + test "list_species/0 returns all species" do + species = species_fixture() + assert Species.list_species() == [species] + end + + test "get_species!/1 returns the species with given id" do + species = species_fixture() + assert Species.get_species!(species.id) == species + end + + test "create_species/1 with valid data creates a species" do + valid_attrs = %{name: "some name", classification: "some classification", designation: "some designation", average_height: "some average_height", average_lifespan: "some average_lifespan", eye_colors: "some eye_colors", hair_colors: "some hair_colors", skin_colors: "some skin_colors", language: "some language"} + + assert {:ok, %SpeciesSchema{} = species} = Species.create_species(valid_attrs) + assert species.name == "some name" + assert species.classification == "some classification" + assert species.designation == "some designation" + assert species.average_height == "some average_height" + assert species.average_lifespan == "some average_lifespan" + assert species.eye_colors == "some eye_colors" + assert species.hair_colors == "some hair_colors" + assert species.skin_colors == "some skin_colors" + assert species.language == "some language" + end + + test "create_species/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = Species.create_species(@invalid_attrs) + end + + test "update_species/2 with valid data updates the species" do + species = species_fixture() + update_attrs = %{name: "some updated name", classification: "some updated classification", designation: "some updated designation", average_height: "some updated average_height", average_lifespan: "some updated average_lifespan", eye_colors: "some updated eye_colors", hair_colors: "some updated hair_colors", skin_colors: "some updated skin_colors", language: "some updated language"} + + assert {:ok, %SpeciesSchema{} = species} = Species.update_species(species, update_attrs) + assert species.name == "some updated name" + assert species.classification == "some updated classification" + assert species.designation == "some updated designation" + assert species.average_height == "some updated average_height" + assert species.average_lifespan == "some updated average_lifespan" + assert species.eye_colors == "some updated eye_colors" + assert species.hair_colors == "some updated hair_colors" + assert species.skin_colors == "some updated skin_colors" + assert species.language == "some updated language" + end + + test "update_species/2 with invalid data returns error changeset" do + species = species_fixture() + assert {:error, %Ecto.Changeset{}} = Species.update_species(species, @invalid_attrs) + assert species == Species.get_species!(species.id) + end + + test "delete_species/1 deletes the species" do + species = species_fixture() + assert {:ok, %SpeciesSchema{}} = Species.delete_species(species) + assert_raise Ecto.NoResultsError, fn -> Species.get_species!(species.id) end + end + + test "change_species/1 returns a species changeset" do + species = species_fixture() + assert %Ecto.Changeset{} = Species.change_species(species) + end + end +end diff --git a/test/swapi/starships_test.exs b/test/swapi/starships_test.exs new file mode 100644 index 0000000..1cd12ab --- /dev/null +++ b/test/swapi/starships_test.exs @@ -0,0 +1,131 @@ +defmodule SWAPI.StarshipsTest do + use SWAPI.DataCase + + alias SWAPI.Starships + + describe "starships" do + alias SWAPI.Schemas.Starship + + import SWAPI.StarshipsFixtures + + @invalid_attrs %{ + transport: %{ + name: nil, + model: nil, + manufacturer: nil, + length: nil, + cost_in_credits: nil, + crew: nil, + passengers: nil, + max_atmosphering_speed: nil, + cargo_capacity: nil, + consumables: nil + }, + starship_class: nil, + hyperdrive_rating: nil, + mglt: nil + } + + test "list_starships/0 returns all starships" do + starship = starship_fixture() + assert Starships.list_starships() == [starship] + end + + test "get_starship!/1 returns the starship with given id" do + starship = starship_fixture() + assert Starships.get_starship!(starship.id) == starship + end + + test "create_starship/1 with valid data creates a starship" do + valid_attrs = %{ + transport: %{ + name: "some name", + model: "some model", + manufacturer: "some manufacturer", + length: "some length", + cost_in_credits: "some cost_in_credits", + crew: "some crew", + passengers: "some passengers", + max_atmosphering_speed: "some max_atmosphering_speed", + cargo_capacity: "some cargo_capacity", + consumables: "some consumables" + }, + starship_class: "some starship_class", + hyperdrive_rating: "some hyperdrive_rating", + mglt: "some mglt" + } + + assert {:ok, %Starship{} = starship} = Starships.create_starship(valid_attrs) + assert starship.transport.name == "some name" + assert starship.transport.model == "some model" + assert starship.transport.manufacturer == "some manufacturer" + assert starship.transport.length == "some length" + assert starship.transport.cost_in_credits == "some cost_in_credits" + assert starship.transport.crew == "some crew" + assert starship.transport.passengers == "some passengers" + assert starship.transport.max_atmosphering_speed == "some max_atmosphering_speed" + assert starship.transport.cargo_capacity == "some cargo_capacity" + assert starship.transport.consumables == "some consumables" + assert starship.starship_class == "some starship_class" + assert starship.hyperdrive_rating == "some hyperdrive_rating" + assert starship.mglt == "some mglt" + end + + test "create_starship/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = Starships.create_starship(@invalid_attrs) + end + + test "update_starship/2 with valid data updates the starship" do + starship = starship_fixture() + update_attrs = %{ + transport: %{ + name: "some updated name", + model: "some updated model", + manufacturer: "some updated manufacturer", + length: "some updated length", + cost_in_credits: "some updated cost_in_credits", + crew: "some updated crew", + passengers: "some updated passengers", + max_atmosphering_speed: "some updated max_atmosphering_speed", + cargo_capacity: "some updated cargo_capacity", + consumables: "some updated consumables" + }, + starship_class: "some updated starship_class", + hyperdrive_rating: "some updated hyperdrive_rating", + mglt: "some updated mglt" + } + + assert {:ok, %Starship{} = starship} = Starships.update_starship(starship, update_attrs) + assert starship.transport.name == "some updated name" + assert starship.transport.model == "some updated model" + assert starship.transport.manufacturer == "some updated manufacturer" + assert starship.transport.length == "some updated length" + assert starship.transport.cost_in_credits == "some updated cost_in_credits" + assert starship.transport.crew == "some updated crew" + assert starship.transport.passengers == "some updated passengers" + assert starship.transport.max_atmosphering_speed == "some updated max_atmosphering_speed" + assert starship.transport.cargo_capacity == "some updated cargo_capacity" + assert starship.transport.consumables == "some updated consumables" + assert starship.starship_class == "some updated starship_class" + assert starship.hyperdrive_rating == "some updated hyperdrive_rating" + assert starship.mglt == "some updated mglt" + end + + test "update_starship/2 with invalid data returns error changeset" do + starship = starship_fixture() + assert {:error, %Ecto.Changeset{}} = Starships.update_starship(starship, @invalid_attrs) + assert starship == Starships.get_starship!(starship.id) + end + + test "delete_starship/1 deletes the starship" do + starship = starship_fixture() + assert {:ok, %Starship{}} = Starships.delete_starship(starship) + assert_raise Ecto.NoResultsError, fn -> Starships.get_starship!(starship.id) end + end + + test "change_starship/1 returns a starship changeset" do + starship = starship_fixture() + assert %Ecto.Changeset{} = Starships.change_starship(starship) + end + end +end diff --git a/test/swapi/vehicles_test.exs b/test/swapi/vehicles_test.exs new file mode 100644 index 0000000..903573a --- /dev/null +++ b/test/swapi/vehicles_test.exs @@ -0,0 +1,121 @@ +defmodule SWAPI.VehiclesTest do + use SWAPI.DataCase + + alias SWAPI.Vehicles + + describe "vehicles" do + alias SWAPI.Schemas.Vehicle + + import SWAPI.VehiclesFixtures + + @invalid_attrs %{ + transport: %{ + name: nil, + model: nil, + manufacturer: nil, + length: nil, + cost_in_credits: nil, + crew: nil, + passengers: nil, + max_atmosphering_speed: nil, + cargo_capacity: nil, + consumables: nil + }, + vehicle_class: nil + } + + test "list_vehicles/0 returns all vehicles" do + vehicle = vehicle_fixture() + assert Vehicles.list_vehicles() == [vehicle] + end + + test "get_vehicle!/1 returns the vehicle with given id" do + vehicle = vehicle_fixture() + assert Vehicles.get_vehicle!(vehicle.id) == vehicle + end + + test "create_vehicle/1 with valid data creates a vehicle" do + valid_attrs = %{ + transport: %{ + name: "some name", + model: "some model", + manufacturer: "some manufacturer", + length: "some length", + cost_in_credits: "some cost_in_credits", + crew: "some crew", + passengers: "some passengers", + max_atmosphering_speed: "some max_atmosphering_speed", + cargo_capacity: "some cargo_capacity", + consumables: "some consumables" + }, + vehicle_class: "some vehicle_class" + } + + assert {:ok, %Vehicle{} = vehicle} = Vehicles.create_vehicle(valid_attrs) + assert vehicle.transport.name == "some name" + assert vehicle.transport.model == "some model" + assert vehicle.transport.manufacturer == "some manufacturer" + assert vehicle.transport.length == "some length" + assert vehicle.transport.cost_in_credits == "some cost_in_credits" + assert vehicle.transport.crew == "some crew" + assert vehicle.transport.passengers == "some passengers" + assert vehicle.transport.max_atmosphering_speed == "some max_atmosphering_speed" + assert vehicle.transport.cargo_capacity == "some cargo_capacity" + assert vehicle.transport.consumables == "some consumables" + assert vehicle.vehicle_class == "some vehicle_class" + end + + test "create_vehicle/1 with invalid data returns error changeset" do + assert {:error, %Ecto.Changeset{}} = Vehicles.create_vehicle(@invalid_attrs) + end + + test "update_vehicle/2 with valid data updates the vehicle" do + vehicle = vehicle_fixture() + update_attrs = %{ + transport: %{ + name: "some updated name", + model: "some updated model", + manufacturer: "some updated manufacturer", + length: "some updated length", + cost_in_credits: "some updated cost_in_credits", + crew: "some updated crew", + passengers: "some updated passengers", + max_atmosphering_speed: "some updated max_atmosphering_speed", + cargo_capacity: "some updated cargo_capacity", + consumables: "some updated consumables" + }, + vehicle_class: "some updated vehicle_class" + } + + assert {:ok, %Vehicle{} = vehicle} = Vehicles.update_vehicle(vehicle, update_attrs) + assert vehicle.transport.name == "some updated name" + assert vehicle.transport.model == "some updated model" + assert vehicle.transport.manufacturer == "some updated manufacturer" + assert vehicle.transport.length == "some updated length" + assert vehicle.transport.cost_in_credits == "some updated cost_in_credits" + assert vehicle.transport.crew == "some updated crew" + assert vehicle.transport.passengers == "some updated passengers" + assert vehicle.transport.max_atmosphering_speed == "some updated max_atmosphering_speed" + assert vehicle.transport.cargo_capacity == "some updated cargo_capacity" + assert vehicle.transport.consumables == "some updated consumables" + assert vehicle.vehicle_class == "some updated vehicle_class" + end + + test "update_vehicle/2 with invalid data returns error changeset" do + vehicle = vehicle_fixture() + assert {:error, %Ecto.Changeset{}} = Vehicles.update_vehicle(vehicle, @invalid_attrs) + assert vehicle == Vehicles.get_vehicle!(vehicle.id) + end + + test "delete_vehicle/1 deletes the vehicle" do + vehicle = vehicle_fixture() + assert {:ok, %Vehicle{}} = Vehicles.delete_vehicle(vehicle) + assert_raise Ecto.NoResultsError, fn -> Vehicles.get_vehicle!(vehicle.id) end + end + + test "change_vehicle/1 returns a vehicle changeset" do + vehicle = vehicle_fixture() + assert %Ecto.Changeset{} = Vehicles.change_vehicle(vehicle) + end + end +end