Skip to content

Commit

Permalink
chore: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis committed Dec 9, 2022
1 parent faccd12 commit d5ef35e
Showing 1 changed file with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,79 @@ describe('recursivelyFindPathsBasedOnCondition', () => {
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([]);
});
});
});

0 comments on commit d5ef35e

Please sign in to comment.