2019-12-09 04:08:00 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Pages::DeleteService do
|
2021-02-08 13:09:49 -05:00
|
|
|
let_it_be(:admin) { create(:admin) }
|
2019-12-09 04:08:00 -05:00
|
|
|
|
2022-08-02 23:09:00 -04:00
|
|
|
let(:project) { create(:project, path: "my.project") }
|
|
|
|
let(:service) { described_class.new(project, admin) }
|
2019-12-09 04:08:00 -05:00
|
|
|
|
2021-02-08 13:09:49 -05:00
|
|
|
before do
|
|
|
|
project.mark_pages_as_deployed
|
|
|
|
end
|
|
|
|
|
2021-05-26 11:10:57 -04:00
|
|
|
it 'marks pages as not deployed' do
|
|
|
|
expect do
|
|
|
|
service.execute
|
|
|
|
end.to change { project.reload.pages_deployed? }.from(true).to(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'deletes all domains' do
|
|
|
|
domain = create(:pages_domain, project: project)
|
|
|
|
unrelated_domain = create(:pages_domain)
|
2021-02-08 13:09:49 -05:00
|
|
|
|
|
|
|
service.execute
|
|
|
|
|
2021-05-26 11:10:57 -04:00
|
|
|
expect(PagesDomain.find_by_id(domain.id)).to eq(nil)
|
|
|
|
expect(PagesDomain.find_by_id(unrelated_domain.id)).to be
|
2021-02-08 13:09:49 -05:00
|
|
|
end
|
2020-08-25 20:10:31 -04:00
|
|
|
|
2021-02-08 13:09:49 -05:00
|
|
|
it 'schedules a destruction of pages deployments' do
|
|
|
|
expect(DestroyPagesDeploymentsWorker).to(
|
|
|
|
receive(:perform_async).with(project.id)
|
|
|
|
)
|
2020-08-25 20:10:31 -04:00
|
|
|
|
2021-02-08 13:09:49 -05:00
|
|
|
service.execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes pages deployments', :sidekiq_inline do
|
|
|
|
create(:pages_deployment, project: project)
|
2020-08-25 20:10:31 -04:00
|
|
|
|
2021-02-08 13:09:49 -05:00
|
|
|
expect do
|
|
|
|
service.execute
|
|
|
|
end.to change { PagesDeployment.count }.by(-1)
|
2019-12-09 04:08:00 -05:00
|
|
|
end
|
2022-06-06 14:09:02 -04:00
|
|
|
|
|
|
|
it 'publishes a ProjectDeleted event with project id and namespace id' do
|
2022-06-29 17:09:23 -04:00
|
|
|
expected_data = {
|
|
|
|
project_id: project.id,
|
|
|
|
namespace_id: project.namespace_id,
|
|
|
|
root_namespace_id: project.root_namespace.id
|
|
|
|
}
|
2022-06-06 14:09:02 -04:00
|
|
|
|
|
|
|
expect { service.execute }.to publish_event(Pages::PageDeletedEvent).with(expected_data)
|
|
|
|
end
|
2019-12-09 04:08:00 -05:00
|
|
|
end
|