Skip to content

Commit

Permalink
Make Fs::DownloadSentMessageRelatedMessagesJob fail unless related me…
Browse files Browse the repository at this point in the history
…ssages exist
  • Loading branch information
luciajanikova committed Nov 28, 2024
1 parent 3029a29 commit 2d22d8d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/jobs/fs/download_sent_message_related_messages_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/boxes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/message_threads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions test/jobs/fs/download_sent_message_related_messages_job_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2d22d8d

Please sign in to comment.