Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
virgilchiriac committed Jan 8, 2024
1 parent 140883c commit f5e982b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 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!`);
}
}
6 changes: 2 additions & 4 deletions apps/server/src/mikro-orm.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* istanbul ignore file */
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 @@ -15,9 +12,10 @@ export const mikroOrmConfig: MikroOrmModuleSyncOptions = {
user: DB_USERNAME,
entities: [...ALL_ENTITIES, FileEntity, FileRecord],
allowGlobalContext: true,
/*
findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) =>
/* istanbul ignore next */
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
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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,mikro-orm.config.ts
sonar.coverage.exclusions=**/board-management.uc.ts,**/*.module.ts,**/*.factory.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 f5e982b

Please sign in to comment.