fix: CMS module issues

This commit is contained in:
yassinedorbozgithub
2025-01-07 11:37:03 +01:00
parent 2910de0058
commit 0101655e33
25 changed files with 235 additions and 207 deletions

View File

@@ -84,9 +84,12 @@ describe('ContentTypeService', () => {
);
jest.spyOn(blockService, 'findOne').mockResolvedValueOnce(null);
const contentType = await contentTypeService.findOne({ name: 'Product' });
const result = await contentTypeService.deleteCascadeOne(contentType.id);
expect(deleteContentTypeSpy).toHaveBeenCalledWith(contentType.id);
expect(await contentService.find({ entity: contentType.id })).toEqual([]);
const result = await contentTypeService.deleteCascadeOne(contentType!.id);
expect(deleteContentTypeSpy).toHaveBeenCalledWith(contentType!.id);
expect(await contentService.find({ entity: contentType!.id })).toEqual(
[],
);
expect(result).toEqual({ acknowledged: true, deletedCount: 1 });
});
});

View File

@@ -82,9 +82,10 @@ describe('ContentService', () => {
it('should return a content and populate its corresponding content type', async () => {
const findSpy = jest.spyOn(contentRepository, 'findOneAndPopulate');
const content = await contentService.findOne({ title: 'Jean' });
const contentType = await contentTypeService.findOne(content.entity);
const result = await contentService.findOneAndPopulate(content.id);
expect(findSpy).toHaveBeenCalledWith(content.id, undefined);
const contentType = await contentTypeService.findOne(content!.entity);
const result = await contentService.findOneAndPopulate(content!.id);
expect(findSpy).toHaveBeenCalledWith(content!.id, undefined);
expect(result).toEqualPayload({
...contentFixtures.find(({ title }) => title === 'Jean'),
entity: contentType,
@@ -235,14 +236,14 @@ describe('ContentService', () => {
it('should get content for a specific entity', async () => {
const contentType = await contentTypeService.findOne({ name: 'Product' });
const actualData = await contentService.findPage(
{ status: true, entity: contentType.id },
{ status: true, entity: contentType!.id },
{ skip: 0, limit: 10, sort: ['createdAt', 'desc'] },
);
const flattenedElements = actualData.map(Content.toElement);
const content = await contentService.getContent(
{
...contentOptions,
entity: contentType.id,
entity: contentType!.id,
},
0,
);
@@ -253,7 +254,7 @@ describe('ContentService', () => {
contentOptions.entity = 1;
const contentType = await contentTypeService.findOne({ name: 'Product' });
const actualData = await contentService.findPage(
{ status: true, entity: contentType.id, title: /^Jean/ },
{ status: true, entity: contentType!.id, title: /^Jean/ },
{ skip: 0, limit: 10, sort: ['createdAt', 'desc'] },
);
const flattenedElements = actualData.map(Content.toElement);

View File

@@ -150,7 +150,7 @@ export class ContentService extends BaseService<
async getContent(
options: ContentOptions,
skip: number,
): Promise<Omit<StdOutgoingListMessage, 'options'> | undefined> {
): Promise<Omit<StdOutgoingListMessage, 'options'>> {
let query: TFilterQuery<Content> = { status: true };
const limit = options.limit;

View File

@@ -94,17 +94,20 @@ export class MenuService extends BaseService<Menu, MenuPopulate, MenuFull> {
const parents: Map<string | symbol, AnyMenu[]> = new Map();
parents.set(this.RootSymbol, []);
menuItems.forEach((m) => {
const menuParent = m.parent?.toString();
if (!m.parent) {
parents.get(this.RootSymbol).push(m);
menuItems.forEach((menuItem) => {
const menuParent = menuItem.parent?.toString();
if (!menuItem.parent) {
parents.get(this.RootSymbol)!.push(menuItem);
return;
}
if (parents.has(menuParent)) {
parents.get(menuParent).push(m);
return;
if (menuParent) {
if (parents.has(menuParent)) {
parents.get(menuParent)!.push(menuItem);
return;
}
parents.set(menuParent, [menuItem]);
}
parents.set(menuParent, [m]);
});
return parents;
@@ -122,8 +125,9 @@ export class MenuService extends BaseService<Menu, MenuPopulate, MenuFull> {
parents: Map<string | symbol, AnyMenu[]>,
parent: string | symbol = this.RootSymbol,
): MenuTree {
if (!parents.has(parent)) return undefined;
const children: MenuTree = parents.get(parent).map((menu) => {
const item = parents.get(parent);
if (!item) return [];
const children: MenuTree = item.map((menu) => {
return {
...menu,
call_to_actions: