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:
Muhsin Keloth
2026-01-16 10:16:00 +04:00
committed by GitHub
parent d451615811
commit 96b5780ea7
4 changed files with 88 additions and 105 deletions

View File

@@ -88,6 +88,25 @@ describe CsatSurveyService do
expect(MessageTemplates::Template::CsatSurvey).not_to have_received(:new)
expect(Conversations::ActivityMessageJob).not_to have_received(:perform_later)
end
context 'when survey rules block sending' do
before do
inbox.update(csat_config: {
'survey_rules' => {
'operator' => 'does_not_contain',
'values' => ['bot-detectado']
}
})
conversation.update(label_list: ['bot-detectado'])
end
it 'does not send CSAT' do
service.perform
expect(MessageTemplates::Template::CsatSurvey).not_to have_received(:new)
expect(conversation.messages.where(content_type: :input_csat)).to be_empty
end
end
end
context 'when it is a WhatsApp channel' do
@@ -306,6 +325,29 @@ describe CsatSurveyService do
expect(MessageTemplates::Template::CsatSurvey).not_to have_received(:new)
end
end
context 'when survey rules block sending' do
before do
whatsapp_inbox.update(csat_config: {
'template' => { 'name' => 'customer_survey_template', 'language' => 'en' },
'message' => 'Please rate your experience',
'survey_rules' => {
'operator' => 'does_not_contain',
'values' => ['bot-detectado']
}
})
whatsapp_conversation.update(label_list: ['bot-detectado'])
end
it 'does not call WhatsApp template or create a CSAT message' do
expect(mock_provider_service).not_to receive(:get_template_status)
expect(mock_provider_service).not_to receive(:send_template)
whatsapp_service.perform
expect(whatsapp_conversation.messages.where(content_type: :input_csat)).to be_empty
end
end
end
end