Skip to content

Commit

Permalink
Add acceptance test - index_test
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrazo committed Apr 27, 2021
1 parent c146fba commit 73ba9bf
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions test/acceptance/index_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
defmodule Test.Acceptance.IndexTest do
use ExUnit.Case, async: true

defmodule Post do
use Ash.Resource,
data_layer: Ash.DataLayer.Ets,
extensions: [
AshJsonApi.Resource
]

ets do
private?(true)
end

json_api do
type("post")

routes do
base("/posts")

index(:read)
end
end

attributes do
uuid_primary_key(:id)
attribute(:name, :string)
end
end

defmodule Api do
use Ash.Api,
extensions: [
AshJsonApi.Api
]

json_api do
log_errors?(false)
end

resources do
resource(Post)
end
end

import AshJsonApi.Test

describe "index endpoint" do
setup do
post =
Post
|> Ash.Changeset.new(%{name: "foo"})
|> Api.create!()

%{post: post}
end

test "returns a list of posts", %{post: post} do
response =
Api
|> get("/posts", status: 200)
|> assert_data_equals([
%{
"attributes" => %{
"name" => "foo"
},
"id" => post.id,
"links" => %{},
"meta" => %{},
"relationships" => %{},
"type" => "post"
}
])
end
end

test "posts table returns empty list" do
Api
|> get("/posts", status: 200)
|> assert_data_equals([])
end
end

0 comments on commit 73ba9bf

Please sign in to comment.