requester_spec.rb 1.6 KB

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