chore: add tests

This commit is contained in:
Josh 2022-12-09 16:29:37 +00:00
parent faccd129f5
commit d5ef35ed03

View File

@ -611,4 +611,79 @@ describe('recursivelyFindPathsBasedOnCondition', () => {
expect(actual).toEqual(['dynamic_relations', 'dynamic_relations.simple']); expect(actual).toEqual(['dynamic_relations', 'dynamic_relations.simple']);
}); });
}); });
describe('components', () => {
test('given that a component exits, it should be returned', () => {
const components = {
'basic.simple': {
attributes: {
id: {
type: 'integer',
},
categories: {
type: 'relation',
relation: 'oneToMany',
target: 'api::category.category',
targetModel: 'api::category.category',
relationType: 'oneToMany',
},
my_name: {
type: 'string',
},
},
},
};
const attributes = {
relation: {
type: 'component',
component: 'basic.simple',
repeatable: false,
},
};
const actual = recursivelyFindPathsBasedOnCondition(
components,
(value) => value.type === 'component' && !value.repeatable
)(attributes);
expect(actual).toEqual(['relation']);
});
test('given that a component is in a dynamic zone it should not return the name of the dynamic zone', () => {
const components = {
'basic.simple': {
attributes: {
id: {
type: 'integer',
},
categories: {
type: 'relation',
relation: 'oneToMany',
target: 'api::category.category',
targetModel: 'api::category.category',
relationType: 'oneToMany',
},
my_name: {
type: 'string',
},
},
},
};
const attributes = {
dynamic_relations: {
type: 'dynamiczone',
components: ['basic.simple'],
},
};
const actual = recursivelyFindPathsBasedOnCondition(
components,
(value) => value.type === 'component' && value.repeatable === false
)(attributes);
expect(actual).toEqual([]);
});
});
}); });