allow deletion of model
This commit is contained in:
parent
6a34aa72f4
commit
6d47e0df89
|
@ -61,5 +61,9 @@ exports.update = async function(ctx) {
|
|||
|
||||
exports.destroy = async function(ctx) {
|
||||
const db = couchdb.db.use(ctx.params.instanceId)
|
||||
ctx.body = await db.destroy(ctx.params.modelId, ctx.params.rev);
|
||||
const model = await db.destroy(ctx.params.modelId, ctx.params.revId);
|
||||
ctx.body = {
|
||||
message: `Model ${model.id} deleted.`,
|
||||
status: 200
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ router
|
|||
.get("/api/:instanceId/models", controller.fetch)
|
||||
.post("/api/:instanceId/models", controller.create)
|
||||
// .patch("/api/:instanceId/models", controller.update)
|
||||
// .delete("/api/:instanceId/models/:modelId", controller.delete)
|
||||
.delete("/api/:instanceId/models/:modelId/:revId", controller.destroy);
|
||||
|
||||
|
||||
module.exports = router;
|
|
@ -16,8 +16,11 @@ exports.createModel = async instanceId => {
|
|||
}
|
||||
]
|
||||
}
|
||||
await couchdb.db.use(instanceId).insert(model);
|
||||
return model;
|
||||
const response = await couchdb.db.use(instanceId).insert(model);
|
||||
return {
|
||||
...response,
|
||||
...model
|
||||
};
|
||||
}
|
||||
|
||||
exports.createClientDatabase = async () => {
|
||||
|
|
|
@ -80,4 +80,29 @@ describe("/models", () => {
|
|||
});
|
||||
})
|
||||
});
|
||||
|
||||
describe("destroy", () => {
|
||||
let testModel;
|
||||
|
||||
beforeEach(async () => {
|
||||
await createInstanceDatabase(TEST_INSTANCE_ID);
|
||||
testModel = await createModel(TEST_INSTANCE_ID);
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await destroyDatabase(TEST_INSTANCE_ID);
|
||||
});
|
||||
|
||||
it("returns all the models for that instance in the response body", done => {
|
||||
request
|
||||
.delete(`/api/${TEST_INSTANCE_ID}/models/${testModel.id}/${testModel.rev}`)
|
||||
.set("Accept", "application/json")
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200)
|
||||
.end(async (_, res) => {
|
||||
expect(res.body.message).toEqual(`Model ${testModel.id} deleted.`);
|
||||
done();
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue