feat: Add support for minutes in auto resolve feature (#11269)
### Summary - Converts conversation auto-resolution duration from days to minutes for more granular control - Updates validation to allow values from 10 minutes (minimum) to 999 days (maximum) - Implements smart messaging to show appropriate time units in activity messages ### Changes - Created migration to convert existing durations from days to minutes (x1440) - Updated conversation resolver to use minutes instead of days - Added dynamic translation key selection based on duration value - Updated related specs and documentation - Added support for displaying durations in days, hours, or minutes based on value ### Test plan - Verify account validation accepts new minute-based ranges - Confirm existing account settings are correctly migrated - Test auto-resolution works properly with minute values - Ensure proper time unit display in activity messages --------- Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
This commit is contained in:
@@ -3,9 +3,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Account do
|
||||
it { is_expected.to validate_numericality_of(:auto_resolve_duration).is_greater_than_or_equal_to(1) }
|
||||
it { is_expected.to validate_numericality_of(:auto_resolve_duration).is_less_than_or_equal_to(999) }
|
||||
|
||||
it { is_expected.to have_many(:users).through(:account_users) }
|
||||
it { is_expected.to have_many(:account_users) }
|
||||
it { is_expected.to have_many(:inboxes).dependent(:destroy_async) }
|
||||
@@ -134,4 +131,86 @@ RSpec.describe Account do
|
||||
expect(account.locale_english_name).to eq('portuguese')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'settings' do
|
||||
let(:account) { create(:account) }
|
||||
|
||||
context 'when auto_resolve_after' do
|
||||
it 'validates minimum value' do
|
||||
account.settings = { auto_resolve_after: 4 }
|
||||
expect(account).to be_invalid
|
||||
expect(account.errors.messages).to eq({ auto_resolve_after: ['must be greater than or equal to 10'] })
|
||||
end
|
||||
|
||||
it 'validates maximum value' do
|
||||
account.settings = { auto_resolve_after: 1_439_857 }
|
||||
expect(account).to be_invalid
|
||||
expect(account.errors.messages).to eq({ auto_resolve_after: ['must be less than or equal to 1439856'] })
|
||||
end
|
||||
|
||||
it 'allows valid values' do
|
||||
account.settings = { auto_resolve_after: 15 }
|
||||
expect(account).to be_valid
|
||||
|
||||
account.settings = { auto_resolve_after: 1_439_856 }
|
||||
expect(account).to be_valid
|
||||
end
|
||||
|
||||
it 'allows null values' do
|
||||
account.settings = { auto_resolve_after: nil }
|
||||
expect(account).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'when auto_resolve_message' do
|
||||
it 'allows string values' do
|
||||
account.settings = { auto_resolve_message: 'This conversation has been resolved automatically.' }
|
||||
expect(account).to be_valid
|
||||
end
|
||||
|
||||
it 'allows empty string' do
|
||||
account.settings = { auto_resolve_message: '' }
|
||||
expect(account).to be_valid
|
||||
end
|
||||
|
||||
it 'allows nil values' do
|
||||
account.settings = { auto_resolve_message: nil }
|
||||
expect(account).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context 'when using store_accessor' do
|
||||
it 'correctly gets and sets auto_resolve_after' do
|
||||
account.auto_resolve_after = 30
|
||||
expect(account.auto_resolve_after).to eq(30)
|
||||
expect(account.settings['auto_resolve_after']).to eq(30)
|
||||
end
|
||||
|
||||
it 'correctly gets and sets auto_resolve_message' do
|
||||
message = 'This conversation was automatically resolved'
|
||||
account.auto_resolve_message = message
|
||||
expect(account.auto_resolve_message).to eq(message)
|
||||
expect(account.settings['auto_resolve_message']).to eq(message)
|
||||
end
|
||||
|
||||
it 'handles nil values correctly' do
|
||||
account.auto_resolve_after = nil
|
||||
account.auto_resolve_message = nil
|
||||
expect(account.auto_resolve_after).to be_nil
|
||||
expect(account.auto_resolve_message).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when using with_auto_resolve scope' do
|
||||
it 'finds accounts with auto_resolve_after set' do
|
||||
account.update(auto_resolve_after: 40 * 24 * 60)
|
||||
expect(described_class.with_auto_resolve).to include(account)
|
||||
end
|
||||
|
||||
it 'does not find accounts without auto_resolve_after' do
|
||||
account.update(auto_resolve_after: nil)
|
||||
expect(described_class.with_auto_resolve).not_to include(account)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user