Merge branch 'develop' into codex/fix-imap-contact-name-truncation

This commit is contained in:
Sony Mathew 2026-06-03 13:38:44 +05:30 committed by GitHub
commit 473f2de2ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 3 deletions

View File

@ -6,8 +6,7 @@ class Api::V1::Accounts::Microsoft::AuthorizationsController < Api::V1::Accounts
{
redirect_uri: "#{base_url}/microsoft/callback",
scope: scope,
state: state,
prompt: 'consent'
state: state
}
)
if redirect_url

View File

@ -147,7 +147,7 @@ class Whatsapp::IncomingMessageBaseService
def attach_location
location = messages_data.first['location']
location_name = location['name'] ? "#{location['name']}, #{location['address']}" : ''
location_name = (location['name'] ? "#{location['name']}, #{location['address']}" : '').first(255)
@message.attachments.new(
account_id: @message.account_id,
file_type: file_content_type(message_type),

View File

@ -43,6 +43,7 @@ RSpec.describe 'Microsoft Authorization API', type: :request do
]
expect(params['scope']).to eq(expected_scope)
expect(params['redirect_uri']).to eq(["#{ENV.fetch('FRONTEND_URL', 'http://localhost:3000')}/microsoft/callback"])
expect(url).not_to match(/(?:\?|&)prompt=/)
# Validate state parameter exists and can be decoded back to the account
expect(params['state']).to be_present

View File

@ -381,6 +381,32 @@ describe Whatsapp::IncomingMessageService do
expect(location_attachment.coordinates_long).to eq(-122.3895553)
expect(location_attachment.external_url).to eq('http://location_url.test')
end
it 'truncates long fallback titles to avoid dropping location messages' do
long_place_name = [
'Gremi de Fusters, 33, Edificio VIP Asima, Piso 2, Local 2, Norte',
'07009 Poligon industrial de Son Castello, Illes Balears, Espana'
].join(', ')
source_id = 'wamid.long-location-fallback-title'
params = {
'contacts' => [{ 'profile' => { 'name' => 'Sojan Jose' }, 'wa_id' => '2423423243' }],
'messages' => [{ 'from' => '2423423243', 'id' => source_id,
'location' => { 'id' => 'b1c68f38-8734-4ad3-b4a1-ef0c10d683',
:address => long_place_name,
:latitude => 37.7893768,
:longitude => -122.3895553,
:name => long_place_name,
:url => 'http://location_url.test' },
'timestamp' => '1633034394', 'type' => 'location' }]
}.with_indifferent_access
expect { described_class.new(inbox: whatsapp_channel.inbox, params: params).perform }
.to change { Message.where(source_id: source_id).count }.from(0).to(1)
location_attachment = Message.find_by!(source_id: source_id).attachments.first
expect(location_attachment.fallback_title).to eq("#{long_place_name}, #{long_place_name}".first(255))
expect(location_attachment.fallback_title.length).to eq(255)
end
end
context 'when valid contact message params' do