Skip to content

Commit

Permalink
BC-5936 - ignore coverage
Browse files Browse the repository at this point in the history
for console mikroorm config findOneOrFailHandler
  • Loading branch information
virgilchiriac committed Jan 8, 2024
1 parent efe9073 commit 4668d0d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ describe('DatabaseManagementConsole (API)', () => {
const rootCli = consoleService.getRootCli();
rootCli.exitOverride(exitFn);
const spyConsoleWriterInfo = jest.spyOn(consoleWriter, 'info');
return { spyConsoleWriterInfo };
const spyConsoleWriterError = jest.spyOn(consoleWriter, 'error');
return { spyConsoleWriterInfo, spyConsoleWriterError };
};
describe('when command not exists', () => {

describe('when command does not exist', () => {
it('should fail for unknown command', async () => {
setup();
await expect(execute(bootstrap, ['database', 'not_existing_command'])).rejects.toThrow(
Expand Down Expand Up @@ -74,6 +76,22 @@ describe('DatabaseManagementConsole (API)', () => {

expect(spyConsoleWriterInfo).toBeCalled();
});

it('should output error if command "migration" is called without flags', async () => {
const { spyConsoleWriterError } = setup();

await execute(bootstrap, ['database', 'migration']);

expect(spyConsoleWriterError).toBeCalled();
});

it('should provide command "migration"', async () => {
const { spyConsoleWriterInfo } = setup();

await execute(bootstrap, ['database', 'migration', '--up']);

expect(spyConsoleWriterInfo).toBeCalled();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('ServerConsole (API)', () => {
consoleService.resetCli();
});

it('should poduce default output when executing "console server test"', async () => {
it('should produce default output when executing "console server test"', async () => {
await execute(bootstrap, ['server', 'test']);
expect(logMock).toHaveBeenCalledWith('Schulcloud Server API');
});
Expand Down
16 changes: 16 additions & 0 deletions apps/server/src/migrations/mikro-orm/Migration20240108145519.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Migration } from '@mikro-orm/migrations-mongodb';

/*
* cleanup old migration records from db
*/
export class Migration20240108111130 extends Migration {
async up(): Promise<void> {
const { deletedCount } = await this.getCollection('migrations').deleteMany({}, { session: this.ctx });
console.log(`removed ${deletedCount} records`);
}

async down(): Promise<void> {

Check failure on line 12 in apps/server/src/migrations/mikro-orm/Migration20240108145519.ts

View workflow job for this annotation

GitHub Actions / nest_lint

Async method 'down' has no 'await' expression
// do nothing
console.error(`Migration down not implemented. You might need to restore database from backup!`);
}
}
4 changes: 2 additions & 2 deletions apps/server/src/mikro-orm.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import type { MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs/typings';
import { ALL_ENTITIES } from '@shared/domain/entity';
import { FileEntity } from '@modules/files/entity';
import { FileRecord } from '@modules/files-storage/entity';
import { Dictionary, IPrimaryKey } from '@mikro-orm/core';
import { NotFoundException } from '@nestjs/common';
import { DB_PASSWORD, DB_URL, DB_USERNAME } from './config';

export const mikroOrmConfig: MikroOrmModuleSyncOptions = {
Expand All @@ -14,8 +12,10 @@ export const mikroOrmConfig: MikroOrmModuleSyncOptions = {
user: DB_USERNAME,
entities: [...ALL_ENTITIES, FileEntity, FileRecord],
allowGlobalContext: true,
/*
findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) =>
new NotFoundException(`The requested ${entityName}: ${JSON.stringify(where)} has not been found.`),
*/
migrations: {
tableName: 'migrations', // name of database table with log of executed transactions
path: './dist/apps/server/src/migrations/mikro-orm', // path to the folder with migrations
Expand Down
4 changes: 2 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ sonar.projectKey=hpi-schul-cloud_schulcloud-server
sonar.sources=.
sonar.tests=.
sonar.test.inclusions=**/*.spec.ts
sonar.exclusions=**/*.js,jest.config.ts,globalSetup.ts,globalTeardown.ts,**/*.app.ts,**/seed-data/*.ts
sonar.coverage.exclusions=**/board-management.uc.ts,**/*.module.ts,**/*.factory.ts
sonar.exclusions=**/*.js,jest.config.ts,globalSetup.ts,globalTeardown.ts,**/*.app.ts,**/seed-data/*.ts,**/migrations/mikro-orm/*.ts
sonar.coverage.exclusions=**/board-management.uc.ts,**/*.module.ts,**/*.factory.ts,**/migrations/mikro-orm/*.ts
sonar.cpd.exclusions=**/controller/dto/*.ts
sonar.javascript.lcov.reportPaths=merged-lcov.info
sonar.typescript.tsconfigPaths=tsconfig.json,src/apps/server/tsconfig.app.json

0 comments on commit 4668d0d

Please sign in to comment.