Skip to content

Commit

Permalink
use dig instead of multiple []
Browse files Browse the repository at this point in the history
  • Loading branch information
acoffman committed Dec 23, 2024
1 parent b35501c commit 6dac099
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions server/test/controllers/token_authorization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,29 @@ def setup

test "getting the viewer without a bearer token" do
post "/api/graphql", params: { query: @query_string }
assert_nil JSON.parse(@response.body)["data"]["viewer"]
assert_nil JSON.parse(@response.body).dig("data", "viewer")
end

test "getting the viewer with a bearer token" do
post "/api/graphql", params: { query: @query_string }, headers: { "Authorization" => "Bearer #{@api_key.token}" }
response_data = JSON.parse(@response.body)["data"]["viewer"]
response_data = JSON.parse(@response.body).dig("data", "viewer")
assert_equal response_data["id"], @user1.id
assert_equal response_data["username"], @user1.username
end

test "getting the viewer with a revoked bearer token" do
post "/api/graphql", params: { query: @query_string }, headers: { "Authorization" => "Bearer #{@revoked_api_key.token}" }
assert_nil JSON.parse(@response.body)["data"]["viewer"]
assert_nil JSON.parse(@response.body).dig("data", "viewer")
end

test "adding a comment without a bearer token" do
post "/api/graphql", params: { query: @mutation_string }
assert_match (/You must log in to perform this mutation/), JSON.parse(@response.body)["errors"].first["message"]
assert_match (/You must log in to perform this mutation/), JSON.parse(@response.body).dig("errors", 0, "message")
end

test "adding a comment with a valid bearer token" do
post "/api/graphql", params: { query: @mutation_string }, headers: { "Authorization" => "Bearer #{@api_key.token}" }
response_data = JSON.parse(@response.body)["data"]["addComment"]["comment"]
response_data = JSON.parse(@response.body).dig("data", "addComment", "comment")
assert_not_nil response_data
assert_equal response_data["comment"], "This is a test comment"
end
Expand Down

0 comments on commit 6dac099

Please sign in to comment.