Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO-145 Download messages received during period of time #506

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/jobs/govbox/sync_folder_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ def perform(folder, upvs_client: UpvsEnvironment.upvs_client, batch_size: 1000)
edesk_api = upvs_client.api(folder.box).edesk
new_messages_ids = []

sync_since = Date.parse(folder.box.settings['sync_since']) if folder.box.settings['sync_since'].present?

0.step do |k|
response_status, raw_messages = edesk_api.fetch_messages(folder.edesk_folder_id, page: k + 1, count: batch_size)

Expand All @@ -15,6 +17,8 @@ def perform(folder, upvs_client: UpvsEnvironment.upvs_client, batch_size: 1000)
moved_edesk_message_ids = []

raw_messages.each do |raw_message|
next if sync_since && (Date.parse(raw_message['delivered_at']) < sync_since)

edesk_message_id = raw_message['id']
old_folder_id = edesk_message_ids_to_folder_ids[edesk_message_id]

Expand Down
100 changes: 97 additions & 3 deletions test/jobs/govbox/sync_folder_job_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,101 @@
require "test_helper"

class Govbox::SyncFolderJobTest < ActiveJob::TestCase
# test "the truth" do
# assert true
# end
test "downloads all messages unless box sync_since value in box settings set" do
box = boxes(:ssd_main)

folder = govbox_folders(:ssd_one)

edesk_api_mock = Minitest::Mock.new
edesk_api_mock.expect :fetch_messages, [200, [
{
"id"=>4905707493,
"class"=>"ED_DELIVERY_NOTIFICATION",
"message_id"=>"7cb378ef-9c76-493b-b41d-51f1e40dd68e",
"correlation_id"=>"6baa28c3-96e5-493b-a76c-9837a6d637b3",
"subject"=>"Notifikácia o doručení k \"Všeobecná agenda - rozhodnutie do vlastných rúk s fikciou doručenia\"",
"delivered_at"=>"2023-07-10T09:51:36.533Z"
},
{
"id"=>4906445420,
"class"=>"EGOV_DOCUMENT",
"message_id"=>"1fe26465-ff59-4fed-b948-630cc994507a",
"correlation_id"=>"5aeddd85-952e-4534-a9fd-9c73774049f3",
"subject"=>"Všeobecná agenda - rozhodnutie do vlastných rúk s fikciou doručenia",
"delivered_at"=>"2023-11-14T12:51:50.337Z"
},
{
"id"=>4906376126,
"class"=>"EGOV_DOCUMENT",
"message_id"=>"1d5f449c-7b8e-40d6-9662-64ff0af527cd",
"correlation_id"=>"7f2956fd-d8d8-4062-9d34-f9b0418c9f0b",
"subject"=>"Všeobecná agenda - rozhodnutie do vlastných rúk",
"delivered_at"=>"2023-11-15T14:16:32.600Z"
},
{
"id"=>4905707496,
"class"=>"ED_DELIVERY_NOTIFICATION",
"message_id"=>"14fe42a3-c3b7-419b-bb76-485f49543e53",
"correlation_id"=>"8c359d95-3d72-4e76-b0f2-ddeba11c3b5b",
"subject"=>"Notifikácia o doručení k \"Všeobecná agenda - rozhodnutie do vlastných rúk s fikciou doručenia\"",
"delivered_at"=>"2024-07-10T09:51:36.560Z"
},
]], [folder.edesk_folder_id], **{ page: 1, count: 1000 }

::Upvs::GovboxApi::Edesk.stub :new, edesk_api_mock do
Govbox::SyncFolderJob.new.perform(folder)
end

assert_enqueued_jobs 4
end

test "does not download older messages than box sync_since value in box settings" do
box = boxes(:ssd_main)
box.settings['sync_since'] = '2023-11-15'
box.save

folder = govbox_folders(:ssd_one)

edesk_api_mock = Minitest::Mock.new
edesk_api_mock.expect :fetch_messages, [200, [
{
"id"=>4905707493,
"class"=>"ED_DELIVERY_NOTIFICATION",
"message_id"=>"7cb378ef-9c76-493b-b41d-51f1e40dd68e",
"correlation_id"=>"6baa28c3-96e5-493b-a76c-9837a6d637b3",
"subject"=>"Notifikácia o doručení k \"Všeobecná agenda - rozhodnutie do vlastných rúk s fikciou doručenia\"",
"delivered_at"=>"2023-07-10T09:51:36.533Z"
},
{
"id"=>4906445420,
"class"=>"EGOV_DOCUMENT",
"message_id"=>"1fe26465-ff59-4fed-b948-630cc994507a",
"correlation_id"=>"5aeddd85-952e-4534-a9fd-9c73774049f3",
"subject"=>"Všeobecná agenda - rozhodnutie do vlastných rúk s fikciou doručenia",
"delivered_at"=>"2023-11-14T12:51:50.337Z"
},
{
"id"=>4906376126,
"class"=>"EGOV_DOCUMENT",
"message_id"=>"1d5f449c-7b8e-40d6-9662-64ff0af527cd",
"correlation_id"=>"7f2956fd-d8d8-4062-9d34-f9b0418c9f0b",
"subject"=>"Všeobecná agenda - rozhodnutie do vlastných rúk",
"delivered_at"=>"2023-11-15T14:16:32.600Z"
},
{
"id"=>4905707496,
"class"=>"ED_DELIVERY_NOTIFICATION",
"message_id"=>"14fe42a3-c3b7-419b-bb76-485f49543e53",
"correlation_id"=>"8c359d95-3d72-4e76-b0f2-ddeba11c3b5b",
"subject"=>"Notifikácia o doručení k \"Všeobecná agenda - rozhodnutie do vlastných rúk s fikciou doručenia\"",
"delivered_at"=>"2024-07-10T09:51:36.560Z"
},
]], [folder.edesk_folder_id], **{ page: 1, count: 1000 }

::Upvs::GovboxApi::Edesk.stub :new, edesk_api_mock do
Govbox::SyncFolderJob.new.perform(folder)
end

assert_enqueued_jobs 2
end
end
Loading