Skip to content

Commit

Permalink
add builder for the PushDeletionRequestsOptions class, add unit tests…
Browse files Browse the repository at this point in the history
… for the DeletionQueueConsole
  • Loading branch information
bn-pass committed Nov 8, 2023
1 parent b35aa9c commit 667427f
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/server/src/modules/deletion/console/builder/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './push-delete-requests-options.builder';
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);
});
});
});
});
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,
};
}
}
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);
});
});
});
});

0 comments on commit 667427f

Please sign in to comment.