You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Request do
  4. subject { Request.new(:get, 'http://example.com') }
  5. describe '#headers' do
  6. it 'returns user agent' do
  7. expect(subject.headers['User-Agent']).to be_present
  8. end
  9. it 'returns the date header' do
  10. expect(subject.headers['Date']).to be_present
  11. end
  12. it 'returns the host header' do
  13. expect(subject.headers['Host']).to be_present
  14. end
  15. it 'does not return virtual request-target header' do
  16. expect(subject.headers['(request-target)']).to be_nil
  17. end
  18. end
  19. describe '#on_behalf_of' do
  20. it 'when used, adds signature header' do
  21. subject.on_behalf_of(Fabricate(:account))
  22. expect(subject.headers['Signature']).to be_present
  23. end
  24. end
  25. describe '#add_headers' do
  26. it 'adds headers to the request' do
  27. subject.add_headers('Test' => 'Foo')
  28. expect(subject.headers['Test']).to eq 'Foo'
  29. end
  30. end
  31. describe '#perform' do
  32. before do
  33. stub_request(:get, 'http://example.com')
  34. subject.perform
  35. end
  36. it 'executes a HTTP request' do
  37. expect(a_request(:get, 'http://example.com')).to have_been_made.once
  38. end
  39. it 'sets headers' do
  40. expect(a_request(:get, 'http://example.com').with(headers: subject.headers)).to have_been_made
  41. end
  42. end
  43. end