fix: standardize contact import company name
This commit is contained in:
@@ -5,7 +5,7 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
|
||||
sort_on :phone_number, type: :string
|
||||
sort_on :last_activity_at, internal_name: :order_on_last_activity_at, type: :scope, scope_params: [:direction]
|
||||
sort_on :created_at, internal_name: :order_on_created_at, type: :scope, scope_params: [:direction]
|
||||
sort_on :company, internal_name: :order_on_company_name, type: :scope, scope_params: [:direction]
|
||||
sort_on :company_name, internal_name: :order_on_company_name, type: :scope, scope_params: [:direction]
|
||||
sort_on :city, internal_name: :order_on_city, type: :scope, scope_params: [:direction]
|
||||
sort_on :country, internal_name: :order_on_country_name, type: :scope, scope_params: [:direction]
|
||||
|
||||
|
||||
@@ -182,6 +182,7 @@
|
||||
"BROWSER_LANGUAGE": "Browser Language",
|
||||
"MAIL_SUBJECT": "Email Subject",
|
||||
"COUNTRY_NAME": "Country",
|
||||
"COMPANY_NAME": "Company",
|
||||
"REFERER_LINK": "Referrer Link",
|
||||
"ASSIGNEE_NAME": "Assignee",
|
||||
"TEAM_NAME": "Team",
|
||||
|
||||
@@ -74,6 +74,12 @@ export const AUTOMATIONS = {
|
||||
inputType: 'plain_text',
|
||||
filterOperators: OPERATOR_TYPES_6,
|
||||
},
|
||||
{
|
||||
key: 'company_name',
|
||||
name: 'COMPANY_NAME',
|
||||
inputType: 'plain_text',
|
||||
filterOperators: OPERATOR_TYPES_2,
|
||||
},
|
||||
{
|
||||
key: 'labels',
|
||||
name: 'LABELS',
|
||||
@@ -180,6 +186,12 @@ export const AUTOMATIONS = {
|
||||
inputType: 'plain_text',
|
||||
filterOperators: OPERATOR_TYPES_6,
|
||||
},
|
||||
{
|
||||
key: 'company_name',
|
||||
name: 'COMPANY_NAME',
|
||||
inputType: 'plain_text',
|
||||
filterOperators: OPERATOR_TYPES_2,
|
||||
},
|
||||
{
|
||||
key: 'referer',
|
||||
name: 'REFERER_LINK',
|
||||
@@ -314,6 +326,12 @@ export const AUTOMATIONS = {
|
||||
inputType: 'plain_text',
|
||||
filterOperators: OPERATOR_TYPES_6,
|
||||
},
|
||||
{
|
||||
key: 'company_name',
|
||||
name: 'COMPANY_NAME',
|
||||
inputType: 'plain_text',
|
||||
filterOperators: OPERATOR_TYPES_2,
|
||||
},
|
||||
{
|
||||
key: 'assignee_id',
|
||||
name: 'ASSIGNEE_NAME',
|
||||
@@ -460,6 +478,12 @@ export const AUTOMATIONS = {
|
||||
inputType: 'plain_text',
|
||||
filterOperators: OPERATOR_TYPES_6,
|
||||
},
|
||||
{
|
||||
key: 'company_name',
|
||||
name: 'COMPANY_NAME',
|
||||
inputType: 'plain_text',
|
||||
filterOperators: OPERATOR_TYPES_2,
|
||||
},
|
||||
{
|
||||
key: 'team_id',
|
||||
name: 'TEAM_NAME',
|
||||
@@ -590,6 +614,12 @@ export const AUTOMATIONS = {
|
||||
inputType: 'plain_text',
|
||||
filterOperators: OPERATOR_TYPES_6,
|
||||
},
|
||||
{
|
||||
key: 'company_name',
|
||||
name: 'COMPANY_NAME',
|
||||
inputType: 'plain_text',
|
||||
filterOperators: OPERATOR_TYPES_2,
|
||||
},
|
||||
{
|
||||
key: 'team_id',
|
||||
name: 'TEAM_NAME',
|
||||
|
||||
@@ -35,7 +35,7 @@ class AutomationRule < ApplicationRecord
|
||||
scope :active, -> { where(active: true) }
|
||||
|
||||
def conditions_attributes
|
||||
%w[content email country_code status message_type browser_language assignee_id team_id referer city company inbox_id
|
||||
%w[content email country_code status message_type browser_language assignee_id team_id referer city company_name inbox_id
|
||||
mail_subject phone_number priority conversation_language labels private_note]
|
||||
end
|
||||
|
||||
|
||||
@@ -61,11 +61,7 @@ class DataImport::ContactManager
|
||||
def update_contact_attributes(params, contact)
|
||||
contact.name = params[:name] if params[:name].present?
|
||||
contact.additional_attributes ||= {}
|
||||
# The rest of the app (contact model scope, serializer, dashboard UI) reads
|
||||
# `additional_attributes[:company_name]`. Accept either `company` or
|
||||
# `company_name` from the CSV so older import templates keep working.
|
||||
company_name = params[:company_name].presence || params[:company].presence
|
||||
contact.additional_attributes[:company_name] = company_name if company_name.present?
|
||||
contact.additional_attributes[:company_name] = params[:company_name] if params[:company_name].present?
|
||||
contact.additional_attributes[:city] = params[:city] if params[:city].present?
|
||||
contact.assign_attributes(custom_attributes: contact.custom_attributes.merge(params.except(:identifier, :email, :name, :phone_number)))
|
||||
end
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
class RenameCompanyConditionKeyInAutomationRules < ActiveRecord::Migration[7.1]
|
||||
def up
|
||||
migrate_automation_rule_conditions
|
||||
migrate_contact_custom_filter_queries
|
||||
end
|
||||
|
||||
def down; end
|
||||
|
||||
private
|
||||
|
||||
def migrate_automation_rule_conditions
|
||||
AutomationRule.find_each do |rule|
|
||||
conditions = rename_company_attribute_key(rule.conditions)
|
||||
|
||||
next if conditions == rule.conditions
|
||||
|
||||
rule.update_column(:conditions, conditions) # rubocop:disable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
|
||||
def migrate_contact_custom_filter_queries
|
||||
CustomFilter.contact.find_each do |filter|
|
||||
query = filter.query.deep_dup
|
||||
payload = rename_company_attribute_key(query['payload'])
|
||||
next if payload == query['payload']
|
||||
|
||||
query['payload'] = payload
|
||||
filter.update_column(:query, query) # rubocop:disable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
|
||||
def rename_company_attribute_key(conditions)
|
||||
conditions.map do |condition|
|
||||
next condition unless standard_company_condition?(condition)
|
||||
|
||||
condition.merge('attribute_key' => 'company_name')
|
||||
end
|
||||
end
|
||||
|
||||
def standard_company_condition?(condition)
|
||||
condition['attribute_key'] == 'company' &&
|
||||
condition['custom_attribute_type'].blank? &&
|
||||
condition['attribute_model'].in?([nil, '', 'standard'])
|
||||
end
|
||||
end
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2026_04_10_092753) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2026_04_27_094500) do
|
||||
# These extensions should be enabled to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
enable_extension "pg_trgm"
|
||||
|
||||
@@ -167,7 +167,7 @@ contacts:
|
||||
- "not_equal_to"
|
||||
- "contains"
|
||||
- "does_not_contain"
|
||||
company:
|
||||
company_name:
|
||||
attribute_type: "additional_attributes"
|
||||
data_type: "text_case_insensitive"
|
||||
filter_operators:
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
id,name,email,identifier,phone_number,ip_address,custom_attribute_1,custom_attribute_2
|
||||
1,Clarice Uzzell,cuzzell0@mozilla.org,bb4e11cd-0f23-49da-a123-dcc1fec6852c,+498963648018,70.61.11.201,Random-value-1,Random-value-1
|
||||
2,Marieann Creegan,mcreegan1@cornell.edu,e60bab4c-9fbb-47eb-8f75-42025b789c47,+15417543010,168.186.4.241,Random-value0,Random-value0
|
||||
3,Nancey Windibank,nwindibank2@bluehost.com,f793e813-4210-4bf3-a812-711418de25d2,+15417543011,73.44.41.59,Random-value1,Random-value1
|
||||
4,Sibel Stennine,sstennine3@yellowbook.com,d6e35a2d-d093-4437-a577-7df76316b937,+15417543011,115.249.27.155,Random-value2,Random-value2
|
||||
5,Tina O'Lunney,tolunney4@si.edu,3540d40a-5567-4f28-af98-5583a7ddbc56,+15417543011,219.181.212.8,Random-value3,Random-value3
|
||||
6,Quinn Neve,qneve5@army.mil,ba0e1bf0-c74b-41ce-8a2d-0b08fa0e5aa5,+15417543011,231.210.115.166,Random-value4,Random-value4
|
||||
7,Karylin Gaunson,kgaunson6@tripod.com,d24cac79-c81b-4b84-a33e-0441b7c6a981,+15417543011,160.189.41.11,Random-value5,Random-value5
|
||||
8,Jamison Shenton,jshenton7@upenn.edu,29a7a8c0-c7f7-4af9-852f-761b1a784a7a,+15417543011,53.94.18.201,Random-value6,Random-value6
|
||||
9,Gavan Threlfall,gthrelfall8@spotify.com,847d4943-ddb5-47cc-8008-ed5092c675c5,+15417543011,18.87.247.249,Random-value7,Random-value7
|
||||
10,Katina Hemmingway,khemmingway9@ameblo.jp,8f0b5efd-b6a8-4f1e-a1e3-b0ea8c9e3048,+15417543011,25.191.96.124,Random-value8,Random-value8
|
||||
11,Jillian Deinhard,jdeinharda@canalblog.com,bd952787-1b05-411f-9975-b916ec0950cc,+15417543011,11.211.174.93,Random-value9,Random-value9
|
||||
12,Blake Finden,bfindenb@wsj.com,12c95613-e49d-4fa2-86fb-deabb6ebe600,+15417543011,47.26.205.153,Random-value10,Random-value10
|
||||
13,Liane Maxworthy,lmaxworthyc@un.org,36b68e4c-40d6-4e09-bf59-7db3b27b18f0,+15417543011,157.196.34.166,Random-value11,Random-value11
|
||||
14,Martynne Ledley,mledleyd@sourceforge.net,1856bceb-cb36-415c-8ffc-0527f3f750d8,+15417543011,109.231.152.148,Random-value12,Random-value12
|
||||
15,Katharina Ruffli,krufflie@huffingtonpost.com,604de5c9-b154-4279-8978-41fb71f0f773,+15417543011,20.43.146.179,Random-value13,Random-value13
|
||||
16,Tucker Simmance,tsimmancef@bbc.co.uk,0a8fc3a7-4986-4a51-a503-6c7f974c90ad,+15417543011,179.76.226.171,Random-value14,Random-value14
|
||||
17,Wenona Martinson,wmartinsong@census.gov,0e5ea6e3-6824-4e78-a6f5-672847eafa17,+15417543011,92.243.194.160,Random-value15,Random-value15
|
||||
18,Gretna Vedyasov,gvedyasovh@lycos.com,6becf55b-a7b5-48f6-8788-b89cae85b066,+15417543011,25.22.86.101,Random-value16,Random-value16
|
||||
19,Lurline Abdon,labdoni@archive.org,afa9429f-9034-4b06-9efa-980e01906ebf,+15417543011,150.249.116.118,Random-value17,Random-value17
|
||||
20,Fiann Norcliff,fnorcliffj@istockphoto.com,59f72dec-14ba-4d6e-b17c-0d962e69ffac,+15417543011,237.167.197.197,Random-value18,Random-value18
|
||||
21,Zed Linn,zlinnk@phoca.cz,95f7bc56-be92-4c9c-ad58-eff3e63c7bea,+15417543011,88.102.64.113,Random-value19,Random-value19
|
||||
22,Averyl Simyson,asimysonl@livejournal.com,bde1fe59-c9bd-440c-bb39-79fe61dac1d1,+15417543011,141.248.89.29,Random-value20,Random-value20
|
||||
23,Camella Blackadder,cblackadderm@nifty.com,0c981752-5857-487c-b9b5-5d0253df740a,+15417543011,118.123.138.115,Random-value21,Random-value21
|
||||
24,Aurie Spatig,aspatign@printfriendly.com,4cf22bfb-2c3f-41d1-9993-6e3758e457ba,+15417543011,157.45.102.235,Random-value22,Random-value22
|
||||
25,Adrienne Bellard,abellardo@cnn.com,f10f9b8d-38ac-4e17-8a7d-d2e6a055f944,+15417543011,170.73.198.47,Random-value23,Random-value23
|
||||
id,name,email,identifier,phone_number,ip_address,company_name,custom_attribute_1,custom_attribute_2
|
||||
1,Clarice Uzzell,cuzzell0@mozilla.org,bb4e11cd-0f23-49da-a123-dcc1fec6852c,+498963648018,70.61.11.201,Acme Inc,Random-value-1,Random-value-1
|
||||
2,Marieann Creegan,mcreegan1@cornell.edu,e60bab4c-9fbb-47eb-8f75-42025b789c47,+15417543010,168.186.4.241,Acme Inc,Random-value0,Random-value0
|
||||
3,Nancey Windibank,nwindibank2@bluehost.com,f793e813-4210-4bf3-a812-711418de25d2,+15417543011,73.44.41.59,Acme Inc,Random-value1,Random-value1
|
||||
4,Sibel Stennine,sstennine3@yellowbook.com,d6e35a2d-d093-4437-a577-7df76316b937,+15417543011,115.249.27.155,Acme Inc,Random-value2,Random-value2
|
||||
5,Tina O'Lunney,tolunney4@si.edu,3540d40a-5567-4f28-af98-5583a7ddbc56,+15417543011,219.181.212.8,Acme Inc,Random-value3,Random-value3
|
||||
6,Quinn Neve,qneve5@army.mil,ba0e1bf0-c74b-41ce-8a2d-0b08fa0e5aa5,+15417543011,231.210.115.166,Acme Inc,Random-value4,Random-value4
|
||||
7,Karylin Gaunson,kgaunson6@tripod.com,d24cac79-c81b-4b84-a33e-0441b7c6a981,+15417543011,160.189.41.11,Acme Inc,Random-value5,Random-value5
|
||||
8,Jamison Shenton,jshenton7@upenn.edu,29a7a8c0-c7f7-4af9-852f-761b1a784a7a,+15417543011,53.94.18.201,Acme Inc,Random-value6,Random-value6
|
||||
9,Gavan Threlfall,gthrelfall8@spotify.com,847d4943-ddb5-47cc-8008-ed5092c675c5,+15417543011,18.87.247.249,Acme Inc,Random-value7,Random-value7
|
||||
10,Katina Hemmingway,khemmingway9@ameblo.jp,8f0b5efd-b6a8-4f1e-a1e3-b0ea8c9e3048,+15417543011,25.191.96.124,Acme Inc,Random-value8,Random-value8
|
||||
11,Jillian Deinhard,jdeinharda@canalblog.com,bd952787-1b05-411f-9975-b916ec0950cc,+15417543011,11.211.174.93,Acme Inc,Random-value9,Random-value9
|
||||
12,Blake Finden,bfindenb@wsj.com,12c95613-e49d-4fa2-86fb-deabb6ebe600,+15417543011,47.26.205.153,Acme Inc,Random-value10,Random-value10
|
||||
13,Liane Maxworthy,lmaxworthyc@un.org,36b68e4c-40d6-4e09-bf59-7db3b27b18f0,+15417543011,157.196.34.166,Acme Inc,Random-value11,Random-value11
|
||||
14,Martynne Ledley,mledleyd@sourceforge.net,1856bceb-cb36-415c-8ffc-0527f3f750d8,+15417543011,109.231.152.148,Acme Inc,Random-value12,Random-value12
|
||||
15,Katharina Ruffli,krufflie@huffingtonpost.com,604de5c9-b154-4279-8978-41fb71f0f773,+15417543011,20.43.146.179,Acme Inc,Random-value13,Random-value13
|
||||
16,Tucker Simmance,tsimmancef@bbc.co.uk,0a8fc3a7-4986-4a51-a503-6c7f974c90ad,+15417543011,179.76.226.171,Acme Inc,Random-value14,Random-value14
|
||||
17,Wenona Martinson,wmartinsong@census.gov,0e5ea6e3-6824-4e78-a6f5-672847eafa17,+15417543011,92.243.194.160,Acme Inc,Random-value15,Random-value15
|
||||
18,Gretna Vedyasov,gvedyasovh@lycos.com,6becf55b-a7b5-48f6-8788-b89cae85b066,+15417543011,25.22.86.101,Acme Inc,Random-value16,Random-value16
|
||||
19,Lurline Abdon,labdoni@archive.org,afa9429f-9034-4b06-9efa-980e01906ebf,+15417543011,150.249.116.118,Acme Inc,Random-value17,Random-value17
|
||||
20,Fiann Norcliff,fnorcliffj@istockphoto.com,59f72dec-14ba-4d6e-b17c-0d962e69ffac,+15417543011,237.167.197.197,Acme Inc,Random-value18,Random-value18
|
||||
21,Zed Linn,zlinnk@phoca.cz,95f7bc56-be92-4c9c-ad58-eff3e63c7bea,+15417543011,88.102.64.113,Acme Inc,Random-value19,Random-value19
|
||||
22,Averyl Simyson,asimysonl@livejournal.com,bde1fe59-c9bd-440c-bb39-79fe61dac1d1,+15417543011,141.248.89.29,Acme Inc,Random-value20,Random-value20
|
||||
23,Camella Blackadder,cblackadderm@nifty.com,0c981752-5857-487c-b9b5-5d0253df740a,+15417543011,118.123.138.115,Acme Inc,Random-value21,Random-value21
|
||||
24,Aurie Spatig,aspatign@printfriendly.com,4cf22bfb-2c3f-41d1-9993-6e3758e457ba,+15417543011,157.45.102.235,Acme Inc,Random-value22,Random-value22
|
||||
25,Adrienne Bellard,abellardo@cnn.com,f10f9b8d-38ac-4e17-8a7d-d2e6a055f944,+15417543011,170.73.198.47,Acme Inc,Random-value23,Random-value23
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
id,first_name,last_name,email,gender,ip_address,identifier,phone_number,company
|
||||
id,first_name,last_name,email,gender,ip_address,identifier,phone_number,company_name
|
||||
1,Clarice,Uzzell,cuzzell0@mozilla.org,Genderfluid,70.61.11.201,bb4e11cd-0f23-49da-a123-dcc1fec6852c,918080808080,My Company Name
|
||||
2,Marieann,Creegan,mcreegan1@cornell.edu,Genderfluid,168.186.4.241,e60bab4c-9fbb-47eb-8f75-42025b789c47,+918080808081
|
||||
3,Nancey,Windibank,nwindibank2@bluehost.com,Agender,73.44.41.59,f793e813-4210-4bf3-a812-711418de25d2,+918080808082
|
||||
|
||||
|
@@ -101,7 +101,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
end
|
||||
|
||||
it 'returns all contacts with company name desc order' do
|
||||
get "/api/v1/accounts/#{account.id}/contacts?include_contact_inboxes=false&sort=-company",
|
||||
get "/api/v1/accounts/#{account.id}/contacts?include_contact_inboxes=false&sort=-company_name",
|
||||
headers: admin.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
@@ -112,7 +112,7 @@ RSpec.describe 'Contacts API', type: :request do
|
||||
end
|
||||
|
||||
it 'returns all contacts with company name asc order with null values at last' do
|
||||
get "/api/v1/accounts/#{account.id}/contacts?include_contact_inboxes=false&sort=-company",
|
||||
get "/api/v1/accounts/#{account.id}/contacts?include_contact_inboxes=false&sort=-company_name",
|
||||
headers: admin.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
|
||||
@@ -43,17 +43,6 @@ RSpec.describe DataImportJob do
|
||||
expect(contact).to be_truthy
|
||||
expect(contact['additional_attributes']['company_name']).to eq('My Company Name')
|
||||
end
|
||||
|
||||
it 'stores the company_name CSV column into additional_attributes[:company_name]' do
|
||||
csv_data = [
|
||||
%w[id name email phone_number company_name],
|
||||
['1', 'Clarice Uzzell', 'cuzzell0@mozilla.org', '918080808080', 'Acmecorp']
|
||||
]
|
||||
import = create(:data_import, import_file: generate_csv_file(csv_data))
|
||||
described_class.perform_now(import)
|
||||
contact = Contact.find_by(phone_number: '+918080808080')
|
||||
expect(contact.additional_attributes['company_name']).to eq('Acmecorp')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the data contains errors' do
|
||||
@@ -121,7 +110,7 @@ RSpec.describe DataImportJob do
|
||||
context 'when the data contains existing records' do
|
||||
let(:existing_data) do
|
||||
[
|
||||
%w[id name email phone_number company],
|
||||
%w[id name email phone_number company_name],
|
||||
['1', 'Clarice Uzzell', 'cuzzell0@mozilla.org', '918080808080', 'Acmecorp'],
|
||||
['2', 'Marieann Creegan', 'mcreegan1@cornell.edu', '+918080808081', 'Acmecorp'],
|
||||
['3', 'Nancey Windibank', 'nwindibank2@bluehost.com', '+918080808082', 'Acmecorp']
|
||||
@@ -143,7 +132,7 @@ RSpec.describe DataImportJob do
|
||||
expect(contact).to be_present
|
||||
expect(contact.phone_number).to eq("+#{csv_data[0]['phone_number']}")
|
||||
expect(contact.name).to eq((csv_data[0]['name']).to_s)
|
||||
expect(contact.additional_attributes['company_name']).to eq((csv_data[0]['company']).to_s)
|
||||
expect(contact.additional_attributes['company_name']).to eq((csv_data[0]['company_name']).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -160,7 +149,7 @@ RSpec.describe DataImportJob do
|
||||
expect(contact).to be_present
|
||||
expect(contact.email).to eq(csv_data[0]['email'])
|
||||
expect(contact.name).to eq((csv_data[0]['name']).to_s)
|
||||
expect(contact.additional_attributes['company_name']).to eq((csv_data[0]['company']).to_s)
|
||||
expect(contact.additional_attributes['company_name']).to eq((csv_data[0]['company_name']).to_s)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -182,7 +171,9 @@ RSpec.describe DataImportJob do
|
||||
|
||||
context 'when the CSV file is invalid' do
|
||||
let(:invalid_csv_content) do
|
||||
"id,name,email,phone_number,company\n1,\"Clarice Uzzell,\"missing_quote,918080808080,Acmecorp\n2,Marieann Creegan,,+918080808081,Acmecorp"
|
||||
"id,name,email,phone_number,company_name\n" \
|
||||
"1,\"Clarice Uzzell,\"missing_quote,918080808080,Acmecorp\n" \
|
||||
'2,Marieann Creegan,,+918080808081,Acmecorp'
|
||||
end
|
||||
|
||||
before do
|
||||
|
||||
@@ -67,7 +67,7 @@ describe AutomationRuleListener do
|
||||
describe '#conversation_updated with contacts attributes' do
|
||||
before do
|
||||
conversation.contact.update!(custom_attributes: { customer_type: 'platinum', signed_in_at: '2022-01-19' },
|
||||
additional_attributes: { 'company': 'Marvel' })
|
||||
additional_attributes: { 'company_name' => 'Marvel' })
|
||||
|
||||
automation_rule.update!(
|
||||
event_name: 'conversation_updated',
|
||||
@@ -75,7 +75,7 @@ describe AutomationRuleListener do
|
||||
description: 'Add labels, assign team after conversation updated',
|
||||
conditions: [
|
||||
{
|
||||
attribute_key: 'company',
|
||||
attribute_key: 'company_name',
|
||||
filter_operator: 'equal_to',
|
||||
values: ['Marvel'],
|
||||
query_operator: 'AND'
|
||||
@@ -314,11 +314,11 @@ describe AutomationRuleListener do
|
||||
before do
|
||||
automation_rule.update!(
|
||||
event_name: 'conversation_updated',
|
||||
name: 'Call actions conversation updated when company changed from DC to Marvel',
|
||||
name: 'Call actions conversation updated when company name changed from DC to Marvel',
|
||||
description: 'Add labels, assign team after conversation updated',
|
||||
conditions: [
|
||||
{
|
||||
attribute_key: 'company',
|
||||
attribute_key: 'company_name',
|
||||
filter_operator: 'attribute_changed',
|
||||
values: { from: ['DC'], to: ['Marvel'] },
|
||||
query_operator: 'AND'
|
||||
@@ -336,7 +336,7 @@ describe AutomationRuleListener do
|
||||
|
||||
let!(:event) do
|
||||
Events::Base.new('conversation_updated', Time.zone.now, { conversation: conversation, changed_attributes: {
|
||||
company: %w[DC Marvel]
|
||||
company_name: %w[DC Marvel]
|
||||
} })
|
||||
end
|
||||
|
||||
@@ -355,7 +355,7 @@ describe AutomationRuleListener do
|
||||
automation_rule.update!(
|
||||
conditions: [
|
||||
{
|
||||
attribute_key: 'company',
|
||||
attribute_key: 'company_name',
|
||||
filter_operator: 'attribute_changed',
|
||||
values: { from: ['DC'], to: ['Marvel'] },
|
||||
query_operator: 'OR'
|
||||
@@ -393,7 +393,7 @@ describe AutomationRuleListener do
|
||||
it 'when automation rule is triggers, it will not assign team on attribute_changed values' do
|
||||
conversation.update(status: :snoozed)
|
||||
event = Events::Base.new('conversation_updated', Time.zone.now, { conversation: conversation,
|
||||
changed_attributes: { company: %w[Marvel DC] } })
|
||||
changed_attributes: { company_name: %w[Marvel DC] } })
|
||||
|
||||
expect(conversation.team_id).not_to eq(team.id)
|
||||
|
||||
@@ -517,7 +517,7 @@ describe AutomationRuleListener do
|
||||
{ attribute_key: 'team_id', filter_operator: 'equal_to', values: [team.id], query_operator: 'AND' }.with_indifferent_access,
|
||||
{ attribute_key: 'message_type', filter_operator: 'equal_to', values: ['incoming'], query_operator: 'AND' }.with_indifferent_access,
|
||||
{ attribute_key: 'email', filter_operator: 'contains', values: ['example.com'], query_operator: 'AND' }.with_indifferent_access,
|
||||
{ attribute_key: 'company', filter_operator: 'equal_to', values: ['Marvel'], query_operator: nil }.with_indifferent_access
|
||||
{ attribute_key: 'company_name', filter_operator: 'equal_to', values: ['Marvel'], query_operator: nil }.with_indifferent_access
|
||||
],
|
||||
actions: [
|
||||
{ 'action_name' => 'send_message', 'action_params' => ['Send this message.'] },
|
||||
@@ -525,7 +525,7 @@ describe AutomationRuleListener do
|
||||
]
|
||||
)
|
||||
conversation.update!(team_id: team.id)
|
||||
conversation.contact.update!(email: 'tj@example.com', additional_attributes: { 'company': 'Marvel' })
|
||||
conversation.contact.update!(email: 'tj@example.com', additional_attributes: { 'company_name' => 'Marvel' })
|
||||
end
|
||||
|
||||
let!(:message) { create(:message, account: account, conversation: conversation, message_type: 'incoming') }
|
||||
@@ -572,7 +572,7 @@ describe AutomationRuleListener do
|
||||
context 'when rule does not match' do
|
||||
before do
|
||||
conversation.update!(team_id: team.id)
|
||||
conversation.contact.update!(email: 'tj@ex.com', additional_attributes: { 'company': 'DC' })
|
||||
conversation.contact.update!(email: 'tj@ex.com', additional_attributes: { 'company_name' => 'DC' })
|
||||
end
|
||||
|
||||
let!(:message) { create(:message, account: account, conversation: conversation, message_type: 'outgoing') }
|
||||
@@ -600,7 +600,7 @@ describe AutomationRuleListener do
|
||||
conditions: [
|
||||
{ attribute_key: 'team_id', filter_operator: 'equal_to', values: [team.id], query_operator: 'AND' }.with_indifferent_access,
|
||||
{ attribute_key: 'email', filter_operator: 'contains', values: ['example.com'], query_operator: 'AND' }.with_indifferent_access,
|
||||
{ attribute_key: 'company', filter_operator: 'equal_to', values: ['Marvel'], query_operator: nil }.with_indifferent_access
|
||||
{ attribute_key: 'company_name', filter_operator: 'equal_to', values: ['Marvel'], query_operator: nil }.with_indifferent_access
|
||||
],
|
||||
actions: [
|
||||
{ 'action_name' => 'send_message', 'action_params' => ['Send this message.'] },
|
||||
@@ -608,7 +608,7 @@ describe AutomationRuleListener do
|
||||
]
|
||||
)
|
||||
conversation.update!(team_id: team.id)
|
||||
conversation.contact.update!(email: 'tj@example.com', additional_attributes: { 'company': 'Marvel' })
|
||||
conversation.contact.update!(email: 'tj@example.com', additional_attributes: { 'company_name' => 'Marvel' })
|
||||
end
|
||||
|
||||
let!(:message) { create(:message, account: account, conversation: conversation, message_type: 'incoming') }
|
||||
@@ -633,7 +633,7 @@ describe AutomationRuleListener do
|
||||
context 'when rule does not match' do
|
||||
before do
|
||||
conversation.update!(team_id: team.id)
|
||||
conversation.contact.update!(email: 'tj@ex.com', additional_attributes: { 'company': 'DC' })
|
||||
conversation.contact.update!(email: 'tj@ex.com', additional_attributes: { 'company_name' => 'DC' })
|
||||
end
|
||||
|
||||
let!(:message) { create(:message, account: account, conversation: conversation, message_type: 'outgoing') }
|
||||
|
||||
Reference in New Issue
Block a user