Move audit logs register

This commit is contained in:
Fernando Chavez 2022-12-12 18:09:24 +01:00
parent bdda90ebf6
commit 964654b29f
3 changed files with 19 additions and 16 deletions

View File

@ -4,7 +4,6 @@
const { features } = require('@strapi/strapi/lib/utils/ee');
const executeCEBootstrap = require('../../server/bootstrap');
const { getService } = require('../../server/utils');
const createAuditLogsService = require('./services/audit-logs');
const SSO_ACTIONS = [
{
@ -25,18 +24,12 @@ const SSO_ACTIONS = [
},
];
module.exports = async ({ strapi }) => {
module.exports = async () => {
const { actionProvider } = getService('permission');
if (features.isEnabled('sso')) {
await actionProvider.registerMany(SSO_ACTIONS);
}
if (features.isEnabled('audit-logs')) {
const auditLogsService = createAuditLogsService(strapi);
strapi.container.register('audit-logs', auditLogsService);
auditLogsService.bootstrap();
}
await executeCEBootstrap();
};

View File

@ -1,8 +1,16 @@
'use strict';
const { features } = require('@strapi/strapi/lib/utils/ee');
const executeCERegister = require('../../server/register');
const createAuditLogsService = require('./services/audit-logs');
module.exports = async ({ strapi }) => {
if (features.isEnabled('audit-logs')) {
const auditLogsService = createAuditLogsService(strapi);
strapi.container.register('audit-logs', auditLogsService);
auditLogsService.bootstrap();
}
// TODO: register auditLogs provider here
await executeCERegister({ strapi });
};

View File

@ -3,7 +3,7 @@
const createEventHub = require('../../../../../strapi/lib/services/event-hub');
const createAuditLogsService = require('../audit-logs');
jest.mock('../../../../server/bootstrap');
jest.mock('../../../../server/register');
describe('Audit logs auth', () => {
afterEach(() => {
@ -20,8 +20,8 @@ describe('Audit logs auth', () => {
}));
});
it('should not register the audit logs service when bootstraped', async () => {
const eeAdminBootstrap = require('../../bootstrap');
it('should not register the audit logs service when registered', async () => {
const eeAdminRegister = require('../../register');
const mockRegister = jest.fn();
global.strapi = {
@ -37,7 +37,7 @@ describe('Audit logs auth', () => {
},
};
await eeAdminBootstrap({ strapi });
await eeAdminRegister({ strapi });
expect(mockRegister).not.toHaveBeenCalledWith('audit-logs', expect.anything());
});
@ -68,10 +68,10 @@ describe('Audit logs auth', () => {
};
});
it('should register and init the audit logs service when bootstraped', async () => {
const eeAdminBootstrap = require('../../bootstrap');
it('should register and init the audit logs service when registered', async () => {
const eeAdminRegister = require('../../register');
await eeAdminBootstrap({ strapi });
await eeAdminRegister({ strapi });
expect(mockRegister).toHaveBeenCalledWith('audit-logs', expect.anything());
});
@ -95,7 +95,9 @@ describe('Audit logs auth', () => {
const auditLogsService = createAuditLogsService(strapi);
auditLogsService.bootstrap();
expect(() => strapi.eventHub.emit('', { meta: 'test' })).toThrowError('Name is required');
expect(() => {
strapi.eventHub.emit('', { meta: 'test' });
}).toThrowError('Name is required');
});
});
});