Skip to content

Commit

Permalink
Add deletion integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennettnz committed Aug 31, 2015
1 parent 22fbcc5 commit 2396f15
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test/app/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const ObjectId = mongoose.Types.ObjectId;
const govtId = ObjectId("54419d550a5069a2129ef254");
const smithId = ObjectId("53f54dd98d1e62ff12539db2");
const doeId = ObjectId("53f54dd98d1e62ff12539db3");
const stateCollegeId = ObjectId("53f54dd98d1e62ff12539db4");
/*eslint-enable new-cap */

const OrganizationModel = OrganizationModelSchema.model;
Expand All @@ -33,7 +34,7 @@ fixtures.save("all", {
],
School: [
{name: "City College", description: "Just your average local college.", liaisons: [smithId]},
{name: "State College", description: "Just your average state college."}
{name: "State College", description: "Just your average state college.", _id: stateCollegeId}
]
});

Expand Down
8 changes: 7 additions & 1 deletion test/app/src/resource-descriptions/schools.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Promise } from "q";
import API from "../../../../../index";
let APIError = API.types.Error;

module.exports = {
parentType: "organizations",
Expand All @@ -23,10 +25,14 @@ module.exports = {
}
},

beforeSave: function(resource) {
beforeSave(resource) {
return new Promise((resolve, reject) => {
resource.attrs.description = "Modified in a Promise";
resolve(resource);
});
},

beforeDelete(resource) {
throw new APIError(403, "undefined", "You are not allowed to delete people.");
}
};
39 changes: 39 additions & 0 deletions test/integration/delete-resource/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {expect} from "chai";
import AgentPromise from "../../app/agent";
import { VALID_ORG_STATE_GOVT_PATCH } from "../fixtures/updates";

describe("", () => {
AgentPromise.then((Agent) => {
Agent.request("DEL", "/organizations/" + VALID_ORG_STATE_GOVT_PATCH.id)
.type("application/vnd.api+json")
.promise()
.then((res) => {
describe("Deleting a resource", () => {
it("should return 204", () => {
expect(res.status).to.equal(204);
});
});
}).done();
}).done();
});

describe("", () => {
AgentPromise.then((Agent) => {
Agent.request("DEL", "/schools/53f54dd98d1e62ff12539db4")
.type("application/vnd.api+json")
.promise()
.then((res) => {
describe("Deleting a resource without permission", () => {
it("should return 403", () => {
expect(false).to.be.ok; // should not run
});
});
}, (res) => {
describe("Deleting a resource without permission", () => {
it("should return 403", () => {
expect(res.status).to.equal(403);
});
});
}).done();
}).done();
});
1 change: 1 addition & 0 deletions test/integration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ before((done) => {
require("./content-negotiation");
require("./fetch-collection");
require("./create-resource");
require("./delete-resource");
done();
}).done();
});
Expand Down

0 comments on commit 2396f15

Please sign in to comment.