Skip to content

Commit

Permalink
Merge pull request #526 from slovensko-digital/GO-166/update_content_…
Browse files Browse the repository at this point in the history
…match_conditions_is_automation

GO-166 Update content_match? conditions in Automation
  • Loading branch information
luciajanikova authored Dec 12, 2024
2 parents f8ea9d3 + 9822c39 commit 240a511
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/automation/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def content_match?(object, value)
if object.pdf?
pdf_match?(object.content, value)
elsif object.xml?
object.content.match?(value)
# TODO: fix encoding when saving content to DB
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 240a511

Please sign in to comment.