Maintenance: Improve logging of failures when sending SMS via Massenversand.de.
This commit is contained in:
parent
9dd2b59037
commit
4696a85cd4
2 changed files with 53 additions and 58 deletions
|
@ -12,13 +12,20 @@ class Channel::Driver::Sms::Massenversand
|
|||
|
||||
if Setting.get('developer_mode') != true
|
||||
response = Faraday.get(url).body
|
||||
raise response if !response.match?('OK')
|
||||
|
||||
if !response.match?('OK')
|
||||
message = "Received non-OK response from gateway URL '#{url}'"
|
||||
Rails.logger.error "#{message}: #{response.inspect}"
|
||||
raise message
|
||||
end
|
||||
end
|
||||
|
||||
true
|
||||
rescue => e
|
||||
Rails.logger.debug "Massenversand error: #{e.inspect}"
|
||||
raise e
|
||||
message = "Error while performing request to gateway URL '#{url}'"
|
||||
Rails.logger.error message
|
||||
Rails.logger.error e
|
||||
raise message
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,30 +1,24 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Channel::Driver::Sms::Massenversand do
|
||||
it 'passes' do
|
||||
channel = create_channel
|
||||
|
||||
stub_request(:get, url_to_mock)
|
||||
.to_return(body: 'OK')
|
||||
|
||||
api = channel.driver_instance.new
|
||||
expect(api.send(channel.options, { recipient: receiver_number, message: message_body })).to be true
|
||||
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(
|
||||
authToken: token,
|
||||
getID: 1,
|
||||
msg: message_body,
|
||||
msgtype: 'c',
|
||||
receiver: receiver_number,
|
||||
sender: sender_number
|
||||
)
|
||||
end
|
||||
|
||||
it 'fails' do
|
||||
channel = create_channel
|
||||
|
||||
stub_request(:get, url_to_mock)
|
||||
.to_return(body: 'blocked receiver ()')
|
||||
|
||||
api = channel.driver_instance.new
|
||||
expect { api.send(channel.options, { recipient: receiver_number, message: message_body }) }.to raise_exception(RuntimeError)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_channel
|
||||
FactoryBot.create(:channel,
|
||||
let(:channel) do
|
||||
create(:channel,
|
||||
options: {
|
||||
adapter: 'sms/massenversand',
|
||||
gateway: gateway,
|
||||
|
@ -34,39 +28,33 @@ RSpec.describe Channel::Driver::Sms::Massenversand do
|
|||
created_by_id: 1,
|
||||
updated_by_id: 1)
|
||||
end
|
||||
let(:instance) { described_class.new }
|
||||
|
||||
def url_to_mock
|
||||
params = {
|
||||
authToken: token,
|
||||
getID: 1,
|
||||
msg: message_body,
|
||||
msgtype: 'c',
|
||||
receiver: receiver_number,
|
||||
sender: sender_number
|
||||
context 'when gateway returns OK' do
|
||||
|
||||
before do
|
||||
stub_request(:get, url).to_return(body: 'OK')
|
||||
end
|
||||
|
||||
it 'passes' do
|
||||
expect(instance.send(channel.options, { recipient: receiver_number, message: message_body })).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when gateway response is invalid' do
|
||||
|
||||
before do
|
||||
stub_request(:get, url).to_return(body: body)
|
||||
end
|
||||
|
||||
context 'when receiver is blocked' do
|
||||
let(:body) { 'blocked receiver ()' }
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
gateway + '?' + URI.encode_www_form(params)
|
||||
end
|
||||
|
||||
# api parameters
|
||||
|
||||
def gateway
|
||||
'https://gate1.goyyamobile.com/sms/sendsms.asp'
|
||||
end
|
||||
|
||||
def message_body
|
||||
'Test'
|
||||
end
|
||||
|
||||
def receiver_number
|
||||
'+37060010000'
|
||||
end
|
||||
|
||||
def sender_number
|
||||
'+491000000000'
|
||||
end
|
||||
|
||||
def token
|
||||
'00q1234123423r5rwefdfsfsfef'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue