-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add console command for triggering the deletion execution
- Loading branch information
Showing
4 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
apps/server/src/modules/deletion/console/deletion-execution.console.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
apps/server/src/modules/deletion/console/deletion-execution.console.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |