From 2396f15c0fc486445792c1b2577f3c401e22925b Mon Sep 17 00:00:00 2001 From: Carl Bennett Date: Mon, 31 Aug 2015 10:59:30 +1200 Subject: [PATCH] Add deletion integration tests --- test/app/database/index.js | 3 +- test/app/src/resource-descriptions/schools.js | 8 +++- test/integration/delete-resource/index.js | 39 +++++++++++++++++++ test/integration/index.js | 1 + 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 test/integration/delete-resource/index.js diff --git a/test/app/database/index.js b/test/app/database/index.js index ca748b9d..95daf35a 100644 --- a/test/app/database/index.js +++ b/test/app/database/index.js @@ -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; @@ -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} ] }); diff --git a/test/app/src/resource-descriptions/schools.js b/test/app/src/resource-descriptions/schools.js index 6c71421e..1816f3e3 100755 --- a/test/app/src/resource-descriptions/schools.js +++ b/test/app/src/resource-descriptions/schools.js @@ -1,4 +1,6 @@ import { Promise } from "q"; +import API from "../../../../../index"; +let APIError = API.types.Error; module.exports = { parentType: "organizations", @@ -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."); } }; diff --git a/test/integration/delete-resource/index.js b/test/integration/delete-resource/index.js new file mode 100644 index 00000000..95a29573 --- /dev/null +++ b/test/integration/delete-resource/index.js @@ -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(); +}); diff --git a/test/integration/index.js b/test/integration/index.js index b2aaef43..541a1a4c 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -16,6 +16,7 @@ before((done) => { require("./content-negotiation"); require("./fetch-collection"); require("./create-resource"); + require("./delete-resource"); done(); }).done(); });