mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat(api): add automatic DI to CMS module
This commit is contained in:
parent
3d6994ecda
commit
2d799e0886
@ -7,12 +7,9 @@
|
||||
*/
|
||||
|
||||
import { NotFoundException } from '@nestjs/common/exceptions';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
|
||||
import { AttachmentRepository } from '@/attachment/repositories/attachment.repository';
|
||||
import { AttachmentModel } from '@/attachment/schemas/attachment.schema';
|
||||
import { AttachmentService } from '@/attachment/services/attachment.service';
|
||||
import { BlockService } from '@/chat/services/block.service';
|
||||
import { I18nService } from '@/i18n/services/i18n.service';
|
||||
import { FieldType } from '@/setting/schemas/types';
|
||||
import { NOT_FOUND_ID } from '@/utils/constants/mock';
|
||||
import { getUpdateOneError } from '@/utils/test/errors/messages';
|
||||
@ -26,10 +23,7 @@ import {
|
||||
import { buildTestingMocks } from '@/utils/test/utils';
|
||||
|
||||
import { ContentTypeCreateDto } from '../dto/contentType.dto';
|
||||
import { ContentTypeRepository } from '../repositories/content-type.repository';
|
||||
import { ContentRepository } from '../repositories/content.repository';
|
||||
import { ContentType, ContentTypeModel } from '../schemas/content-type.schema';
|
||||
import { ContentModel } from '../schemas/content.schema';
|
||||
import { ContentType } from '../schemas/content-type.schema';
|
||||
import { ContentTypeService } from '../services/content-type.service';
|
||||
import { ContentService } from '../services/content.service';
|
||||
|
||||
@ -44,26 +38,14 @@ describe('ContentTypeController', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
autoInjectFrom: ['controllers'],
|
||||
controllers: [ContentTypeController],
|
||||
imports: [
|
||||
rootMongooseTestModule(installContentFixtures),
|
||||
MongooseModule.forFeature([
|
||||
ContentTypeModel,
|
||||
ContentModel,
|
||||
AttachmentModel,
|
||||
]),
|
||||
],
|
||||
imports: [rootMongooseTestModule(installContentFixtures)],
|
||||
providers: [
|
||||
ContentTypeRepository,
|
||||
ContentRepository,
|
||||
AttachmentRepository,
|
||||
ContentTypeService,
|
||||
ContentService,
|
||||
AttachmentService,
|
||||
{
|
||||
provide: BlockService,
|
||||
provide: I18nService,
|
||||
useValue: {
|
||||
findOne: jest.fn(),
|
||||
t: jest.fn().mockImplementation((t) => t),
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -7,8 +7,8 @@
|
||||
*/
|
||||
|
||||
import { NotFoundException } from '@nestjs/common/exceptions';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
|
||||
import { I18nService } from '@/i18n/services/i18n.service';
|
||||
import { NOT_FOUND_ID } from '@/utils/constants/mock';
|
||||
import { PageQueryDto } from '@/utils/pagination/pagination-query.dto';
|
||||
import { IGNORED_TEST_FIELDS } from '@/utils/test/constants';
|
||||
@ -25,10 +25,8 @@ import {
|
||||
import { buildTestingMocks } from '@/utils/test/utils';
|
||||
|
||||
import { ContentCreateDto } from '../dto/content.dto';
|
||||
import { ContentTypeRepository } from '../repositories/content-type.repository';
|
||||
import { ContentRepository } from '../repositories/content.repository';
|
||||
import { ContentType, ContentTypeModel } from '../schemas/content-type.schema';
|
||||
import { Content, ContentModel } from '../schemas/content.schema';
|
||||
import { ContentType } from '../schemas/content-type.schema';
|
||||
import { Content } from '../schemas/content.schema';
|
||||
import { ContentTypeService } from '../services/content-type.service';
|
||||
import { ContentService } from '../services/content.service';
|
||||
|
||||
@ -45,16 +43,16 @@ describe('ContentController', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
autoInjectFrom: ['controllers'],
|
||||
controllers: [ContentController],
|
||||
imports: [
|
||||
rootMongooseTestModule(installContentFixtures),
|
||||
MongooseModule.forFeature([ContentTypeModel, ContentModel]),
|
||||
],
|
||||
imports: [rootMongooseTestModule(installContentFixtures)],
|
||||
providers: [
|
||||
ContentTypeService,
|
||||
ContentService,
|
||||
ContentRepository,
|
||||
ContentTypeRepository,
|
||||
{
|
||||
provide: I18nService,
|
||||
useValue: {
|
||||
t: jest.fn().mockImplementation((t) => t),
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
[contentController, contentService, contentTypeService] = await getMocks([
|
||||
|
@ -6,9 +6,6 @@
|
||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||
*/
|
||||
|
||||
import { CACHE_MANAGER } from '@nestjs/cache-manager';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
|
||||
import {
|
||||
installMenuFixtures,
|
||||
offerMenuFixture,
|
||||
@ -21,8 +18,6 @@ import {
|
||||
} from '@/utils/test/test';
|
||||
import { buildTestingMocks } from '@/utils/test/utils';
|
||||
|
||||
import { MenuRepository } from '../repositories/menu.repository';
|
||||
import { MenuModel } from '../schemas/menu.schema';
|
||||
import { MenuType } from '../schemas/types/menu';
|
||||
import { MenuService } from '../services/menu.service';
|
||||
import { verifyTree } from '../utilities/verifyTree';
|
||||
@ -34,22 +29,8 @@ describe('MenuController', () => {
|
||||
let menuService: MenuService;
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
imports: [
|
||||
rootMongooseTestModule(installMenuFixtures),
|
||||
MongooseModule.forFeature([MenuModel]),
|
||||
],
|
||||
providers: [
|
||||
MenuRepository,
|
||||
MenuService,
|
||||
{
|
||||
provide: CACHE_MANAGER,
|
||||
useValue: {
|
||||
del: jest.fn(),
|
||||
get: jest.fn(),
|
||||
set: jest.fn(),
|
||||
},
|
||||
},
|
||||
],
|
||||
autoInjectFrom: ['controllers'],
|
||||
imports: [rootMongooseTestModule(installMenuFixtures)],
|
||||
controllers: [MenuController],
|
||||
});
|
||||
[menuController, menuService] = await getMocks([
|
||||
|
@ -6,27 +6,22 @@
|
||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||
*/
|
||||
|
||||
import { MongooseModule, getModelToken } from '@nestjs/mongoose';
|
||||
import { getModelToken } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
|
||||
import { BlockRepository } from '@/chat/repositories/block.repository';
|
||||
import { BlockModel } from '@/chat/schemas/block.schema';
|
||||
import { BlockService } from '@/chat/services/block.service';
|
||||
import {
|
||||
ContentType,
|
||||
ContentTypeModel,
|
||||
} from '@/cms/schemas/content-type.schema';
|
||||
import { ContentType } from '@/cms/schemas/content-type.schema';
|
||||
import { I18nService } from '@/i18n/services/i18n.service';
|
||||
import {
|
||||
closeInMongodConnection,
|
||||
rootMongooseTestModule,
|
||||
} from '@/utils/test/test';
|
||||
import { buildTestingMocks } from '@/utils/test/utils';
|
||||
|
||||
import { Content, ContentModel } from '../schemas/content.schema';
|
||||
import { Content } from '../schemas/content.schema';
|
||||
|
||||
import { installContentFixtures } from './../../utils/test/fixtures/content';
|
||||
import { ContentTypeRepository } from './content-type.repository';
|
||||
import { ContentRepository } from './content.repository';
|
||||
|
||||
describe('ContentTypeRepository', () => {
|
||||
let contentTypeRepository: ContentTypeRepository;
|
||||
@ -36,19 +31,14 @@ describe('ContentTypeRepository', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
imports: [
|
||||
rootMongooseTestModule(installContentFixtures),
|
||||
MongooseModule.forFeature([ContentTypeModel, ContentModel, BlockModel]),
|
||||
],
|
||||
autoInjectFrom: ['providers'],
|
||||
imports: [rootMongooseTestModule(installContentFixtures)],
|
||||
providers: [
|
||||
ContentRepository,
|
||||
ContentTypeRepository,
|
||||
BlockService,
|
||||
BlockRepository,
|
||||
{
|
||||
provide: BlockService,
|
||||
provide: I18nService,
|
||||
useValue: {
|
||||
findOne: jest.fn(),
|
||||
t: jest.fn().mockImplementation((t) => t),
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -6,13 +6,10 @@
|
||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||
*/
|
||||
|
||||
import { MongooseModule, getModelToken } from '@nestjs/mongoose';
|
||||
import { getModelToken } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
|
||||
import {
|
||||
ContentType,
|
||||
ContentTypeModel,
|
||||
} from '@/cms/schemas/content-type.schema';
|
||||
import { ContentType } from '@/cms/schemas/content-type.schema';
|
||||
import { contentTypeFixtures } from '@/utils/test/fixtures/contenttype';
|
||||
import { getPageQuery } from '@/utils/test/pagination';
|
||||
import {
|
||||
@ -21,7 +18,7 @@ import {
|
||||
} from '@/utils/test/test';
|
||||
import { buildTestingMocks } from '@/utils/test/utils';
|
||||
|
||||
import { Content, ContentModel } from '../schemas/content.schema';
|
||||
import { Content } from '../schemas/content.schema';
|
||||
|
||||
import {
|
||||
contentFixtures,
|
||||
@ -36,10 +33,9 @@ describe('ContentRepository', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
imports: [
|
||||
rootMongooseTestModule(installContentFixtures),
|
||||
MongooseModule.forFeature([ContentTypeModel, ContentModel]),
|
||||
],
|
||||
models: ['ContentTypeModel'],
|
||||
autoInjectFrom: ['providers'],
|
||||
imports: [rootMongooseTestModule(installContentFixtures)],
|
||||
providers: [ContentRepository],
|
||||
});
|
||||
[contentRepository, contentModel, contentTypeModel] = await getMocks([
|
||||
|
@ -6,8 +6,6 @@
|
||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||
*/
|
||||
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
|
||||
import {
|
||||
installMenuFixtures,
|
||||
rootMenuFixtures,
|
||||
@ -18,7 +16,6 @@ import {
|
||||
} from '@/utils/test/test';
|
||||
import { buildTestingMocks } from '@/utils/test/utils';
|
||||
|
||||
import { MenuModel } from '../schemas/menu.schema';
|
||||
import { MenuType } from '../schemas/types/menu';
|
||||
|
||||
import { MenuRepository } from './menu.repository';
|
||||
@ -27,10 +24,8 @@ describe('MenuRepository', () => {
|
||||
let menuRepository: MenuRepository;
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
imports: [
|
||||
rootMongooseTestModule(installMenuFixtures),
|
||||
MongooseModule.forFeature([MenuModel]),
|
||||
],
|
||||
autoInjectFrom: ['providers'],
|
||||
imports: [rootMongooseTestModule(installMenuFixtures)],
|
||||
providers: [MenuRepository],
|
||||
});
|
||||
[menuRepository] = await getMocks([MenuRepository]);
|
||||
|
@ -6,12 +6,8 @@
|
||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||
*/
|
||||
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
|
||||
import { AttachmentRepository } from '@/attachment/repositories/attachment.repository';
|
||||
import { AttachmentModel } from '@/attachment/schemas/attachment.schema';
|
||||
import { AttachmentService } from '@/attachment/services/attachment.service';
|
||||
import { BlockService } from '@/chat/services/block.service';
|
||||
import { I18nService } from '@/i18n/services/i18n.service';
|
||||
import { installContentFixtures } from '@/utils/test/fixtures/content';
|
||||
import {
|
||||
closeInMongodConnection,
|
||||
@ -20,9 +16,6 @@ import {
|
||||
import { buildTestingMocks } from '@/utils/test/utils';
|
||||
|
||||
import { ContentTypeRepository } from '../repositories/content-type.repository';
|
||||
import { ContentRepository } from '../repositories/content.repository';
|
||||
import { ContentTypeModel } from '../schemas/content-type.schema';
|
||||
import { ContentModel } from '../schemas/content.schema';
|
||||
|
||||
import { ContentTypeService } from './content-type.service';
|
||||
import { ContentService } from './content.service';
|
||||
@ -35,25 +28,14 @@ describe('ContentTypeService', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
imports: [
|
||||
rootMongooseTestModule(installContentFixtures),
|
||||
MongooseModule.forFeature([
|
||||
ContentTypeModel,
|
||||
ContentModel,
|
||||
AttachmentModel,
|
||||
]),
|
||||
],
|
||||
autoInjectFrom: ['providers'],
|
||||
imports: [rootMongooseTestModule(installContentFixtures)],
|
||||
providers: [
|
||||
ContentTypeRepository,
|
||||
ContentRepository,
|
||||
AttachmentRepository,
|
||||
ContentTypeService,
|
||||
ContentService,
|
||||
AttachmentService,
|
||||
{
|
||||
provide: BlockService,
|
||||
provide: I18nService,
|
||||
useValue: {
|
||||
findOne: jest.fn(),
|
||||
t: jest.fn().mockImplementation((t) => t),
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -6,10 +6,9 @@
|
||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||
*/
|
||||
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
|
||||
import { OutgoingMessageFormat } from '@/chat/schemas/types/message';
|
||||
import { ContentOptions } from '@/chat/schemas/types/options';
|
||||
import { I18nService } from '@/i18n/services/i18n.service';
|
||||
import { IGNORED_TEST_FIELDS } from '@/utils/test/constants';
|
||||
import {
|
||||
contentFixtures,
|
||||
@ -22,10 +21,8 @@ import {
|
||||
} from '@/utils/test/test';
|
||||
import { buildTestingMocks } from '@/utils/test/utils';
|
||||
|
||||
import { ContentTypeRepository } from '../repositories/content-type.repository';
|
||||
import { ContentRepository } from '../repositories/content.repository';
|
||||
import { ContentTypeModel } from '../schemas/content-type.schema';
|
||||
import { Content, ContentModel } from '../schemas/content.schema';
|
||||
import { Content } from '../schemas/content.schema';
|
||||
|
||||
import { ContentTypeService } from './content-type.service';
|
||||
import { ContentService } from './content.service';
|
||||
@ -37,15 +34,16 @@ describe('ContentService', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
imports: [
|
||||
rootMongooseTestModule(installContentFixtures),
|
||||
MongooseModule.forFeature([ContentTypeModel, ContentModel]),
|
||||
],
|
||||
autoInjectFrom: ['providers'],
|
||||
imports: [rootMongooseTestModule(installContentFixtures)],
|
||||
providers: [
|
||||
ContentTypeRepository,
|
||||
ContentRepository,
|
||||
ContentTypeService,
|
||||
ContentService,
|
||||
{
|
||||
provide: I18nService,
|
||||
useValue: {
|
||||
t: jest.fn().mockImplementation((t) => t),
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
[contentService, contentTypeService, contentRepository] = await getMocks([
|
||||
|
@ -6,9 +6,7 @@
|
||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||
*/
|
||||
|
||||
import { CACHE_MANAGER } from '@nestjs/cache-manager';
|
||||
import { NotFoundException } from '@nestjs/common';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
|
||||
import {
|
||||
installMenuFixtures,
|
||||
@ -21,7 +19,6 @@ import {
|
||||
import { buildTestingMocks } from '@/utils/test/utils';
|
||||
|
||||
import { MenuRepository } from '../repositories/menu.repository';
|
||||
import { MenuModel } from '../schemas/menu.schema';
|
||||
import { MenuType } from '../schemas/types/menu';
|
||||
import { verifyTree } from '../utilities/verifyTree';
|
||||
|
||||
@ -32,22 +29,9 @@ describe('MenuService', () => {
|
||||
let menuRepository: MenuRepository;
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
imports: [
|
||||
rootMongooseTestModule(installMenuFixtures),
|
||||
MongooseModule.forFeature([MenuModel]),
|
||||
],
|
||||
providers: [
|
||||
MenuRepository,
|
||||
MenuService,
|
||||
{
|
||||
provide: CACHE_MANAGER,
|
||||
useValue: {
|
||||
del: jest.fn(),
|
||||
get: jest.fn(),
|
||||
set: jest.fn(),
|
||||
},
|
||||
},
|
||||
],
|
||||
autoInjectFrom: ['providers'],
|
||||
imports: [rootMongooseTestModule(installMenuFixtures)],
|
||||
providers: [MenuService],
|
||||
});
|
||||
[menuService, menuRepository] = await getMocks([
|
||||
MenuService,
|
||||
|
Loading…
Reference in New Issue
Block a user