base_spec.rb 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Cti::Driver::Base do
  4. subject!(:driver) { described_class.new(mapping: {}, params: params, config: config) }
  5. let(:direction) { 'in' }
  6. let(:event) { 'newCall' }
  7. let(:config) { {} }
  8. let(:params) { { 'direction' => direction, 'event' => event } }
  9. describe '.direction_check' do
  10. context 'for in direction' do
  11. subject!(:direction) { 'in' }
  12. it 'returns nil' do
  13. expect(driver.direction_check).to be_nil
  14. end
  15. end
  16. context 'for out direction' do
  17. subject!(:direction) { 'out' }
  18. it 'returns nil' do
  19. expect(driver.direction_check).to be_nil
  20. end
  21. end
  22. context 'for not existing direction' do
  23. subject!(:direction) { 'not existing' }
  24. it 'returns invalid_direction action' do
  25. expect(driver.direction_check).to eq({ action: 'invalid_direction', params: { 'direction' => 'not existing', 'event' => 'newCall' } })
  26. end
  27. end
  28. end
  29. describe '.reject_check' do
  30. context 'with reject number in from param and matching caller_id' do
  31. let(:params) { { 'direction' => direction, 'event' => event, 'from' => '1234' } }
  32. let(:config) do
  33. {
  34. inbound: {
  35. block_caller_ids: [ { caller_id: '1234' } ],
  36. },
  37. }
  38. end
  39. it 'returns reject action' do
  40. expect(driver.reject_check).to eq(action: 'reject')
  41. end
  42. end
  43. context 'with reject number in from param and matching caller_id but wrong direction' do
  44. let(:params) { { 'direction' => direction, 'event' => event, 'from' => '1234' } }
  45. let(:direction) { 'out' }
  46. let(:config) do
  47. {
  48. inbound: {
  49. block_caller_ids: [ { caller_id: '1234' } ],
  50. },
  51. }
  52. end
  53. it 'returns nil' do
  54. expect(driver.reject_check).to be_nil
  55. end
  56. end
  57. context 'with reject number in from param but not matching caller_id' do
  58. let(:params) { { 'direction' => direction, 'event' => event, 'from' => '12345' } }
  59. let(:direction) { 'in' }
  60. let(:config) do
  61. {
  62. inbound: {
  63. block_caller_ids: [ { caller_id: '1234' } ],
  64. },
  65. }
  66. end
  67. it 'returns nil' do
  68. expect(driver.reject_check).to be_nil
  69. end
  70. end
  71. end
  72. describe '.push_open_ticket_screen_recipient' do
  73. context 'with direct number in answeringNumber params' do
  74. let(:params) { { 'direction' => direction, 'event' => event, answeringNumber: user.phone } }
  75. let!(:user) { create(:agent, phone: '1234567') }
  76. it 'returns related user' do
  77. expect(driver.push_open_ticket_screen_recipient).to eq(user)
  78. end
  79. end
  80. context 'with not existing direct number in answeringNumber params' do
  81. let(:params) { { 'direction' => direction, 'event' => event, answeringNumber: '98765421' } }
  82. let!(:user) { create(:agent, phone: '1234567') }
  83. it 'returns nil' do
  84. expect(driver.push_open_ticket_screen_recipient).to be_nil
  85. end
  86. end
  87. context 'with real phone number in answeringNumber params' do
  88. let(:params) { { 'direction' => direction, 'event' => event, answeringNumber: '491711000001' } }
  89. let!(:user) { create(:agent, phone: '0171 1000001') }
  90. it 'returns related user' do
  91. expect(driver.push_open_ticket_screen_recipient).to eq(user)
  92. end
  93. end
  94. context 'with user in upcase in params' do
  95. let(:params) { { 'direction' => direction, 'event' => event, user: user.login.upcase } }
  96. let!(:user) { create(:agent) }
  97. it 'returns related user' do
  98. expect(driver.push_open_ticket_screen_recipient).to eq(user)
  99. end
  100. end
  101. context 'with user_id in params' do
  102. let(:params) { { 'direction' => direction, 'event' => event, user_id: user.id } }
  103. let!(:user) { create(:agent) }
  104. it 'returns related user' do
  105. expect(driver.push_open_ticket_screen_recipient).to eq(user)
  106. end
  107. end
  108. end
  109. end