-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create functions to initialise client (#19)
Needed for #7
- Loading branch information
Showing
3 changed files
with
96 additions
and
3 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,59 @@ | ||
import { PoWebClient } from './PoWebClient'; | ||
|
||
describe('PoWebClient', () => { | ||
describe('initLocal', () => { | ||
test('Host name should be the localhost IP address', () => { | ||
const client = PoWebClient.initLocal(); | ||
|
||
expect(client.hostName).toEqual('127.0.0.1'); | ||
}); | ||
|
||
test('TLS should not be used', () => { | ||
const client = PoWebClient.initLocal(); | ||
|
||
expect(client.useTLS).toBeFalsy(); | ||
}); | ||
|
||
test('Port should default to 276', () => { | ||
const client = PoWebClient.initLocal(); | ||
|
||
expect(client.port).toEqual(276); | ||
}); | ||
|
||
test('Port should be overridable', () => { | ||
const port = 13276; | ||
const client = PoWebClient.initLocal(port); | ||
|
||
expect(client.port).toEqual(port); | ||
}); | ||
}); | ||
|
||
describe('initRemote', () => { | ||
const hostName = 'gw.relaycorp.tech'; | ||
|
||
test('Specified host name should be honored', () => { | ||
const client = PoWebClient.initRemote(hostName); | ||
|
||
expect(client.hostName).toEqual(hostName); | ||
}); | ||
|
||
test('TLS should be used', () => { | ||
const client = PoWebClient.initRemote(hostName); | ||
|
||
expect(client.useTLS).toBeTruthy(); | ||
}); | ||
|
||
test('Port should default to 443', () => { | ||
const client = PoWebClient.initRemote(hostName); | ||
|
||
expect(client.port).toEqual(443); | ||
}); | ||
|
||
test('Port should be overridable', () => { | ||
const port = 13276; | ||
const client = PoWebClient.initRemote(hostName, port); | ||
|
||
expect(client.port).toEqual(port); | ||
}); | ||
}); | ||
}); |
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,37 @@ | ||
/** | ||
* PoWeb client. | ||
*/ | ||
export class PoWebClient { | ||
/** | ||
* Connect to a private gateway from a private endpoint. | ||
* | ||
* @param port The port for the PoWeb server | ||
* | ||
* TLS won't be used. | ||
*/ | ||
public static initLocal(port: number = PoWebClient.DEFAULT_LOCAL_PORT): PoWebClient { | ||
return new PoWebClient('127.0.0.1', port, false); | ||
} | ||
|
||
/** | ||
* Connect to a public gateway from a private gateway via TLS. | ||
* | ||
* @param hostName The IP address or domain for the PoWeb server | ||
* @param port The port for the PoWeb server | ||
*/ | ||
public static initRemote( | ||
hostName: string, | ||
port: number = PoWebClient.DEFAULT_REMOVE_PORT, | ||
): PoWebClient { | ||
return new PoWebClient(hostName, port, true); | ||
} | ||
|
||
private static readonly DEFAULT_LOCAL_PORT = 276; | ||
private static readonly DEFAULT_REMOVE_PORT = 443; | ||
|
||
protected constructor( | ||
public readonly hostName: string, | ||
public readonly port: number, | ||
public readonly useTLS: boolean, | ||
) {} | ||
} |
This file was deleted.
Oops, something went wrong.