2014-12-19 09:15:29 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe API::API, api: true do
|
|
|
|
include ApiHelpers
|
|
|
|
|
|
|
|
let!(:user) { create(:user) }
|
2015-06-22 09:05:19 -04:00
|
|
|
let!(:application) { Doorkeeper::Application.create!(name: "MyApp", redirect_uri: "https://app.com", owner: user) }
|
|
|
|
let!(:token) { Doorkeeper::AccessToken.create! application_id: application.id, resource_owner_id: user.id }
|
|
|
|
|
2014-12-19 09:15:29 -05:00
|
|
|
describe "when unauthenticated" do
|
|
|
|
it "returns authentication success" do
|
2015-06-22 09:05:19 -04:00
|
|
|
get api("/user"), access_token: token.token
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2014-12-19 09:15:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when token invalid" do
|
|
|
|
it "returns authentication error" do
|
2015-06-22 09:05:19 -04:00
|
|
|
get api("/user"), access_token: "123a"
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(401)
|
2014-12-19 09:15:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "authorization by private token" do
|
|
|
|
it "returns authentication success" do
|
|
|
|
get api("/user", user)
|
2016-06-27 14:10:42 -04:00
|
|
|
expect(response).to have_http_status(200)
|
2014-12-19 09:15:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|