Skip to content

Commit

Permalink
BC-8424 Fix KNL job configurations (#5345)
Browse files Browse the repository at this point in the history
* Move defaultMirkoOrmOptions to shared, to avoid implicit importing the server code by using it.
* Fix configuration for idp-console and deletion-console module
  • Loading branch information
CeEv authored Nov 27, 2024
1 parent 340b59b commit 02f404f
Show file tree
Hide file tree
Showing 64 changed files with 314 additions and 329 deletions.
2 changes: 1 addition & 1 deletion apps/server/src/apps/deletion-console.app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* istanbul ignore file */
import { DeletionConsoleModule } from '@src/modules/deletion-console';
import { DeletionConsoleModule } from '@modules/deletion-console/deletion-console.app.module';
import { BootstrapConsole } from 'nestjs-console';

async function run() {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/apps/idp-console.app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* istanbul ignore file */
import { IdpConsoleModule } from '@modules/idp-console';
import { IdpConsoleModule } from '@modules/idp-console/idp-console.app.module';
import { BootstrapConsole } from 'nestjs-console';

async function run() {
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/infra/console/console-writer.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ConsoleWriterConfig {}
3 changes: 2 additions & 1 deletion apps/server/src/infra/console/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './console-writer';
export { ConsoleWriterModule, ConsoleWriterService } from './console-writer';
export { ConsoleWriterConfig } from './console-writer.config';
9 changes: 8 additions & 1 deletion apps/server/src/infra/rabbitmq/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
export * from './error.mapper';
export * from './exchange';
export * from './rabbitmq.config';
export {
RabbitMqConfig,
FilesPreviewExchange,
FilesStorageExchange,
MailSendExchange,
AntivirusExchange,
RabbitMqURI,
} from './rabbitmq.config';
export * from './rabbitmq.module';
export * from './rpc-message';
export * from './rpc-message-producer';
4 changes: 4 additions & 0 deletions apps/server/src/infra/rabbitmq/rabbitmq.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Configuration } from '@hpi-schul-cloud/commons/lib';

// should be move to config interface and added reading on places that use the module
export const FilesPreviewExchange = Configuration.get('FILES_STORAGE__EXCHANGE') as string;
export const FilesStorageExchange = Configuration.get('FILES_STORAGE__EXCHANGE') as string;
export const MailSendExchange = Configuration.get('MAIL_SEND_EXCHANGE') as string;
export const AntivirusExchange = Configuration.get('ANTIVIRUS_EXCHANGE') as string;
export const RabbitMqURI = Configuration.get('RABBITMQ_URI') as string;

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface RabbitMqConfig {}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AuthGuardModule, AuthGuardOptions } from '@infra/auth-guard';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { defaultMikroOrmOptions } from '@modules/server';
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ALL_ENTITIES } from '@shared/domain/entity';
import { createConfigModuleOptions, DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config';
import { CoreModule } from '@src/core';
import { RabbitMQWrapperModule } from '@src/infra/rabbitmq';
import { defaultMikroOrmOptions } from '@shared/common';
import { AuthorizationModule } from '../authorization';
import { config } from './board-collaboration.config';
import { BoardWsApiModule } from './board-ws-api.module';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultMikroOrmOptions, serverConfig } from '@modules/server';
import { serverConfig } from '@modules/server';
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ALL_ENTITIES } from '@shared/domain/entity';
Expand All @@ -7,6 +7,7 @@ import { CoreModule } from '@src/core';
import { AuthGuardModule, AuthGuardOptions } from '@src/infra/auth-guard';
import { MongoMemoryDatabaseModule } from '@src/infra/database';
import { RabbitMQWrapperTestModule } from '@src/infra/rabbitmq';
import { defaultMikroOrmOptions } from '@shared/common';
import { AuthenticationApiModule } from '../authentication/authentication-api.module';
import { AuthorizationModule } from '../authorization';
import { config as boardCollaborationConfig } from './board-collaboration.config';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Module } from '@nestjs/common';
import { ALL_ENTITIES } from '@shared/domain/entity';
import { DB_PASSWORD, DB_URL, DB_USERNAME } from '@src/config';
import { RabbitMQWrapperModule } from '@src/infra/rabbitmq';
import { defaultMikroOrmOptions } from '../server';
import { defaultMikroOrmOptions } from '@shared/common';
import { BoardClientModule } from './common-cartridge-client/board-client';
import { CoursesClientModule } from './common-cartridge-client/course-client';
import { CommonCartridgeExportService } from './service/common-cartridge-export.service';
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,22 @@ import { axiosResponseFactory } from '@shared/testing';
import { DeletionRequestInputBuilder, DeletionRequestOutputBuilder } from '.';
import { DeletionRequestOutput } from './interface';
import { DeletionClient } from './deletion.client';
import { DeletionConsoleConfig } from '../deletion.config';

describe(DeletionClient.name, () => {
let module: TestingModule;
let client: DeletionClient;
let configService: DeepMocked<ConfigService>;
let httpService: DeepMocked<HttpService>;

beforeEach(async () => {
module = await Test.createTestingModule({
providers: [
DeletionClient,
{
provide: ConfigService,
useValue: createMock<ConfigService>({
get: jest.fn((key: string) => {
if (key === 'ADMIN_API_CLIENT_BASE_URL') {
return 'http://localhost:4030';
}

// Default is for the Admin APIs API Key.
return '6b3df003-61e9-467c-9e6b-579634801896';
}),
}),
useValue: createMock<ConfigService<DeletionConsoleConfig, true>>(),
},
DeletionClient,
{
provide: HttpService,
useValue: createMock<HttpService>(),
Expand All @@ -39,6 +32,7 @@ describe(DeletionClient.name, () => {
}).compile();

client = module.get(DeletionClient);
configService = module.get(ConfigService);
httpService = module.get(HttpService);
});

Expand All @@ -50,9 +44,17 @@ describe(DeletionClient.name, () => {
await module.close();
});

const setupConfig = () => {
// Please take a look that the order is correct if the code order is changed
configService.get
.mockReturnValueOnce('652559c2-93da-42ad-94e1-640e3afbaca0')
.mockReturnValueOnce('http://api-admin:4030');
};

describe('queueDeletionRequest', () => {
describe('when sending the HTTP request failed', () => {
const setup = () => {
setupConfig();
const input = DeletionRequestInputBuilder.build('user', '652f1625e9bc1a13bdaae48b');

const error = new Error('unknown error');
Expand All @@ -70,6 +72,7 @@ describe(DeletionClient.name, () => {

describe('when received valid response with expected HTTP status code', () => {
const setup = () => {
setupConfig();
const input = DeletionRequestInputBuilder.build('user', '652f1625e9bc1a13bdaae48b');

const output: DeletionRequestOutput = DeletionRequestOutputBuilder.build(
Expand Down Expand Up @@ -98,6 +101,7 @@ describe(DeletionClient.name, () => {

describe('when received invalid HTTP status code in a response', () => {
const setup = () => {
setupConfig();
const input = DeletionRequestInputBuilder.build('user', '652f1625e9bc1a13bdaae48b');

const output: DeletionRequestOutput = DeletionRequestOutputBuilder.build('', new Date());
Expand All @@ -121,6 +125,7 @@ describe(DeletionClient.name, () => {

describe('when received no requestId in a response', () => {
const setup = () => {
setupConfig();
const input = DeletionRequestInputBuilder.build('user', '652f1625e9bc1a13bdaae48b');

const output: DeletionRequestOutput = DeletionRequestOutputBuilder.build(
Expand All @@ -147,6 +152,7 @@ describe(DeletionClient.name, () => {

describe('when received no deletionPlannedAt in a response', () => {
const setup = () => {
setupConfig();
const input = DeletionRequestInputBuilder.build('user', '652f1625e9bc1a13bdaae48b');

const response: AxiosResponse<DeletionRequestOutput> = axiosResponseFactory.build({
Expand All @@ -172,6 +178,7 @@ describe(DeletionClient.name, () => {
describe('executeDeletions', () => {
describe('when sending the HTTP request failed', () => {
const setup = () => {
setupConfig();
const error = new Error('unknown error');
httpService.post.mockReturnValueOnce(throwError(() => error));
};
Expand All @@ -185,6 +192,7 @@ describe(DeletionClient.name, () => {

describe('when received valid response with expected HTTP status code', () => {
const setup = () => {
setupConfig();
const limit = 10;

const response: AxiosResponse<DeletionRequestOutput> = axiosResponseFactory.build({
Expand All @@ -203,8 +211,31 @@ describe(DeletionClient.name, () => {
});
});

describe('when pass invalid limit', () => {
const setup = () => {
setupConfig();
const limit = true;

const response: AxiosResponse<DeletionRequestOutput> = axiosResponseFactory.build({
status: 204,
});

httpService.post.mockReturnValueOnce(of(response));

return { limit };
};

it('should ignore limit and use default headers', async () => {
const { limit } = setup();

// @ts-expect-error test case
await expect(client.executeDeletions(limit)).resolves.not.toThrow();
});
});

describe('when received invalid HTTP status code in a response', () => {
const setup = () => {
setupConfig();
const response: AxiosResponse<DeletionRequestOutput> = axiosResponseFactory.build({
status: 200,
});
Expand Down
Loading

0 comments on commit 02f404f

Please sign in to comment.