diff --git a/app/models/govbox/message.rb b/app/models/govbox/message.rb index 4f78bd5e..ccf41f77 100644 --- a/app/models/govbox/message.rb +++ b/app/models/govbox/message.rb @@ -149,17 +149,17 @@ def self.add_upvs_related_tags(message, govbox_message) def self.migrate_tags_from_draft(message, tags_to_migrate) tags_to_migrate[:objects].each do |object_data| object = message.objects.find_by(uuid: object_data[:uuid]) - object_data[:tags].each do |object_tag_id| - object&.assign_tag(Tag.find(object_tag_id)) + object_data[:tags].each do |object_tag| + object&.assign_tag(object_tag) end end - tags_to_migrate[:message].each do |message_tag_id| - message.tags.add_cascading_tag(Tag.find(message_tag_id)) + tags_to_migrate[:message].each do |message_tag| + message.tags.add_cascading_tag(message_tag) end - tags_to_migrate[:thread].each do |thread_tag_id| - message.thread.assign_tag(Tag.find(thread_tag_id)) + tags_to_migrate[:thread].each do |thread_tag| + message.thread.assign_tag(thread_tag) end end diff --git a/app/models/message_draft.rb b/app/models/message_draft.rb index 15bb90c4..cfa63f95 100644 --- a/app/models/message_draft.rb +++ b/app/models/message_draft.rb @@ -85,11 +85,11 @@ def tags_to_migrate_to_message migration_list[:objects] = objects.map do |object| { uuid: object.uuid, - tags: object.tags.signed.map(&:id) + tags: object.tags.signed.to_a } if object.tags.signed.any? end.compact - migration_list[:message] = tags.simple.or(tags.signed).map(&:id) - migration_list[:thread] = (thread.tags.simple + thread.tags.signed).map(&:id) + migration_list[:message] = tags.simple.or(tags.signed).to_a + migration_list[:thread] = (thread.tags.simple + thread.tags.signed).to_a migration_list end diff --git a/test/fixtures/govbox/messages.yml b/test/fixtures/govbox/messages.yml index 2d66bde6..1ba47166 100644 --- a/test/fixtures/govbox/messages.yml +++ b/test/fixtures/govbox/messages.yml @@ -141,7 +141,7 @@ ssd_referring_to_outbox_message: ssd_general_created_from_draft: message_id: 9b1b718a-c06c-487c-86c2-b68b8606aa5c - correlation_id: <%= SecureRandom.uuid %> + correlation_id: 7a364355-882c-41d2-b1b3-e215644f805b edesk_message_id: 7 delivered_at: <%= DateTime.current %> edesk_class: TEST @@ -161,7 +161,7 @@ ssd_general_created_from_draft: class: FORM content: MyContent - id: af0e1c11-d226-45b7-8816-a5c24e139d35 - name: Attachment2 + name: Attachment mime_type: MyString class: ATTACHMENT content: MyContent diff --git a/test/fixtures/message_thread_merge_identifiers.yml b/test/fixtures/message_thread_merge_identifiers.yml index 73d80505..5951701c 100644 --- a/test/fixtures/message_thread_merge_identifiers.yml +++ b/test/fixtures/message_thread_merge_identifiers.yml @@ -19,3 +19,8 @@ ssd_main_issue_one: message_thread: ssd_main_issue uuid: <%= SecureRandom.uuid %> box: ssd_main + +ssd_main_draft_to_be_signed: + message_thread: ssd_main_draft_to_be_signed + uuid: 7a364355-882c-41d2-b1b3-e215644f805b + box: ssd_main diff --git a/test/fixtures/messages.yml b/test/fixtures/messages.yml index 4a85b932..f45a8061 100644 --- a/test/fixtures/messages.yml +++ b/test/fixtures/messages.yml @@ -195,6 +195,7 @@ ssd_main_draft_to_be_signed_draft_one: replyable: false metadata: status: created + correlation_id: 7a364355-882c-41d2-b1b3-e215644f805b author: basic ssd_main_draft_to_be_signed_draft_two: @@ -203,7 +204,7 @@ ssd_main_draft_to_be_signed_draft_two: title: MyStringDraft2 html_visualization: MyString delivered_at: 2023-05-18 16:18:26 - thread: ssd_main_draft_to_be_signed + thread: ssd_main_draft_to_be_signed2 replyable: false metadata: status: created diff --git a/test/models/govbox/message_test.rb b/test/models/govbox/message_test.rb index c5e5f642..b73a0776 100644 --- a/test/models/govbox/message_test.rb +++ b/test/models/govbox/message_test.rb @@ -30,7 +30,6 @@ class Govbox::MessageTest < ActiveSupport::TestCase end test "#create_message_with_thread! migrates tags from associated MessageDraft" do - message_draft = messages(:ssd_main_draft_to_be_signed_draft_one) govbox_message = govbox_messages(:ssd_general_created_from_draft) Govbox::Message.create_message_with_thread!(govbox_message) @@ -38,14 +37,13 @@ class Govbox::MessageTest < ActiveSupport::TestCase message = Message.last # Simple and Signed tags copied to MessageThread - assert message.thread.tags.visible.simple.map(&:name).difference(message_draft.thread.tags.visible.simple.map(&:name)).none? - assert message.thread.tags.signed.map(&:name).all? { |tag_name| message.thread.tags.signed.map(&:name).include?(tag_name) } + assert ['Finance', 'Podpísané', 'Podpísané: Signer user'].map { |tag_name| message.thread.tags.include?(tag_name) } # No SignatureRequested, Submiited tags copied to MessageThread assert message.thread.tags.where(type: ['SignatureRequestedTag', 'SignatureRequestedFromTag', 'Submitted']).none? # Signed tags copied to MessageObjects - assert message.objects.first.tags.signed.map(&:name).all? { |tag_name| message.objects.first.tags.signed.map(&:name).include?(tag_name) } + assert message.objects.find_by(name: 'Attachment2').tags.include?(tags(:ssd_signer_user_signed)) # No SignatureRequested tags copied to MessageObjects assert message.form_object.tags.where(type: ['SignatureRequestedTag', 'SignatureRequestedFromTag']).none?