base_spec.rb 3.9 KB

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