require 'spec_helper'
require 'pry'

RSpec.describe QAHelpers::GrassTokenHelper do
  let(:token_helper) { QAHelpers::GrassTokenHelper.new }

  describe '#vectorapi_access_token' do
    it 'returns token information for a label contact' do
      vectorapi_data = token_helper.vectorapi_access_token(7412)
      expect(vectorapi_data['client_id']).to eq('5656789871')
      expect(vectorapi_data['user_type']).to eq('alw')
      expect(vectorapi_data['oauth_token'].length).to be > 30
    end
  end

  describe '#vend_contact_id' do
    it 'gives information for simple label' do
      expect(token_helper.vend_contact_id(7482)).to eq(7412)
    end

    it 'gives information for D3' do
      expect(token_helper.vend_contact_id(18805)).to eq(26122)
    end

    it 'gives information for Sub' do
      expect(token_helper.vend_contact_id(13823)).to eq(24240)
    end
  end

  describe '#user_grass' do
    it 'should work by vendor_id' do
      token = token_helper.user_grass(vendor_id: 10303)
      puts token
      expect(token).not_to be_empty
      expect(token.length).to be > 30
    end


    it 'should work by vend_contact_id' do
      token = token_helper.user_grass(vend_contact_id: 7412)
      puts token
      expect(token).not_to be_empty
      expect(token.length).to be > 30
    end

    it 'should raise an error if neither vendor_id nor vend_contact_id were specified' do
      expect { token_helper.user_grass(id: 7412) }.to raise_error (
        'Provide :vend_contact_id or :vendor_id to get the grass token'
                                                                  )
    end
  end
end
