chore: Add validation for processed content field (#7306)

* logging the messages id for message validation exception

* Update the processed_message_content validation over length

* codeclimate

* specs failing for contacts
This commit is contained in:
Tejaswini Chile
2023-06-14 18:28:42 +05:30
committed by GitHub
parent 6eb4fa41ff
commit 1ee6a8fe90
3 changed files with 7 additions and 1 deletions

View File

@@ -70,6 +70,7 @@ class Message < ApplicationRecord
validates :content_type, presence: true
validates :content, length: { maximum: 150_000 }
validates :processed_message_content, length: { maximum: 150_000 }
# when you have a temperory id in your frontend and want it echoed back via action cable
attr_accessor :echo_id
@@ -220,7 +221,8 @@ class Message < ApplicationRecord
text_content_quoted = content_attributes.dig(:email, :text_content, :quoted)
html_content_quoted = content_attributes.dig(:email, :html_content, :quoted)
self.processed_message_content = text_content_quoted || html_content_quoted || content
message_content = text_content_quoted || html_content_quoted || content
self.processed_message_content = message_content&.truncate(150_000)
end
def ensure_content_type

View File

@@ -43,6 +43,7 @@ RSpec.describe Account::ContactsExportJob do
last_contact = account.contacts.last
expect(csv_data.length).to eq(account.contacts.count)
expect([first_row['email'], last_row['email']]).to contain_exactly(first_contact.email, last_contact.email)
expect([first_row['phone_number'], last_row['phone_number']]).to contain_exactly(first_contact.phone_number, last_contact.phone_number)
end

View File

@@ -21,7 +21,10 @@ RSpec.describe Message do
it 'invalid when crossed the limit' do
message.content = 'a' * 150_001
message.processed_message_content = 'a' * 150_001
message.valid?
expect(message.errors[:processed_message_content]).to include('is too long (maximum is 150000 characters)')
expect(message.errors[:content]).to include('is too long (maximum is 150000 characters)')
end
end