diff --git a/app/jobs/fs/download_sent_message_related_messages_job.rb b/app/jobs/fs/download_sent_message_related_messages_job.rb index 43f9fc69..7220f88a 100644 --- a/app/jobs/fs/download_sent_message_related_messages_job.rb +++ b/app/jobs/fs/download_sent_message_related_messages_job.rb @@ -9,6 +9,8 @@ def perform(outbox_message, from: nil, to: nil, fs_client: FsEnvironment.fs_clie 0.step do |k| received_messages = fs_api.fetch_received_messages(sent_message_id: outbox_message.metadata['fs_message_id'], page: k + 1, count: batch_size, from: from, to: to) + raise "No related messages!" if outbox_message.thread.messages.excluding(outbox_message).none? && received_messages['messages'].none? && outbox_message.delivered_at < 1.hour.ago + received_messages['messages'].each do |received_message| ::Fs::DownloadReceivedMessageJob.perform_later(received_message['message_id'], box: outbox_message.box) end diff --git a/test/fixtures/boxes.yml b/test/fixtures/boxes.yml index 87c00c55..0fa8a43c 100644 --- a/test/fixtures/boxes.yml +++ b/test/fixtures/boxes.yml @@ -77,6 +77,7 @@ fs_accountants: short_name: FSJJ api_connection: fs_api_connection1 settings: {"dic": "1122334455", "subject_id": "df2f9373-30b7-4a44-9738-5b4e24e4866c", "message_drafts_import_enabled": true} + syncable: true type: 'Fs::Box' fs_accountants2: diff --git a/test/fixtures/message_threads.yml b/test/fixtures/message_threads.yml index 4cc60e30..65ac7df3 100644 --- a/test/fixtures/message_threads.yml +++ b/test/fixtures/message_threads.yml @@ -70,6 +70,13 @@ ssd_main_empty_draft: delivered_at: 2023-05-18 16:05:00 last_message_delivered_at: 2023-05-18 16:05:00 +fs_accountants_outbox: + box: fs_accountants + title: Podanie + original_title: MyString + delivered_at: <%= 2.hours.ago %> + last_message_delivered_at: <%= 2.hours.ago %> + solver_main_general_agenda: box: solver_main title: General agenda Solver diff --git a/test/fixtures/messages.yml b/test/fixtures/messages.yml index 7c252063..744b7946 100644 --- a/test/fixtures/messages.yml +++ b/test/fixtures/messages.yml @@ -289,6 +289,16 @@ ssd_main_empty_draft: correlation_id: <%= SecureRandom.uuid %> author: basic +fs_accountants_outbox: + uuid: <%= SecureRandom.uuid %> + title: FS podanie + delivered_at: <%= 2.hours.ago %> + thread: fs_accountants_outbox + replyable: false + metadata: + fs_message_id: 1234/2024 + author: accountants_basic + solver_main_delivery_notification_one: uuid: bbff2617-3430-44c6-b827-519059ff1e90 title: Authorized Delivery notification diff --git a/test/jobs/fs/download_sent_message_related_messages_job_test.rb b/test/jobs/fs/download_sent_message_related_messages_job_test.rb new file mode 100644 index 00000000..fa843ce8 --- /dev/null +++ b/test/jobs/fs/download_sent_message_related_messages_job_test.rb @@ -0,0 +1,20 @@ +require "test_helper" + +class Fs::DownloadSentMessageRelatedMessagesJobTest < ActiveJob::TestCase + test "raises error if no related messages for outbox_message" do + outbox_message = messages(:fs_accountants_outbox) + + fs_api = Minitest::Mock.new + fs_api.expect :fetch_received_messages, { + "count" => 0, + "messages" => [] + }, + **{sent_message_id: outbox_message.metadata['fs_message_id'], page: 1, count: 25, from: nil, to: nil} + + FsEnvironment.fs_client.stub :api, fs_api do + assert_raise(StandardError, match: /No related messages!/) do + Fs::DownloadSentMessageRelatedMessagesJob.new.perform(outbox_message) + end + end + end +end