Skip to content

Commit

Permalink
Update content_match? conditions in Automation
Browse files Browse the repository at this point in the history
  • Loading branch information
luciajanikova committed Dec 11, 2024
1 parent 63f8e3f commit 4d62037
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/automation/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/automation/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 5 additions & 0 deletions test/fixtures/automation/conditions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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á"
7 changes: 7 additions & 0 deletions test/fixtures/automation/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ five:
tenant: ssd
name: AttachmentContentContainsCondition
trigger_event: message_created

six:
user: basic
tenant: ssd
name: AttachmentContentContainsCondition2
trigger_event: message_created

25 changes: 25 additions & 0 deletions test/fixtures/govbox/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <ns6:InformationMessage xmlns:ns6="http://schemas.gov.sk/form/G2G.InformationMessage/1.3">
<ns6:Subject>Spracovanie po&#x17E;iadavky v registri autentifika&#x10D;n&#xFD;ch certifik&#xE1;tov</ns6:Subject>
<ns6:Text>&#x17D;iados&#x165; o zmenu z&#xE1;pisu autentifika&#x10D;n&#xE9;ho certifik&#xE1;tu v registri autentifika&#x10D;n&#xFD;ch certifik&#xE1;tov bola &#xFA;spe&#x161;ne spracovan&#xE1; 29.11.2024 13:00.</ns6:Text>
</ns6:InformationMessage>
6 changes: 6 additions & 0 deletions test/fixtures/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/models/automation/rule_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4d62037

Please sign in to comment.