This repository has been archived by the owner on Oct 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#32): Add support of array of link
- links can not be array - upgrade documentation close #32
- Loading branch information
Showing
6 changed files
with
125 additions
and
26 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { test } from "tape-async"; | ||
|
||
import { createClient, HalResource, resetCache } from "../"; | ||
|
||
import * as nock from "nock"; | ||
|
||
// mock list response | ||
function initTests() { | ||
nock.cleanAll(); | ||
resetCache(); | ||
const project1 = { | ||
_links: { | ||
related: [ | ||
{ href: "http://test.fr/projects/1" }, | ||
{ href: "http://test.fr/projects/2" }, | ||
{ href: "http://test.fr/projects/3" }, | ||
], | ||
self: { | ||
href: "http://test.fr/projects/1", | ||
}, | ||
}, | ||
test: "test", | ||
}; | ||
|
||
const project2 = { | ||
_links: { | ||
self: { | ||
href: "http://test.fr/projects/2", | ||
}, | ||
}, | ||
}; | ||
|
||
const testNock = nock("http://test.fr/"); | ||
|
||
testNock | ||
.get("/projects/1") | ||
.reply(200, project1); | ||
|
||
testNock | ||
.get("/projects/2") | ||
.reply(200, project2); | ||
} | ||
|
||
test("list of links are resources", async (t) => { | ||
initTests(); | ||
const project = await createClient().fetch("http://test.fr/projects/1", HalResource); | ||
const related = project.link("related"); | ||
t.equals(Array.isArray(related), true); | ||
t.equals(related.every((item) => item instanceof HalResource), true); | ||
}); | ||
|
||
test("list links can be fetched", async (t) => { | ||
initTests(); | ||
const project = await createClient().fetch("http://test.fr/projects/1", HalResource); | ||
const related = project.link("related"); | ||
await related[0].fetch(); | ||
t.equals(related[0].prop("test"), "test"); | ||
}); |