Skip to content

Commit

Permalink
Merge pull request #479 from slovensko-digital/GO-83/index_template_m…
Browse files Browse the repository at this point in the history
…essage_drafts_content

GO-83 Save templates MessageDraft content to HTML visualization in order to be searchable
  • Loading branch information
luciajanikova authored Oct 24, 2024
2 parents be6639d + 8dfb31c commit 98ba735
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models/upvs/message_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def build_message_from_template(message)
filled_content.gsub!(template_item[:placeholder], message.metadata['data'][template_item[:name]].to_s)
end

message.update(
html_visualization: message.metadata["data"].map { _1.join(": ") }.join(", ")
) if message.metadata["data"]

if message.form_object.message_object_datum
message.form_object.message_object_datum.update(
blob: filled_content
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/message_object_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ draft_two:
message_object: ssd_main_general_draft_two_form
blob: <GeneralAgenda xmlns="http://schemas.gov.sk/form/App.GeneralAgenda/1.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><subject>predmet</subject><text>text</text></GeneralAgenda>

empty_draft:
message_object: ssd_main_empty_draft_form
blob: <GeneralAgenda xmlns="http://schemas.gov.sk/form/App.GeneralAgenda/1.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><subject></subject><text></text></GeneralAgenda>

fs_one:
message_object: ssd_main_fs_one_form
blob: <n0:ElectronicOfficialDocument xmlns:n0="http://schemas.gov.sk/form/42499500.FS_EUD_v1_0.sk/1.6"> <n0:Sender> <n0:PersonData> <n0:CorporateBody> <n0:FinancialAdministrationAuthority>Daňový úrad Bratislava</n0:FinancialAdministrationAuthority> </n0:CorporateBody> <n0:PhysicalAddress> <n0:AddressLine>Ševčenkova 32, 850 00 Bratislava</n0:AddressLine> </n0:PhysicalAddress> </n0:PersonData> </n0:Sender> <n0:Document> <n0:DocumentReference>000000000/2022</n0:DocumentReference> <n0:ContactPerson>Mgr. X Y</n0:ContactPerson> <n0:PhoneNumber>02/00000000</n0:PhoneNumber> <n0:EmailAddress>[email protected]</n0:EmailAddress> <n0:IssuePlace>Bratislava</n0:IssuePlace> <n0:IssueDate>2022-04-19</n0:IssueDate> <n0:Subject>Rozhodnutie</n0:Subject> </n0:Document></n0:ElectronicOfficialDocument>
6 changes: 6 additions & 0 deletions test/fixtures/message_objects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,9 @@ ssd_main_draft_to_be_signed4_draft_form:
name: MyString
mimetype: MyString
object_type: FORM

ssd_main_empty_draft_form:
message: ssd_main_empty_draft
name: MyString
mimetype: MyString
object_type: FORM
7 changes: 7 additions & 0 deletions test/fixtures/message_threads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ ssd_main_draft_to_be_signed4:
delivered_at: 2023-05-18 18:15:22
last_message_delivered_at: 2023-05-18 18:16:22

ssd_main_empty_draft:
box: ssd_main
title: Empty Draft
original_title: MyString
delivered_at: 2023-05-18 16:05:00
last_message_delivered_at: 2023-05-18 16:05:00

solver_main_general_agenda:
box: solver_main
title: General agenda Solver
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/message_threads_tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,7 @@ ssd_main_draft_to_be_signed4_ssd_signature_requested:
ssd_main_draft_to_be_signed4_ssd_signers_signature_requested:
message_thread: ssd_main_draft_to_be_signed4
tag: ssd_signers_signature_requested

ssd_main_empty_draft_ssd_basic_user_drafts:
message_thread: ssd_main_empty_draft
tag: ssd_basic_user_drafts
14 changes: 14 additions & 0 deletions test/fixtures/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ ssd_main_draft_to_be_signed4_draft:
status: created
author: basic

ssd_main_empty_draft:
type: Upvs::MessageDraft
uuid: <%= SecureRandom.uuid %>
title: Všeobecná agenda
delivered_at: 2023-05-18 16:05:00
thread: ssd_main_empty_draft
replyable: false
metadata:
status: created
template_id: 2
recipient_uri: ico://sk/83369723
correlation_id: <%= SecureRandom.uuid %>
author: basic

solver_main_delivery_notification_one:
uuid: bbff2617-3430-44c6-b827-519059ff1e90
title: Authorized Delivery notification
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/tag_groups.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

drafts_basic_user:
tag: ssd_basic_user_drafts
group: ssd_basic_user

finance_basic_user:
tag: ssd_finance
group: ssd_basic_user
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ solver_everything:
visible: false
tenant: solver

solver_basic_user_drafts:
ssd_basic_user_drafts:
name: Drafts-Basic user
owner: basic
type: DraftTag
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/upvs/message_templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ message_reply:
type: Upvs::MessageTemplate

general_agenda:
id: 2
content: <GeneralAgenda xmlns="http://schemas.gov.sk/form/App.GeneralAgenda/1.9">
<subject>{{ Predmet:text_field }}</subject>
<text>{{ Text:text_area }}</text>
Expand Down
53 changes: 53 additions & 0 deletions test/system/message_drafts_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,59 @@
require "application_system_test_case"

class MessageDraftsTest < ApplicationSystemTestCase
setup do
Searchable::MessageThread.reindex_all

silence_warnings do
@old_value = MessageThreadCollection.const_get("PER_PAGE")
MessageThreadCollection.const_set("PER_PAGE", 1)
end

sign_in_as(:basic)
end

teardown do
silence_warnings do
MessageThreadCollection.const_set("PER_PAGE", @old_value)
end
end

test "user can create message draft as reply on replyable message" do
end

test "templated message draft content is searchable" do
message = messages(:ssd_main_empty_draft)
thread = message_threads(:ssd_main_empty_draft)

visit message_thread_path thread

within "#body_upvs_message_draft_#{message.id}_form" do
fill_in "message_draft_Text", with: "Pozdrav zo Slovensko.Digital! :)"
fill_in "message_draft_Predmet", with: "Pozdravovacia sprava"
end

assert_text "Zmeny boli uložené"

GoodJob.perform_inline

# Search the draft content keywords
visit message_threads_path

assert_no_selector "#next_page_area"

fill_in "search", with: "Slovensko.Digital"
find("#search").send_keys(:enter)

assert_no_selector "#next_page_area"

thread_general = message_threads(:ssd_main_general)
thread_issue = message_threads(:ssd_main_issue)

within_thread_in_listing(thread) do
assert_text "Slovensko.Digital"
end

refute_selector(thread_in_listing_selector(thread_general))
refute_selector(thread_in_listing_selector(thread_issue))
end
end

0 comments on commit 98ba735

Please sign in to comment.