forked from loafle/openapi-generator-original
* Switch Poison to Jason * generate-samples.sh * Finalize Poison -> Jason switch * parse date-time values to Elixir DateTime * improve formatting in various places, so there's less changes by `mix format` later * fix Java version in flake.nix * Use List.delete/2 instead of Enum.reject/2 for performance reasons * mix format test/* * Install dialyxir and fix reported issues * Fix RequestBuilder.decode/2 hardcoded module name * Update docs * Revert changes to API spec (HTTP -> HTTPS) * Revert uneeded change to Elixir code generator * Use HTTP in Elixir tests HTTPS doesn't work for folks who setup petstore.swagger.io as described in docs/faq-contributing.md. --------- Co-authored-by: Wojciech Piekutowski <wojciech@piekutowski.net>
67 lines
2.1 KiB
Elixir
67 lines
2.1 KiB
Elixir
defmodule PetTest do
|
|
use ExUnit.Case, async: true
|
|
alias OpenapiPetstore.Connection
|
|
alias OpenapiPetstore.Api.Pet, as: PetApi
|
|
alias OpenapiPetstore.Model.Pet
|
|
alias OpenapiPetstore.Model.Category
|
|
alias OpenapiPetstore.Model.Tag
|
|
|
|
setup do
|
|
%{connection: Connection.new()}
|
|
end
|
|
|
|
test "add and delete a pet", %{connection: connection} do
|
|
petId = 10007
|
|
|
|
pet = %Pet{
|
|
:id => petId,
|
|
:name => "elixir client test",
|
|
:photoUrls => ["http://test_elixir_unit_test.com"],
|
|
:category => %Category{:id => petId, :name => "test elixir category"},
|
|
:tags => [%Tag{:id => petId, :name => "test elixir tag"}]
|
|
}
|
|
|
|
{:ok, %Tesla.Env{} = response} = PetApi.add_pet(connection, pet)
|
|
assert response.status == 200
|
|
|
|
{:ok, pet} = PetApi.get_pet_by_id(connection, petId)
|
|
assert pet.id == petId
|
|
assert pet.name == "elixir client test"
|
|
assert pet.photoUrls == ["http://test_elixir_unit_test.com"]
|
|
assert pet.category == %Category{id: petId, name: "test elixir category"}
|
|
assert pet.tags == [%Tag{:id => petId, :name => "test elixir tag"}]
|
|
|
|
{:ok, response} = PetApi.delete_pet(connection, petId)
|
|
assert response.status == 200
|
|
{:ok, response} = PetApi.get_pet_by_id(connection, petId)
|
|
assert response.status == 404
|
|
end
|
|
|
|
test "update a pet", %{connection: connection} do
|
|
petId = 10007
|
|
|
|
pet = %Pet{
|
|
:id => petId,
|
|
:name => "elixir client updatePet",
|
|
:status => "pending",
|
|
:photoUrls => ["http://test_elixir_unit_test.com"]
|
|
}
|
|
|
|
{:ok, response} = PetApi.update_pet(connection, pet)
|
|
assert response.status == 200
|
|
|
|
{:ok, pet} = PetApi.get_pet_by_id(connection, petId)
|
|
assert pet.id == petId
|
|
assert pet.name == "elixir client updatePet"
|
|
assert pet.status == "pending"
|
|
end
|
|
|
|
test "find pet by status", %{connection: connection} do
|
|
{:ok, listPets} = PetApi.find_pets_by_status(connection, "available")
|
|
assert List.first(listPets) != nil
|
|
|
|
{:ok, listPets} = PetApi.find_pets_by_status(connection, "unknown_and_incorrect_status")
|
|
assert List.first(listPets) == nil
|
|
end
|
|
end
|