fix: RemoveStaleRedisKeys service (#10562)

Fixes issues with RemoveStaleRedisKeys service

Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
Vishnu Narayanan
2024-12-11 01:08:25 +05:30
committed by GitHub
parent 1b0e94ec95
commit 9a405d65ba
6 changed files with 61 additions and 7 deletions

View File

@@ -0,0 +1,15 @@
require 'rails_helper'
RSpec.describe Internal::ProcessStaleRedisKeysJob do
let(:account) { create(:account) }
describe '#perform' do
it 'calls the RemoveStaleRedisKeysService with the correct account ID' do
expect(Internal::RemoveStaleRedisKeysService).to receive(:new)
.with(account_id: account.id)
.and_call_original
described_class.perform_now(account)
end
end
end

View File

@@ -0,0 +1,13 @@
require 'rails_helper'
RSpec.describe Internal::RemoveStaleRedisKeysJob do
let(:account) { create(:account) }
describe '#perform' do
it 'enqueues ProcessStaleRedisKeysJob for the account' do
expect(Internal::ProcessStaleRedisKeysJob).to receive(:perform_later).with(account)
described_class.perform_now
end
end
end

View File

@@ -0,0 +1,18 @@
require 'rails_helper'
RSpec.describe Internal::RemoveStaleRedisKeysService, type: :service do
let(:account_id) { 1 }
let(:service) { described_class.new(account_id: account_id) }
describe '#perform' do
it 'removes stale Redis keys for the specified account' do
presence_key = OnlineStatusTracker.presence_key(account_id, 'Contact')
# Mock Redis calls
expect(Redis::Alfred).to receive(:zremrangebyscore)
.with(presence_key, '-inf', anything)
service.perform
end
end
end