Add tests for obliterate
This commit is contained in:
1 parent
b063fa267a
commit
fde9303b8f
2 files changed
+41
-1
No files matched your search
@@ -46,7 +46,9 @@ const addJob = async (req, res, next) => {
|
|||||||
const obliterateQueue = async (req, res, next) => {
|
const obliterateQueue = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
await req.jobQueue.obliterate();
|
await req.jobQueue.obliterate();
|
||||||
return res.status(200).send("Obliterated queue");
|
return res
|
||||||
|
.status(200)
|
||||||
|
.json({ success: true, msg: successMessages.QUEUE_OBLITERATE });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(handleError(error, SERVICE_NAME, "obliterateQueue"));
|
next(handleError(error, SERVICE_NAME, "obliterateQueue"));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -127,4 +127,42 @@ describe("Queue Controller - addJob", () => {
|
|||||||
msg: successMessages.QUEUE_ADD_JOB,
|
msg: successMessages.QUEUE_ADD_JOB,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Queue Controller - obliterateQueue", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
req = {
|
||||||
|
headers: {},
|
||||||
|
params: {},
|
||||||
|
body: {},
|
||||||
|
db: {},
|
||||||
|
jobQueue: {
|
||||||
|
obliterate: sinon.stub(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
res = {
|
||||||
|
status: sinon.stub().returnsThis(),
|
||||||
|
json: sinon.stub(),
|
||||||
|
};
|
||||||
|
next = sinon.stub();
|
||||||
|
handleError = sinon.stub();
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
sinon.restore();
|
||||||
|
});
|
||||||
|
it("should reject with an error if obliterateQueue throws an error", async () => {
|
||||||
|
req.jobQueue.obliterate.throws(new Error("obliterateQueue error"));
|
||||||
|
await obliterateQueue(req, res, next);
|
||||||
|
expect(next.firstCall.args[0]).to.be.an("error");
|
||||||
|
expect(next.firstCall.args[0].message).to.equal("obliterateQueue error");
|
||||||
|
});
|
||||||
|
it("should return a success message if obliterateQueue is successful", async () => {
|
||||||
|
req.jobQueue.obliterate.resolves();
|
||||||
|
await obliterateQueue(req, res, next);
|
||||||
|
expect(res.status.firstCall.args[0]).to.equal(200);
|
||||||
|
expect(res.json.firstCall.args[0]).to.deep.equal({
|
||||||
|
success: true,
|
||||||
|
msg: successMessages.QUEUE_OBLITERATE,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user