Browse Source

Fixes #5364 - Searching for a ticket with a keyword from an checklist item is not working

Mantas Masalskis 5 months ago
parent
commit
1d542d1b31
2 changed files with 46 additions and 0 deletions
  1. 17 0
      app/models/ticket/search_index.rb
  2. 29 0
      spec/requests/search_spec.rb

+ 17 - 0
app/models/ticket/search_index.rb

@@ -14,6 +14,9 @@ module Ticket::SearchIndex
     # mentions
     attributes['mention_user_ids'] = mentions.pluck(:user_id)
 
+    # checklists
+    add_checklist(attributes)
+
     # current payload size
     total_size_current = 0
 
@@ -109,4 +112,18 @@ module Ticket::SearchIndex
     false
   end
 
+  def add_checklist(attributes)
+    return if !checklist
+
+    attrs = {}
+
+    attrs['name'] = checklist.name if checklist.name.present?
+
+    items = checklist.items.pluck(:text).compact_blank
+    attrs['items'] = items if items.present?
+
+    return if attrs.blank?
+
+    attributes['checklist'] = attrs
+  end
 end

+ 29 - 0
spec/requests/search_spec.rb

@@ -378,6 +378,35 @@ RSpec.describe 'Search', type: :request do
       expect(json_response).to be_truthy
       expect(json_response['assets']['Ticket'][ticket1.id.to_s]).to be_truthy
     end
+
+    it 'does find the ticket by the checklist name', current_user_id: 1 do
+      authenticated_as(agent)
+
+      ticket1.create_checklist! name: 'chcklst name'
+      perform_enqueued_jobs
+      SearchIndexBackend.refresh
+
+      post '/api/v1/search/Ticket', params: { query: 'chcklst' }, as: :json
+      expect(response).to have_http_status(:ok)
+      expect(json_response).to be_a(Hash)
+      expect(json_response).to be_truthy
+      expect(json_response['assets']['Ticket'][ticket1.id.to_s]).to be_truthy
+    end
+
+    it 'does find the ticket by a checklist entry', current_user_id: 1 do
+      authenticated_as(agent)
+
+      ticket1.create_checklist!
+      ticket1.checklist.items.create! text: 'checklist entry'
+      perform_enqueued_jobs
+      SearchIndexBackend.refresh
+
+      post '/api/v1/search/Ticket', params: { query: 'checklist entry' }, as: :json
+      expect(response).to have_http_status(:ok)
+      expect(json_response).to be_a(Hash)
+      expect(json_response).to be_truthy
+      expect(json_response['assets']['Ticket'][ticket1.id.to_s]).to be_truthy
+    end
   end
 
   describe 'Assign user to multiple organizations #1573' do