mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat(api): add automatic DI to extensions module
This commit is contained in:
parent
b494efdb9a
commit
b36d8939b2
@ -6,15 +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 { CACHE_MANAGER } from '@nestjs/cache-manager';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { Request } from 'express';
|
||||
|
||||
import { AttachmentRepository } from '@/attachment/repositories/attachment.repository';
|
||||
import { AttachmentModel } from '@/attachment/schemas/attachment.schema';
|
||||
import { AttachmentService } from '@/attachment/services/attachment.service';
|
||||
import { ChannelService } from '@/channel/channel.service';
|
||||
import {
|
||||
attachmentMessage,
|
||||
buttonsMessage,
|
||||
@ -22,30 +16,17 @@ import {
|
||||
quickRepliesMessage,
|
||||
textMessage,
|
||||
} from '@/channel/lib/__test__/common.mock';
|
||||
import { MessageRepository } from '@/chat/repositories/message.repository';
|
||||
import { SubscriberRepository } from '@/chat/repositories/subscriber.repository';
|
||||
import { LabelModel } from '@/chat/schemas/label.schema';
|
||||
import { MessageModel } from '@/chat/schemas/message.schema';
|
||||
import { SubscriberModel } from '@/chat/schemas/subscriber.schema';
|
||||
import { OutgoingMessageFormat } from '@/chat/schemas/types/message';
|
||||
import { MessageService } from '@/chat/services/message.service';
|
||||
import { SubscriberService } from '@/chat/services/subscriber.service';
|
||||
import { MenuRepository } from '@/cms/repositories/menu.repository';
|
||||
import { MenuModel } from '@/cms/schemas/menu.schema';
|
||||
import { MenuService } from '@/cms/services/menu.service';
|
||||
import { I18nService } from '@/i18n/services/i18n.service';
|
||||
import { SettingService } from '@/setting/services/setting.service';
|
||||
import { UserModel } from '@/user/schemas/user.schema';
|
||||
import { installMessageFixtures } from '@/utils/test/fixtures/message';
|
||||
import {
|
||||
closeInMongodConnection,
|
||||
rootMongooseTestModule,
|
||||
} from '@/utils/test/test';
|
||||
import { buildTestingMocks } from '@/utils/test/utils';
|
||||
import { SocketEventDispatcherService } from '@/websocket/services/socket-event-dispatcher.service';
|
||||
import { SocketRequest } from '@/websocket/utils/socket-request';
|
||||
import { SocketResponse } from '@/websocket/utils/socket-response';
|
||||
import { WebsocketGateway } from '@/websocket/websocket.gateway';
|
||||
|
||||
import WebChannelHandler from '../index.channel';
|
||||
|
||||
@ -61,47 +42,18 @@ import {
|
||||
describe('WebChannelHandler', () => {
|
||||
let subscriberService: SubscriberService;
|
||||
let handler: WebChannelHandler;
|
||||
const webSettings = {};
|
||||
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
models: ['LabelModel', 'UserModel'],
|
||||
autoInjectFrom: ['providers'],
|
||||
imports: [
|
||||
rootMongooseTestModule(async () => {
|
||||
await installMessageFixtures();
|
||||
}),
|
||||
MongooseModule.forFeature([
|
||||
SubscriberModel,
|
||||
AttachmentModel,
|
||||
MessageModel,
|
||||
MenuModel,
|
||||
LabelModel,
|
||||
UserModel,
|
||||
]),
|
||||
JwtModule,
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
provide: SettingService,
|
||||
useValue: {
|
||||
getConfig: jest.fn(() => ({
|
||||
chatbot: { lang: { default: 'fr' } },
|
||||
})),
|
||||
getSettings: jest.fn(() => ({
|
||||
web: webSettings,
|
||||
})),
|
||||
},
|
||||
},
|
||||
ChannelService,
|
||||
WebsocketGateway,
|
||||
SocketEventDispatcherService,
|
||||
SubscriberService,
|
||||
SubscriberRepository,
|
||||
AttachmentService,
|
||||
AttachmentRepository,
|
||||
MessageService,
|
||||
MessageRepository,
|
||||
MenuService,
|
||||
MenuRepository,
|
||||
JwtService,
|
||||
WebChannelHandler,
|
||||
{
|
||||
provide: I18nService,
|
||||
@ -109,14 +61,6 @@ describe('WebChannelHandler', () => {
|
||||
t: jest.fn().mockImplementation((t) => t),
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: CACHE_MANAGER,
|
||||
useValue: {
|
||||
del: jest.fn(),
|
||||
get: jest.fn(),
|
||||
set: jest.fn(),
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
[subscriberService, handler] = await getMocks([
|
||||
|
@ -6,41 +6,20 @@
|
||||
* 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 { JwtModule } from '@nestjs/jwt';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
|
||||
import { AttachmentRepository } from '@/attachment/repositories/attachment.repository';
|
||||
import {
|
||||
Attachment,
|
||||
AttachmentModel,
|
||||
} from '@/attachment/schemas/attachment.schema';
|
||||
import { AttachmentService } from '@/attachment/services/attachment.service';
|
||||
import { ChannelService } from '@/channel/channel.service';
|
||||
import { MessageRepository } from '@/chat/repositories/message.repository';
|
||||
import { SubscriberRepository } from '@/chat/repositories/subscriber.repository';
|
||||
import { MessageModel } from '@/chat/schemas/message.schema';
|
||||
import { SubscriberModel } from '@/chat/schemas/subscriber.schema';
|
||||
import { Attachment } from '@/attachment/schemas/attachment.schema';
|
||||
import {
|
||||
IncomingMessageType,
|
||||
StdEventType,
|
||||
} from '@/chat/schemas/types/message';
|
||||
import { MessageService } from '@/chat/services/message.service';
|
||||
import { SubscriberService } from '@/chat/services/subscriber.service';
|
||||
import { MenuRepository } from '@/cms/repositories/menu.repository';
|
||||
import { MenuModel } from '@/cms/schemas/menu.schema';
|
||||
import { MenuService } from '@/cms/services/menu.service';
|
||||
import { I18nService } from '@/i18n/services/i18n.service';
|
||||
import { NlpService } from '@/nlp/services/nlp.service';
|
||||
import { SettingService } from '@/setting/services/setting.service';
|
||||
import { installSubscriberFixtures } from '@/utils/test/fixtures/subscriber';
|
||||
import {
|
||||
closeInMongodConnection,
|
||||
rootMongooseTestModule,
|
||||
} from '@/utils/test/test';
|
||||
import { buildTestingMocks } from '@/utils/test/utils';
|
||||
import { SocketEventDispatcherService } from '@/websocket/services/socket-event-dispatcher.service';
|
||||
import { WebsocketGateway } from '@/websocket/websocket.gateway';
|
||||
|
||||
import WebChannelHandler from '../index.channel';
|
||||
import { WEB_CHANNEL_NAME } from '../settings';
|
||||
@ -50,48 +29,12 @@ import { webEvents } from './events.mock';
|
||||
|
||||
describe(`Web event wrapper`, () => {
|
||||
let handler: WebChannelHandler;
|
||||
const webSettings = {};
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
imports: [
|
||||
rootMongooseTestModule(installSubscriberFixtures),
|
||||
MongooseModule.forFeature([
|
||||
SubscriberModel,
|
||||
AttachmentModel,
|
||||
MessageModel,
|
||||
MenuModel,
|
||||
]),
|
||||
JwtModule,
|
||||
],
|
||||
autoInjectFrom: ['providers'],
|
||||
imports: [rootMongooseTestModule(installSubscriberFixtures)],
|
||||
providers: [
|
||||
{
|
||||
provide: SettingService,
|
||||
useValue: {
|
||||
getConfig: jest.fn(() => ({
|
||||
chatbot: { lang: { default: 'fr' } },
|
||||
})),
|
||||
getSettings: jest.fn(() => ({
|
||||
web: webSettings,
|
||||
})),
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: NlpService,
|
||||
useValue: {
|
||||
getNLP: jest.fn(() => undefined),
|
||||
},
|
||||
},
|
||||
ChannelService,
|
||||
SubscriberService,
|
||||
SubscriberRepository,
|
||||
WebsocketGateway,
|
||||
SocketEventDispatcherService,
|
||||
AttachmentService,
|
||||
AttachmentRepository,
|
||||
MessageService,
|
||||
MessageRepository,
|
||||
MenuService,
|
||||
MenuRepository,
|
||||
JwtService,
|
||||
WebChannelHandler,
|
||||
{
|
||||
provide: I18nService,
|
||||
@ -99,14 +42,6 @@ describe(`Web event wrapper`, () => {
|
||||
t: jest.fn().mockImplementation((t) => t),
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: CACHE_MANAGER,
|
||||
useValue: {
|
||||
del: jest.fn(),
|
||||
get: jest.fn(),
|
||||
set: jest.fn(),
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
[handler] = await getMocks([WebChannelHandler]);
|
||||
|
Loading…
Reference in New Issue
Block a user