Skip to content
Snippets Groups Projects
Commit 25d9bef7 authored by Kassio Borges's avatar Kassio Borges :three:
Browse files

Add Pages::PageDeletedEvent

Related to: #364070

Changelog: added
parent d336050e
No related branches found
No related tags found
1 merge request!89162Add Pages::PageDeletedEvent
# frozen_string_literal: true
module Pages
class PageDeletedEvent < ::Gitlab::EventStore::Event
def schema
{
'type' => 'object',
'properties' => {
'project_id' => { 'type' => 'integer' },
'namespace_id' => { 'type' => 'integer' }
},
'required' => %w[project_id namespace_id]
}
end
end
end
......@@ -11,7 +11,20 @@ def execute
# > The default strategy is :nullify which sets the foreign keys to NULL.
PagesDomain.for_project(project).delete_all
publish_deleted_event
DestroyPagesDeploymentsWorker.perform_async(project.id)
end
private
def publish_deleted_event
event = Pages::PageDeletedEvent.new(data: {
project_id: project.id,
namespace_id: project.namespace_id
})
Gitlab::EventStore.publish(event)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Pages::PageDeletedEvent do
where(:data, :valid) do
[
[{ project_id: 1, namespace_id: 2 }, true],
[{ project_id: 1 }, false],
[{ namespace_id: 1 }, false],
[{ project_id: 'foo', namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: 'foo' }, false],
[{ project_id: [], namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: [] }, false],
[{ project_id: {}, namespace_id: 2 }, false],
[{ project_id: 1, namespace_id: {} }, false],
['foo', false],
[123, false],
[[], false]
]
end
with_them do
it 'validates data' do
constructor = -> { described_class.new(data: data) }
if valid
expect { constructor.call }.not_to raise_error
else
expect { constructor.call }.to raise_error(Gitlab::EventStore::InvalidEvent)
end
end
end
end
......@@ -43,4 +43,10 @@
service.execute
end.to change { PagesDeployment.count }.by(-1)
end
it 'publishes a ProjectDeleted event with project id and namespace id' do
expected_data = { project_id: project.id, namespace_id: project.namespace_id }
expect { service.execute }.to publish_event(Pages::PageDeletedEvent).with(expected_data)
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment