mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat(api): add automatic DI to attachment module
This commit is contained in:
parent
c465ebc11e
commit
6ad85a7b3b
@ -8,26 +8,17 @@
|
|||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
import { CACHE_MANAGER } from '@nestjs/cache-manager';
|
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
MethodNotAllowedException,
|
MethodNotAllowedException,
|
||||||
} from '@nestjs/common/exceptions';
|
} from '@nestjs/common/exceptions';
|
||||||
import { NotFoundException } from '@nestjs/common/exceptions/not-found.exception';
|
import { NotFoundException } from '@nestjs/common/exceptions/not-found.exception';
|
||||||
import { MongooseModule } from '@nestjs/mongoose';
|
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
|
|
||||||
import LocalStorageHelper from '@/extensions/helpers/local-storage/index.helper';
|
import LocalStorageHelper from '@/extensions/helpers/local-storage/index.helper';
|
||||||
import { HelperService } from '@/helper/helper.service';
|
import { HelperService } from '@/helper/helper.service';
|
||||||
import { LoggerService } from '@/logger/logger.service';
|
import { LoggerService } from '@/logger/logger.service';
|
||||||
import { SettingRepository } from '@/setting/repositories/setting.repository';
|
|
||||||
import { SettingModel } from '@/setting/schemas/setting.schema';
|
|
||||||
import { SettingSeeder } from '@/setting/seeds/setting.seed';
|
|
||||||
import { SettingService } from '@/setting/services/setting.service';
|
import { SettingService } from '@/setting/services/setting.service';
|
||||||
import { ModelRepository } from '@/user/repositories/model.repository';
|
|
||||||
import { PermissionRepository } from '@/user/repositories/permission.repository';
|
|
||||||
import { ModelModel } from '@/user/schemas/model.schema';
|
|
||||||
import { PermissionModel } from '@/user/schemas/permission.schema';
|
|
||||||
import { ModelService } from '@/user/services/model.service';
|
import { ModelService } from '@/user/services/model.service';
|
||||||
import { PermissionService } from '@/user/services/permission.service';
|
import { PermissionService } from '@/user/services/permission.service';
|
||||||
import { NOT_FOUND_ID } from '@/utils/constants/mock';
|
import { NOT_FOUND_ID } from '@/utils/constants/mock';
|
||||||
@ -44,8 +35,7 @@ import {
|
|||||||
import { buildTestingMocks } from '@/utils/test/utils';
|
import { buildTestingMocks } from '@/utils/test/utils';
|
||||||
|
|
||||||
import { attachment, attachmentFile } from '../mocks/attachment.mock';
|
import { attachment, attachmentFile } from '../mocks/attachment.mock';
|
||||||
import { AttachmentRepository } from '../repositories/attachment.repository';
|
import { Attachment } from '../schemas/attachment.schema';
|
||||||
import { Attachment, AttachmentModel } from '../schemas/attachment.schema';
|
|
||||||
import { AttachmentService } from '../services/attachment.service';
|
import { AttachmentService } from '../services/attachment.service';
|
||||||
import {
|
import {
|
||||||
AttachmentAccess,
|
AttachmentAccess,
|
||||||
@ -64,39 +54,15 @@ describe('AttachmentController', () => {
|
|||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const { getMocks, resolveMocks } = await buildTestingMocks({
|
const { getMocks, resolveMocks } = await buildTestingMocks({
|
||||||
|
autoInjectFrom: ['all'],
|
||||||
controllers: [AttachmentController],
|
controllers: [AttachmentController],
|
||||||
imports: [
|
imports: [
|
||||||
rootMongooseTestModule(async () => {
|
rootMongooseTestModule(async () => {
|
||||||
await installSettingFixtures();
|
await installSettingFixtures();
|
||||||
await installAttachmentFixtures();
|
await installAttachmentFixtures();
|
||||||
}),
|
}),
|
||||||
MongooseModule.forFeature([
|
|
||||||
AttachmentModel,
|
|
||||||
PermissionModel,
|
|
||||||
ModelModel,
|
|
||||||
SettingModel,
|
|
||||||
]),
|
|
||||||
],
|
|
||||||
providers: [
|
|
||||||
AttachmentService,
|
|
||||||
AttachmentRepository,
|
|
||||||
PermissionService,
|
|
||||||
PermissionRepository,
|
|
||||||
SettingRepository,
|
|
||||||
ModelService,
|
|
||||||
ModelRepository,
|
|
||||||
SettingSeeder,
|
|
||||||
SettingService,
|
|
||||||
HelperService,
|
|
||||||
{
|
|
||||||
provide: CACHE_MANAGER,
|
|
||||||
useValue: {
|
|
||||||
del: jest.fn(),
|
|
||||||
get: jest.fn(),
|
|
||||||
set: jest.fn(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
|
providers: [PermissionService, ModelService],
|
||||||
});
|
});
|
||||||
[attachmentController, attachmentService, helperService, settingService] =
|
[attachmentController, attachmentService, helperService, settingService] =
|
||||||
await getMocks([
|
await getMocks([
|
||||||
|
Loading…
Reference in New Issue
Block a user