Skip to content

Commit

Permalink
Merge pull request #6 from tallysmartins/ci_setup
Browse files Browse the repository at this point in the history
Ci setup
  • Loading branch information
michalmuskala committed Mar 25, 2018
2 parents 7c20d9b + 95ef3e7 commit 001df18
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .travis.yml
@@ -0,0 +1,10 @@
language: elixir
sudo: false
elixir: '1.5'
otp_release: '20.0'

addons:
postgresql: "9.6"

script:
- mix test
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -2,6 +2,9 @@

# ElixirBench API

[![Travis build](https://secure.travis-ci.org/elixir-bench/elixir-bench-api.svg?branch=master
"Build Status")](https://travis-ci.org/elixir-bench/elixir-bench-api)

This project provides a public GraphQL API for exploring the results of the
benchmarks and is responsible for jobs scheduling.

Expand Down
2 changes: 1 addition & 1 deletion lib/elixir_bench_web/schema.ex
Expand Up @@ -15,7 +15,7 @@ defmodule ElixirBenchWeb.Schema do
end
end

field :repo, non_null(:repo) do
field :repo, (:repo) do
arg :slug, non_null(:string)
resolve fn %{slug: slug}, _ ->
Repos.fetch_repo_by_slug(slug)
Expand Down
108 changes: 108 additions & 0 deletions test/elixir_bench_web/schema/schema_test.exs
@@ -0,0 +1,108 @@
defmodule ElixirBenchWeb.SchemaTest do
use ElixirBenchWeb.ConnCase

alias ElixirBenchWeb.AbsintheHelpers
alias ElixirBench.Repos

@repo %{owner: "tallysmartins", name: "ecto"}

describe "repos query" do
test "not break when there is no registered repo", context do
query = """
repos {
name
owner
}
"""

json = context.conn
|> post("/api", AbsintheHelpers.query_skeleton(query))
|> Map.get(:resp_body)
|> Antidote.decode

{:ok, %{"data" => %{"repos" => []}}} = json
end

test "return repos list", context do
{:ok, _} = Repos.create_repo(@repo)
query = """
repos {
name
owner
slug
}
"""

json_data =
%{
"data" => %{
"repos" => [
%{
"name" => "ecto",
"owner" => "tallysmartins",
"slug" => "tallysmartins/ecto"
}
]
}
}

{:ok, resp} = context.conn
|> post("/api", AbsintheHelpers.query_skeleton(query))
|> Map.get(:resp_body)
|> Antidote.decode

assert ^json_data = resp
end
end

describe "repo query" do
test "fetch repo by slug", context do
{:ok, _} = Repos.create_repo(@repo)

query = """
repo (slug: "tallysmartins/ecto") {
name
owner
slug
}
"""

json_data =
%{
"data" => %{
"repo" => %{
"name" => "ecto",
"owner" => "tallysmartins",
"slug" => "tallysmartins/ecto"
}
}
}

{:ok, resp} = context.conn
|> post("/api", AbsintheHelpers.query_skeleton(query))
|> Map.get(:resp_body)
|> Antidote.decode

assert ^json_data = resp
end

test "not break when repo not found", context do
query = """
repo (slug: "Idont/exist") {
name
}
"""

{:ok, resp} = context.conn
|> post("/api", AbsintheHelpers.query_skeleton(query))
|> Map.get(:resp_body)
|> Antidote.decode

error_message = Enum.at(resp["errors"], 0)

refute resp["data"]["repo"]
assert %{"message" => "not_found"} = error_message
end
end
end

17 changes: 17 additions & 0 deletions test/test_helper.exs
Expand Up @@ -2,3 +2,20 @@ ExUnit.start()

Ecto.Adapters.SQL.Sandbox.mode(ElixirBench.Repo, :manual)

defmodule ElixirBenchWeb.AbsintheHelpers do
def query_skeleton(query) do
%{
"query" => "query { #{query} }",
"variables" => "{}"
}
end

def mutation_skeleton(query) do
%{
"operationName" => "",
"query" => "#{query}",
"variables" => ""
}
end
end

0 comments on commit 001df18

Please sign in to comment.