chore: Update MarkMessagesAsReadJob to accept delivered status (#8319)
This commit is contained in:
@@ -173,7 +173,7 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
||||
|
||||
allow(Rails.configuration.dispatcher).to receive(:dispatch)
|
||||
expect(conversation.contact_last_seen_at).to be_nil
|
||||
expect(Conversations::MarkMessagesAsReadJob).to receive(:perform_later).with(conversation.id, current_time)
|
||||
expect(Conversations::UpdateMessageStatusJob).to receive(:perform_later).with(conversation.id, current_time)
|
||||
|
||||
post '/api/v1/widget/conversations/update_last_seen',
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
|
||||
@@ -83,7 +83,7 @@ RSpec.describe 'Public Inbox Contact Conversations API', type: :request do
|
||||
current_time = DateTime.now.utc
|
||||
allow(DateTime).to receive(:now).and_return(current_time)
|
||||
contact_last_seen_at = conversation.contact_last_seen_at
|
||||
expect(Conversations::MarkMessagesAsReadJob).to receive(:perform_later).with(conversation.id, current_time)
|
||||
expect(Conversations::UpdateMessageStatusJob).to receive(:perform_later).with(conversation.id, current_time)
|
||||
post update_last_seen_path
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Conversations::MarkMessagesAsReadJob do
|
||||
RSpec.describe Conversations::UpdateMessageStatusJob do
|
||||
subject(:job) { described_class.perform_later(account) }
|
||||
|
||||
let!(:account) { create(:account) }
|
||||
@@ -21,6 +21,13 @@ RSpec.describe Conversations::MarkMessagesAsReadJob do
|
||||
end.to change(message, :status).from('sent').to('read')
|
||||
end
|
||||
|
||||
it 'marks all sent messages in a conversation as delivered if specified' do
|
||||
expect do
|
||||
described_class.perform_now(conversation.id, conversation.contact_last_seen_at, :delivered)
|
||||
message.reload
|
||||
end.to change(message, :status).from('sent').to('delivered')
|
||||
end
|
||||
|
||||
it 'marks all delivered messages in a conversation as read' do
|
||||
message.update!(status: 'delivered')
|
||||
expect do
|
||||
@@ -63,5 +70,11 @@ RSpec.describe Conversations::MarkMessagesAsReadJob do
|
||||
described_class.perform_now(1212, conversation.contact_last_seen_at)
|
||||
end.not_to change(message.reload, :status)
|
||||
end
|
||||
|
||||
it 'does not run the job if the status is failed' do
|
||||
expect do
|
||||
described_class.perform_now(conversation.id, conversation.contact_last_seen_at, :failed)
|
||||
end.not_to change(message.reload, :status)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -18,10 +18,10 @@ describe Instagram::ReadStatusService do
|
||||
let(:message) { conversation.messages.last }
|
||||
|
||||
before do
|
||||
allow(Conversations::MarkMessagesAsReadJob).to receive(:perform_later)
|
||||
allow(Conversations::UpdateMessageStatusJob).to receive(:perform_later)
|
||||
end
|
||||
|
||||
it 'enqueues the MarkMessagesAsReadJob with correct parameters if the message is found' do
|
||||
it 'enqueues the UpdateMessageStatusJob with correct parameters if the message is found' do
|
||||
params = {
|
||||
recipient: {
|
||||
id: 'chatwoot-app-user-id-1'
|
||||
@@ -31,10 +31,10 @@ describe Instagram::ReadStatusService do
|
||||
}
|
||||
}
|
||||
described_class.new(params: params).perform
|
||||
expect(Conversations::MarkMessagesAsReadJob).to have_received(:perform_later).with(conversation.id, message.created_at)
|
||||
expect(Conversations::UpdateMessageStatusJob).to have_received(:perform_later).with(conversation.id, message.created_at)
|
||||
end
|
||||
|
||||
it 'does not enqueue the MarkMessagesAsReadJob if the message is not found' do
|
||||
it 'does not enqueue the UpdateMessageStatusJob if the message is not found' do
|
||||
params = {
|
||||
recipient: {
|
||||
id: 'chatwoot-app-user-id-1'
|
||||
@@ -44,7 +44,7 @@ describe Instagram::ReadStatusService do
|
||||
}
|
||||
}
|
||||
described_class.new(params: params).perform
|
||||
expect(Conversations::MarkMessagesAsReadJob).not_to have_received(:perform_later)
|
||||
expect(Conversations::UpdateMessageStatusJob).not_to have_received(:perform_later)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user