Sha256: 6108a2126d282af66ecdb5a0b07ced0092be2138e6f1a3181dc261f0a96ef0d3

Contents?: true

Size: 815 Bytes

Versions: 1

Compression:

Stored size: 815 Bytes

Contents

require 'habitica_cli/api'

RSpec.describe HabiticaCli::Api do
  def response_headers
    { 'content-type' => 'application/json' }
  end

  it 'attaches user name and token to request' do
    stub_request(:get, /.*habitica.com.*/)
    api = HabiticaCli::Api.new('test_user', 'test_key')

    api.get('test')

    expect(WebMock).to have_requested(:get, 'https://habitica.com/api/v2/test')
      .with(headers: { :'X-Api-Key' => 'test_key', :'X-Api-User' => 'test_user' }) # rubocop:disable Metrics/LineLength
  end

  it 'returns json' do
    stub_request(:get, /.*habitica.com.*/).to_return(
      body: JSON.dump(key: 'value'),
      headers: response_headers
    )
    api = HabiticaCli::Api.new('test_user', 'test_key')

    response = api.get('test')
    expect(response.body['key']).to eql('value')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
habitica_cli-0.0.1 spec/api_spec.rb