Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
luciajanikova committed Oct 24, 2024
1 parent db253a7 commit f0a7a73
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
12 changes: 6 additions & 6 deletions app/models/govbox/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions app/models/message_draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/govbox/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/message_thread_merge_identifiers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion test/fixtures/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions test/models/govbox/message_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,20 @@ 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)

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?
Expand Down

0 comments on commit f0a7a73

Please sign in to comment.