cti_spec.rb 1.8 KB

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