2018-10-16 08:45:15 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Trigger do
|
|
|
|
|
|
|
|
describe 'sms' do
|
2020-01-27 09:28:17 +00:00
|
|
|
before do
|
|
|
|
Translation.fetch(locale)
|
|
|
|
Setting.set('locale_default', locale)
|
|
|
|
Setting.set('timezone_default', time_zone)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:time_zone) { 'Europe/Vilnius' }
|
|
|
|
let(:locale) { 'de-de' }
|
|
|
|
|
|
|
|
context 'sends interpolated, html-free SMS' do
|
|
|
|
before do
|
|
|
|
another_agent = create(:admin_user, mobile: '+37061010000')
|
|
|
|
Group.lookup(id: 1).users << another_agent
|
|
|
|
|
|
|
|
create(:channel, area: 'Sms::Notification')
|
|
|
|
create(:trigger,
|
|
|
|
disable_notification: false,
|
|
|
|
perform: {
|
|
|
|
'notification.sms': {
|
|
|
|
recipient: 'ticket_agents',
|
|
|
|
body: message_body,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:message_body) { 'space between #{ticket.title} #{ticket.created_at}' } # rubocop:disable Lint/InterpolationCheck
|
|
|
|
|
|
|
|
let(:agent) { create(:agent_user) }
|
|
|
|
let(:ticket) do
|
|
|
|
ticket = create(:ticket, group: Group.lookup(id: 1), created_by_id: agent.id)
|
|
|
|
Observer::Transaction.commit
|
|
|
|
ticket
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:triggered_article) do
|
|
|
|
ticket.articles.last
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders HTML chars' do
|
|
|
|
expect(triggered_article.body).to match(/space between/)
|
|
|
|
end
|
2018-10-16 08:45:15 +00:00
|
|
|
|
2020-01-27 09:28:17 +00:00
|
|
|
it 'interpolates ticket properties' do
|
|
|
|
expect(triggered_article.body).to match(ticket.title)
|
|
|
|
end
|
2018-10-16 08:45:15 +00:00
|
|
|
|
2020-01-27 09:28:17 +00:00
|
|
|
it 'interpolates time in selected time zone' do
|
|
|
|
time_in_zone = triggered_article.ticket.created_at.in_time_zone(time_zone)
|
2018-10-16 08:45:15 +00:00
|
|
|
|
2020-01-27 09:28:17 +00:00
|
|
|
expect(triggered_article.body).to match(time_in_zone.strftime('%H:%M'))
|
|
|
|
end
|
2018-10-16 08:45:15 +00:00
|
|
|
|
2020-01-27 09:28:17 +00:00
|
|
|
it 'interpolates date in selected locale format' do
|
|
|
|
time_in_zone = triggered_article.ticket.created_at.in_time_zone(time_zone)
|
2018-10-16 08:45:15 +00:00
|
|
|
|
2020-01-27 09:28:17 +00:00
|
|
|
expect(triggered_article.body).to match(time_in_zone.strftime('%d.%m.%y'))
|
|
|
|
end
|
2018-10-16 08:45:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|