Skip to content

Commit

Permalink
Add activity genserver test
Browse files Browse the repository at this point in the history
  • Loading branch information
abshierjoel committed Oct 6, 2021
1 parent 7cbe38e commit 410d094
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
17 changes: 17 additions & 0 deletions test/gql_preferences/activity_server_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule UserPreferences.ActivityServer.Test do
use ExUnit.Case
alias ActivityServer

describe "ActivityServer" do
test "returns count for existing resolver" do
key = "get_all_users"
assert {:ok, 0} = GenServer.whereis(ActivityServer) |> GenServer.call({:get, key})
end

test "returns error for non-existing resolver" do
key = "burn_all_ships"
{:error, msg} = GenServer.whereis(ActivityServer) |> GenServer.call({:get, key})
assert msg == "Requested key: #{key} is invalid"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ defmodule UserPreferences.ActivityMonitorTest do
key = "not_a_key"

assert {:ok, %{data: %{"resolverHits" => count}, errors: errors}} =
Absinthe.run(@get_resolver_hits, Schema, variables: %{"key" => "not_a_key"})
Absinthe.run(@get_resolver_hits, Schema, variables: %{"key" => key})

assert is_nil(count) === true
assert List.first(errors).message === "Requested key: not_a_key is invalid"
assert List.first(errors).message === "Requested key: #{key} is invalid"
end
end
end
31 changes: 31 additions & 0 deletions test/gql_preferences_web/create_user_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
defmodule UserPreferences.ActivityMonitorTest do
use ExUnit.Case, async: true
alias UserPreferencesWeb.Schema

@get_resolver_hits """
query getResolverHits($key: String){
resolverHits(key: $key)
}
"""

describe "@resolverHits" do
test "returns the count for a resolver" do
key = "get_all_users"

assert {:ok, %{data: %{"resolverHits" => count}}} =
Absinthe.run(@get_resolver_hits, Schema, variables: %{"key" => key})

assert count === 0
end

test "returns" do
key = "not_a_key"

assert {:ok, %{data: %{"resolverHits" => count}, errors: errors}} =
Absinthe.run(@get_resolver_hits, Schema, variables: %{"key" => key})

assert is_nil(count) === true
assert List.first(errors).message === "Requested key: #{key} is invalid"
end
end
end

0 comments on commit 410d094

Please sign in to comment.