Skip to content

Commit

Permalink
add console command for triggering the deletion execution
Browse files Browse the repository at this point in the history
  • Loading branch information
bn-pass committed Nov 15, 2023
1 parent b7472d1 commit af2268f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import { createConfigModuleOptions } from '@src/config';
import { DeletionClient } from '../client';
import { getDeletionClientConfig } from '../client/deletion-client.config';
import { BatchDeletionService } from '../services';
import { BatchDeletionUc } from '../uc';
import { BatchDeletionUc, DeletionExecutionUc } from '../uc';
import { DeletionQueueConsole } from './deletion-queue.console';
import { DeletionExecutionConsole } from './deletion-execution.console';

@Module({
imports: [
Expand All @@ -17,6 +18,13 @@ import { DeletionQueueConsole } from './deletion-queue.console';
HttpModule,
ConfigModule.forRoot(createConfigModuleOptions(getDeletionClientConfig)),
],
providers: [DeletionClient, BatchDeletionService, BatchDeletionUc, DeletionQueueConsole],
providers: [
DeletionClient,
BatchDeletionService,
BatchDeletionUc,
DeletionExecutionUc,
DeletionQueueConsole,
DeletionExecutionConsole,
],
})
export class DeletionConsoleModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Test, TestingModule } from '@nestjs/testing';
import { createMock } from '@golevelup/ts-jest';
import { ConsoleWriterService } from '@infra/console';
import { DeletionExecutionUc } from '../uc';
import { DeletionExecutionConsole } from './deletion-execution.console';
import { TriggerDeletionExecutionOptionsBuilder } from './builder';

describe(DeletionExecutionConsole.name, () => {
let module: TestingModule;
let console: DeletionExecutionConsole;
let deletionExecutionUc: DeletionExecutionUc;

beforeAll(async () => {
module = await Test.createTestingModule({
providers: [
DeletionExecutionConsole,
{
provide: ConsoleWriterService,
useValue: createMock<ConsoleWriterService>(),
},
{
provide: DeletionExecutionUc,
useValue: createMock<DeletionExecutionUc>(),
},
],
}).compile();

console = module.get(DeletionExecutionConsole);
deletionExecutionUc = module.get(DeletionExecutionUc);
});

beforeEach(() => {
jest.clearAllMocks();
});

afterAll(async () => {
await module.close();
});

it('console should be defined', () => {
expect(console).toBeDefined();
});

describe('triggerDeletionExecution', () => {
describe('when called with valid options', () => {
const setup = () => {
const limit = 1000;

const options = TriggerDeletionExecutionOptionsBuilder.build(1000);

return { limit, options };
};

it(`should call ${DeletionExecutionUc.name} with proper arguments`, async () => {
const { limit, options } = setup();

const spy = jest.spyOn(deletionExecutionUc, 'triggerDeletionExecution');

await console.triggerDeletionExecution(options);

expect(spy).toBeCalledWith(limit);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Command, Console } from 'nestjs-console';
import { ConsoleWriterService } from '@infra/console';
import { DeletionExecutionUc } from '../uc';
import { TriggerDeletionExecutionOptions } from './interface';

@Console({ command: 'execution', description: 'Console providing an access to the deletion execution(s).' })
export class DeletionExecutionConsole {
constructor(private consoleWriter: ConsoleWriterService, private deletionExecutionUc: DeletionExecutionUc) {}

@Command({
command: 'trigger',
description: 'Trigger execution of deletion requests.',
options: [
{
flags: '-l, --limit <value>',
description: 'Limit of the requested deletion executions that should be performed.',
required: false,
},
],
})
async triggerDeletionExecution(options: TriggerDeletionExecutionOptions): Promise<void> {
const result = await this.deletionExecutionUc.triggerDeletionExecution(
options.limit ? Number(options.limit) : undefined
);

this.consoleWriter.info(JSON.stringify(result));
}
}
1 change: 1 addition & 0 deletions apps/server/src/modules/deletion/uc/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './interface';
export * from './batch-deletion.uc';
export * from './deletion-execution.uc';

0 comments on commit af2268f

Please sign in to comment.