Skip to content

Commit 2396f15

Browse files
committed
Add deletion integration tests
1 parent 22fbcc5 commit 2396f15

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

test/app/database/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const ObjectId = mongoose.Types.ObjectId;
1111
const govtId = ObjectId("54419d550a5069a2129ef254");
1212
const smithId = ObjectId("53f54dd98d1e62ff12539db2");
1313
const doeId = ObjectId("53f54dd98d1e62ff12539db3");
14+
const stateCollegeId = ObjectId("53f54dd98d1e62ff12539db4");
1415
/*eslint-enable new-cap */
1516

1617
const OrganizationModel = OrganizationModelSchema.model;
@@ -33,7 +34,7 @@ fixtures.save("all", {
3334
],
3435
School: [
3536
{name: "City College", description: "Just your average local college.", liaisons: [smithId]},
36-
{name: "State College", description: "Just your average state college."}
37+
{name: "State College", description: "Just your average state college.", _id: stateCollegeId}
3738
]
3839
});
3940

test/app/src/resource-descriptions/schools.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Promise } from "q";
2+
import API from "../../../../../index";
3+
let APIError = API.types.Error;
24

35
module.exports = {
46
parentType: "organizations",
@@ -23,10 +25,14 @@ module.exports = {
2325
}
2426
},
2527

26-
beforeSave: function(resource) {
28+
beforeSave(resource) {
2729
return new Promise((resolve, reject) => {
2830
resource.attrs.description = "Modified in a Promise";
2931
resolve(resource);
3032
});
33+
},
34+
35+
beforeDelete(resource) {
36+
throw new APIError(403, "undefined", "You are not allowed to delete people.");
3137
}
3238
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {expect} from "chai";
2+
import AgentPromise from "../../app/agent";
3+
import { VALID_ORG_STATE_GOVT_PATCH } from "../fixtures/updates";
4+
5+
describe("", () => {
6+
AgentPromise.then((Agent) => {
7+
Agent.request("DEL", "/organizations/" + VALID_ORG_STATE_GOVT_PATCH.id)
8+
.type("application/vnd.api+json")
9+
.promise()
10+
.then((res) => {
11+
describe("Deleting a resource", () => {
12+
it("should return 204", () => {
13+
expect(res.status).to.equal(204);
14+
});
15+
});
16+
}).done();
17+
}).done();
18+
});
19+
20+
describe("", () => {
21+
AgentPromise.then((Agent) => {
22+
Agent.request("DEL", "/schools/53f54dd98d1e62ff12539db4")
23+
.type("application/vnd.api+json")
24+
.promise()
25+
.then((res) => {
26+
describe("Deleting a resource without permission", () => {
27+
it("should return 403", () => {
28+
expect(false).to.be.ok; // should not run
29+
});
30+
});
31+
}, (res) => {
32+
describe("Deleting a resource without permission", () => {
33+
it("should return 403", () => {
34+
expect(res.status).to.equal(403);
35+
});
36+
});
37+
}).done();
38+
}).done();
39+
});

test/integration/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ before((done) => {
1616
require("./content-negotiation");
1717
require("./fetch-collection");
1818
require("./create-resource");
19+
require("./delete-resource");
1920
done();
2021
}).done();
2122
});

0 commit comments

Comments
 (0)