massenversand_spec.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Channel::Driver::Sms::Massenversand do
  4. let(:gateway) { 'https://gate1.goyyamobile.com/sms/sendsms.asp' }
  5. let(:message_body) { 'Test' }
  6. let(:receiver_number) { '+37060010000' }
  7. let(:sender_number) { '+491000000000' }
  8. let(:token) { '00q1234123423r5rwefdfsfsfef' }
  9. let(:url) { "#{gateway}?#{params}" }
  10. let(:params) do
  11. URI.encode_www_form(
  12. authToken: token,
  13. getID: 1,
  14. msg: message_body,
  15. msgtype: 'c',
  16. receiver: receiver_number,
  17. sender: sender_number
  18. )
  19. end
  20. let(:channel) do
  21. create(:channel,
  22. options: {
  23. adapter: 'sms/massenversand',
  24. gateway: gateway,
  25. sender: sender_number,
  26. token: token
  27. },
  28. created_by_id: 1,
  29. updated_by_id: 1)
  30. end
  31. let(:instance) { described_class.new }
  32. context 'when gateway returns OK' do
  33. before do
  34. stub_request(:get, url).to_return(body: 'OK')
  35. end
  36. it 'passes' do
  37. expect(instance.deliver(channel.options, { recipient: receiver_number, message: message_body })).to be true
  38. end
  39. end
  40. context 'when gateway response is invalid' do
  41. before do
  42. stub_request(:get, url).to_return(body: body)
  43. end
  44. context 'when receiver is blocked' do
  45. let(:body) { 'blocked receiver ()' }
  46. it 'raises RuntimeError', :aggregate_failures do
  47. expect { instance.deliver(channel.options, { recipient: receiver_number, message: message_body }) }.to raise_error { |error|
  48. expect(error.message).not_to include(body)
  49. }
  50. end
  51. end
  52. end
  53. end