check if there are no components

This commit is contained in:
Marc-Roig 2022-08-27 20:30:59 +02:00
parent 2200f279ab
commit 6f76aee4d7
2 changed files with 3 additions and 6 deletions

View File

@ -3,11 +3,6 @@
const createEntityService = require('..'); const createEntityService = require('..');
const entityValidator = require('../../entity-validator'); const entityValidator = require('../../entity-validator');
jest.mock('../components', () => ({
...jest.requireActual('../components'),
getComponents: jest.fn(),
}));
describe('Entity service triggers webhooks', () => { describe('Entity service triggers webhooks', () => {
global.strapi = { global.strapi = {
getModel: () => ({}), getModel: () => ({}),

View File

@ -104,10 +104,12 @@ const createComponents = async (uid, data) => {
/** /**
* @param {str} uid * @param {str} uid
* @param {object} entity * @param {object} entity
* @return {Promise<{uid: string, entity: object}[]>} * @return {Promise<{uid: string, entity: object}>}
*/ */
const getComponents = async (uid, entity) => { const getComponents = async (uid, entity) => {
const componentAttributes = getComponentAttributes(strapi.getModel(uid)); const componentAttributes = getComponentAttributes(strapi.getModel(uid));
if (_.isEmpty(componentAttributes)) return {};
return strapi.query(uid).load(entity, componentAttributes); return strapi.query(uid).load(entity, componentAttributes);
}; };