Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luciajanikova committed Jul 24, 2024
1 parent c2e3020 commit 90b0bb8
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ solver_main_delivery_notification_two:
delivered_at: <%= DateTime.current %>
metadata:
delivery_notification:
delivery_period_end_at: 2023-07-04T21:59:59.000Z,
delivery_period_end_at: 2030-07-04T21:59:59.000Z,
delivery_period: 15
consignment:
message_id: x7800b40-44b1-4012-ae78-774de6457cc2
Expand Down
80 changes: 77 additions & 3 deletions test/jobs/govbox/sync_box_job_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,81 @@
require "test_helper"

class Govbox::SyncBoxJobTest < ActiveJob::TestCase
# test "the truth" do
# assert true
# end
test "schedules Govbox::SyncFolderJob with low priority if initial box sync" do
box = boxes(:ssd_main)

edesk_api_mock = Minitest::Mock.new
edesk_api_mock.expect :fetch_folders, [200, [
{
"id" => "123456",
"name" => "Inbox",
"system" => true
},
{
"id" => "7890123",
"name" => "MyName",
"system" => false
},
{
"id" => "135790",
"name" => "Bin",
"system" => true
},
{
"id" => "24580",
"name" => "Drafts",
"system" => true
},
{
"id" => "24589",
"name" => "SentItems",
"system" => true
},
]]

::Upvs::GovboxApi::Edesk.stub :new, edesk_api_mock do
assert_enqueued_with(job: Govbox::SyncFolderJob, priority: 100) do
Govbox::SyncBoxJob.new.perform(box, initial_import: true)
end
end
end

test "schedules Govbox::SyncFolderJob with no priority unless initial box sync" do
box = boxes(:ssd_main)

edesk_api_mock = Minitest::Mock.new
edesk_api_mock.expect :fetch_folders, [200, [
{
"id" => "123456",
"name" => "Inbox",
"system" => true
},
{
"id" => "7890123",
"name" => "MyName",
"system" => false
},
{
"id" => "135790",
"name" => "Bin",
"system" => true
},
{
"id" => "24580",
"name" => "Drafts",
"system" => true
},
{
"id" => "24589",
"name" => "SentItems",
"system" => true
},
]]

::Upvs::GovboxApi::Edesk.stub :new, edesk_api_mock do
assert_enqueued_with(job: Govbox::SyncFolderJob, priority: nil) do
Govbox::SyncBoxJob.new.perform(box)
end
end
end
end
8 changes: 8 additions & 0 deletions test/models/box_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ class BoxTest < ActiveSupport::TestCase
assert_not box.valid?
end

test "sync method schedules Govbox::SyncBoxJob with highest priority" do
box = boxes(:ssd_main)

assert_enqueued_with(job: Govbox::SyncBoxJob, priority: -1000) do
box.sync
end
end

test "sync_all schedules sync of all boxes" do
assert_enqueued_with(job: Govbox::SyncBoxJob) do
Box.sync_all
Expand Down
13 changes: 13 additions & 0 deletions test/models/govbox/authorize_delivery_notification_action_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "test_helper"

class Govbox::AuthorizeDeliveryNotificationActionTest < ActiveSupport::TestCase
include ActiveJob::TestHelper

test "schedules Govbox::AuthorizeDeliveryNotificationJob with highest priority" do
message = messages(:solver_main_delivery_notification_two)

assert_enqueued_with(job: Govbox::AuthorizeDeliveryNotificationJob, priority: -1000) do
Govbox::AuthorizeDeliveryNotificationAction.run(message)
end
end
end

0 comments on commit 90b0bb8

Please sign in to comment.