-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joel Abshier
committed
Oct 6, 2021
1 parent
410d094
commit 6cb2b65
Showing
6 changed files
with
102 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,39 @@ | ||
defmodule UserPreferences.ActivityMonitorTest do | ||
defmodule UserPreferencesTest.CreateUserTest 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" | ||
@create_user """ | ||
mutation createUser( | ||
$name: String, | ||
$email: String, | ||
$likesEmails: Boolean, | ||
$likesPhoneCalls: Boolean | ||
) { | ||
createUser( | ||
name: $name, | ||
email: $email, | ||
preferences: { | ||
likesEmails: $likesEmails, | ||
likesPhoneCalls: $likesPhoneCalls | ||
} | ||
) { | ||
id | ||
name | ||
preferences { | ||
likesEmails | ||
likesPhoneCalls | ||
} | ||
} | ||
} | ||
""" | ||
|
||
assert {:ok, %{data: %{"resolverHits" => count}, errors: errors}} = | ||
Absinthe.run(@get_resolver_hits, Schema, variables: %{"key" => key}) | ||
setup do | ||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(UserPreferences.Repo) | ||
end | ||
|
||
assert is_nil(count) === true | ||
assert List.first(errors).message === "Requested key: #{key} is invalid" | ||
end | ||
describe "@createUser" do | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
defmodule UserPreferencesTest.FindUserTest do | ||
use ExUnit.Case, async: true | ||
alias UserPreferences.{Repo, User, Preferences} | ||
alias UserPreferencesWeb.{Schema} | ||
import ExMock | ||
|
||
@user """ | ||
query findById($id: ID){ | ||
user(id: $id){ | ||
name | ||
id | ||
preferences{ | ||
likesEmails | ||
likesPhoneCalls | ||
} | ||
} | ||
} | ||
""" | ||
|
||
setup do | ||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Repo) | ||
end | ||
|
||
describe "@findById" do | ||
test "returns a user" do | ||
pref_mock = %{ | ||
likes_emails: true, | ||
likes_phone_calls: false | ||
} | ||
|
||
user_mock = %{ | ||
id: "55", | ||
name: "TestGuy", | ||
email: "[email protected]" | ||
} | ||
|
||
with_mock Repo, | ||
get: fn User, _ -> user_mock end, | ||
get_by: fn Preferences, _ -> pref_mock end do | ||
assert {:ok, res} = Absinthe.run(@user, Schema, variables: %{"id" => 55}) | ||
|
||
assert Map.equal?(res, %{ | ||
data: %{ | ||
"user" => %{ | ||
"id" => "55", | ||
"name" => "TestGuy", | ||
"email" => "[email protected]", | ||
"preferences" => %{ | ||
"likesEmails" => true, | ||
"likesPhoneCalls" => false | ||
} | ||
} | ||
} | ||
}) | ||
end | ||
end | ||
|
||
test "returns nil if no user is found" do | ||
user_id = 1_234_456_789 | ||
|
||
assert {:ok, %{data: %{"user" => nil}}} = | ||
Absinthe.run(@user, Schema, variables: %{"id" => user_id}) | ||
end | ||
end | ||
end |