Skip to content

Commit

Permalink
Maintenance: Add fallback link text for nameless WhatsApp locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvuckovic committed Mar 11, 2024
1 parent e7c6f8b commit bd57a42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/whatsapp/webhook/message/location.rb
Expand Up @@ -4,7 +4,7 @@ class Whatsapp::Webhook::Message::Location < Whatsapp::Webhook::Message
private

def body
"📍 <a href='https://www.google.com/maps/search/?api=1&query=#{message[:latitude]},#{message[:longitude]}' target='_blank'>#{message[:name]}</a>"
"📍 <a href='https://www.google.com/maps/search/?api=1&query=#{message[:latitude]},#{message[:longitude]}' target='_blank'>#{message[:name] || 'Location'}</a>"
end

def content_type
Expand Down
16 changes: 14 additions & 2 deletions spec/lib/whatsapp/webhook/message/location_spec.rb
Expand Up @@ -4,7 +4,8 @@

RSpec.describe Whatsapp::Webhook::Message::Location, :aggregate_failures, current_user_id: 1 do
describe '#process' do
let(:channel) { create(:whatsapp_channel, welcome: 'Hey there!') }
let(:channel) { create(:whatsapp_channel, welcome: 'Hey there!') }
let(:location_name) { 'Langenbach Arena' }

let(:from) do
{
Expand Down Expand Up @@ -38,7 +39,7 @@
location: {
latitude: 50.697254180908,
longitude: 7.9327116012573,
name: 'Langenbach Arena',
name: location_name,
url: 'https://foursquare.com/v/4fddbd3ee4b06434e8dc7504'
},
type: 'location',
Expand Down Expand Up @@ -98,6 +99,17 @@
content_type: 'text/plain',
)
end

context 'when location has no name set' do
let(:location_name) { nil }

it 'uses fallback text for the link' do
described_class.new(data:, channel:).process

expect(Ticket::Article.second_to_last.body).to include('Location')
.and include('target="_blank"')
end
end
end
end
end

0 comments on commit bd57a42

Please sign in to comment.