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
|
if Setting.get('developer_mode') != true
|
||||||
response = Faraday.get(url).body
|
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
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.debug "Massenversand error: #{e.inspect}"
|
message = "Error while performing request to gateway URL '#{url}'"
|
||||||
raise e
|
Rails.logger.error message
|
||||||
|
Rails.logger.error e
|
||||||
|
raise message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,72 +1,60 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Channel::Driver::Sms::Massenversand do
|
RSpec.describe Channel::Driver::Sms::Massenversand do
|
||||||
it 'passes' do
|
let(:gateway) { 'https://gate1.goyyamobile.com/sms/sendsms.asp' }
|
||||||
channel = create_channel
|
let(:message_body) { 'Test' }
|
||||||
|
let(:receiver_number) { '+37060010000' }
|
||||||
stub_request(:get, url_to_mock)
|
let(:sender_number) { '+491000000000' }
|
||||||
.to_return(body: 'OK')
|
let(:token) { '00q1234123423r5rwefdfsfsfef' }
|
||||||
|
let(:url) { "#{gateway}?#{params}" }
|
||||||
api = channel.driver_instance.new
|
let(:params) do
|
||||||
expect(api.send(channel.options, { recipient: receiver_number, message: message_body })).to be true
|
URI.encode_www_form(
|
||||||
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,
|
|
||||||
options: {
|
|
||||||
adapter: 'sms/massenversand',
|
|
||||||
gateway: gateway,
|
|
||||||
sender: sender_number,
|
|
||||||
token: token
|
|
||||||
},
|
|
||||||
created_by_id: 1,
|
|
||||||
updated_by_id: 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
def url_to_mock
|
|
||||||
params = {
|
|
||||||
authToken: token,
|
authToken: token,
|
||||||
getID: 1,
|
getID: 1,
|
||||||
msg: message_body,
|
msg: message_body,
|
||||||
msgtype: 'c',
|
msgtype: 'c',
|
||||||
receiver: receiver_number,
|
receiver: receiver_number,
|
||||||
sender: sender_number
|
sender: sender_number
|
||||||
}
|
)
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
let(:instance) { described_class.new }
|
||||||
|
|
||||||
gateway + '?' + URI.encode_www_form(params)
|
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
|
end
|
||||||
|
|
||||||
# api parameters
|
context 'when gateway response is invalid' do
|
||||||
|
|
||||||
def gateway
|
before do
|
||||||
'https://gate1.goyyamobile.com/sms/sendsms.asp'
|
stub_request(:get, url).to_return(body: body)
|
||||||
end
|
end
|
||||||
|
|
||||||
def message_body
|
context 'when receiver is blocked' do
|
||||||
'Test'
|
let(:body) { 'blocked receiver ()' }
|
||||||
end
|
|
||||||
|
|
||||||
def receiver_number
|
it 'raises RuntimeError' do # rubocop:disable RSpec/MultipleExpectations
|
||||||
'+37060010000'
|
expect { instance.send(channel.options, { recipient: receiver_number, message: message_body }) }.to raise_error { |error|
|
||||||
end
|
expect(error.message).not_to include(body)
|
||||||
|
}
|
||||||
def sender_number
|
end
|
||||||
'+491000000000'
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def token
|
|
||||||
'00q1234123423r5rwefdfsfsfef'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue