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

feat(repeater): refrain from utilizing non standard ports #197

Merged
merged 18 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
524 changes: 470 additions & 54 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
ostridm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
"form-data": "^4.0.0",
"reflect-metadata": "^0.1.13",
"semver": "^7.5.2",
"socket.io-client": "^4.7.5",
"socket.io-msgpack-parser": "^3.0.2",
"socks-proxy-agent": "^6.2.0-beta.0",
"tslib": "~2.3.1",
"tsyringe": "^4.6.0",
Expand Down Expand Up @@ -129,6 +131,7 @@
"nx": "14.5.6",
"prettier": "2.7.1",
"semantic-release": "~19.0.3",
"socket.io": "^4.7.5",
"ts-jest": "27.1.4",
"ts-mockito": "^2.6.1",
"typescript": "4.7.4"
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/logger/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ export class Logger {
this._logLevel = logLevel;
}

public error(message: string, ...args: any[]): void {
this.write(message, LogLevel.ERROR, ...args);
public error(errorOrMessage: string | Error, ...args: any[]): void {
ostridm marked this conversation as resolved.
Show resolved Hide resolved
if (typeof errorOrMessage === 'string') {
this.write(errorOrMessage, LogLevel.ERROR, ...args);
} else {
this.write(errorOrMessage.message, LogLevel.ERROR, ...args);
}
}

public warn(message: string, ...args: any[]): void {
Expand Down
32 changes: 1 addition & 31 deletions packages/repeater/src/api/DefaultRepeatersManager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import 'reflect-metadata';
import {
CreateRepeaterRequest,
DeleteRepeaterRequest,
GetRepeaterRequest
} from './commands';
import { CreateRepeaterRequest, DeleteRepeaterRequest } from './commands';
import { DefaultRepeatersManager } from './DefaultRepeatersManager';
import { RepeatersManager } from './RepeatersManager';
import { CommandDispatcher } from '@sectester/core';
Expand Down Expand Up @@ -67,32 +63,6 @@ describe('DefaultRepeatersManager', () => {
});
});

describe('getRepeater', () => {
it('should return repeater', async () => {
const repeaterId = '142';
when(
mockedCommandDispatcher.execute(anyOfClass(GetRepeaterRequest))
).thenResolve({ id: repeaterId });

const result = await manager.getRepeater(repeaterId);

verify(
mockedCommandDispatcher.execute(anyOfClass(GetRepeaterRequest))
).once();
expect(result).toMatchObject({ repeaterId });
});

it('should throw an error if cannot find repeater', async () => {
when(
mockedCommandDispatcher.execute(anyOfClass(GetRepeaterRequest))
).thenResolve();

const act = manager.getRepeater('123');

await expect(act).rejects.toThrow('Cannot find repeater');
});
});

describe('deleteRepeater', () => {
it('should remove repeater', async () => {
when(
Expand Down
20 changes: 1 addition & 19 deletions packages/repeater/src/api/DefaultRepeatersManager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { RepeatersManager } from './RepeatersManager';
import {
CreateRepeaterRequest,
DeleteRepeaterRequest,
GetRepeaterRequest
} from './commands';
import { CreateRepeaterRequest, DeleteRepeaterRequest } from './commands';
import { inject, injectable } from 'tsyringe';
import { CommandDispatcher } from '@sectester/core';

Expand All @@ -14,20 +10,6 @@ export class DefaultRepeatersManager implements RepeatersManager {
private readonly commandDispatcher: CommandDispatcher
) {}

public async getRepeater(
repeaterId: string
): Promise<{ repeaterId: string }> {
const repeater = await this.commandDispatcher.execute(
new GetRepeaterRequest(repeaterId)
);

if (!repeater?.id) {
throw new Error('Cannot find repeater');
}

return { repeaterId: repeater.id };
}

public async createRepeater({
projectId,
...options
Expand Down
23 changes: 2 additions & 21 deletions packages/repeater/src/api/ExecuteRequestEventHandler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'reflect-metadata';
import { ExecuteRequestEventHandler } from './ExecuteRequestEventHandler';
import { Protocol } from '../models';
import { Request, RequestRunner } from '../request-runner';
import { anything, capture, instance, mock, reset, when } from 'ts-mockito';
import { RequestRunner } from '../request-runner';
import { anything, instance, mock, reset, when } from 'ts-mockito';

describe('ExecuteRequestEventHandler', () => {
const requestRunnerResponse = {
Expand Down Expand Up @@ -65,24 +65,5 @@ describe('ExecuteRequestEventHandler', () => {

await expect(res).rejects.toThrow(`Unsupported protocol "http"`);
});

it('`correlation_id_regex` should become `correlationIdRegex` in runner input', async () => {
const payload = {
protocol: Protocol.HTTP,
url: 'http://foo.bar/',
headers: {},
correlation_id_regex: 'baz'
};
const handler = new ExecuteRequestEventHandler([
instance(mockedRequestRunner)
]);

await handler.handle(payload);

const [request]: [Request] = capture<Request>(
mockedRequestRunner.run
).first();
expect(request.correlationIdRegex).toBeInstanceOf(RegExp);
});
});
});
2 changes: 0 additions & 2 deletions packages/repeater/src/api/RepeatersManager.ts
ostridm marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
export interface RepeatersManager {
getRepeater(repeaterId: string): Promise<{ repeaterId: string }>;

createRepeater(options: {
name: string;
projectId?: string;
Expand Down
20 changes: 0 additions & 20 deletions packages/repeater/src/api/commands/GetRepeaterRequest.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/repeater/src/api/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export { CreateRepeaterRequest } from './CreateRepeaterRequest';
export { DeleteRepeaterRequest } from './DeleteRepeaterRequest';
export { GetRepeaterRequest } from './GetRepeaterRequest';
export {
RegisterRepeaterCommand,
RegisterRepeaterCommandPayload,
Expand Down
Loading
Loading