Skip to content

Commit b4eba48

Browse files
committed
Merge branch 'master' of github.com:wikibus/Alcaeus
2 parents 94ee71f + 2860ff6 commit b4eba48

3 files changed

Lines changed: 40 additions & 130 deletions

File tree

src/ResponseWrapper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export class ResponseWrapper implements IResponseWrapper {
5151
const links = li(linkHeaders);
5252

5353
if (links[Constants.Core.Vocab('apiDocumentation')]) {
54-
return links[Constants.Core.Vocab('apiDocumentation')].url;
54+
const linkUrl = links[Constants.Core.Vocab('apiDocumentation')].url;
55+
56+
return new URL(linkUrl, this.redirectUrl || this.requestedUri).toString();
5557
}
5658
}
5759

tests/ResponseWrapper-spec.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,28 @@ import {Bodies} from './test-objects';
33
import {responseBuilder} from './test-utils';
44

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

1010
// when
11-
const res = new ResponseWrapper('', xhrResponse);
11+
const res = new ResponseWrapper('http://resources.example.com/', xhrResponse);
1212

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

17+
it('should get relative documentation link', async () => {
18+
// given
19+
const xhrResponse = await responseBuilder().body(Bodies.someJsonLd).apiDocumentation('doc/').build();
20+
21+
// when
22+
const res = new ResponseWrapper('http://api.example.com/resource/', xhrResponse);
23+
24+
// then
25+
expect(res.apiDocumentationLink).toBe('http://api.example.com/resource/doc/');
26+
});
27+
1728
it('should get redirect URL if redirected', async () => {
1829
// given
1930
const xhrResponse = {
@@ -28,4 +39,23 @@ describe('ResponseWrapper', () => {
2839
// then
2940
expect(res.redirectUrl).toBe('urn:actual:resource');
3041
});
42+
43+
it('should base relative documentation link on redirect target', async () => {
44+
// given
45+
const xhrResponse = {
46+
headers: {
47+
get: () => '</api-doc>; rel=http://www.w3.org/ns/hydra/core#apiDocumentation',
48+
has: () => true,
49+
},
50+
redirected: true,
51+
url: 'http://other.example.api',
52+
} as any;
53+
xhrResponse.clone = () => xhrResponse;
54+
55+
// when
56+
const res = new ResponseWrapper('http://api.example.com/resorce/', xhrResponse);
57+
58+
// then
59+
expect(res.apiDocumentationLink).toBe('http://other.example.api/api-doc');
60+
});
3161
});

yarn.lock

Lines changed: 5 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,6 @@ ansi-align@^2.0.0:
294294
dependencies:
295295
string-width "^2.0.0"
296296

297-
ansi-red@^0.1.1:
298-
version "0.1.1"
299-
resolved "https://registry.yarnpkg.com/ansi-red/-/ansi-red-0.1.1.tgz#8c638f9d1080800a353c9c28c8a81ca4705d946c"
300-
dependencies:
301-
ansi-wrap "0.1.0"
302-
303297
ansi-regex@^2.0.0:
304298
version "2.1.1"
305299
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
@@ -319,10 +313,6 @@ ansi-styles@^3.2.1:
319313
dependencies:
320314
color-convert "^1.9.0"
321315

322-
ansi-wrap@0.1.0:
323-
version "0.1.0"
324-
resolved "https://registry.yarnpkg.com/ansi-wrap/-/ansi-wrap-0.1.0.tgz#a82250ddb0015e9a27ca82e82ea603bbfa45efaf"
325-
326316
ansi@^0.3.0, ansi@~0.3.1:
327317
version "0.3.1"
328318
resolved "https://registry.yarnpkg.com/ansi/-/ansi-0.3.1.tgz#0c42d4fb17160d5a9af1e484bace1c66922c1b21"
@@ -387,13 +377,6 @@ argparse@^1.0.7:
387377
dependencies:
388378
sprintf-js "~1.0.2"
389379

390-
argparse@~0.1.15:
391-
version "0.1.16"
392-
resolved "https://registry.yarnpkg.com/argparse/-/argparse-0.1.16.tgz#cfd01e0fbba3d6caed049fbd758d40f65196f57c"
393-
dependencies:
394-
underscore "~1.7.0"
395-
underscore.string "~2.4.0"
396-
397380
arr-diff@^2.0.0:
398381
version "2.0.0"
399382
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-2.0.0.tgz#8f3b827f955a8bd669697e4a4256ac3ceae356cf"
@@ -496,10 +479,6 @@ atob@^2.1.1:
496479
version "2.1.1"
497480
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.1.tgz#ae2d5a729477f289d60dd7f96a6314a22dd6c22a"
498481

499-
autolinker@~0.15.0:
500-
version "0.15.3"
501-
resolved "https://registry.yarnpkg.com/autolinker/-/autolinker-0.15.3.tgz#342417d8f2f3461b14cf09088d5edf8791dc9832"
502-
503482
aws-sign2@~0.6.0:
504483
version "0.6.0"
505484
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.6.0.tgz#14342dd38dbcc94d0e5b87d763cd63612c0e794f"
@@ -1822,10 +1801,6 @@ code-point-at@^1.0.0:
18221801
version "1.1.0"
18231802
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
18241803

1825-
coffee-script@^1.12.4:
1826-
version "1.12.7"
1827-
resolved "https://registry.yarnpkg.com/coffee-script/-/coffee-script-1.12.7.tgz#c05dae0cb79591d05b3070a8433a98c9a89ccc53"
1828-
18291804
collection-visit@^1.0.0:
18301805
version "1.0.0"
18311806
resolved "https://registry.yarnpkg.com/collection-visit/-/collection-visit-1.0.0.tgz#4bc0373c164bc3291b4d368c829cf1a80a59dca0"
@@ -1969,7 +1944,7 @@ concat-map@0.0.1:
19691944
version "0.0.1"
19701945
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
19711946

1972-
concat-stream@1.6.2, concat-stream@^1.5.0, concat-stream@^1.5.1, concat-stream@^1.5.2, concat-stream@^1.6.2:
1947+
concat-stream@1.6.2, concat-stream@^1.5.0, concat-stream@^1.5.2, concat-stream@^1.6.2:
19731948
version "1.6.2"
19741949
resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.2.tgz#904bdf194cd3122fc675c77fc4ac3d4ff0fd1a34"
19751950
integrity sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==
@@ -3192,29 +3167,6 @@ gitbook-cli@^2.3.2:
31923167
tmp "0.0.31"
31933168
user-home "2.0.0"
31943169

3195-
gitbook-plugin-etoc@^1.2.2:
3196-
version "1.2.2"
3197-
resolved "https://registry.yarnpkg.com/gitbook-plugin-etoc/-/gitbook-plugin-etoc-1.2.2.tgz#8de530b841d2ead68e1a51f727c1778dd3106f62"
3198-
dependencies:
3199-
github-slugid "^1.0.1"
3200-
markdown-toc "^0.12.16"
3201-
3202-
gitbook-plugin-forkmegithub@^2.2.0:
3203-
version "2.2.0"
3204-
resolved "https://registry.yarnpkg.com/gitbook-plugin-forkmegithub/-/gitbook-plugin-forkmegithub-2.2.0.tgz#b64b62a1402b099b1b48c396a9d5b0aba967c04a"
3205-
3206-
gitbook-plugin-hints@^1.0.2:
3207-
version "1.0.2"
3208-
resolved "https://registry.yarnpkg.com/gitbook-plugin-hints/-/gitbook-plugin-hints-1.0.2.tgz#e6589983e3ea84749f16dc631e282fafd45ec39b"
3209-
3210-
gitbook-plugin-runkit@0.0.1:
3211-
version "0.0.1"
3212-
resolved "https://registry.yarnpkg.com/gitbook-plugin-runkit/-/gitbook-plugin-runkit-0.0.1.tgz#512ca4c110775ee23249bac611fd6a6588fe1f72"
3213-
3214-
github-slugid@^1.0.1:
3215-
version "1.0.1"
3216-
resolved "https://registry.yarnpkg.com/github-slugid/-/github-slugid-1.0.1.tgz#bccdd0815bfad69d8a359fa4fd65947d606ec3c0"
3217-
32183170
github-url-from-git@~1.4.0:
32193171
version "1.4.0"
32203172
resolved "https://registry.yarnpkg.com/github-url-from-git/-/github-url-from-git-1.4.0.tgz#285e6b520819001bde128674704379e4ff03e0de"
@@ -3320,16 +3272,6 @@ graceful-fs@~4.1.11, graceful-fs@~4.1.6:
33203272
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
33213273
integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==
33223274

3323-
gray-matter@^2.0.2:
3324-
version "2.1.1"
3325-
resolved "https://registry.yarnpkg.com/gray-matter/-/gray-matter-2.1.1.tgz#3042d9adec2a1ded6a7707a9ed2380f8a17a430e"
3326-
dependencies:
3327-
ansi-red "^0.1.1"
3328-
coffee-script "^1.12.4"
3329-
extend-shallow "^2.0.1"
3330-
js-yaml "^3.8.1"
3331-
toml "^2.3.2"
3332-
33333275
handlebars@^4.0.11:
33343276
version "4.0.12"
33353277
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.12.tgz#2c15c8a96d46da5e266700518ba8cb8d919d5bc5"
@@ -4104,7 +4046,7 @@ js-yaml@^3.12.0:
41044046
argparse "^1.0.7"
41054047
esprima "^4.0.0"
41064048

4107-
js-yaml@^3.7.0, js-yaml@^3.8.1:
4049+
js-yaml@^3.7.0:
41084050
version "3.12.0"
41094051
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1"
41104052
dependencies:
@@ -4443,12 +4385,6 @@ lazy-cache@^1.0.3:
44434385
version "1.0.4"
44444386
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e"
44454387

4446-
lazy-cache@^2.0.1:
4447-
version "2.0.2"
4448-
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-2.0.2.tgz#b9190a4f913354694840859f8a8f7084d8822264"
4449-
dependencies:
4450-
set-getter "^0.1.0"
4451-
44524388
lazy-property@~1.0.0:
44534389
version "1.0.0"
44544390
resolved "https://registry.yarnpkg.com/lazy-property/-/lazy-property-1.0.0.tgz#84ddc4b370679ba8bd4cdcfa4c06b43d57111147"
@@ -4460,15 +4396,6 @@ lcid@^1.0.0:
44604396
dependencies:
44614397
invert-kv "^1.0.0"
44624398

4463-
list-item@^1.1.1:
4464-
version "1.1.1"
4465-
resolved "https://registry.yarnpkg.com/list-item/-/list-item-1.1.1.tgz#0c65d00e287cb663ccb3cb3849a77e89ec268a56"
4466-
dependencies:
4467-
expand-range "^1.8.1"
4468-
extend-shallow "^2.0.1"
4469-
is-number "^2.1.0"
4470-
repeat-string "^1.5.2"
4471-
44724399
listenercount@~1.0.1:
44734400
version "1.0.1"
44744401
resolved "https://registry.yarnpkg.com/listenercount/-/listenercount-1.0.1.tgz#84c8a72ab59c4725321480c975e6508342e70937"
@@ -4719,26 +4646,6 @@ map-visit@^1.0.0:
47194646
dependencies:
47204647
object-visit "^1.0.0"
47214648

4722-
markdown-link@^0.1.1:
4723-
version "0.1.1"
4724-
resolved "https://registry.yarnpkg.com/markdown-link/-/markdown-link-0.1.1.tgz#32c5c65199a6457316322d1e4229d13407c8c7cf"
4725-
4726-
markdown-toc@^0.12.16:
4727-
version "0.12.16"
4728-
resolved "https://registry.yarnpkg.com/markdown-toc/-/markdown-toc-0.12.16.tgz#8f14f4b94b30c785f3640213ccea0c3001f79fb3"
4729-
dependencies:
4730-
concat-stream "^1.5.1"
4731-
gray-matter "^2.0.2"
4732-
lazy-cache "^2.0.1"
4733-
list-item "^1.1.1"
4734-
markdown-link "^0.1.1"
4735-
minimist "^1.2.0"
4736-
mixin-deep "^1.1.3"
4737-
object.pick "^1.1.2"
4738-
remarkable "^1.6.2"
4739-
repeat-string "^1.5.4"
4740-
strip-color "^0.1.0"
4741-
47424649
math-random@^1.0.1:
47434650
version "1.0.1"
47444651
resolved "https://registry.yarnpkg.com/math-random/-/math-random-1.0.1.tgz#8b3aac588b8a66e4975e3cdea67f7bb329601fac"
@@ -4932,7 +4839,7 @@ mississippi@^2.0.0:
49324839
stream-each "^1.1.0"
49334840
through2 "^2.0.0"
49344841

4935-
mixin-deep@^1.1.3, mixin-deep@^1.2.0:
4842+
mixin-deep@^1.2.0:
49364843
version "1.3.1"
49374844
resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.1.tgz#a49e7268dce1a0d9698e45326c5626df3543d0fe"
49384845
dependencies:
@@ -5570,7 +5477,7 @@ object.omit@^2.0.0:
55705477
for-own "^0.1.4"
55715478
is-extendable "^0.1.1"
55725479

5573-
object.pick@^1.1.2, object.pick@^1.3.0:
5480+
object.pick@^1.3.0:
55745481
version "1.3.0"
55755482
resolved "https://registry.yarnpkg.com/object.pick/-/object.pick-1.3.0.tgz#87a10ac4c1694bd2e1cbf53591a66141fb5dd747"
55765483
dependencies:
@@ -6383,13 +6290,6 @@ regjsparser@^0.1.4:
63836290
dependencies:
63846291
jsesc "~0.5.0"
63856292

6386-
remarkable@^1.6.2:
6387-
version "1.7.1"
6388-
resolved "https://registry.yarnpkg.com/remarkable/-/remarkable-1.7.1.tgz#aaca4972100b66a642a63a1021ca4bac1be3bff6"
6389-
dependencies:
6390-
argparse "~0.1.15"
6391-
autolinker "~0.15.0"
6392-
63936293
remove-trailing-separator@^1.0.1:
63946294
version "1.1.0"
63956295
resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef"
@@ -6402,7 +6302,7 @@ repeat-string@^0.2.2:
64026302
version "0.2.2"
64036303
resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-0.2.2.tgz#c7a8d3236068362059a7e4651fc6884e8b1fb4ae"
64046304

6405-
repeat-string@^1.5.2, repeat-string@^1.5.4, repeat-string@^1.6.1:
6305+
repeat-string@^1.5.2, repeat-string@^1.6.1:
64066306
version "1.6.1"
64076307
resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637"
64086308

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

6704-
set-getter@^0.1.0:
6705-
version "0.1.0"
6706-
resolved "https://registry.yarnpkg.com/set-getter/-/set-getter-0.1.0.tgz#d769c182c9d5a51f409145f2fba82e5e86e80376"
6707-
dependencies:
6708-
to-object-path "^0.3.0"
6709-
67106604
set-immediate-shim@^1.0.1:
67116605
version "1.0.1"
67126606
resolved "https://registry.yarnpkg.com/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz#4b2b1b27eb808a9f8dcc481a58e5e56f599f3f61"
@@ -7139,10 +7033,6 @@ strip-bom@^3.0.0:
71397033
version "3.0.0"
71407034
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
71417035

7142-
strip-color@^0.1.0:
7143-
version "0.1.0"
7144-
resolved "https://registry.yarnpkg.com/strip-color/-/strip-color-0.1.0.tgz#106f65d3d3e6a2d9401cac0eb0ce8b8a702b4f7b"
7145-
71467036
strip-eof@^1.0.0:
71477037
version "1.0.0"
71487038
resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf"
@@ -7342,10 +7232,6 @@ to-regex@^3.0.1, to-regex@^3.0.2:
73427232
regex-not "^1.0.2"
73437233
safe-regex "^1.1.0"
73447234

7345-
toml@^2.3.2:
7346-
version "2.3.3"
7347-
resolved "https://registry.yarnpkg.com/toml/-/toml-2.3.3.tgz#8d683d729577cb286231dfc7a8affe58d31728fb"
7348-
73497235
tough-cookie@~2.3.0, tough-cookie@~2.3.3:
73507236
version "2.3.4"
73517237
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655"
@@ -7493,14 +7379,6 @@ umask@~1.1.0:
74937379
resolved "https://registry.yarnpkg.com/umask/-/umask-1.1.0.tgz#f29cebf01df517912bb58ff9c4e50fde8e33320d"
74947380
integrity sha1-8pzr8B31F5ErtY/5xOUP3o4zMg0=
74957381

7496-
underscore.string@~2.4.0:
7497-
version "2.4.0"
7498-
resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-2.4.0.tgz#8cdd8fbac4e2d2ea1e7e2e8097c42f442280f85b"
7499-
7500-
underscore@~1.7.0:
7501-
version "1.7.0"
7502-
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.7.0.tgz#6bbaf0877500d36be34ecaa584e0db9fef035209"
7503-
75047382
union-value@^1.0.0:
75057383
version "1.0.0"
75067384
resolved "https://registry.yarnpkg.com/union-value/-/union-value-1.0.0.tgz#5c71c34cb5bad5dcebe3ea0cd08207ba5aa1aea4"

0 commit comments

Comments
 (0)