-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathpromises.js
51 lines (42 loc) · 1.54 KB
/
promises.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"use strict";
var assert = require("assert");
var Client = require("../.");
require("./_testServer.js");
var client = new Client("http://localhost:16006/rest");
describe("Testing jsonapi-client", function() {
context("supports promises", function() {
it("client.find", function(done) {
client.find("people", { }).then(function(people) {
assert.ok(people[0] instanceof Client.Resource);
}).then(done, done);
});
it("client.get", function(done) {
client.get("people", "d850ea75-4427-4f81-8595-039990aeede5", { }).then(function(person) {
assert.ok(person instanceof Client.Resource);
}).then(done, done);
});
it("client.fetch", function(done) {
client.get("people", "d850ea75-4427-4f81-8595-039990aeede5", { }).then(function(person) {
return person.fetch("articles", { include: "photos" });
}).then(function(articles) {
assert.ok(articles[0] instanceof Client.Resource);
assert.ok(articles[0].photos[0] instanceof Client.Resource);
}).then(done, done);
});
it("create-sync-delete", function(done) {
var newPerson = client.create("people");
var uuid;
newPerson.sync().then(function() {
uuid = newPerson._getUid();
return newPerson.delete();
}).then(function() {
return client.get("people", uuid, { });
}).then(function() {
throw new Error("Should have errored!");
}, function(err) {
assert.ok(err.message.match(/There is no people with id /));
done();
});
});
});
});