BigW Consortium Gitlab

doorkeeper_access_spec.rb 901 Bytes
Newer Older
Valery Sizov committed
1 2 3 4 5 6
require 'spec_helper'

describe API::API, api: true  do
  include ApiHelpers

  let!(:user) { create(:user) }
7 8 9
  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 }

Valery Sizov committed
10 11
  describe "when unauthenticated" do
    it "returns authentication success" do
12
      get api("/user"), access_token: token.token
13
      expect(response).to have_http_status(200)
Valery Sizov committed
14 15 16 17 18
    end
  end

  describe "when token invalid" do
    it "returns authentication error" do
19
      get api("/user"), access_token: "123a"
20
      expect(response).to have_http_status(401)
Valery Sizov committed
21 22 23 24 25 26
    end
  end

  describe "authorization by private token" do
    it "returns authentication success" do
      get api("/user", user)
27
      expect(response).to have_http_status(200)
Valery Sizov committed
28 29 30
    end
  end
end