2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2018-10-16 08:45:15 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Channel::Driver::Sms::Massenversand do
|
2020-08-26 11:46:08 +00:00
|
|
|
let(:gateway) { 'https://gate1.goyyamobile.com/sms/sendsms.asp' }
|
|
|
|
let(:message_body) { 'Test' }
|
|
|
|
let(:receiver_number) { '+37060010000' }
|
|
|
|
let(:sender_number) { '+491000000000' }
|
|
|
|
let(:token) { '00q1234123423r5rwefdfsfsfef' }
|
|
|
|
let(:url) { "#{gateway}?#{params}" }
|
|
|
|
let(:params) do
|
|
|
|
URI.encode_www_form(
|
2018-10-16 08:45:15 +00:00
|
|
|
authToken: token,
|
2018-12-19 17:31:51 +00:00
|
|
|
getID: 1,
|
|
|
|
msg: message_body,
|
|
|
|
msgtype: 'c',
|
|
|
|
receiver: receiver_number,
|
|
|
|
sender: sender_number
|
2020-08-26 11:46:08 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
let(:channel) do
|
|
|
|
create(:channel,
|
|
|
|
options: {
|
|
|
|
adapter: 'sms/massenversand',
|
|
|
|
gateway: gateway,
|
|
|
|
sender: sender_number,
|
|
|
|
token: token
|
|
|
|
},
|
|
|
|
created_by_id: 1,
|
|
|
|
updated_by_id: 1)
|
2018-10-16 08:45:15 +00:00
|
|
|
end
|
2020-08-26 11:46:08 +00:00
|
|
|
let(:instance) { described_class.new }
|
2018-10-16 08:45:15 +00:00
|
|
|
|
2020-08-26 11:46:08 +00:00
|
|
|
context 'when gateway returns OK' do
|
2018-10-16 08:45:15 +00:00
|
|
|
|
2020-08-26 11:46:08 +00:00
|
|
|
before do
|
|
|
|
stub_request(:get, url).to_return(body: 'OK')
|
|
|
|
end
|
2018-10-16 08:45:15 +00:00
|
|
|
|
2020-08-26 11:46:08 +00:00
|
|
|
it 'passes' do
|
|
|
|
expect(instance.send(channel.options, { recipient: receiver_number, message: message_body })).to be true
|
|
|
|
end
|
2018-10-16 08:45:15 +00:00
|
|
|
end
|
|
|
|
|
2020-08-26 11:46:08 +00:00
|
|
|
context 'when gateway response is invalid' do
|
2018-10-16 08:45:15 +00:00
|
|
|
|
2020-08-26 11:46:08 +00:00
|
|
|
before do
|
|
|
|
stub_request(:get, url).to_return(body: body)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when receiver is blocked' do
|
|
|
|
let(:body) { 'blocked receiver ()' }
|
2018-10-16 08:45:15 +00:00
|
|
|
|
2020-08-26 11:46:08 +00:00
|
|
|
it 'raises RuntimeError' do # rubocop:disable RSpec/MultipleExpectations
|
|
|
|
expect { instance.send(channel.options, { recipient: receiver_number, message: message_body }) }.to raise_error { |error|
|
|
|
|
expect(error.message).not_to include(body)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2018-10-16 08:45:15 +00:00
|
|
|
end
|
|
|
|
end
|