Skip to content

Commit

Permalink
Fix the events_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mereghost committed Jun 26, 2024
1 parent c70486b commit d76ab1b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
12 changes: 6 additions & 6 deletions modules/storages/lib/open_project/storages/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def self.permissions
OpenProject::Events::MEMBER_UPDATED,
OpenProject::Events::MEMBER_DESTROYED
].each do |event|
OpenProject::Notifications.subscribe(event) do |_payload|
Storages::Storage.joins(project_storages: :project)
OpenProject::Notifications.subscribe(event) do |payload|
::Storages::Storage.joins(project_storages: :project)
.where(project_storages: { project_id: payload[:member].project_id }).find_each do |storage|
::Storages::AutomaticallyManagedStorageSyncJob.debounce(storage)
end
Expand All @@ -70,8 +70,8 @@ def self.permissions
OpenProject::Events::PROJECT_ARCHIVED,
OpenProject::Events::PROJECT_UNARCHIVED].each do |event|
OpenProject::Notifications.subscribe(event) do |payload|
Storages::Storage.joins(project_storages: :project)
.where(project_storages: { project_id: payload[:project] }).find_each do |storage|
::Storages::Storage.joins(project_storages: :project)
.where(project_storages: { project: payload[:project] }).find_each do |storage|
::Storages::AutomaticallyManagedStorageSyncJob.debounce(storage)
end
end
Expand Down Expand Up @@ -117,13 +117,13 @@ def self.permissions
OpenProject::Notifications.subscribe(
::OpenProject::Events::STORAGE_TURNED_UNHEALTHY
) do |payload|
Storages::HealthService.new(storage: payload[:storage]).unhealthy(reason: payload[:reason])
::Storages::HealthService.new(storage: payload[:storage]).unhealthy(reason: payload[:reason])
end

OpenProject::Notifications.subscribe(
::OpenProject::Events::STORAGE_TURNED_HEALTHY
) do |payload|
Storages::HealthService.new(storage: payload[:storage]).healthy
::Storages::HealthService.new(storage: payload[:storage]).healthy
end
end
end
Expand Down
36 changes: 27 additions & 9 deletions spec/lib/open_project/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def fire_event(event_constant_name)

before do
allow(Storages::ManageStorageIntegrationsJob).to receive(:debounce)
allow(Storages::AutomaticallyManagedStorageSyncJob).to receive(:debounce)
end

%w[
Expand All @@ -53,16 +54,16 @@ def fire_event(event_constant_name)

it do
subject
expect(Storages::ManageStorageIntegrationsJob).not_to have_received(:debounce)
expect(Storages::AutomaticallyManagedStorageSyncJob).not_to have_received(:debounce)
end
end

context "when payload contains automatic project_folder_mode" do
let(:payload) { { project_folder_mode: :automatic } }
let(:payload) { { project_folder_mode: :automatic, storage: create(:nextcloud_storage) } }

it do
subject
expect(Storages::ManageStorageIntegrationsJob).to have_received(:debounce)
expect(Storages::AutomaticallyManagedStorageSyncJob).to have_received(:debounce).with(payload[:storage])
end

it do
Expand All @@ -78,19 +79,36 @@ def fire_event(event_constant_name)
MEMBER_CREATED
MEMBER_UPDATED
MEMBER_DESTROYED
PROJECT_UPDATED
PROJECT_RENAMED
PROJECT_ARCHIVED
PROJECT_UNARCHIVED
].each do |event|
describe(event) do
let(:project_role) { create(:existing_project_role) }
let(:project_storage) { create(:project_storage) }
let(:member) { create(:work_package_member, roles: [project_role], project: project_storage.project) }

let(:payload) { { member: } }

subject { fire_event(event) }

let(:payload) { {} }
it do
subject
expect(Storages::AutomaticallyManagedStorageSyncJob).to have_received(:debounce).with(project_storage.storage)
end
end
end

%w[PROJECT_UPDATED
PROJECT_RENAMED
PROJECT_ARCHIVED
PROJECT_UNARCHIVED].each do |event|
describe(event) do
let(:project_storage) { create(:project_storage, :as_automatically_managed) }
let(:payload) { { project: project_storage.project } }

subject { fire_event(event) }

it do
subject
expect(Storages::ManageStorageIntegrationsJob).to have_received(:debounce)
expect(Storages::AutomaticallyManagedStorageSyncJob).to have_received(:debounce).with(project_storage.storage)
end
end
end
Expand Down

0 comments on commit d76ab1b

Please sign in to comment.