31 lines
920 B
Ruby
31 lines
920 B
Ruby
require "test_helper"
|
|
|
|
class ApiTest < ActionDispatch::IntegrationTest
|
|
setup do
|
|
@davids_bearer_token = bearer_token_env(identity_access_tokens(:davids_api_token).token)
|
|
end
|
|
|
|
test "authenticate with valid access token" do
|
|
get boards_path(format: :json), env: @davids_bearer_token
|
|
assert_response :success
|
|
end
|
|
|
|
test "fail to authenticate with invalid access token" do
|
|
get boards_path(format: :json), env: bearer_token_env("nonsense")
|
|
assert_response :unauthorized
|
|
end
|
|
|
|
test "boards" do
|
|
get boards_path(format: :json), env: @davids_bearer_token
|
|
assert_equal users(:david).boards.count, @response.parsed_body.count
|
|
|
|
get board_path(boards(:writebook), format: :json), env: @jasons_bearer_token
|
|
assert_equal boards(:writebook).name, @response.parsed_body["name"]
|
|
end
|
|
|
|
private
|
|
def bearer_token_env(token)
|
|
{ "HTTP_AUTHORIZATION" => "Bearer #{token}" }
|
|
end
|
|
end
|