mirror of
https://github.com/strapi/strapi.git
synced 2025-08-07 00:09:23 +00:00
55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
const createLifecycleManager = require('../lifecycle-manager');
|
|
|
|
describe('Lifecycle Manager', () => {
|
|
test('Allows registering lifecycles', () => {
|
|
const manager = createLifecycleManager();
|
|
|
|
const lifecycle = {};
|
|
manager.register(lifecycle);
|
|
|
|
expect(manager.lifecycles).toEqual([lifecycle]);
|
|
});
|
|
|
|
test('Will run all the lifecycles if no model specified', async () => {
|
|
const lifecycleA = {
|
|
find: jest.fn(),
|
|
};
|
|
|
|
const lifecycleB = {
|
|
find: jest.fn(),
|
|
};
|
|
|
|
const manager = createLifecycleManager();
|
|
|
|
manager.register(lifecycleA).register(lifecycleB);
|
|
|
|
await manager.run('find', { uid: 'test-uid' });
|
|
|
|
expect(lifecycleA.find).toHaveBeenCalled();
|
|
expect(lifecycleB.find).toHaveBeenCalled();
|
|
});
|
|
|
|
test('Will match on model if specified', async () => {
|
|
const lifecycleA = {
|
|
model: 'test-uid',
|
|
find: jest.fn(),
|
|
};
|
|
|
|
const lifecycleB = {
|
|
model: 'other-uid',
|
|
find: jest.fn(),
|
|
};
|
|
|
|
const manager = createLifecycleManager();
|
|
|
|
manager.register(lifecycleA).register(lifecycleB);
|
|
|
|
await manager.run('find', { uid: 'test-uid' });
|
|
|
|
expect(lifecycleA.find).toHaveBeenCalled();
|
|
expect(lifecycleB.find).not.toHaveBeenCalled();
|
|
});
|
|
});
|