-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repeater): refrain from utilizing non standard ports (#197)
closes #196
- Loading branch information
Showing
41 changed files
with
2,661 additions
and
1,281 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
29 changes: 0 additions & 29 deletions
29
packages/repeater/src/api/commands/RegisterRepeaterCommand.ts
This file was deleted.
Oops, something went wrong.
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,9 +1,3 @@ | ||
export { CreateRepeaterRequest } from './CreateRepeaterRequest'; | ||
export { DeleteRepeaterRequest } from './DeleteRepeaterRequest'; | ||
export { GetRepeaterRequest } from './GetRepeaterRequest'; | ||
export { | ||
RegisterRepeaterCommand, | ||
RegisterRepeaterCommandPayload, | ||
RegisterRepeaterResult, | ||
RepeaterRegisteringError | ||
} from './RegisterRepeaterCommand'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,10 +1,2 @@ | ||
export { | ||
RepeaterRegisteringError, | ||
RegisterRepeaterResult, | ||
RegisterRepeaterCommandPayload, | ||
RegisterRepeaterCommand | ||
} from './commands'; | ||
export { RepeaterStatusEvent } from './events'; | ||
export * from './RepeatersManager'; | ||
export * from './DefaultRepeatersManager'; | ||
export * from './ExecuteRequestEventHandler'; |
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,11 +1,5 @@ | ||
import './register'; | ||
|
||
export { | ||
RepeatersManager, | ||
ExecuteRequestEventHandler, | ||
ExecuteRequestPayload, | ||
ExecuteRequestResult | ||
} from './api'; | ||
export { RepeatersManager } from './api'; | ||
export * from './lib'; | ||
export * from './models'; | ||
export * from './request-runner'; |
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,62 @@ | ||
import { DefaultRepeaterCommands } from './DefaultRepeaterCommands'; | ||
import { Protocol } from '../models/Protocol'; | ||
import { RequestRunner, Request, Response } from '../request-runner'; | ||
import { instance, mock, reset, when } from 'ts-mockito'; | ||
|
||
describe('DefaultRepeaterCommands', () => { | ||
let sut!: DefaultRepeaterCommands; | ||
|
||
const mockedRequestRunner = mock<RequestRunner>(); | ||
|
||
beforeEach(() => { | ||
sut = new DefaultRepeaterCommands([instance(mockedRequestRunner)]); | ||
}); | ||
|
||
afterEach(() => reset<RequestRunner>(mockedRequestRunner)); | ||
|
||
describe('sendRequest', () => { | ||
it('should send', async () => { | ||
// arrange | ||
const request = new Request({ | ||
protocol: Protocol.HTTP, | ||
url: 'http://foo.bar', | ||
method: 'GET' | ||
}); | ||
|
||
const response = new Response({ | ||
protocol: Protocol.HTTP, | ||
statusCode: 200 | ||
}); | ||
|
||
when(mockedRequestRunner.protocol).thenReturn(Protocol.HTTP); | ||
when(mockedRequestRunner.run(request)).thenResolve(response); | ||
|
||
// act | ||
const result = await sut.sendRequest(request); | ||
|
||
// assert | ||
expect(result).toEqual(response); | ||
}); | ||
|
||
it('should throw when there are no suitable protocol handler', async () => { | ||
// arrange | ||
const request = new Request({ | ||
protocol: Protocol.HTTP, | ||
url: 'http://foo.bar', | ||
method: 'GET' | ||
}); | ||
|
||
when(mockedRequestRunner.protocol).thenReturn( | ||
'someOtherProtocol' as Protocol | ||
); | ||
|
||
// act | ||
const act = () => sut.sendRequest(request); | ||
|
||
// assert | ||
await expect(act).rejects.toThrow( | ||
`Unsupported protocol "${Protocol.HTTP}"` | ||
); | ||
}); | ||
}); | ||
}); |
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,25 @@ | ||
import { RepeaterCommands } from './RepeaterCommands'; | ||
import { Request, Response, RequestRunner } from '../request-runner'; | ||
import { injectable, injectAll } from 'tsyringe'; | ||
|
||
@injectable() | ||
export class DefaultRepeaterCommands implements RepeaterCommands { | ||
constructor( | ||
@injectAll(RequestRunner) | ||
private readonly requestRunners: RequestRunner[] | ||
) {} | ||
|
||
public async sendRequest(request: Request): Promise<Response> { | ||
const { protocol } = request; | ||
|
||
const requestRunner = this.requestRunners.find( | ||
x => x.protocol === protocol | ||
); | ||
|
||
if (!requestRunner) { | ||
throw new Error(`Unsupported protocol "${protocol}"`); | ||
} | ||
|
||
return requestRunner.run(request); | ||
} | ||
} |
Oops, something went wrong.