cti_spec.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. require 'rails_helper'
  2. RSpec.describe 'Caller log', type: %i[system request], authenticated_as: true do # rubocop:disable RSpec/DescribeClass
  3. let(:admin) do
  4. create(:admin, groups: Group.all)
  5. end
  6. let!(:customer) { create(:customer, phone: '0190333') }
  7. let(:params) do
  8. {
  9. direction: 'in',
  10. from: '0190333',
  11. to: '0190111',
  12. callId: '111',
  13. cause: 'busy'
  14. }
  15. end
  16. def prepare
  17. Setting.set('cti_integration', true)
  18. Setting.set('cti_token', 'token1234')
  19. current_user.update(phone: '0190111')
  20. end
  21. context 'without active tickets' do
  22. it 'checks opening of the ticket creation screen after phone call inbound' do
  23. prepare
  24. travel(-2.months)
  25. create(:ticket, customer: customer)
  26. travel_back
  27. visit 'cti'
  28. post "#{Capybara.app_host}/api/v1/cti/token1234", params: params.merge(event: 'newCall'), as: :json
  29. post "#{Capybara.app_host}/api/v1/cti/token1234", params: params.merge(event: 'answer', answeringNumber: '0190111' ), as: :json
  30. within(:active_content) do
  31. expect(page).to have_text('New Ticket', wait: 5)
  32. end
  33. end
  34. end
  35. context 'with active tickets' do
  36. it 'checks opening of the user profile screen after phone call inbound with tickets in the last month' do
  37. prepare
  38. create(:ticket, customer: customer)
  39. visit 'cti'
  40. post "#{Capybara.app_host}/api/v1/cti/token1234", params: params.merge(event: 'newCall'), as: :json
  41. post "#{Capybara.app_host}/api/v1/cti/token1234", params: params.merge(event: 'answer', answeringNumber: '0190111' ), as: :json
  42. within(:active_content) do
  43. expect(page).to have_text(customer.fullname, wait: 5)
  44. end
  45. end
  46. end
  47. end