Skip to content
Permalink
Browse files

feat(api): HZN-1357 tests for uri.js

  • Loading branch information...
smith-opennms committed Aug 21, 2018
1 parent d354040 commit e98cfa4df8f0a66e6c0a98ee976b0df9df161668
Showing with 19 additions and 2 deletions.
  1. +4 −2 src/api/OnmsServer.ts
  2. +15 −0 test/api/OnmsServer.spec.ts
@@ -70,10 +70,12 @@ export class OnmsServer {
if (forFragment === undefined) {
return this.url;
}
let uri = URI(this.url);
if (forFragment.indexOf('/') === 0 || forFragment.indexOf('http') === 0) {
return forFragment;
uri = URI(forFragment);
} else {
uri = uri.segment(forFragment);
}
let uri = URI(this.url).segment(forFragment);
if (withQuery !== undefined) {
uri = uri.addQuery(withQuery);
}
@@ -51,6 +51,21 @@ describe('Given an instance of OnmsServer...', () => {
expect(server.resolveURL('foo')).toEqual(SERVER_URL + 'foo');
expect(server.resolveURL('foo/')).toEqual(SERVER_URL + 'foo');
});
it('URL starting with "/" are returned as-is.', () => {
expect(server.resolveURL('/rest/foo/')).toEqual('/rest/foo/');
});
it('Absolute with query appends query', () => {
expect(server.resolveURL('/rest/foo', 'foo=bar')).toEqual('/rest/foo?foo%3Dbar');
});
it('multi segment urls are handled.', () => {
expect(server.resolveURL('rest/foo/')).toEqual(SERVER_URL + 'rest/foo');
});
it('Colons are not escaped', () => {
expect(server.resolveURL('rest/foo/A:B:0.0.0.0:C')).toEqual(SERVER_URL + 'rest/foo/A:B:0.0.0.0:C');
});
it('Escape forward slashes', () => {
expect(server.resolveURL('rest/S%2FA%3AB%3A0.0.0.0%3AC')).toEqual(SERVER_URL + 'rest/S%2FA:B:0.0.0.0:C');
});
it('it should have a "host" property', () => {
expect(server.host).toBeDefined();
expect(server.host).toEqual('demo.opennms.org');

0 comments on commit e98cfa4

Please sign in to comment.
You can’t perform that action at this time.