Sha256: 0018f3d18bfc01ddf66eb631c5306b35430ed81d09faa47ca4802a7e25a68695

Contents?: true

Size: 1.63 KB

Versions: 12

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Zoom::Actions::Token do
  let(:zc) { oauth_client }
  let(:args) { { grant_type: 'authorization_code', auth_code: 'xxx', redirect_uri: 'http://localhost:3000', code_verifier: 'xxx' } }
  let(:body) { { grant_type: 'authorization_code', redirect_uri: 'http://localhost:3000', code_verifier: 'xxx', code: 'xxx'  } }

  describe '#access_tokens action' do
    let(:path) { '/oauth/token' }

    let(:params) do
      {
        base_uri: 'https://zoom.us/',
        body: URI.encode_www_form(body.to_a),
        headers: {
          'Accept'=>'application/json',
          'Authorization'=>'Basic eHh4Onh4eA==',
          'Content-Type'=>'application/x-www-form-urlencoded'
        }
      }
    end

    before :each do
      Zoom.configure do |config|
        config.api_key = 'xxx'
        config.api_secret = 'xxx'
      end

      allow(Zoom::Utils).to receive(:parse_response).and_return(code: 200)
      allow(Zoom::Client::OAuth).to(
        receive(:post).with(path, params)
          .and_return(body: json_response('token', 'access_token'),
                        headers: { 'Content-Type' => 'application/json' })
      )
    end

    it "raises an error when args missing" do
      expect { zc.access_tokens }.to raise_error(Zoom::ParameterMissing, [:grant_type, :code, :redirect_uri].to_s)
    end

    it 'returns a hash' do
      expect(zc.access_tokens(args)).to be_kind_of(Hash)
    end

    it 'passes args in the body and sends x-www-form-urlencoded header' do
      zc.access_tokens(args)
      expect(Zoom::Client::OAuth).to have_received(:post).with(path, params)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
zoom_rb-1.1.11 spec/lib/zoom/actions/token/access_token_spec.rb
zoom_rb-1.1.10 spec/lib/zoom/actions/token/access_token_spec.rb
zoom_rb-1.1.9 spec/lib/zoom/actions/token/access_token_spec.rb
zoom_rb-1.1.8 spec/lib/zoom/actions/token/access_token_spec.rb
zoom_rb-1.1.7 spec/lib/zoom/actions/token/access_token_spec.rb
zoom_rb-1.1.6 spec/lib/zoom/actions/token/access_token_spec.rb
zoom_rb-1.1.5 spec/lib/zoom/actions/token/access_token_spec.rb
zoom_rb-1.1.4 spec/lib/zoom/actions/token/access_token_spec.rb
zoom_rb-1.1.3 spec/lib/zoom/actions/token/access_token_spec.rb
zoom_rb-1.1.2 spec/lib/zoom/actions/token/access_token_spec.rb
zoom_rb-1.1.1 spec/lib/zoom/actions/token/access_token_spec.rb
zoom_rb-1.1.0 spec/lib/zoom/actions/token/access_token_spec.rb