requester_spec.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. require 'rails_helper'
  2. RSpec.describe Import::OTRS::Requester do
  3. context '.list' do
  4. it 'responds to list' do
  5. expect(described_class).to respond_to(:list)
  6. end
  7. end
  8. context '.load' do
  9. it 'responds to load' do
  10. expect(described_class).to respond_to(:load)
  11. end
  12. context 'caching request results' do
  13. let(:response) do
  14. response = double()
  15. response_body = double()
  16. expect(response_body).to receive(:to_s).at_least(:once).and_return('{"Result": {}}')
  17. expect(response).to receive('success?').at_least(:once).and_return(true)
  18. expect(response).to receive('body').at_least(:once).and_return(response_body)
  19. response
  20. end
  21. it 'is active if no args are given' do
  22. expect(UserAgent).to receive(:post).and_return(response)
  23. described_class.load('Ticket')
  24. described_class.load('Ticket')
  25. end
  26. it 'is not active if args are given' do
  27. expect(UserAgent).to receive(:post).twice.and_return(response)
  28. described_class.load('Ticket', offset: 10)
  29. described_class.load('Ticket', offset: 20)
  30. end
  31. end
  32. end
  33. context '.connection_test' do
  34. it 'responds to connection_test' do
  35. expect(described_class).to respond_to(:connection_test)
  36. end
  37. end
  38. it 'retries request 3 times on errors' do
  39. expect(UserAgent).to receive(:post).and_raise(Errno::ECONNRESET).exactly(3).times
  40. # disable sleep time to speed up tests
  41. described_class.retry_sleep = 0
  42. expect { described_class.list }.to raise_error(Errno::ECONNRESET)
  43. end
  44. end