Files
assistant-storefront/spec/services/liquid/campaign_template_service_spec.rb
Liang XJ 092fb2e083
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
Initial commit: Add logistics and order_detail message types
- 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>
2026-01-26 11:16:56 +08:00

108 lines
3.7 KiB
Ruby

require 'rails_helper'
describe Liquid::CampaignTemplateService do
subject(:template_service) { described_class.new(campaign: campaign, contact: contact) }
let(:account) { create(:account) }
let(:agent) { create(:user, account: account) }
let(:inbox) { create(:inbox, account: account) }
let(:contact) { create(:contact, account: account, name: 'John Doe', phone_number: '+1234567890') }
let(:campaign) { create(:campaign, account: account, inbox: inbox, sender: agent, message: message_content) }
describe '#call' do
context 'with liquid template variables' do
let(:message_content) { 'Hello {{contact.name}}, this is {{agent.name}} from {{account.name}}' }
it 'processes liquid template correctly' do
result = template_service.call(message_content)
agent_drop_name = UserDrop.new(agent).name
contact_drop_name = ContactDrop.new(contact).name
expect(result).to eq("Hello #{contact_drop_name}, this is #{agent_drop_name} from #{account.name}")
end
end
context 'with code blocks' do
let(:message_content) { 'Check this code: `const x = {{contact.name}}`' }
it 'preserves code blocks without processing liquid' do
result = template_service.call(message_content)
expect(result).to include('`const x = {{contact.name}}`')
expect(result).not_to include(contact.name)
end
end
context 'with multiline code blocks' do
let(:message_content) do
<<~MESSAGE
Here's some code:
```
function greet() {
return "Hello {{contact.name}}";
}
```
MESSAGE
end
it 'preserves multiline code blocks without processing liquid' do
result = template_service.call(message_content)
expect(result).to include('{{contact.name}}')
expect(result).not_to include(contact.name)
end
end
context 'with malformed liquid syntax' do
let(:message_content) { 'Hello {{contact.name missing closing braces' }
it 'returns original message when liquid parsing fails' do
result = template_service.call(message_content)
expect(result).to eq(message_content)
end
end
context 'with invalid liquid tags' do
let(:message_content) { 'Hello {% invalid_tag %} world' }
it 'returns original message when liquid parsing fails' do
result = template_service.call(message_content)
expect(result).to eq(message_content)
end
end
context 'with mixed content' do
let(:message_content) { 'Hi {{contact.name}}, use this code: `{{agent.name}}` to contact {{agent.name}}' }
it 'processes liquid outside code blocks but preserves code blocks' do
result = template_service.call(message_content)
agent_drop_name = UserDrop.new(agent).name
contact_drop_name = ContactDrop.new(contact).name
expect(result).to include("Hi #{contact_drop_name}")
expect(result).to include("contact #{agent_drop_name}")
expect(result).to include('`{{agent.name}}`')
end
end
context 'with all drop types' do
let(:message_content) do
'Contact: {{contact.name}}, Agent: {{agent.name}}, Inbox: {{inbox.name}}, Account: {{account.name}}'
end
it 'processes all available drops' do
result = template_service.call(message_content)
agent_drop_name = UserDrop.new(agent).name
contact_drop_name = ContactDrop.new(contact).name
expect(result).to include("Contact: #{contact_drop_name}")
expect(result).to include("Agent: #{agent_drop_name}")
expect(result).to include("Inbox: #{inbox.name}")
expect(result).to include("Account: #{account.name}")
end
end
end
end