Sha256: b3b6ec168a4673745a43481489bb37a646c13232ee6740d8dea6a617925bfdd5

Contents?: true

Size: 1.54 KB

Versions: 3

Compression:

Stored size: 1.54 KB

Contents

require 'contextio/connect_token'

describe ContextIO::ConnectToken do
  let(:api) { double('API') }

  describe ".new" do
    subject { ContextIO::ConnectToken.new(api, token: '1234', foo: 'bar') }

    it "takes an api handle" do
      expect(subject.api).to eq(api)
    end

    it "assigns instance variables for hash arguments" do
      expect(subject.instance_variable_get('@token')).to eq('1234')
      expect(subject.instance_variable_get('@foo')).to eq('bar')
    end

    context "with a token passed in" do
      it "doesn't raise an error" do
        expect { ContextIO::ConnectToken.new(api, token: '1234') }.to_not raise_error
      end
    end

    context "with neither a provider_token nor a resource_url passed in" do
      it "raises an ArgumentError" do
        expect { ContextIO::ConnectToken.new(api, foo: 'bar') }.to raise_error(ArgumentError)
      end
    end
  end

  describe "#token" do
    context "when input at creation" do
      subject { ContextIO::ConnectToken.new(api, token: '1234') }

      it "uses the input key" do
        expect(api).to_not receive(:request)

        expect(subject.token).to eq('1234')
      end
    end

    context "when not input at creation" do
      subject { ContextIO::ConnectToken.new(api, resource_url: 'http://example.com/hitme') }

      it "loads it from the API" do
        expect(api).to receive(:request).with(
          :get,
          'http://example.com/hitme'
        ).and_return({
          'token' => 'baphoo'
        })

        expect(subject.token).to eq('baphoo')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
contextio-2.0.0 spec/unit/contextio/connect_token_spec.rb
contextio-1.8.1 spec/unit/contextio/connect_token_spec.rb
contextio-1.8.0 spec/unit/contextio/connect_token_spec.rb