fix: Respect survey label rules for WhatsApp CSAT template (#13285)
Ensure CSAT survey label rules are evaluated once in CsatSurveyService before any channel-specific sending (including WhatsApp/Twilio templates), remove the duplicated rule check from the template builder, and cover the blocking-label scenario in service specs while simplifying the template specs accordingly. Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -17,83 +17,24 @@ describe MessageTemplates::Template::CsatSurvey do
|
||||
expect(conversation.messages.template.first.content_type).to eq('input_csat')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#perform with contains operator' do
|
||||
let(:csat_config) do
|
||||
{
|
||||
'display_type' => 'emoji',
|
||||
'message' => 'Please rate your experience',
|
||||
'survey_rules' => {
|
||||
'operator' => 'contains',
|
||||
'values' => %w[support help]
|
||||
context 'when csat config is provided' do
|
||||
let(:csat_config) do
|
||||
{
|
||||
'display_type' => 'star',
|
||||
'message' => 'Please rate your experience'
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
inbox.update(csat_config: csat_config)
|
||||
end
|
||||
|
||||
context 'when conversation has matching labels' do
|
||||
it 'creates a CSAT survey message' do
|
||||
conversation.update(label_list: %w[support urgent])
|
||||
before { inbox.update(csat_config: csat_config) }
|
||||
|
||||
it 'creates a CSAT message with configured attributes' do
|
||||
service.perform
|
||||
|
||||
expect(conversation.messages.template.count).to eq(1)
|
||||
message = conversation.messages.template.first
|
||||
message = conversation.messages.template.last
|
||||
expect(message.content_type).to eq('input_csat')
|
||||
expect(message.content).to eq('Please rate your experience')
|
||||
expect(message.content_attributes['display_type']).to eq('emoji')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when conversation has no matching labels' do
|
||||
it 'does not create a CSAT survey message' do
|
||||
conversation.update(label_list: %w[billing-support payment])
|
||||
|
||||
service.perform
|
||||
|
||||
expect(conversation.messages.template.count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#perform with does_not_contain operator' do
|
||||
let(:csat_config) do
|
||||
{
|
||||
'display_type' => 'emoji',
|
||||
'message' => 'Please rate your experience',
|
||||
'survey_rules' => {
|
||||
'operator' => 'does_not_contain',
|
||||
'values' => %w[support help]
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
before do
|
||||
inbox.update(csat_config: csat_config)
|
||||
end
|
||||
|
||||
context 'when conversation does not have matching labels' do
|
||||
it 'creates a CSAT survey message' do
|
||||
conversation.update(label_list: %w[billing payment])
|
||||
|
||||
service.perform
|
||||
|
||||
expect(conversation.messages.template.count).to eq(1)
|
||||
expect(conversation.messages.template.first.content_type).to eq('input_csat')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when conversation has matching labels' do
|
||||
it 'does not create a CSAT survey message' do
|
||||
conversation.update(label_list: %w[support urgent])
|
||||
|
||||
service.perform
|
||||
|
||||
expect(conversation.messages.template.count).to eq(0)
|
||||
expect(message.content_attributes['display_type']).to eq('star')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user