Sha256: 703dcd40afaa8d63ba12b2f52d8fb45cd76d453f5cb1f895a7eec2ee851376f5

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require "spec_helper"

describe Doorkeeper::OAuth::CodeRequest do
  let(:pre_auth) do
    server = Doorkeeper.configuration
    allow(server)
      .to receive(:default_scopes).and_return(Doorkeeper::OAuth::Scopes.from_string("public"))
    allow(server)
      .to receive(:grant_flows).and_return(Doorkeeper::OAuth::Scopes.from_string("authorization_code"))

    application = FactoryBot.create(:application, scopes: "public")
    client = Doorkeeper::OAuth::Client.new(application)

    attributes = {
      client_id: client.uid,
      response_type: "code",
      redirect_uri: "https://app.com/callback",
    }

    pre_auth = Doorkeeper::OAuth::PreAuthorization.new(server, attributes)
    pre_auth.authorizable?
    pre_auth
  end

  let(:owner) { double :owner, id: 8900 }

  subject do
    described_class.new(pre_auth, owner)
  end

  context "when pre_auth is authorized" do
    it "creates an access grant and returns a code response" do
      expect { subject.authorize }.to change { Doorkeeper::AccessGrant.count }.by(1)
      expect(subject.authorize).to be_a(Doorkeeper::OAuth::CodeResponse)
    end
  end

  context "when pre_auth is denied" do
    it "does not create access grant and returns a error response" do
      expect { subject.deny }.not_to(change { Doorkeeper::AccessGrant.count })
      expect(subject.deny).to be_a(Doorkeeper::OAuth::ErrorResponse)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
doorkeeper-5.3.3 spec/lib/oauth/code_request_spec.rb
doorkeeper-5.3.2 spec/lib/oauth/code_request_spec.rb
doorkeeper-5.3.1 spec/lib/oauth/code_request_spec.rb
doorkeeper-5.3.0 spec/lib/oauth/code_request_spec.rb