Some checks failed
Lock Threads / action (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
- Add Logistics component with progress tracking - Add OrderDetail component for order information - Support data-driven steps and actions - Add blue color scale to widget SCSS - Fix node overflow and progress bar rendering issues - Add English translations for dashboard components Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
92 lines
2.9 KiB
Ruby
92 lines
2.9 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Webhooks::TiktokEventsJob do
|
|
let(:account) { create(:account) }
|
|
let!(:channel) { create(:channel_tiktok, account: account, business_id: 'biz-123') }
|
|
let(:job) { described_class.new }
|
|
|
|
before do
|
|
allow(job).to receive(:with_lock).and_yield
|
|
end
|
|
|
|
describe '#perform' do
|
|
it 'processes im_receive_msg events via Tiktok::MessageService' do
|
|
message_service = instance_double(Tiktok::MessageService, perform: true)
|
|
allow(Tiktok::MessageService).to receive(:new).and_return(message_service)
|
|
|
|
event = {
|
|
event: 'im_receive_msg',
|
|
user_openid: 'biz-123',
|
|
content: { conversation_id: 'tt-conv-1' }.to_json
|
|
}
|
|
|
|
job.perform(event)
|
|
|
|
expect(Tiktok::MessageService).to have_received(:new).with(channel: channel, content: hash_including(conversation_id: 'tt-conv-1'))
|
|
expect(message_service).to have_received(:perform)
|
|
end
|
|
|
|
it 'processes im_mark_read_msg events via Tiktok::ReadStatusService' do
|
|
read_status_service = instance_double(Tiktok::ReadStatusService, perform: true)
|
|
allow(Tiktok::ReadStatusService).to receive(:new).and_return(read_status_service)
|
|
|
|
event = {
|
|
event: 'im_mark_read_msg',
|
|
user_openid: 'biz-123',
|
|
content: { conversation_id: 'tt-conv-1', read: { last_read_timestamp: 1_700_000_000_000 }, from_user: { id: 'user-1' } }.to_json
|
|
}
|
|
|
|
job.perform(event)
|
|
|
|
expect(Tiktok::ReadStatusService).to have_received(:new).with(channel: channel, content: hash_including(conversation_id: 'tt-conv-1'))
|
|
expect(read_status_service).to have_received(:perform)
|
|
end
|
|
|
|
it 'ignores unsupported event types' do
|
|
allow(Tiktok::MessageService).to receive(:new)
|
|
|
|
event = {
|
|
event: 'unknown_event',
|
|
user_openid: 'biz-123',
|
|
content: { conversation_id: 'tt-conv-1' }.to_json
|
|
}
|
|
|
|
job.perform(event)
|
|
|
|
expect(Tiktok::MessageService).not_to have_received(:new)
|
|
end
|
|
|
|
it 'does nothing when channel is missing' do
|
|
allow(Tiktok::MessageService).to receive(:new)
|
|
|
|
event = {
|
|
event: 'im_receive_msg',
|
|
user_openid: 'biz-does-not-exist',
|
|
content: { conversation_id: 'tt-conv-1' }.to_json
|
|
}
|
|
|
|
job.perform(event)
|
|
|
|
expect(Tiktok::MessageService).not_to have_received(:new)
|
|
end
|
|
|
|
it 'does nothing when account is inactive' do
|
|
allow(Channel::Tiktok).to receive(:find_by).and_return(channel)
|
|
allow(channel.account).to receive(:active?).and_return(false)
|
|
|
|
message_service = instance_double(Tiktok::MessageService, perform: true)
|
|
allow(Tiktok::MessageService).to receive(:new).and_return(message_service)
|
|
|
|
event = {
|
|
event: 'im_receive_msg',
|
|
user_openid: 'biz-123',
|
|
content: { conversation_id: 'tt-conv-1' }.to_json
|
|
}
|
|
|
|
job.perform(event)
|
|
|
|
expect(Tiktok::MessageService).not_to have_received(:new)
|
|
end
|
|
end
|
|
end
|