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).
|
* 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 { JwtService } from '@nestjs/jwt';
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
|
||||||
import { MongooseModule } from '@nestjs/mongoose';
|
|
||||||
import { Request } from 'express';
|
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 {
|
import {
|
||||||
attachmentMessage,
|
attachmentMessage,
|
||||||
buttonsMessage,
|
buttonsMessage,
|
||||||
@ -22,30 +16,17 @@ import {
|
|||||||
quickRepliesMessage,
|
quickRepliesMessage,
|
||||||
textMessage,
|
textMessage,
|
||||||
} from '@/channel/lib/__test__/common.mock';
|
} 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 { OutgoingMessageFormat } from '@/chat/schemas/types/message';
|
||||||
import { MessageService } from '@/chat/services/message.service';
|
|
||||||
import { SubscriberService } from '@/chat/services/subscriber.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 { 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 { installMessageFixtures } from '@/utils/test/fixtures/message';
|
||||||
import {
|
import {
|
||||||
closeInMongodConnection,
|
closeInMongodConnection,
|
||||||
rootMongooseTestModule,
|
rootMongooseTestModule,
|
||||||
} from '@/utils/test/test';
|
} from '@/utils/test/test';
|
||||||
import { buildTestingMocks } from '@/utils/test/utils';
|
import { buildTestingMocks } from '@/utils/test/utils';
|
||||||
import { SocketEventDispatcherService } from '@/websocket/services/socket-event-dispatcher.service';
|
|
||||||
import { SocketRequest } from '@/websocket/utils/socket-request';
|
import { SocketRequest } from '@/websocket/utils/socket-request';
|
||||||
import { SocketResponse } from '@/websocket/utils/socket-response';
|
import { SocketResponse } from '@/websocket/utils/socket-response';
|
||||||
import { WebsocketGateway } from '@/websocket/websocket.gateway';
|
|
||||||
|
|
||||||
import WebChannelHandler from '../index.channel';
|
import WebChannelHandler from '../index.channel';
|
||||||
|
|
||||||
@ -61,47 +42,18 @@ import {
|
|||||||
describe('WebChannelHandler', () => {
|
describe('WebChannelHandler', () => {
|
||||||
let subscriberService: SubscriberService;
|
let subscriberService: SubscriberService;
|
||||||
let handler: WebChannelHandler;
|
let handler: WebChannelHandler;
|
||||||
const webSettings = {};
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const { getMocks } = await buildTestingMocks({
|
const { getMocks } = await buildTestingMocks({
|
||||||
|
models: ['LabelModel', 'UserModel'],
|
||||||
|
autoInjectFrom: ['providers'],
|
||||||
imports: [
|
imports: [
|
||||||
rootMongooseTestModule(async () => {
|
rootMongooseTestModule(async () => {
|
||||||
await installMessageFixtures();
|
await installMessageFixtures();
|
||||||
}),
|
}),
|
||||||
MongooseModule.forFeature([
|
|
||||||
SubscriberModel,
|
|
||||||
AttachmentModel,
|
|
||||||
MessageModel,
|
|
||||||
MenuModel,
|
|
||||||
LabelModel,
|
|
||||||
UserModel,
|
|
||||||
]),
|
|
||||||
JwtModule,
|
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{
|
JwtService,
|
||||||
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,
|
|
||||||
WebChannelHandler,
|
WebChannelHandler,
|
||||||
{
|
{
|
||||||
provide: I18nService,
|
provide: I18nService,
|
||||||
@ -109,14 +61,6 @@ describe('WebChannelHandler', () => {
|
|||||||
t: jest.fn().mockImplementation((t) => t),
|
t: jest.fn().mockImplementation((t) => t),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
provide: CACHE_MANAGER,
|
|
||||||
useValue: {
|
|
||||||
del: jest.fn(),
|
|
||||||
get: jest.fn(),
|
|
||||||
set: jest.fn(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
[subscriberService, handler] = await getMocks([
|
[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).
|
* 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 { JwtService } from '@nestjs/jwt';
|
||||||
import { JwtModule } from '@nestjs/jwt';
|
|
||||||
import { MongooseModule } from '@nestjs/mongoose';
|
|
||||||
|
|
||||||
import { AttachmentRepository } from '@/attachment/repositories/attachment.repository';
|
import { Attachment } from '@/attachment/schemas/attachment.schema';
|
||||||
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 {
|
import {
|
||||||
IncomingMessageType,
|
IncomingMessageType,
|
||||||
StdEventType,
|
StdEventType,
|
||||||
} from '@/chat/schemas/types/message';
|
} 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 { 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 { installSubscriberFixtures } from '@/utils/test/fixtures/subscriber';
|
||||||
import {
|
import {
|
||||||
closeInMongodConnection,
|
closeInMongodConnection,
|
||||||
rootMongooseTestModule,
|
rootMongooseTestModule,
|
||||||
} from '@/utils/test/test';
|
} from '@/utils/test/test';
|
||||||
import { buildTestingMocks } from '@/utils/test/utils';
|
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 WebChannelHandler from '../index.channel';
|
||||||
import { WEB_CHANNEL_NAME } from '../settings';
|
import { WEB_CHANNEL_NAME } from '../settings';
|
||||||
@ -50,48 +29,12 @@ import { webEvents } from './events.mock';
|
|||||||
|
|
||||||
describe(`Web event wrapper`, () => {
|
describe(`Web event wrapper`, () => {
|
||||||
let handler: WebChannelHandler;
|
let handler: WebChannelHandler;
|
||||||
const webSettings = {};
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const { getMocks } = await buildTestingMocks({
|
const { getMocks } = await buildTestingMocks({
|
||||||
imports: [
|
autoInjectFrom: ['providers'],
|
||||||
rootMongooseTestModule(installSubscriberFixtures),
|
imports: [rootMongooseTestModule(installSubscriberFixtures)],
|
||||||
MongooseModule.forFeature([
|
|
||||||
SubscriberModel,
|
|
||||||
AttachmentModel,
|
|
||||||
MessageModel,
|
|
||||||
MenuModel,
|
|
||||||
]),
|
|
||||||
JwtModule,
|
|
||||||
],
|
|
||||||
providers: [
|
providers: [
|
||||||
{
|
JwtService,
|
||||||
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,
|
|
||||||
WebChannelHandler,
|
WebChannelHandler,
|
||||||
{
|
{
|
||||||
provide: I18nService,
|
provide: I18nService,
|
||||||
@ -99,14 +42,6 @@ describe(`Web event wrapper`, () => {
|
|||||||
t: jest.fn().mockImplementation((t) => t),
|
t: jest.fn().mockImplementation((t) => t),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
provide: CACHE_MANAGER,
|
|
||||||
useValue: {
|
|
||||||
del: jest.fn(),
|
|
||||||
get: jest.fn(),
|
|
||||||
set: jest.fn(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
[handler] = await getMocks([WebChannelHandler]);
|
[handler] = await getMocks([WebChannelHandler]);
|
||||||
|
Loading…
Reference in New Issue
Block a user