2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Import::OTRS::Requester do
|
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
describe '.list' do
|
2017-03-28 14:19:37 +00:00
|
|
|
it 'responds to list' do
|
|
|
|
expect(described_class).to respond_to(:list)
|
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
describe '.load' do
|
2016-11-25 16:10:37 +00:00
|
|
|
|
2017-03-28 14:19:37 +00:00
|
|
|
it 'responds to load' do
|
|
|
|
expect(described_class).to respond_to(:load)
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
2017-03-28 14:19:37 +00:00
|
|
|
context 'caching request results' do
|
|
|
|
|
2017-10-01 12:25:52 +00:00
|
|
|
let(:response) do
|
2021-07-16 13:29:38 +00:00
|
|
|
response = double
|
|
|
|
response_body = double
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(response_body).to receive(:to_s).at_least(:once).and_return('{"Result": {}}')
|
|
|
|
allow(response).to receive('success?').at_least(:once).and_return(true)
|
|
|
|
allow(response).to receive('body').at_least(:once).and_return(response_body)
|
2017-03-28 14:19:37 +00:00
|
|
|
response
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2017-03-28 14:19:37 +00:00
|
|
|
|
|
|
|
it 'is active if no args are given' do
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(UserAgent).to receive(:post).and_return(response)
|
2017-03-28 14:19:37 +00:00
|
|
|
described_class.load('Ticket')
|
|
|
|
described_class.load('Ticket')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not active if args are given' do
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(UserAgent).to receive(:post).twice.and_return(response)
|
2017-03-28 14:19:37 +00:00
|
|
|
described_class.load('Ticket', offset: 10)
|
|
|
|
described_class.load('Ticket', offset: 20)
|
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
end
|
2017-03-28 14:19:37 +00:00
|
|
|
|
2020-02-18 19:51:31 +00:00
|
|
|
describe '.connection_test' do
|
2017-03-28 14:19:37 +00:00
|
|
|
it 'responds to connection_test' do
|
|
|
|
expect(described_class).to respond_to(:connection_test)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'retries request 3 times on errors' do
|
|
|
|
expect(UserAgent).to receive(:post).and_raise(Errno::ECONNRESET).exactly(3).times
|
|
|
|
# disable sleep time to speed up tests
|
|
|
|
described_class.retry_sleep = 0
|
|
|
|
expect { described_class.list }.to raise_error(Errno::ECONNRESET)
|
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|