## Linear task: https://linear.app/chatwoot/issue/CW-6318/searchkickimporterror-type-=-mapper-parsing-exception-reason-=-failed ## Description Fixes Elasticsearch `mapper_parsing_exception` errors that occur when `campaign_id` contain non-numeric string values ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? - Unit tests - use a local OpenSearch 3.4.0 cluster to verify actual indexing behavior. ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Removes `campaign_id` from the message search index payload to simplify `additional_attributes`, keeping only `automation_rule_id`. > > - `Messages::SearchDataPresenter#additional_attributes_data` now returns only `automation_rule_id` > - Specs updated to stop asserting `campaign_id` and continue validating `automation_rule_id` and email subject handling > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5a9c8eb794a044e3f258b644f67a6731de9e904c. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
74 lines
2.4 KiB
Ruby
74 lines
2.4 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Messages::SearchDataPresenter do
|
|
let(:presenter) { described_class.new(message) }
|
|
let(:account) { create(:account) }
|
|
let(:inbox) { create(:inbox, account: account) }
|
|
let(:contact) { create(:contact, account: account) }
|
|
let(:conversation) { create(:conversation, account: account, inbox: inbox, contact: contact) }
|
|
let(:message) { create(:message, account: account, inbox: inbox, conversation: conversation, sender: contact) }
|
|
|
|
describe '#search_data' do
|
|
let(:expected_data) do
|
|
{
|
|
content: message.content,
|
|
account_id: message.account_id,
|
|
inbox_id: message.inbox_id,
|
|
conversation_id: message.conversation_id,
|
|
message_type: message.message_type,
|
|
private: message.private,
|
|
created_at: message.created_at,
|
|
source_id: message.source_id,
|
|
sender_id: message.sender_id,
|
|
sender_type: message.sender_type,
|
|
conversation: {
|
|
id: conversation.display_id
|
|
}
|
|
}
|
|
end
|
|
|
|
it 'returns search index payload with core fields' do
|
|
expect(presenter.search_data).to include(expected_data)
|
|
end
|
|
|
|
context 'with attachments' do
|
|
before do
|
|
attachment = message.attachments.new(account_id: message.account_id, file_type: :image)
|
|
attachment.file.attach(io: Rails.root.join('spec/assets/avatar.png').open, filename: 'avatar.png', content_type: 'image/png')
|
|
attachment.meta = { 'transcribed_text' => 'Hello world' }
|
|
end
|
|
|
|
it 'includes attachment transcriptions' do
|
|
attachments_data = presenter.search_data[:attachments]
|
|
expect(attachments_data).to be_an(Array)
|
|
expect(attachments_data.first).to include(transcribed_text: 'Hello world')
|
|
end
|
|
end
|
|
|
|
context 'with email content attributes' do
|
|
before do
|
|
message.update(
|
|
content_attributes: { email: { subject: 'Test Subject' } }
|
|
)
|
|
end
|
|
|
|
it 'includes email subject' do
|
|
content_attrs = presenter.search_data[:content_attributes]
|
|
expect(content_attrs[:email][:subject]).to eq('Test Subject')
|
|
end
|
|
end
|
|
|
|
context 'with campaign and automation data' do
|
|
before do
|
|
message.update(
|
|
content_attributes: { 'automation_rule_id' => '456' }
|
|
)
|
|
end
|
|
|
|
it 'includes automation_rule_id' do
|
|
expect(presenter.search_data[:additional_attributes][:automation_rule_id]).to eq('456')
|
|
end
|
|
end
|
|
end
|
|
end
|