Skip to content

Commit

Permalink
Merge branch 'master' of github.com:wikibus/Alcaeus
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed May 1, 2019
2 parents 94ee71f + 2860ff6 commit b4eba48
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 130 deletions.
4 changes: 3 additions & 1 deletion src/ResponseWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export class ResponseWrapper implements IResponseWrapper {
const links = li(linkHeaders);

if (links[Constants.Core.Vocab('apiDocumentation')]) {
return links[Constants.Core.Vocab('apiDocumentation')].url;
const linkUrl = links[Constants.Core.Vocab('apiDocumentation')].url;

return new URL(linkUrl, this.redirectUrl || this.requestedUri).toString();
}
}

Expand Down
34 changes: 32 additions & 2 deletions tests/ResponseWrapper-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@ import {Bodies} from './test-objects';
import {responseBuilder} from './test-utils';

describe('ResponseWrapper', () => {
it('should get documentation link', async () => {
it('should get absolute documentation link', async () => {
// given
const xhrResponse = await responseBuilder().body(Bodies.someJsonLd).apiDocumentation().build();

// when
const res = new ResponseWrapper('', xhrResponse);
const res = new ResponseWrapper('http://resources.example.com/', xhrResponse);

// then
expect(res.apiDocumentationLink).toBe('http://api.example.com/doc/');
});

it('should get relative documentation link', async () => {
// given
const xhrResponse = await responseBuilder().body(Bodies.someJsonLd).apiDocumentation('doc/').build();

// when
const res = new ResponseWrapper('http://api.example.com/resource/', xhrResponse);

// then
expect(res.apiDocumentationLink).toBe('http://api.example.com/resource/doc/');
});

it('should get redirect URL if redirected', async () => {
// given
const xhrResponse = {
Expand All @@ -28,4 +39,23 @@ describe('ResponseWrapper', () => {
// then
expect(res.redirectUrl).toBe('urn:actual:resource');
});

it('should base relative documentation link on redirect target', async () => {
// given
const xhrResponse = {
headers: {
get: () => '</api-doc>; rel=http://www.w3.org/ns/hydra/core#apiDocumentation',
has: () => true,
},
redirected: true,
url: 'http://other.example.api',
} as any;
xhrResponse.clone = () => xhrResponse;

// when
const res = new ResponseWrapper('http://api.example.com/resorce/', xhrResponse);

// then
expect(res.apiDocumentationLink).toBe('http://other.example.api/api-doc');
});
});
132 changes: 5 additions & 127 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,6 @@ ansi-align@^2.0.0:
dependencies:
string-width "^2.0.0"

ansi-red@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/ansi-red/-/ansi-red-0.1.1.tgz#8c638f9d1080800a353c9c28c8a81ca4705d946c"
dependencies:
ansi-wrap "0.1.0"

ansi-regex@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
Expand All @@ -319,10 +313,6 @@ ansi-styles@^3.2.1:
dependencies:
color-convert "^1.9.0"

[email protected]:
version "0.1.0"
resolved "https://registry.yarnpkg.com/ansi-wrap/-/ansi-wrap-0.1.0.tgz#a82250ddb0015e9a27ca82e82ea603bbfa45efaf"

ansi@^0.3.0, ansi@~0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/ansi/-/ansi-0.3.1.tgz#0c42d4fb17160d5a9af1e484bace1c66922c1b21"
Expand Down Expand Up @@ -387,13 +377,6 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"

argparse@~0.1.15:
version "0.1.16"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-0.1.16.tgz#cfd01e0fbba3d6caed049fbd758d40f65196f57c"
dependencies:
underscore "~1.7.0"
underscore.string "~2.4.0"

arr-diff@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-2.0.0.tgz#8f3b827f955a8bd669697e4a4256ac3ceae356cf"
Expand Down Expand Up @@ -496,10 +479,6 @@ atob@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.1.tgz#ae2d5a729477f289d60dd7f96a6314a22dd6c22a"

autolinker@~0.15.0:
version "0.15.3"
resolved "https://registry.yarnpkg.com/autolinker/-/autolinker-0.15.3.tgz#342417d8f2f3461b14cf09088d5edf8791dc9832"

aws-sign2@~0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.6.0.tgz#14342dd38dbcc94d0e5b87d763cd63612c0e794f"
Expand Down Expand Up @@ -1822,10 +1801,6 @@ code-point-at@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"

coffee-script@^1.12.4:
version "1.12.7"
resolved "https://registry.yarnpkg.com/coffee-script/-/coffee-script-1.12.7.tgz#c05dae0cb79591d05b3070a8433a98c9a89ccc53"

collection-visit@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/collection-visit/-/collection-visit-1.0.0.tgz#4bc0373c164bc3291b4d368c829cf1a80a59dca0"
Expand Down Expand Up @@ -1969,7 +1944,7 @@ [email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"

[email protected], concat-stream@^1.5.0, concat-stream@^1.5.1, concat-stream@^1.5.2, concat-stream@^1.6.2:
[email protected], concat-stream@^1.5.0, concat-stream@^1.5.2, concat-stream@^1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.2.tgz#904bdf194cd3122fc675c77fc4ac3d4ff0fd1a34"
integrity sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==
Expand Down Expand Up @@ -3192,29 +3167,6 @@ gitbook-cli@^2.3.2:
tmp "0.0.31"
user-home "2.0.0"

gitbook-plugin-etoc@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/gitbook-plugin-etoc/-/gitbook-plugin-etoc-1.2.2.tgz#8de530b841d2ead68e1a51f727c1778dd3106f62"
dependencies:
github-slugid "^1.0.1"
markdown-toc "^0.12.16"

gitbook-plugin-forkmegithub@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/gitbook-plugin-forkmegithub/-/gitbook-plugin-forkmegithub-2.2.0.tgz#b64b62a1402b099b1b48c396a9d5b0aba967c04a"

gitbook-plugin-hints@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/gitbook-plugin-hints/-/gitbook-plugin-hints-1.0.2.tgz#e6589983e3ea84749f16dc631e282fafd45ec39b"

[email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/gitbook-plugin-runkit/-/gitbook-plugin-runkit-0.0.1.tgz#512ca4c110775ee23249bac611fd6a6588fe1f72"

github-slugid@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/github-slugid/-/github-slugid-1.0.1.tgz#bccdd0815bfad69d8a359fa4fd65947d606ec3c0"

github-url-from-git@~1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/github-url-from-git/-/github-url-from-git-1.4.0.tgz#285e6b520819001bde128674704379e4ff03e0de"
Expand Down Expand Up @@ -3320,16 +3272,6 @@ graceful-fs@~4.1.11, graceful-fs@~4.1.6:
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==

gray-matter@^2.0.2:
version "2.1.1"
resolved "https://registry.yarnpkg.com/gray-matter/-/gray-matter-2.1.1.tgz#3042d9adec2a1ded6a7707a9ed2380f8a17a430e"
dependencies:
ansi-red "^0.1.1"
coffee-script "^1.12.4"
extend-shallow "^2.0.1"
js-yaml "^3.8.1"
toml "^2.3.2"

handlebars@^4.0.11:
version "4.0.12"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.12.tgz#2c15c8a96d46da5e266700518ba8cb8d919d5bc5"
Expand Down Expand Up @@ -4104,7 +4046,7 @@ js-yaml@^3.12.0:
argparse "^1.0.7"
esprima "^4.0.0"

js-yaml@^3.7.0, js-yaml@^3.8.1:
js-yaml@^3.7.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1"
dependencies:
Expand Down Expand Up @@ -4443,12 +4385,6 @@ lazy-cache@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e"

lazy-cache@^2.0.1:
version "2.0.2"
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-2.0.2.tgz#b9190a4f913354694840859f8a8f7084d8822264"
dependencies:
set-getter "^0.1.0"

lazy-property@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lazy-property/-/lazy-property-1.0.0.tgz#84ddc4b370679ba8bd4cdcfa4c06b43d57111147"
Expand All @@ -4460,15 +4396,6 @@ lcid@^1.0.0:
dependencies:
invert-kv "^1.0.0"

list-item@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/list-item/-/list-item-1.1.1.tgz#0c65d00e287cb663ccb3cb3849a77e89ec268a56"
dependencies:
expand-range "^1.8.1"
extend-shallow "^2.0.1"
is-number "^2.1.0"
repeat-string "^1.5.2"

listenercount@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/listenercount/-/listenercount-1.0.1.tgz#84c8a72ab59c4725321480c975e6508342e70937"
Expand Down Expand Up @@ -4719,26 +4646,6 @@ map-visit@^1.0.0:
dependencies:
object-visit "^1.0.0"

markdown-link@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/markdown-link/-/markdown-link-0.1.1.tgz#32c5c65199a6457316322d1e4229d13407c8c7cf"

markdown-toc@^0.12.16:
version "0.12.16"
resolved "https://registry.yarnpkg.com/markdown-toc/-/markdown-toc-0.12.16.tgz#8f14f4b94b30c785f3640213ccea0c3001f79fb3"
dependencies:
concat-stream "^1.5.1"
gray-matter "^2.0.2"
lazy-cache "^2.0.1"
list-item "^1.1.1"
markdown-link "^0.1.1"
minimist "^1.2.0"
mixin-deep "^1.1.3"
object.pick "^1.1.2"
remarkable "^1.6.2"
repeat-string "^1.5.4"
strip-color "^0.1.0"

math-random@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/math-random/-/math-random-1.0.1.tgz#8b3aac588b8a66e4975e3cdea67f7bb329601fac"
Expand Down Expand Up @@ -4932,7 +4839,7 @@ mississippi@^2.0.0:
stream-each "^1.1.0"
through2 "^2.0.0"

mixin-deep@^1.1.3, mixin-deep@^1.2.0:
mixin-deep@^1.2.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.1.tgz#a49e7268dce1a0d9698e45326c5626df3543d0fe"
dependencies:
Expand Down Expand Up @@ -5570,7 +5477,7 @@ object.omit@^2.0.0:
for-own "^0.1.4"
is-extendable "^0.1.1"

object.pick@^1.1.2, object.pick@^1.3.0:
object.pick@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/object.pick/-/object.pick-1.3.0.tgz#87a10ac4c1694bd2e1cbf53591a66141fb5dd747"
dependencies:
Expand Down Expand Up @@ -6383,13 +6290,6 @@ regjsparser@^0.1.4:
dependencies:
jsesc "~0.5.0"

remarkable@^1.6.2:
version "1.7.1"
resolved "https://registry.yarnpkg.com/remarkable/-/remarkable-1.7.1.tgz#aaca4972100b66a642a63a1021ca4bac1be3bff6"
dependencies:
argparse "~0.1.15"
autolinker "~0.15.0"

remove-trailing-separator@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef"
Expand All @@ -6402,7 +6302,7 @@ repeat-string@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-0.2.2.tgz#c7a8d3236068362059a7e4651fc6884e8b1fb4ae"

repeat-string@^1.5.2, repeat-string@^1.5.4, repeat-string@^1.6.1:
repeat-string@^1.5.2, repeat-string@^1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637"

Expand Down Expand Up @@ -6701,12 +6601,6 @@ set-blocking@^2.0.0, set-blocking@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"

set-getter@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/set-getter/-/set-getter-0.1.0.tgz#d769c182c9d5a51f409145f2fba82e5e86e80376"
dependencies:
to-object-path "^0.3.0"

set-immediate-shim@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz#4b2b1b27eb808a9f8dcc481a58e5e56f599f3f61"
Expand Down Expand Up @@ -7139,10 +7033,6 @@ strip-bom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"

strip-color@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/strip-color/-/strip-color-0.1.0.tgz#106f65d3d3e6a2d9401cac0eb0ce8b8a702b4f7b"

strip-eof@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"
Expand Down Expand Up @@ -7342,10 +7232,6 @@ to-regex@^3.0.1, to-regex@^3.0.2:
regex-not "^1.0.2"
safe-regex "^1.1.0"

toml@^2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/toml/-/toml-2.3.3.tgz#8d683d729577cb286231dfc7a8affe58d31728fb"

tough-cookie@~2.3.0, tough-cookie@~2.3.3:
version "2.3.4"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655"
Expand Down Expand Up @@ -7493,14 +7379,6 @@ umask@~1.1.0:
resolved "https://registry.yarnpkg.com/umask/-/umask-1.1.0.tgz#f29cebf01df517912bb58ff9c4e50fde8e33320d"
integrity sha1-8pzr8B31F5ErtY/5xOUP3o4zMg0=

underscore.string@~2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-2.4.0.tgz#8cdd8fbac4e2d2ea1e7e2e8097c42f442280f85b"

underscore@~1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.7.0.tgz#6bbaf0877500d36be34ecaa584e0db9fef035209"

union-value@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.0.tgz#5c71c34cb5bad5dcebe3ea0cd08207ba5aa1aea4"
Expand Down

0 comments on commit b4eba48

Please sign in to comment.