Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
luciajanikova committed Oct 1, 2024
1 parent 2ae51ba commit a42bbd1
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 8 deletions.
33 changes: 33 additions & 0 deletions test/fixtures/govbox/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,39 @@ ssd_referring_to_outbox_message:
class: MyClass
content: MyContent

ssd_general_created_from_draft:
message_id: 9b1b718a-c06c-487c-86c2-b68b8606aa5c
correlation_id: <%= SecureRandom.uuid %>
edesk_message_id: 7
delivered_at: <%= DateTime.current %>
edesk_class: TEST
folder: ssd_sent
payload:
message_id: 9b1b718a-c06c-487c-86c2-b68b8606aa5c
subject: Title is not shown
sender_name: MySender
sender_uri: MySenderURIq
recipient_name: MyRecipient
delivered_at: <%= DateTime.current.to_s %>
original_html: Reply to something
objects:
- id: 6a0f716a-c284-4680-ad7e-ed2bde769dd2
name: MyString
mime_type: MyString
class: FORM
content: MyContent
- id: af0e1c11-d226-45b7-8816-a5c24e139d35
name: Attachment2
mime_type: MyString
class: ATTACHMENT
content: MyContent
- id: 57c9954c-93e2-470c-833c-fd2bc6d8c70f
name: Attachment2
mime_type: MyString
signed: true
class: ATTACHMENT
content: MyContent

ssd_without_recipient_name:
message_id: <%= SecureRandom.uuid %>
correlation_id: <%= SecureRandom.uuid %>
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/message_objects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,27 @@ ssd_main_fs_one_form:
object_type: FORM

ssd_main_draft_to_be_signed_draft_one_form:
uuid: 6a0f716a-c284-4680-ad7e-ed2bde769dd2
message: ssd_main_draft_to_be_signed_draft_one
name: MyString
mimetype: MyString
object_type: FORM

ssd_main_draft_to_be_signed_draft_one_attachment:
uuid: af0e1c11-d226-45b7-8816-a5c24e139d35
message: ssd_main_draft_to_be_signed_draft_one
name: Attachment
mimetype: MyString
object_type: ATTACHMENT

ssd_main_draft_to_be_signed_draft_one_attachment2:
uuid: 57c9954c-93e2-470c-833c-fd2bc6d8c70f
message: ssd_main_draft_to_be_signed_draft_one
name: Attachment2
mimetype: MyString
is_signed: true
object_type: ATTACHMENT

ssd_main_draft_to_be_signed_draft_two_form:
message: ssd_main_draft_to_be_signed_draft_two
name: MyString
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/message_objects_tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ ssd_main_draft_to_be_signed_draft_one_form_signature_requested:
message_object: ssd_main_draft_to_be_signed_draft_one_form
tag: ssd_signer_user_signature_requested

ssd_main_draft_to_be_signed_draft_one_attachment2_signed_ssd_signer:
message_object: ssd_main_draft_to_be_signed_draft_one_attachment2
tag: ssd_signer_user_signed

ssd_main_draft_to_be_signed_draft_two_form_signature_requested:
message_object: ssd_main_draft_to_be_signed_draft_two_form
tag: ssd_signer_user_signature_requested
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/message_threads_tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ ssd_main_draft_to_be_signed_ssd_signer_user_signature_requested:
message_thread: ssd_main_draft_to_be_signed
tag: ssd_signer_user_signature_requested

ssd_main_draft_to_be_signed_ssd_signer_user_signed:
message_thread: ssd_main_draft_to_be_signed
tag: ssd_signer_user_signed

ssd_main_draft_to_be_signed_ssd_signed:
message_thread: ssd_main_draft_to_be_signed
tag: ssd_signed

ssd_main_draft_to_be_signed_ssd_submitted:
message_thread: ssd_main_draft_to_be_signed
tag: ssd_submitted

ssd_main_draft_to_be_signed2_finance:
message_thread: ssd_main_draft_to_be_signed2
tag: ssd_finance
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ ssd_main_collapsed_two:
collapsed: true

ssd_main_draft_to_be_signed_draft_one:
type: MessageDraft
uuid: <%= SecureRandom.uuid %>
type: Upvs::MessageDraft
uuid: 9b1b718a-c06c-487c-86c2-b68b8606aa5c
title: Title is not shown
html_visualization: Reply to something
delivered_at: 2023-05-18 16:18:26
Expand Down
34 changes: 28 additions & 6 deletions test/models/govbox/message_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "test_helper"

class Govbox::MessageTest < ActiveSupport::TestCase
test "should create message, its objects and not visible tag" do
test "#create_message_with_thread! should create message, its objects and not visible tag" do
govbox_message = govbox_messages(:one)

Govbox::Message.create_message_with_thread!(govbox_message)
Expand Down Expand Up @@ -29,7 +29,29 @@ class Govbox::MessageTest < ActiveSupport::TestCase
assert_equal message.tags.first, message.thread.tags.simple.first
end

test "should take name from box as recipient_name if no recipient_name in govbox message" do
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) }

# 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) }

# No SignatureRequested tags copied to MessageObjects
assert message.form_object.tags.where(type: ['SignatureRequestedTag', 'SignatureRequestedFromTag']).none?
end

test "#create_message_with_thread! should take name from box as recipient_name if no recipient_name in govbox message" do
govbox_message = govbox_messages(:ssd_without_recipient_name)

Govbox::Message.create_message_with_thread!(govbox_message)
Expand All @@ -41,7 +63,7 @@ class Govbox::MessageTest < ActiveSupport::TestCase
assert_equal message.recipient_name, "SSD main"
end

test "should include general agenda subject in message title" do
test "#create_message_with_thread! should include general agenda subject in message title" do
govbox_message = govbox_messages(:ssd_general_agenda)

Govbox::Message.create_message_with_thread!(govbox_message)
Expand All @@ -51,7 +73,7 @@ class Govbox::MessageTest < ActiveSupport::TestCase
assert_equal message.title, "Všeobecná Agenda - Rozhodnutie ..."
end

test "should not create new tag if already exists" do
test "#create_message_with_thread! should not create new tag if already exists" do
govbox_message = govbox_messages(:one)

tag = SimpleTag.create!(external_name: "slovensko.sk:#{govbox_message.folder.name}", name: "slovensko.sk:#{govbox_message.folder.name}", tenant: govbox_message.folder.box.tenant, visible: false)
Expand All @@ -66,7 +88,7 @@ class Govbox::MessageTest < ActiveSupport::TestCase
assert_equal tag, message.thread.tags.simple.first
end

test "should not duplicate message thread tags" do
test "#create_message_with_thread! should not duplicate message thread tags" do
govbox_message1 = govbox_messages(:one)
govbox_message2 = govbox_messages(:three)

Expand All @@ -88,7 +110,7 @@ class Govbox::MessageTest < ActiveSupport::TestCase
assert_equal tag, message2.thread.tags.simple.first
end

test "should not use delivery notification title for message thread title" do
test "#create_message_with_thread! should not use delivery notification title for message thread title" do
govbox_message = govbox_messages(:solver_delivery_notification)

Govbox::Message.create_message_with_thread!(govbox_message)
Expand Down

0 comments on commit a42bbd1

Please sign in to comment.