Skip to content

Commit d85e223

Browse files
committed
Build latest
1 parent 5ad8de0 commit d85e223

File tree

6 files changed

+253
-174
lines changed

6 files changed

+253
-174
lines changed

build/src/steps/http/content-negotiation/validate-content-type.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ function validateContentType(requestContext, supportedExt) {
2727
return _q2["default"].Promise(function (resolve, reject) {
2828
var contentType = _contentType2["default"].parse(requestContext.contentType);
2929

30+
// Removed due to issues with Firefox automatically adding charset parameter
31+
// See: https://github.com/ethanresnick/json-api/issues/78
32+
delete contentType.parameters.charset;
33+
3034
// In the future, we might delegate back to the framework if the client
3135
// provides a base content type other than json-api's. But, for now, we 415.
3236
if (contentType.type !== "application/vnd.api+json") {

build/test/integration/content-negotiation/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ _appAgent2["default"].then(function (Agent) {
2828
})["catch"](done);
2929
});
3030

31+
// Spec ignored due to issues with Firefox automatically adding charset parameter
32+
// See: https://github.com/ethanresnick/json-api/issues/78
33+
it("must accept charset parameter", function (done) {
34+
Agent.request("POST", "/organizations").type("application/vnd.api+json;charset=utf-8").send({ "data": _fixturesCreation.VALID_ORG_RESOURCE_NO_ID }).promise().then(function (res) {
35+
(0, _chai.expect)(res.status).to.equal(201);
36+
done();
37+
}, done)["catch"](done);
38+
});
39+
3140
// "Servers MUST send all JSON API data in response documents with the
3241
// header Content-Type: application/vnd.api+json without any media type
3342
// parameters."

build/test/integration/create-resource/index.js

Lines changed: 91 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -10,92 +10,105 @@ var _appAgent2 = _interopRequireDefault(_appAgent);
1010

1111
var _fixturesCreation = require("../fixtures/creation");
1212

13-
describe("", function () {
14-
_appAgent2["default"].then(function (Agent) {
15-
Agent.request("POST", "/organizations").type("application/vnd.api+json").send({ "data": _fixturesCreation.VALID_ORG_RESOURCE_NO_ID_EXTRA_MEMBER, "extra": false }).promise().then(function (res) {
16-
var createdResource = res.body.data;
17-
18-
describe("Creating a Valid Resource (With an Extra Member)", function () {
19-
describe("HTTP", function () {
20-
it("should return 201", function () {
21-
(0, _chai.expect)(res.status).to.equal(201);
22-
});
23-
24-
it("should include a valid Location header", function () {
25-
(0, _chai.expect)(res.headers.location).to.match(/\/organizations\/[a-z0-9]+/);
26-
(0, _chai.expect)(createdResource.links.self).to.equal(res.headers.location);
27-
});
13+
describe("Creating Resources", function () {
14+
var Agent = undefined;
15+
16+
describe("Creating a Valid Resource (With an Extra Member)", function () {
17+
var createdResource = undefined,
18+
createdId = undefined,
19+
res = undefined;
20+
before(function (done) {
21+
_appAgent2["default"].then(function (A) {
22+
Agent = A;
23+
Agent.request("POST", "/organizations").type("application/vnd.api+json").send({ "data": _fixturesCreation.VALID_ORG_RESOURCE_NO_ID_EXTRA_MEMBER, "extra": false }).promise().then(function (response) {
24+
res = response;
25+
createdResource = res.body.data;
26+
createdId = res.body.data.id;
27+
done();
2828
});
29+
})["catch"](done);
30+
});
2931

30-
describe("Document Structure", function () {
31-
// "A JSON object MUST be at the root of every
32-
// JSON API request and response containing data."
33-
it("should have an object/document at the top level", function () {
34-
(0, _chai.expect)(res.body).to.be.an("object");
35-
});
36-
37-
it("should ignore extra document object members", function () {
38-
(0, _chai.expect)(res.status).to.be.within(200, 299);
39-
(0, _chai.expect)(res.body.extra).to.be.undefined;
40-
});
41-
42-
describe("Links", function () {});
43-
44-
describe("Transforms", function () {
45-
describe("beforeSave", function () {
46-
it("should execute beforeSave hook", function () {
47-
(0, _chai.expect)(createdResource.attributes.description).to.equal("Added a description in beforeSave");
48-
});
49-
50-
it("should allow beforeSave to return a Promise", function (done) {
51-
Agent.request("POST", "/schools").type("application/vnd.api+json").send({ "data": _fixturesCreation.VALID_SCHOOL_RESOURCE_NO_ID }).promise().then(function (res2) {
52-
(0, _chai.expect)(res2.body.data.attributes.description).to.equal("Modified in a Promise");
53-
done();
54-
}, done)["catch"](done);
55-
});
56-
});
57-
});
58-
59-
describe("The Created Resource", function () {
60-
it("should return the created resource", function () {
61-
(0, _chai.expect)(createdResource).to.be.an("object");
62-
(0, _chai.expect)(createdResource.type).to.equal("organizations");
63-
(0, _chai.expect)(createdResource.attributes).to.be.an("object");
64-
(0, _chai.expect)(createdResource.relationships).to.be.an("object");
65-
(0, _chai.expect)(createdResource.relationships.liaisons).to.be.an("object");
66-
});
67-
68-
it("should ignore extra resource object members", function () {
69-
(0, _chai.expect)(res.body.data.extraMember).to.be.undefined;
70-
(0, _chai.expect)(res.body.data.attributes.extraMember).to.be.undefined;
71-
});
72-
});
73-
});
32+
describe("HTTP", function () {
33+
it("should return 201", function () {
34+
(0, _chai.expect)(res.status).to.equal(201);
35+
});
36+
37+
it("should include a valid Location header", function () {
38+
(0, _chai.expect)(res.headers.location).to.match(/\/organizations\/[a-z0-9]+/);
39+
(0, _chai.expect)(createdResource.links.self).to.equal(res.headers.location);
40+
});
41+
});
42+
43+
describe("Document Structure", function () {
44+
// "A JSON object MUST be at the root of every
45+
// JSON API request and response containing data."
46+
it("should have an object/document at the top level", function () {
47+
(0, _chai.expect)(res.body).to.be.an("object");
7448
});
75-
}).done();
76-
}).done();
77-
});
7849

79-
describe("", function () {
80-
_appAgent2["default"].then(function (Agent) {
81-
Agent.request("POST", "/organizations").type("application/vnd.api+json").send({ "data": _fixturesCreation.ORG_RESOURCE_CLIENT_ID }).promise().then(function () {
82-
throw new Error("Should not run!");
83-
}, function (err) {
84-
describe("Creating a Resource With A Client-Id", function () {
85-
describe("HTTP", function () {
86-
it("should return 403", function () {
87-
(0, _chai.expect)(err.response.status).to.equal(403);
88-
});
50+
it("should ignore extra document object members", function () {
51+
(0, _chai.expect)(res.status).to.be.within(200, 299);
52+
(0, _chai.expect)(res.body.extra).to.be.undefined;
53+
});
54+
});
55+
56+
describe("Links", function () {});
57+
58+
describe("Transforms", function () {
59+
describe("beforeSave", function () {
60+
it("should execute beforeSave hook", function () {
61+
(0, _chai.expect)(createdResource.attributes.description).to.equal("Added a description in beforeSave");
8962
});
9063

91-
describe("Document Structure", function () {
92-
it("should contain an error", function () {
93-
(0, _chai.expect)(err.response.body.errors).to.be.an("array");
94-
});
64+
it("should allow beforeSave to return a Promise", function (done) {
65+
Agent.request("POST", "/schools").type("application/vnd.api+json").send({ "data": _fixturesCreation.VALID_SCHOOL_RESOURCE_NO_ID }).promise().then(function (response) {
66+
(0, _chai.expect)(response.body.data.attributes.description).to.equal("Modified in a Promise");
67+
done();
68+
}, done)["catch"](done);
9569
});
9670
});
97-
}).done();
98-
}).done();
71+
});
72+
73+
describe("The Created Resource", function () {
74+
it("should be returned in the body", function () {
75+
(0, _chai.expect)(createdResource).to.be.an("object");
76+
(0, _chai.expect)(createdResource.type).to.equal("organizations");
77+
(0, _chai.expect)(createdResource.attributes).to.be.an("object");
78+
(0, _chai.expect)(createdResource.relationships).to.be.an("object");
79+
(0, _chai.expect)(createdResource.relationships.liaisons).to.be.an("object");
80+
});
81+
82+
it("should ignore extra resource object members", function () {
83+
(0, _chai.expect)(res.body.data.extraMember).to.be.undefined;
84+
(0, _chai.expect)(res.body.data.attributes.extraMember).to.be.undefined;
85+
});
86+
});
87+
});
88+
89+
describe("Creating a Resource With A Client-Id", function () {
90+
var err = undefined;
91+
before(function (done) {
92+
Agent.request("POST", "/organizations").type("application/vnd.api+json").send({ "data": _fixturesCreation.ORG_RESOURCE_CLIENT_ID }).promise().then(function () {
93+
return done("Should not run!");
94+
}, function (error) {
95+
err = error;
96+
done();
97+
});
98+
});
99+
100+
describe("HTTP", function () {
101+
it("should return 403", function () {
102+
(0, _chai.expect)(err.response.status).to.equal(403);
103+
});
104+
});
105+
106+
describe("Document Structure", function () {
107+
it("should contain an error", function () {
108+
(0, _chai.expect)(err.response.body.errors).to.be.an("array");
109+
});
110+
});
111+
});
99112
});
100113

101114
// "[S]erver implementations MUST ignore
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
3+
var _interopRequireDefault = require("babel-runtime/helpers/interop-require-default")["default"];
4+
5+
var _chai = require("chai");
6+
7+
var _appAgent = require("../../app/agent");
8+
9+
var _appAgent2 = _interopRequireDefault(_appAgent);
10+
11+
var _fixturesCreation = require("../fixtures/creation");
12+
13+
describe("Deleting a resource", function () {
14+
15+
var Agent = undefined,
16+
id = undefined;
17+
before(function (done) {
18+
_appAgent2["default"].then(function (A) {
19+
Agent = A;
20+
return Agent.request("POST", "/schools").type("application/vnd.api+json").send({ "data": _fixturesCreation.VALID_SCHOOL_RESOURCE_NO_ID }).promise().then(function (response) {
21+
id = response.body.data.id;
22+
return Agent.request("DEL", "/schools/" + id).type("application/vnd.api+json").send().promise();
23+
}, done).then(function () {
24+
return done();
25+
}, done);
26+
}, done)["catch"](done);
27+
});
28+
29+
it("should delete a resource by id", function (done) {
30+
Agent.request("GET", "/schools/" + id).accept("application/vnd.api+json").promise().then(done, function (err) {
31+
(0, _chai.expect)(err.response.statusCode).to.equal(404);
32+
done();
33+
})["catch"](done);
34+
});
35+
});

0 commit comments

Comments
 (0)