Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: adding unit tests #3

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 64 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"jest": "^29.5.0",
"jest-create-mock-instance": "^2.0.0",
"jest-html-reporters": "^3.1.4",
"nock": "^13.5.4",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
"rimraf": "^5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/containerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { validateAndGetHandlersTokens } from './utils/configUtil';
import { SwapJobHandler } from './models/swapJobHandler';
import { IConfig, IJobManagerConfig, IngestionJobsConfig } from './common/interfaces';

const queueClientFactory = (container: DependencyContainer): QueueClient => {
export const queueClientFactory = (container: DependencyContainer): QueueClient => {
const logger = container.resolve<Logger>(SERVICES.LOGGER);
const config = container.resolve<IConfig>(SERVICES.CONFIG);
const queueConfig = config.get<IJobManagerConfig>('jobManagement.config');
Expand Down
4 changes: 2 additions & 2 deletions src/models/jobProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { JOB_HANDLER_FACTORY_SYMBOL, JobHandlerFactory } from './jobHandlerFacto

@injectable()
export class JobProcessor {
private readonly dequeueIntervalMs: number;
private readonly logContext: LogContext;
private readonly jobTypes: string[];
private readonly pollingTaskTypes: string[];
private readonly dequeueIntervalMs: number;
private readonly ingestionConfig: IngestionConfig;
private isRunning = true;
public constructor(
Expand Down Expand Up @@ -82,7 +82,7 @@ export class JobProcessor {
const logCtx: LogContext = { ...this.logContext, function: this.getJobWithTaskType.name };
for (const taskType of this.pollingTaskTypes) {
for (const jobType of this.jobTypes) {
this.logger.debug({ msg: `try to dequeue task of type "${taskType}" and job of type "${jobType}"`, logContext: logCtx });
this.logger.debug({ msg: `trying to dequeue task of type "${taskType}" and job of type "${jobType}"`, logContext: logCtx });
const task = await this.queueClient.dequeue(jobType, taskType);

if (!task) {
Expand Down
8 changes: 4 additions & 4 deletions tests/configurations/integration/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ module.exports = {
testEnvironment: 'node',
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: -10,
branches: 50,
functions: 50,
lines: 50,
statements: 0,
},
},
};
8 changes: 4 additions & 4 deletions tests/configurations/unit/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ module.exports = {
testEnvironment: 'node',
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: -10,
branches: 50,
functions: 50,
lines: 50,
statements: 0,
},
},
};
43 changes: 43 additions & 0 deletions tests/integration/helpers/containerConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import jsLogger from '@map-colonies/js-logger';
import { container, instancePerContainerCachingFactory } from 'tsyringe';
import { trace } from '@opentelemetry/api';
import { InjectionObject } from '../../../src/common/dependencyRegistration';
import { configMock, getMock, hasMock, registerDefaultConfig } from '../../unit/mocks/configMock';
import { SERVICES } from '../../../src/common/constants';
import { queueClientFactory } from '../../../src/containerConfig';
import { IngestionJobsConfig } from '../../../src/common/interfaces';
import { validateAndGetHandlersTokens } from '../../../src/utils/configUtil';
import { NewJobHandler } from '../../../src/models/newJobHandler';
import { UpdateJobHandler } from '../../../src/models/updateJobHandler';
import { SwapJobHandler } from '../../../src/models/swapJobHandler';
import { JOB_HANDLER_FACTORY_SYMBOL, jobHandlerFactory } from '../../../src/models/jobHandlerFactory';

function getTestContainerConfig(): InjectionObject<unknown>[] {
registerDefaultConfig();

const ingestionConfig = configMock.get<IngestionJobsConfig>('jobManagement.ingestion.jobs');

const handlersTokens = validateAndGetHandlersTokens(ingestionConfig);

return [
{ token: SERVICES.LOGGER, provider: { useValue: jsLogger({ enabled: false }) } },
{ token: SERVICES.CONFIG, provider: { useValue: configMock } },
{ token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } },
{ token: SERVICES.QUEUE_CLIENT, provider: { useFactory: instancePerContainerCachingFactory(queueClientFactory) } },
{ token: JOB_HANDLER_FACTORY_SYMBOL, provider: { useFactory: instancePerContainerCachingFactory(jobHandlerFactory) } },
{ token: handlersTokens.Ingestion_New, provider: { useClass: NewJobHandler } },
{ token: handlersTokens.Ingestion_Update, provider: { useClass: UpdateJobHandler } },
{ token: handlersTokens.Ingestion_Swap_Update, provider: { useClass: SwapJobHandler } },
];
}

const resetContainer = (clearInstances = true): void => {
CL-SHLOMIKONCHA marked this conversation as resolved.
Show resolved Hide resolved
if (clearInstances) {
container.clearInstances();
}

getMock.mockReset();
hasMock.mockReset();
};

export { getTestContainerConfig, resetContainer };
Loading
Loading