-
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 builder for the PushDeletionRequestsOptions class, add unit tests…
… for the DeletionQueueConsole
- Loading branch information
Showing
4 changed files
with
140 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './push-delete-requests-options.builder'; |
43 changes: 43 additions & 0 deletions
43
.../server/src/modules/deletion/console/builder/push-delete-requests-options.builder.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,43 @@ | ||
import { PushDeletionRequestsOptions } from '../interface'; | ||
import { PushDeleteRequestsOptionsBuilder } from './push-delete-requests-options.builder'; | ||
|
||
describe(PushDeleteRequestsOptionsBuilder.name, () => { | ||
describe(PushDeleteRequestsOptionsBuilder.build.name, () => { | ||
describe('when called with proper arguments', () => { | ||
const setup = () => { | ||
const refsFilePath = '/tmp/ids.txt'; | ||
const targetRefDomain = 'school'; | ||
const deleteInMinutes = 43200; | ||
const callsDelayMs = 100; | ||
|
||
const expectedOutput: PushDeletionRequestsOptions = { | ||
refsFilePath, | ||
targetRefDomain, | ||
deleteInMinutes, | ||
callsDelayMs, | ||
}; | ||
|
||
return { | ||
refsFilePath, | ||
targetRefDomain, | ||
deleteInMinutes, | ||
callsDelayMs, | ||
expectedOutput, | ||
}; | ||
}; | ||
|
||
it('should return valid object with expected values', () => { | ||
const { refsFilePath, targetRefDomain, deleteInMinutes, callsDelayMs, expectedOutput } = setup(); | ||
|
||
const output = PushDeleteRequestsOptionsBuilder.build( | ||
refsFilePath, | ||
targetRefDomain, | ||
deleteInMinutes, | ||
callsDelayMs | ||
); | ||
|
||
expect(output).toStrictEqual(expectedOutput); | ||
}); | ||
}); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
apps/server/src/modules/deletion/console/builder/push-delete-requests-options.builder.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,17 @@ | ||
import { PushDeletionRequestsOptions } from '../interface'; | ||
|
||
export class PushDeleteRequestsOptionsBuilder { | ||
static build( | ||
refsFilePath: string, | ||
targetRefDomain: string, | ||
deleteInMinutes: number, | ||
callsDelayMs: number | ||
): PushDeletionRequestsOptions { | ||
return { | ||
refsFilePath, | ||
targetRefDomain, | ||
deleteInMinutes, | ||
callsDelayMs, | ||
}; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
apps/server/src/modules/deletion/console/deletion-queue.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,79 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { ConsoleWriterService } from '@infra/console'; | ||
import { createMock } from '@golevelup/ts-jest'; | ||
import { BatchDeletionUc } from '../uc'; | ||
import { DeletionQueueConsole } from './deletion-queue.console'; | ||
import { PushDeleteRequestsOptionsBuilder } from './builder'; | ||
|
||
describe(DeletionQueueConsole.name, () => { | ||
let module: TestingModule; | ||
let console: DeletionQueueConsole; | ||
let batchDeletionUc: BatchDeletionUc; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
providers: [ | ||
DeletionQueueConsole, | ||
{ | ||
provide: ConsoleWriterService, | ||
useValue: createMock<ConsoleWriterService>(), | ||
}, | ||
{ | ||
provide: BatchDeletionUc, | ||
useValue: createMock<BatchDeletionUc>(), | ||
}, | ||
], | ||
}).compile(); | ||
|
||
console = module.get(DeletionQueueConsole); | ||
batchDeletionUc = module.get(BatchDeletionUc); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}); | ||
|
||
it('console should be defined', () => { | ||
expect(console).toBeDefined(); | ||
}); | ||
|
||
describe('pushDeletionRequests', () => { | ||
describe('when called with valid options', () => { | ||
const setup = () => { | ||
const refsFilePath = '/tmp/ids.txt'; | ||
const targetRefDomain = 'school'; | ||
const deleteInMinutes = 43200; | ||
const callsDelayMs = 100; | ||
|
||
const options = PushDeleteRequestsOptionsBuilder.build( | ||
refsFilePath, | ||
targetRefDomain, | ||
deleteInMinutes, | ||
callsDelayMs | ||
); | ||
|
||
return { | ||
refsFilePath, | ||
targetRefDomain, | ||
deleteInMinutes, | ||
callsDelayMs, | ||
options, | ||
}; | ||
}; | ||
|
||
it(`should call ${BatchDeletionUc.name} with proper arguments`, async () => { | ||
const { refsFilePath, targetRefDomain, deleteInMinutes, callsDelayMs, options } = setup(); | ||
|
||
const spy = jest.spyOn(batchDeletionUc, 'deleteRefsFromTxtFile'); | ||
|
||
await console.pushDeletionRequests(options); | ||
|
||
expect(spy).toBeCalledWith(refsFilePath, targetRefDomain, deleteInMinutes, callsDelayMs); | ||
}); | ||
}); | ||
}); | ||
}); |