mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
refactor(api): enhance logic
This commit is contained in:
parent
369ef033a2
commit
b7576c04e9
@ -54,7 +54,7 @@ describe('AttachmentController', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const { getMocks, resolveMocks } = await buildTestingMocks({
|
||||
autoInjectFrom: ['all'],
|
||||
autoInjectFrom: ['controllers', 'providers'],
|
||||
controllers: [AttachmentController],
|
||||
imports: [
|
||||
rootMongooseTestModule(async () => {
|
||||
|
@ -38,7 +38,7 @@ describe('LabelController', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
autoInjectFrom: ['all'],
|
||||
autoInjectFrom: ['controllers', 'providers'],
|
||||
controllers: [LabelController],
|
||||
imports: [rootMongooseTestModule(installSubscriberFixtures)],
|
||||
providers: [SubscriberService],
|
||||
|
@ -41,7 +41,7 @@ describe('MessageController', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
autoInjectFrom: ['all'],
|
||||
autoInjectFrom: ['controllers', 'providers'],
|
||||
controllers: [MessageController],
|
||||
imports: [rootMongooseTestModule(installMessageFixtures)],
|
||||
providers: [UserService],
|
||||
|
@ -39,7 +39,7 @@ describe('SubscriberController', () => {
|
||||
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
autoInjectFrom: ['all'],
|
||||
autoInjectFrom: ['controllers', 'providers'],
|
||||
controllers: [SubscriberController],
|
||||
imports: [rootMongooseTestModule(installSubscriberFixtures)],
|
||||
providers: [LabelService, UserService],
|
||||
|
@ -45,7 +45,7 @@ describe('AuthController', () => {
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
models: ['PermissionModel'],
|
||||
autoInjectFrom: ['all'],
|
||||
autoInjectFrom: ['controllers', 'providers'],
|
||||
controllers: [LocalAuthController],
|
||||
imports: [
|
||||
rootMongooseTestModule(async () => {
|
||||
|
@ -30,7 +30,7 @@ describe('ModelController', () => {
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
models: ['PermissionModel'],
|
||||
autoInjectFrom: ['all'],
|
||||
autoInjectFrom: ['controllers', 'providers'],
|
||||
controllers: [ModelController],
|
||||
imports: [rootMongooseTestModule(installModelFixtures)],
|
||||
providers: [PermissionService],
|
||||
|
@ -37,7 +37,7 @@ describe('RoleController', () => {
|
||||
beforeAll(async () => {
|
||||
const { getMocks } = await buildTestingMocks({
|
||||
models: ['InvitationModel'],
|
||||
autoInjectFrom: ['all'],
|
||||
autoInjectFrom: ['controllers', 'providers'],
|
||||
controllers: [RoleController],
|
||||
imports: [rootMongooseTestModule(installPermissionFixtures)],
|
||||
providers: [PermissionService],
|
||||
|
@ -36,7 +36,7 @@ type buildTestingMocksProps<
|
||||
| {
|
||||
providers: NonNullable<P>;
|
||||
controllers: NonNullable<C>;
|
||||
autoInjectFrom: 'all'[];
|
||||
autoInjectFrom: ('providers' | 'controllers')[];
|
||||
}
|
||||
| {
|
||||
providers: NonNullable<P>;
|
||||
@ -171,17 +171,16 @@ export const buildTestingMocks = async ({
|
||||
}: buildTestingMocksProps) => {
|
||||
const nestedProviders = new Set<Provider>();
|
||||
const injectionFrom = autoInjectFrom as ToUnionArray<typeof autoInjectFrom>;
|
||||
const canAutoInjectFromAll = injectionFrom?.includes('all');
|
||||
const canAutoInjectFromProviders = injectionFrom?.includes('providers');
|
||||
const canAutoInjectFromControllers = injectionFrom?.includes('controllers');
|
||||
|
||||
if (canAutoInjectFromAll || canAutoInjectFromProviders) {
|
||||
if (canAutoInjectFromProviders) {
|
||||
[...providers, ...getNestedDependencies(providers)].forEach((provider) =>
|
||||
nestedProviders.add(provider),
|
||||
);
|
||||
}
|
||||
|
||||
if (canAutoInjectFromAll || canAutoInjectFromControllers) {
|
||||
if (canAutoInjectFromControllers) {
|
||||
[...getNestedDependencies(controllers)].forEach((controller) =>
|
||||
nestedProviders.add(controller),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user