Sha256: 14f28cb73285501c5ed44d30ce72e2dda7bcd48f447b807512c8f1d273cc73ea

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe 'CoreSpring::APIClient' do

  let(:client_id) { SecureRandom.hex(13) }
  let(:client_secret) { SecureRandom.hex(13) }
  let(:client) { CoreSpring::APIClient.new(client_id, client_secret) }

  describe 'get_token' do

    describe 'with valid client_id and client_secret' do
      let(:token) { SecureRandom.hex(13) }
      subject { client.get_token }

      before {
        stub_request(:post, "https://platform.corespring.org/auth/access_token")
          .with(:body => "client_id=#{client_id}&client_secret=#{client_secret}")
          .to_return(:status => 200, body: ({ access_token: token }.to_json))
      }

      it { should == token }

    end

    describe 'with invalid client_id and client_secret' do
      subject { client.get_token }
      before {
        stub_request(:post, "https://staging.corespring.org/auth/access_token")
          .with(:body => "client_id=#{client_id}&client_secret=#{client_secret}")
          .to_return(:status => 403, body: ({"code" => 100, "message" => "Invalid credentials", "moreInfo" => ""}.to_json))
      }

      it 'raises an error' do
        expect { subject }.to raise_error
      end

    end

  end

  describe 'encrypt' do
    let(:options) { {} }
    subject { client.encrypt(options) }

    it { should be_a(String) }

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
corespring-0.0.1 spec/corespring/api_client_spec.rb