Initial commit: Add logistics and order_detail message types
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>
This commit is contained in:
Liang XJ
2026-01-26 11:16:56 +08:00
commit 092fb2e083
7646 changed files with 975643 additions and 0 deletions

View File

@@ -0,0 +1,223 @@
require 'rails_helper'
RSpec.describe Crm::Leadsquared::Api::ActivityClient do
let(:credentials) do
{
access_key: SecureRandom.hex,
secret_key: SecureRandom.hex,
endpoint_url: 'https://api.leadsquared.com/'
}
end
let(:headers) do
{
'Content-Type': 'application/json',
'x-LSQ-AccessKey': credentials[:access_key],
'x-LSQ-SecretKey': credentials[:secret_key]
}
end
let(:client) { described_class.new(credentials[:access_key], credentials[:secret_key], credentials[:endpoint_url]) }
let(:prospect_id) { SecureRandom.uuid }
let(:activity_event) { 1001 } # Example activity event code
let(:activity_note) { 'Test activity note' }
let(:activity_date_time) { '2025-04-11 14:15:00' }
describe '#post_activity' do
let(:path) { '/ProspectActivity.svc/Create' }
let(:full_url) { URI.join(credentials[:endpoint_url], path).to_s }
context 'with missing required parameters' do
it 'raises ArgumentError when prospect_id is missing' do
expect { client.post_activity(nil, activity_event, activity_note) }
.to raise_error(ArgumentError, 'Prospect ID is required')
end
it 'raises ArgumentError when activity_event is missing' do
expect { client.post_activity(prospect_id, nil, activity_note) }
.to raise_error(ArgumentError, 'Activity event code is required')
end
end
context 'when request is successful' do
let(:activity_id) { SecureRandom.uuid }
let(:success_response) do
{
'Status' => 'Success',
'Message' => {
'Id' => activity_id,
'Message' => 'Activity created successfully'
}
}
end
before do
stub_request(:post, full_url)
.with(
body: {
'RelatedProspectId' => prospect_id,
'ActivityEvent' => activity_event,
'ActivityNote' => activity_note
}.to_json,
headers: headers
)
.to_return(
status: 200,
body: success_response.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'returns activity ID directly' do
response = client.post_activity(prospect_id, activity_event, activity_note)
expect(response).to eq(activity_id)
end
end
context 'when response indicates failure' do
let(:error_response) do
{
'Status' => 'Error',
'ExceptionType' => 'NullReferenceException',
'ExceptionMessage' => 'There was an error processing the request.'
}
end
before do
stub_request(:post, full_url)
.with(
body: {
'RelatedProspectId' => prospect_id,
'ActivityEvent' => activity_event,
'ActivityNote' => activity_note
}.to_json,
headers: headers
)
.to_return(
status: 200,
body: error_response.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'raises ApiError when activity creation fails' do
expect { client.post_activity(prospect_id, activity_event, activity_note) }
.to raise_error do |error|
expect(error.class.name).to eq('Crm::Leadsquared::Api::BaseClient::ApiError')
end
end
end
end
describe '#create_activity_type' do
let(:path) { 'ProspectActivity.svc/CreateType' }
let(:full_url) { URI.join(credentials[:endpoint_url], path).to_s }
let(:activity_params) do
{
name: 'Test Activity Type',
score: 10,
direction: 0
}
end
context 'with missing required parameters' do
it 'raises ArgumentError when name is missing' do
expect { client.create_activity_type(name: nil, score: 10) }
.to raise_error(ArgumentError, 'Activity name is required')
end
end
context 'when request is successful' do
let(:activity_event_id) { 1001 }
let(:success_response) do
{
'Status' => 'Success',
'Message' => {
'Id' => activity_event_id
}
}
end
before do
stub_request(:post, full_url)
.with(
body: {
'ActivityEventName' => activity_params[:name],
'Score' => activity_params[:score],
'Direction' => activity_params[:direction]
}.to_json,
headers: headers
)
.to_return(
status: 200,
body: success_response.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'returns activity ID directly' do
response = client.create_activity_type(**activity_params)
expect(response).to eq(activity_event_id)
end
end
context 'when response indicates failure' do
let(:error_response) do
{
'Status' => 'Error',
'ExceptionType' => 'MXInvalidInputException',
'ExceptionMessage' => 'Invalid Input! Parameter Name: activity'
}
end
before do
stub_request(:post, full_url)
.with(
body: {
'ActivityEventName' => activity_params[:name],
'Score' => activity_params[:score],
'Direction' => activity_params[:direction]
}.to_json,
headers: headers
)
.to_return(
status: 200,
body: error_response.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'raises ApiError when activity type creation fails' do
expect { client.create_activity_type(**activity_params) }
.to raise_error do |error|
expect(error.class.name).to eq('Crm::Leadsquared::Api::BaseClient::ApiError')
end
end
end
context 'when API request fails' do
before do
stub_request(:post, full_url)
.with(
body: {
'ActivityEventName' => activity_params[:name],
'Score' => activity_params[:score],
'Direction' => activity_params[:direction]
}.to_json,
headers: headers
)
.to_return(
status: 500,
body: 'Internal Server Error',
headers: { 'Content-Type' => 'text/plain' }
)
end
it 'raises ApiError when the request fails' do
expect { client.create_activity_type(**activity_params) }
.to raise_error do |error|
expect(error.class.name).to eq('Crm::Leadsquared::Api::BaseClient::ApiError')
end
end
end
end
end

View File

@@ -0,0 +1,187 @@
require 'rails_helper'
RSpec.describe Crm::Leadsquared::Api::BaseClient do
let(:access_key) { SecureRandom.hex }
let(:secret_key) { SecureRandom.hex }
let(:headers) do
{
'Content-Type': 'application/json',
'x-LSQ-AccessKey': access_key,
'x-LSQ-SecretKey': secret_key
}
end
let(:endpoint_url) { 'https://api.leadsquared.com/v2' }
let(:client) { described_class.new(access_key, secret_key, endpoint_url) }
describe '#initialize' do
it 'creates a client with valid credentials' do
expect(client.instance_variable_get(:@access_key)).to eq(access_key)
expect(client.instance_variable_get(:@secret_key)).to eq(secret_key)
expect(client.instance_variable_get(:@base_uri)).to eq(endpoint_url)
end
end
describe '#get' do
let(:path) { 'LeadManagement.svc/Leads.Get' }
let(:params) { { leadId: '123' } }
let(:full_url) { URI.join(endpoint_url, path).to_s }
context 'when request is successful' do
before do
stub_request(:get, full_url)
.with(
query: params,
headers: headers
)
.to_return(
status: 200,
body: { Message: 'Success', Status: 'Success' }.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'returns parsed response data directly' do
response = client.get(path, params)
expect(response).to include('Message' => 'Success')
expect(response).to include('Status' => 'Success')
end
end
context 'when request returns error status' do
before do
stub_request(:get, full_url)
.with(
query: params,
headers: headers
)
.to_return(
status: 200,
body: { Status: 'Error', ExceptionMessage: 'Invalid lead ID' }.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'raises ApiError with error message' do
expect { client.get(path, params) }.to raise_error do |error|
expect(error.class.name).to eq(described_class::ApiError.name)
expect(error.message).to eq('Invalid lead ID')
end
end
end
context 'when request fails with non-200 status' do
before do
stub_request(:get, full_url)
.with(
query: params,
headers: headers
)
.to_return(status: 404, body: 'Not Found')
end
it 'raises ApiError with status code' do
expect { client.get(path, params) }.to raise_error do |error|
expect(error.class.name).to eq(described_class::ApiError.name)
expect(error.message).to include('Not Found')
expect(error.code).to eq(404)
end
end
end
end
describe '#post' do
let(:path) { 'LeadManagement.svc/Lead.Create' }
let(:params) { {} }
let(:body) { { FirstName: 'John', LastName: 'Doe' } }
let(:full_url) { URI.join(endpoint_url, path).to_s }
context 'when request is successful' do
before do
stub_request(:post, full_url)
.with(
query: params,
body: body.to_json,
headers: headers
)
.to_return(
status: 200,
body: { Message: 'Lead created', Status: 'Success' }.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'returns parsed response data directly' do
response = client.post(path, params, body)
expect(response).to include('Message' => 'Lead created')
expect(response).to include('Status' => 'Success')
end
end
context 'when request returns error status' do
before do
stub_request(:post, full_url)
.with(
query: params,
body: body.to_json,
headers: headers
)
.to_return(
status: 200,
body: { Status: 'Error', ExceptionMessage: 'Invalid data' }.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'raises ApiError with error message' do
expect { client.post(path, params, body) }.to raise_error do |error|
expect(error.class.name).to eq(described_class::ApiError.name)
expect(error.message).to eq('Invalid data')
end
end
end
context 'when response cannot be parsed' do
before do
stub_request(:post, full_url)
.with(
query: params,
body: body.to_json,
headers: headers
)
.to_return(
status: 200,
body: 'Invalid JSON',
headers: { 'Content-Type' => 'application/json' }
)
end
it 'raises ApiError for invalid JSON' do
expect { client.post(path, params, body) }.to raise_error do |error|
expect(error.class.name).to eq(described_class::ApiError.name)
expect(error.message).to include('Failed to parse')
end
end
end
context 'when request fails with server error' do
before do
stub_request(:post, full_url)
.with(
query: params,
body: body.to_json,
headers: headers
)
.to_return(status: 500, body: 'Internal Server Error')
end
it 'raises ApiError with status code' do
expect { client.post(path, params, body) }.to raise_error do |error|
expect(error.class.name).to eq(described_class::ApiError.name)
expect(error.message).to include('Internal Server Error')
expect(error.code).to eq(500)
end
end
end
end
end

View File

@@ -0,0 +1,231 @@
require 'rails_helper'
RSpec.describe Crm::Leadsquared::Api::LeadClient do
let(:access_key) { SecureRandom.hex }
let(:secret_key) { SecureRandom.hex }
let(:headers) do
{
'Content-Type': 'application/json',
'x-LSQ-AccessKey': access_key,
'x-LSQ-SecretKey': secret_key
}
end
let(:endpoint_url) { 'https://api.leadsquared.com/v2' }
let(:client) { described_class.new(access_key, secret_key, endpoint_url) }
describe '#search_lead' do
let(:path) { 'LeadManagement.svc/Leads.GetByQuickSearch' }
let(:search_key) { 'test@example.com' }
let(:full_url) { URI.join(endpoint_url, path).to_s }
context 'when search key is missing' do
it 'raises ArgumentError' do
expect { client.search_lead(nil) }
.to raise_error(ArgumentError, 'Search key is required')
end
end
context 'when no leads are found' do
before do
stub_request(:get, full_url)
.with(query: { key: search_key }, headers: headers)
.to_return(
status: 200,
body: [].to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'returns empty array directly' do
response = client.search_lead(search_key)
expect(response).to eq([])
end
end
context 'when leads are found' do
let(:lead_data) do
[{
'ProspectID' => SecureRandom.uuid,
'FirstName' => 'John',
'LastName' => 'Doe',
'EmailAddress' => search_key
}]
end
before do
stub_request(:get, full_url)
.with(query: { key: search_key }, headers: headers, body: anything)
.to_return(
status: 200,
body: lead_data.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'returns lead data array directly' do
response = client.search_lead(search_key)
expect(response).to eq(lead_data)
end
end
end
describe '#create_or_update_lead' do
let(:path) { 'LeadManagement.svc/Lead.CreateOrUpdate' }
let(:full_url) { URI.join(endpoint_url, path).to_s }
let(:lead_data) do
{
'FirstName' => 'John',
'LastName' => 'Doe',
'EmailAddress' => 'john.doe@example.com'
}
end
let(:formatted_lead_data) do
lead_data.map do |key, value|
{
'Attribute' => key,
'Value' => value
}
end
end
context 'when lead data is missing' do
it 'raises ArgumentError' do
expect { client.create_or_update_lead(nil) }
.to raise_error(ArgumentError, 'Lead data is required')
end
end
context 'when lead is successfully created' do
let(:lead_id) { '8e0f69ae-e2ac-40fc-a0cf-827326181c8a' }
let(:success_response) do
{
'Status' => 'Success',
'Message' => {
'Id' => lead_id
}
}
end
before do
stub_request(:post, full_url)
.with(
body: formatted_lead_data.to_json,
headers: headers
)
.to_return(
status: 200,
body: success_response.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'returns lead ID directly' do
response = client.create_or_update_lead(lead_data)
expect(response).to eq(lead_id)
end
end
context 'when request fails' do
let(:error_response) do
{
'Status' => 'Error',
'ExceptionMessage' => 'Error message'
}
end
before do
stub_request(:post, full_url)
.with(
body: formatted_lead_data.to_json,
headers: headers
)
.to_return(
status: 200,
body: error_response.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'raises ApiError' do
expect { client.create_or_update_lead(lead_data) }
.to(raise_error { |error| expect(error.class.name).to eq('Crm::Leadsquared::Api::BaseClient::ApiError') })
end
end
# Add test for update_lead method
describe '#update_lead' do
let(:path) { 'LeadManagement.svc/Lead.Update' }
let(:lead_id) { '8e0f69ae-e2ac-40fc-a0cf-827326181c8a' }
let(:full_url) { URI.join(endpoint_url, "#{path}?leadId=#{lead_id}").to_s }
context 'with missing parameters' do
it 'raises ArgumentError when lead_id is missing' do
expect { client.update_lead(lead_data, nil) }
.to raise_error(ArgumentError, 'Lead ID is required')
end
it 'raises ArgumentError when lead_data is missing' do
expect { client.update_lead(nil, lead_id) }
.to raise_error(ArgumentError, 'Lead data is required')
end
end
context 'when update is successful' do
let(:success_response) do
{
'Status' => 'Success',
'Message' => {
'AffectedRows' => 1
}
}
end
before do
stub_request(:post, full_url)
.with(
body: formatted_lead_data.to_json,
headers: headers
)
.to_return(
status: 200,
body: success_response.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'returns affected rows directly' do
response = client.update_lead(lead_data, lead_id)
expect(response).to eq(1)
end
end
context 'when update fails' do
let(:error_response) do
{
'Status' => 'Error',
'ExceptionMessage' => 'Invalid lead ID'
}
end
before do
stub_request(:post, full_url)
.with(
body: formatted_lead_data.to_json,
headers: headers
)
.to_return(
status: 200,
body: error_response.to_json,
headers: { 'Content-Type' => 'application/json' }
)
end
it 'raises ApiError' do
expect { client.update_lead(lead_data, lead_id) }
.to(raise_error { |error| expect(error.class.name).to eq('Crm::Leadsquared::Api::BaseClient::ApiError') })
end
end
end
end
end