From 4d620372647b2f00c4c0e9409e694a9da627a456 Mon Sep 17 00:00:00 2001 From: luciajanikova <19lucia99@gmail.com> Date: Wed, 11 Dec 2024 17:09:40 +0100 Subject: [PATCH] Update content_match? conditions in Automation --- app/models/automation/condition.rb | 2 +- test/fixtures/automation/actions.yml | 5 +++++ test/fixtures/automation/conditions.yml | 5 +++++ test/fixtures/automation/rules.yml | 7 +++++++ test/fixtures/govbox/messages.yml | 25 +++++++++++++++++++++++++ test/fixtures/tags.yml | 6 ++++++ test/models/automation/rule_test.rb | 11 +++++++++++ 7 files changed, 60 insertions(+), 1 deletion(-) diff --git a/app/models/automation/condition.rb b/app/models/automation/condition.rb index 1d3a85ffa..eed0db15e 100644 --- a/app/models/automation/condition.rb +++ b/app/models/automation/condition.rb @@ -120,7 +120,7 @@ def content_match?(object, value) if object.pdf? pdf_match?(object.content, value) elsif object.xml? - object.content.match?(value) + Nokogiri::XML(object.content, nil, 'UTF-8').to_s.match?(value) end end diff --git a/test/fixtures/automation/actions.yml b/test/fixtures/automation/actions.yml index c96ba8e30..19406586c 100644 --- a/test/fixtures/automation/actions.yml +++ b/test/fixtures/automation/actions.yml @@ -32,3 +32,8 @@ six: automation_rule: five type: Automation::ChangeMessageThreadTitleAction value: "New title - {{title}}" + +seven: + automation_rule: six + type: Automation::AddMessageThreadTagAction + action_object: ssd_crac_success (Tag) diff --git a/test/fixtures/automation/conditions.yml b/test/fixtures/automation/conditions.yml index 2007db803..f52bf7880 100644 --- a/test/fixtures/automation/conditions.yml +++ b/test/fixtures/automation/conditions.yml @@ -31,3 +31,8 @@ six: automation_rule: five type: Automation::AttachmentContentContainsCondition value: "Test\\s*string" + +seven: + automation_rule: six + type: Automation::AttachmentContentContainsCondition + value: "úspešne spracovaná" diff --git a/test/fixtures/automation/rules.yml b/test/fixtures/automation/rules.yml index f3d16276f..8817dfb85 100644 --- a/test/fixtures/automation/rules.yml +++ b/test/fixtures/automation/rules.yml @@ -29,3 +29,10 @@ five: tenant: ssd name: AttachmentContentContainsCondition trigger_event: message_created + +six: + user: basic + tenant: ssd + name: AttachmentContentContainsCondition2 + trigger_event: message_created + diff --git a/test/fixtures/govbox/messages.yml b/test/fixtures/govbox/messages.yml index 1ba47166f..ba8f38012 100644 --- a/test/fixtures/govbox/messages.yml +++ b/test/fixtures/govbox/messages.yml @@ -274,3 +274,28 @@ ssd_general_agenda_with_lorem_pdf: signed: true class: MyClass content: Dummy + +ssd_crac: + message_id: <%= SecureRandom.uuid %> + correlation_id: <%= SecureRandom.uuid %> + edesk_message_id: 100 + delivered_at: <%= DateTime.current %> + edesk_class: TEST + folder: ssd_one + payload: + message_id: <%= SecureRandom.uuid %> + subject: MySubject + sender_name: MySender + sender_uri: MySenderURI + recipient_name: MyRecipient + delivered_at: <%= DateTime.current.to_s %> + original_html: MyHtml + objects: + - name: form + mime_type: application/x-eform-xml + signed: false + class: FORM + content: + Spracovanie požiadavky v registri autentifikačných certifikátov + Žiadosť o zmenu zápisu autentifikačného certifikátu v registri autentifikačných certifikátov bola úspešne spracovaná 29.11.2024 13:00. + diff --git a/test/fixtures/tags.yml b/test/fixtures/tags.yml index b8c4d4775..06947b6bf 100644 --- a/test/fixtures/tags.yml +++ b/test/fixtures/tags.yml @@ -74,6 +74,12 @@ ssd_print: visible: true tenant: ssd +ssd_crac_success: + name: CRAC vybavené + type: SimpleTag + visible: true + tenant: ssd + ssd_signature_requested: name: Na podpis type: SignatureRequestedTag diff --git a/test/models/automation/rule_test.rb b/test/models/automation/rule_test.rb index 4f01ce7fa..0a5b118ae 100644 --- a/test/models/automation/rule_test.rb +++ b/test/models/automation/rule_test.rb @@ -68,4 +68,15 @@ class Automation::RuleTest < ActiveSupport::TestCase assert_includes message.thread.tags, tags(:ssd_print) assert_not_includes message.tags, tags(:ssd_print) end + + test 'should run an automation on message created AttachmentContainsConidition AddMessageThreadTagAction' do + govbox_message = govbox_messages(:ssd_crac) + + Govbox::Message.create_message_with_thread!(govbox_message) + travel_to(15.minutes.from_now) { GoodJob.perform_inline } + message = Message.last + + assert_includes message.thread.tags, tags(:ssd_crac_success) + assert_not_includes message.tags, tags(:ssd_crac_success) + end end